Exemple #1
0
/**
 * This file is a part of MyWebSQL package
 *
 * @file:      modules/query.php
 * @author     Samnan ur Rehman
 * @copyright  (c) 2008-2012 Samnan ur Rehman
 * @web        http://mywebsql.net
 * @license    http://mywebsql.net/license
 */
function processRequest(&$db)
{
    // first time query will be from request, then we will get it from session (applying limit scenario)
    $table_select = v($_REQUEST["id"]) == 'table' ? true : false;
    if ($table_select) {
        $query = selectFromTable($db);
    } else {
        $query = simpleQuery($db);
    }
    if (!$query) {
        createErrorGrid($db, $query);
        return;
    }
    loadDbVars($db);
    if ($db->query($query)) {
        if (!$db->hasResult()) {
            $info = getCommandInfo($query);
            if ($info['dbAltered']) {
                Session::set('db', 'altered', true);
            } else {
                if ($info['setvar'] == TRUE) {
                    setDbVar($info['variable'], $info['value']);
                }
            }
            createInfoGrid($db);
        } else {
            createResultGrid($db);
        }
    } else {
        createErrorGrid($db, $query);
    }
}
Exemple #2
0
/**
 * This file is a part of MyWebSQL package
 *
 * @file:      modules/truncate.php
 * @author     Samnan ur Rehman
 * @copyright  (c) 2008-2012 Samnan ur Rehman
 * @web        http://mywebsql.net
 * @license    http://mywebsql.net/license
 */
function processRequest(&$db)
{
    $type = v($_REQUEST["id"]);
    $name = v($_REQUEST["name"]);
    if (!$name) {
        createErrorGrid($db, '');
        return;
    }
    if ($db->truncateTable($name)) {
        createInfoGrid($db, $db->getLastQuery());
    } else {
        createErrorGrid($db, $db->getLastQuery());
    }
}
Exemple #3
0
/**
 * This file is a part of MyWebSQL package
 *
 * @file:      modules/drop.php
 * @author     Samnan ur Rehman
 * @copyright  (c) 2008-2012 Samnan ur Rehman
 * @web        http://mywebsql.net
 * @license    http://mywebsql.net/license
 */
function processRequest(&$db)
{
    $type = v($_REQUEST["id"]);
    $name = v($_REQUEST["name"]);
    if (!$name) {
        createErrorGrid($db, '');
        return;
    }
    $success = $db->dropObject($name, $type);
    if ($success) {
        Session::set('db', 'altered', true);
        createInfoGrid($db, $db->getLastQuery());
    } else {
        createErrorGrid($db, $db->getLastQuery());
    }
}
Exemple #4
0
/**
 * This file is a part of MyWebSQL package
 *
 * @file:      modules/copy.php
 * @author     Samnan ur Rehman
 * @copyright  (c) 2008-2012 Samnan ur Rehman
 * @web        http://mywebsql.net
 * @license    http://mywebsql.net/license
 */
function processRequest(&$db)
{
    $type = v($_REQUEST["id"]);
    $name = v($_REQUEST["name"]);
    $new_name = v($_REQUEST["query"]);
    if (!$name || !$new_name) {
        createErrorGrid($db, '');
        return;
    }
    $success = $db->copyObject($name, $type, $new_name);
    // @@TODO: this can be improved, although it is only information
    $numQueries = $type == 'table' ? 2 : 1;
    if ($success) {
        Session::set('db', 'altered', true);
        createInfoGrid($db, '', $numQueries);
    } else {
        createErrorGrid($db, $db->getLastQuery());
    }
}
Exemple #5
0
/**
 * This file is a part of MyWebSQL package
 *
 * @file:      modules/query.php
 * @author     Samnan ur Rehman
 * @copyright  (c) 2008-2014 Samnan ur Rehman
 * @web        http://mywebsql.net
 * @license    http://mywebsql.net/license
 */
function processRequest(&$db)
{
    // first time query will be from request, then we will get it from session (applying limit scenario)
    $table_select = v($_REQUEST["id"]) == 'table' ? true : false;
    if ($table_select) {
        $query = selectFromTable($db);
    } else {
        $query = simpleQuery($db);
    }
    if (!$query) {
        createErrorGrid($db, $query);
        return;
    }
    loadDbVars($db);
    if ($db->query($query)) {
        if (!$db->hasResult()) {
            $info = getCommandInfo($query);
            if ($info['dbAltered']) {
                Session::set('db', 'altered', true);
            } else {
                if ($info['setvar'] == TRUE && is_scalar($info['variable']) && is_scalar($info['value'])) {
                    setDbVar($info['variable'], $info['value']);
                }
            }
            createInfoGrid($db);
        } else {
            // if it is a data result set, show it as result grid, otherwise in simple grid layout
            $query_type = getQueryType($query);
            if ($query_type['can_limit']) {
                createResultGrid($db);
            } else {
                createSimpleGrid($db, __('Query') . ': ' . $query);
            }
        }
    } else {
        createErrorGrid($db, $query);
    }
}
Exemple #6
0
/**
 * This file is a part of MyWebSQL package
 *
 * @file:      modules/queryall.php
 * @author     Samnan ur Rehman
 * @copyright  (c) 2008-2012 Samnan ur Rehman
 * @web        http://mywebsql.net
 * @license    http://mywebsql.net/license
 */
function processRequest(&$db)
{
    $query = v($_REQUEST["query"]);
    if (!$query) {
        createErrorGrid($db, $query);
        return;
    }
    //Session::set('select', 'query', $query);
    $temp = tmpfile();
    fwrite($temp, $query);
    fseek($temp, 0);
    include BASE_PATH . "/lib/sqlparser.php";
    $parser = new sqlParser($db);
    $parser->collectStats();
    if (!$parser->parseFile($temp)) {
        createErrorGrid($db, $parser->getLastQuery(), $parser->getExecutedQueries(), $parser->getRowsAffected());
    } else {
        $stats = $parser->getStats();
        if ($stats->dbAltered) {
            Session::set('db', 'altered', true);
        }
        createInfoGrid($db, $query, $parser->getExecutedQueries(), $parser->getRowsAffected(), false, $parser->getExecutedTime());
    }
}