コード例 #1
0
ファイル: converter.php プロジェクト: qwexak/parking-paradox
function ConvertDB($fname)
{
    //	echo "=> {$fname}\n";
    if (!file_exists($fname)) {
        exit(10);
    }
    $db = new SQLite3('base.sqlite');
    $db->exec("pragma synchronous = off;");
    $tablename = pathinfo($fname, PATHINFO_FILENAME);
    $pdx = new Paradox();
    $pdx->Open($fname);
    $db->exec(createdb_schema($tablename, $pdx->GetSchema()));
    $db->exec('DELETE FROM ' . $tablename);
    if ($records = $pdx->GetNumRows()) {
        $schema = $pdx->GetSchema();
        //		print_r($schema);
        for ($rec = 0; $rec < $records; $rec++) {
            $pdx->GetRow($rec);
            //			if ($rec > 2) break;
            $query = 'INSERT INTO `' . $tablename . '` VALUES (';
            $values = '';
            foreach ($pdx->row as $fieldName => $value) {
                switch ($schema[$fieldName]['type']) {
                    case 1:
                        $value = brackets(iconv('windows-1251', 'UTF-8', $value));
                        break;
                    case 2:
                        $value = brackets($pdx->GetStringfromDate($value));
                        break;
                    case 21:
                        $value = brackets($pdx->GetStringfromTimestamp($value));
                        break;
                    case 4:
                        $value = (int) $value;
                        break;
                    case 6:
                        $value = (double) $value;
                        break;
                    case 9:
                        $value = (int) $value;
                        break;
                    case 13:
                        $value = "X" . brackets(bin2hex($value));
                        break;
                    default:
                        $value;
                        break;
                }
                $values .= $value . ', ';
                //				print "{$schema[$fieldName]['type']}\t{$fieldName}\t{$value}\n";
            }
            $values = rtrim($values, ', ');
            $query .= $values . ");\n";
            //			print trim($query).PHP_EOL;
            $db->exec($query);
        }
        return true;
    }
    $pdx->Close();
}
コード例 #2
0
 /**
  * Get some table properties
  *
  * @access public
  * @param string $table table name
  */
 function getTableInfo($table = '')
 {
     if (empty($table)) {
         $table = $this->table;
     }
     $this->connId->getResId('PRAGMA table_info(' . brackets($table) . ');');
     $this->infoTable = $this->connId->getArray();
     return $this->infoTable;
 }
コード例 #3
0
ファイル: Pattern.php プロジェクト: lastguest/yay
 private function compile(array $tokens)
 {
     $cg = (object) ['ts' => TokenStream::fromSlice($tokens), 'parsers' => []];
     traverse(rtoken('/^(T_\\w+)·(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
         $token = $result->token();
         $id = $this->lookupCapture($token);
         $type = $this->lookupTokenType($token);
         $cg->parsers[] = token($type)->as($id);
     }), ($parser = chain(rtoken('/^·\\w+$/')->as('type'), token('('), optional(ls(either(future($parser)->as('parser'), chain(token(T_FUNCTION), parentheses()->as('args'), braces()->as('body'))->as('function'), string()->as('string'), rtoken('/^T_\\w+·\\w+$/')->as('token'), rtoken('/^T_\\w+$/')->as('constant'), rtoken('/^·this$/')->as('this'), label()->as('label'))->as('parser'), token(',')))->as('args'), commit(token(')')), optional(rtoken('/^·\\w+$/')->as('label'), null)))->onCommit(function (Ast $result) use($cg) {
         $cg->parsers[] = $this->compileParser($result->type, $result->args, $result->label);
     }), $this->layer('{', '}', braces(), $cg), $this->layer('[', ']', brackets(), $cg), $this->layer('(', ')', parentheses(), $cg), rtoken('/^···(\\w+)$/')->onCommit(function (Ast $result) use($cg) {
         $id = $this->lookupCapture($result->token());
         $cg->parsers[] = layer()->as($id);
     }), token(T_STRING, '·')->onCommit(function (Ast $result) use($cg) {
         $offset = \count($cg->parsers);
         if (0 !== $this->dominance || 0 === $offset) {
             $this->fail(self::E_BAD_DOMINANCE, $offset, $result->token()->line());
         }
         $this->dominance = $offset;
     }), rtoken('/·/')->onCommit(function (Ast $result) {
         $token = $result->token();
         $this->fail(self::E_BAD_CAPTURE, $token, $token->line());
     }), any()->onCommit(function (Ast $result) use($cg) {
         $cg->parsers[] = token($result->token());
     }))->parse($cg->ts);
     // check if macro dominance '·' is last token
     if ($this->dominance === \count($cg->parsers)) {
         $this->fail(self::E_BAD_DOMINANCE, $this->dominance, $cg->ts->last()->line());
     }
     $this->specificity = \count($cg->parsers);
     if ($this->specificity > 1) {
         if (0 === $this->dominance) {
             $pattern = chain(...$cg->parsers);
         } else {
             /*
               dominat macros are partially wrapped in commit()s and dominance
               is the offset used as the 'event horizon' point... once the entry
               point is matched, there is no way back and a parser error arises
             */
             $prefix = array_slice($cg->parsers, 0, $this->dominance);
             $suffix = array_slice($cg->parsers, $this->dominance);
             $pattern = chain(...array_merge($prefix, array_map(commit::class, $suffix)));
         }
     } else {
         /*
           micro optimization to save one function call for every token on the subject
           token stream whenever the macro pattern consists of a single parser
         */
         $pattern = $cg->parsers[0];
     }
     return $pattern;
 }
コード例 #4
0
 /**
  * Class constructor
  *
  * @access public
  * @param string $conn reference to the connection object
  */
 function SQLiteDbOperation(&$connId)
 {
     $this->connId = $connId;
     $error = false;
     $tabInfoDb = $this->getTabDb();
     foreach ($tabInfoDb as $trash => $locDb) {
         $locTabInfoDb[$locDb["id"]] = $locDb["name"];
     }
     if (!isset($GLOBALS['operation_action'])) {
         $GLOBALS['operation_action'] = '';
     }
     switch ($GLOBALS['operation_action']) {
         case '':
             $this->operationView();
             break;
         case 'renameTable':
             $error = $GLOBALS['workDb']->copyTable($_REQUEST["table"], brackets($_REQUEST["newName"]), false);
             echo '<script type="text/javascript">parent.left.location=\'left.php?dbsel=' . $GLOBALS["dbsel"] . '\'; parent.main.location=\'main.php?dbsel=' . $GLOBALS["dbsel"] . '&table=' . $_REQUEST["newName"] . '&action=' . $GLOBALS["action"] . '\'</script>';
             $this->operationView();
             break;
         case 'moveTable':
             if ($_REQUEST["dbDest"] == $GLOBALS["tabInfoDb"]["id"]) {
                 $destTableInfo = brackets($_REQUEST["moveName"]);
             } else {
                 $destTableInfo = brackets($locTabInfoDb[$_REQUEST["dbDest"]]) . "." . brackets($_REQUEST["moveName"]);
             }
             $error = $GLOBALS['workDb']->copyTable($_REQUEST["table"], $destTableInfo, false);
             $this->operationView();
             break;
         case 'copyTable':
             if ($_REQUEST["dbDest"] == $GLOBALS["tabInfoDb"]["id"]) {
                 $destTableInfo = brackets($_REQUEST["copyName"]);
             } else {
                 $destTableInfo = brackets($locTabInfoDb[$_REQUEST["dbDest"]]) . "." . brackets($_REQUEST["copyName"]);
             }
             $error = $GLOBALS['workDb']->copyTable($_REQUEST["table"], $destTableInfo, true);
             $this->operationView();
             break;
     }
     if (!empty($GLOBALS['operation_action']) && !$error) {
         $GLOBALS["redirect"] = "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $GLOBALS["dbsel"] . "'; parent.main.location='main.php?dbsel=" . $GLOBALS["dbsel"] . "';</script>";
     }
 }
コード例 #5
0
 /**
  * Convert MySQL query to SQLite query
  *
  * @access public
  */
 function tabletoSQLite($query)
 {
     $query = eregi_replace('auto_increment=(.*)[[:space:]];', ';', $query);
     $query = eregi_replace('[[:space:]]UNSIGNED[[:space:]]', ' ', $query);
     $query = eregi_replace('TYPE=(.*)[[:space:]];', ';', $query);
     $query = str_replace("\n", ' ', $query);
     $startPar = strpos($query, '(');
     $endPar = strrpos($query, ')');
     preg_match('/TABLE[[:space:]](.*)[[:space:]]\\(/i', substr($query, 0, $startPar + 1), $result);
     $tableName = ereg_replace('\\[|\\]', '', $result[1]);
     $tableElement = explode(',', substr($query, $startPar + 1, $endPar - $startPar - 1));
     $numElement = 0;
     $primaryExist = false;
     while (list($key, $value) = each($tableElement)) {
         $value = preg_replace("/(\\(\\s+)/is", "(", $value);
         $value = preg_replace("/(\\s+\\))/is", ")", $value);
         $numElement++;
         if (eregi('not[[:space:]]null', $value)) {
             $matches = 'not[[:space:]]null';
             $defineElement[$numElement]['null'] = false;
         }
         if ($matches) {
             $value = eregi_replace($matches, '', $value);
         }
         if (!eregi('[[:space:]]key[[:space:]]', $value)) {
             $value = $this->bracketsReplaceSpaces($value, '@¤&');
             $tabValue = explode(' ', trim($value));
             $tabValue[0] = str_replace('@¤&', ' ', $tabValue[0]);
             $defineElement[$numElement]['name'] = trim($tabValue[0]);
             if (eregi('auto_increment', trim($value))) {
                 $defineElement[$numElement]['type'] = 'INTEGER';
                 $defineElement[$numElement]['sup'] = 'PRIMARY KEY';
                 $primaryExist = true;
                 continue;
             }
             $defineElement[$numElement]['type'] = str_replace(' int(', ' INTEGER(', $tabValue[1]);
             for ($i = 2; $i < count($tabValue); $i++) {
                 if (eregi('zerofill[ ]?', $tabValue[$i])) {
                     $tabValue[$i] = eregi_replace('zerofill[ ]?', '', $tabValue[$i]);
                     //$defineElement[$numElement]['type'] .= ' zerofill';
                 }
                 if (!isset($defineElement[$numElement]['sup'])) {
                     $defineElement[$numElement]['sup'] = '';
                 }
                 $defineElement[$numElement]['sup'] .= $tabValue[$i] . ' ';
             }
             if (eregi('set|enum', $tabValue[1])) {
                 if (!ereg('\\)', $tabValue[1])) {
                     if ($defineElement[$numElement]['sup']) {
                         $tabValue[1] .= $defineElement[$numElement]['sup'];
                         unset($defineElement[$numElement]['sup']);
                     }
                     # FIX wrong enum parsing
                     $nb_items = count($tableElement);
                     for ($i = $key + 1; $i <= $nb_items + 1; $i++) {
                         $tabValue[1] .= ',' . $tableElement[$i];
                         unset($tableElement[$i]);
                         if (ereg('\\)', $tabValue[1])) {
                             break;
                         }
                     }
                 }
                 preg_match('/\\((.*)\\)/i', $tabValue[1], $enumRes);
                 $tabPropEnum = explode(',', $enumRes[1]);
                 $maxlen = 0;
                 foreach ($tabPropEnum as $propEnum) {
                     if (strlen($propEnum) > $maxlen) {
                         $maxlen = strlen($propEnum);
                     }
                 }
                 $defineElement[$numElement]['type'] = 'varchar(' . ($maxlen - 2) . ')';
                 preg_match('/\\)(.*)/', $tabValue[1], $supRes);
                 $defineElement[$numElement]['type'] .= $supRes[1];
                 if ($tabPropEnum[0]) {
                     $tabPropEnum[0] = preg_replace("/^'/is", "", trim($tabPropEnum[0]));
                     $tabPropEnum[0] = preg_replace("/'\$/is", "", trim($tabPropEnum[0]));
                     $defineElement[$numElement]['sup'] = 'DEFAULT ' . $tabPropEnum[0];
                 } else {
                     unset($defineElement[$numElement]['sup']);
                 }
             }
         } else {
             if (!ereg('\\)', $value)) {
                 for ($i = $key + 1; $i <= count($tableElement) + 1; $i++) {
                     $value .= ',' . $tableElement[$i];
                     unset($tableElement[$i]);
                     if (ereg('\\)', $value)) {
                         break;
                     }
                 }
             }
             if (isset($tabIndex)) {
                 $numIndex = count($tabIndex) + 1;
             } else {
                 $numIndex = 1;
             }
             preg_match('/key(.*)\\(/i', $value, $indexSearch);
             $indexName = ereg_replace('\\[|\\]', '', trim($indexSearch[1]));
             if (eregi('PRIMARY', $value) && !$primaryExist) {
                 $listChamp = $this->recupFields($value);
                 if (is_array($listChamp)) {
                     $tabIndex[$numIndex]['type'] = 'UNIQUE';
                     $tabIndex[$numIndex]['champ'] = $listChamp;
                     $tabIndex[$numIndex]['name'] = $indexName;
                 } else {
                     $listElem = $defineElement;
                     while (list($key, $value) = each($listElem)) {
                         if ($value['name'] == $listChamp) {
                             $defineElement[$key]['sup'] .= ' PRIMARY KEY';
                         }
                     }
                 }
             } elseif (!eregi('PRIMARY', $value)) {
                 if (eregi('UNIQUE', $value)) {
                     $tabIndex[$numIndex]['type'] = 'UNIQUE';
                 }
                 $listChamp = $this->recupFields($value);
                 $tabIndex[$numIndex]['champ'] = $listChamp;
                 $tabIndex[$numIndex]['name'] = $indexName;
             }
         }
     }
     $finaleQuery = 'CREATE TABLE ' . brackets($tableName) . ' (' . "\n";
     foreach ($defineElement as $elem) {
         $column[] = brackets($elem['name']) . ' ' . $elem['type'] . (isset($elem['null']) && !$elem['null'] ? ' NOT NULL ' : ' ') . $elem['sup'];
     }
     $finaleQuery .= "\t" . implode(",\n\t", $column) . "\n);";
     $tabQ[] = $finaleQuery;
     if (isset($tabIndex) && is_array($tabIndex)) {
         foreach ($tabIndex as $ind) {
             $query = 'CREATE';
             if ($ind['type']) {
                 $query .= ' ' . $ind['type'];
             }
             if (is_array($ind['champ'])) {
                 foreach ($ind['champ'] as $key => $champ) {
                     $ind['champ'][$key] = brackets($champ);
                 }
                 $columns = implode(',', $ind['champ']);
             } else {
                 $columns = brackets($ind['champ']);
             }
             $query .= ' INDEX ' . str_replace(' ', '_', $tableName . '_' . $ind['name']) . ' ON ' . brackets($tableName) . ' (' . $columns . ');';
             $tabQ[] = $query;
         }
     }
     return $tabQ;
 }
コード例 #6
0
ファイル: tableproperties.php プロジェクト: racontemoi/mamp
     break;
 case 'saveFromFile':
     $tableProp->saveFromFile();
     break;
 case 'modifyElement':
     $tableProp->formElement(urldecode(stripslashes($_GET['query'])), $_GET['pos']);
     break;
 case 'saveElement':
 case 'deleteElement':
     $tableProp->saveElement();
     if (isset($GLOBALS['reBrowse']) && $GLOBALS['reBrowse']) {
         include_once INCLUDE_LIB . 'browse.php';
     }
     break;
 case 'empty':
     $query = 'DELETE FROM ' . brackets($table) . ';';
     if ($dbsel) {
         $workDb->getResId($query);
     }
     displayQuery($query, false);
     $redirect = "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=" . $dbsel . "'; parent.main.location='main.php?dbsel={$dbsel}&table={$table}';</script>";
     break;
 case 'export':
     include_once INCLUDE_LIB . 'SQLiteExport.class.php';
     $export =& new SQLiteExport($workDb);
     break;
 case 'select':
     include_once INCLUDE_LIB . 'SQLiteSelect.class.php';
     $select =& new SQLiteSelect($workDb, $table);
     break;
 case 'selectElement':
コード例 #7
0
ファイル: task1.php プロジェクト: OksanaL/logic-tasks
<?php

//$str = '{(a+b)*[a+2c]+[(3*b-4)*(a+2c)]}';
$str = '{((a(bc))([]({})';
echo $str . '<br><br>';
echo brackets($str);
function brackets($str)
{
    $br = array('(' => ')', '[' => ']', '{' => '}');
    $l = strlen($str);
    $stack = array();
    for ($i = 0; $i < $l; $i++) {
        foreach ($br as $op => $cl) {
            if ($str[$i] == $op) {
                array_push($stack, $op);
            } else {
                if ($str[$i] == $cl) {
                    $s = array_pop($stack);
                    if ($br[$s] !== $cl) {
                        return 'false' . ', i = ' . $i;
                    }
                }
            }
        }
    }
    if (empty($stack)) {
        return 'true';
    } else {
        return 'false' . ', i = ' . $i;
    }
}
コード例 #8
0
ファイル: table_import.php プロジェクト: jaketay/raspberry_pi
function Do_ImportTableData($link)
{
    if (count($_POST) && isset($_POST['mysql_confirm'])) {
        $mysqlQ = 'SELECT ';
        $sqlitQ = 'INSERT INTO ' . brackets($GLOBALS['table']) . '(';
        echo '<table class="Browse"><thead><tr><td class="Browse">Transfert... </td></tr></thead><tr><td style="padding:10px">';
        foreach ($_SESSION['plugin_mysql_tables'] as $key => $value) {
            if (substr($key, 0, 4) == 'col_') {
                $mysqlQ .= $value . ', ';
                $sqlitQ .= brackets(substr($key, 4)) . ', ';
            }
        }
        $mysqlQ = substr($mysqlQ, 0, strlen($mysqlQ) - 2);
        $sqlitQ = substr($sqlitQ, 0, strlen($sqlitQ) - 2);
        $mysqlQ .= ' FROM `' . $_SESSION['plugin_mysql_tables']['mysql_tables'][0] . '`;';
        $sqlitQ .= ') VALUES ( %%VALUES%% );';
        echo '<b>MYSQL : ' . htmlentities($mysqlQ) . '<br/>';
        echo 'SQLITE : ' . htmlentities($sqlitQ) . '</b><br/><br/>';
        $cnt = 0;
        $err = 0;
        if (!($res = mysql_query($mysqlQ, $link))) {
            die(mysql_error());
        } else {
            sqlitem_query($GLOBALS['workDb']->connId, 'BEGIN;');
            while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
                foreach ($row as $key => $val) {
                    $row[$key] = "'" . $val . "'";
                }
                $query = str_replace('%%VALUES%%', implode(',', $row), $sqlitQ);
                if ($resInsert = sqlitem_query($GLOBALS['workDb']->connId, $query)) {
                    $cnt++;
                    echo implode(',', $row) . "<br/>";
                } else {
                    sqlitem_query($GLOBALS['workDb']->connId, 'ROLLBACK;');
                    echo "<b>REQUETE EN ERREUR : <br/>" . $query . "</b><br/>";
                    $err = true;
                    break;
                }
            }
            mysql_free_result($res);
            echo '</td></tr>';
            echo '</table>';
            if (!$err) {
                sqlitem_query($GLOBALS['workDb']->connId, 'COMMIT;');
                echo "<b>{$cnt} lignes importées !</b>";
            } else {
                return false;
            }
        }
        return false;
        //$res;
    }
    echo '<form method="POST"><input type="hidden" name="mysql_confirm" value="doIt">';
    echo '<table class="Browse"><thead><tr><td class="Browse">Résumé: </td></tr></thead><tr><td style="padding:10px">';
    echo 'A transférer depuis la base <b>' . $_SESSION['plugin_mysql_base'] . '</b> du serveur MySQL <b>' . $_SESSION['plugin_mysql_server'] . '</b> :</br><ul>';
    foreach ($_POST as $key => $value) {
        if (substr($key, 0, 4) == 'col_') {
            echo '<li>' . htmlentities('`' . $value . '` => ' . substr($key, 4)) . '</li>';
        }
    }
    echo '</ul>';
    echo '</td></tr>';
    echo '<tr><td style="padding-bottom:10px" align="center"><input type="submit" class="button" value="Importer"></td></tr>';
    echo '</table>';
    echo '</form>';
}
コード例 #9
0
					<td align="center" colspan="' . $colspan . '" class="tabproptitle">' . $traduct->get(33) . '</td>' . "\n";
        if ($item == 'Table' || $item == 'View') {
            echo '		<td align="center" class="tabproptitle" style="white-space: nowrap">' . $traduct->get(118) . '</td>' . "\n";
        }
        echo '	</tr></thead>';
        $totItem = $totEnr = 0;
        foreach ($workDb->getPropList($item) as $itemName) {
            if ($totItem % 2) {
                $localBgColor = $GLOBALS['browseColor1'];
            } else {
                $localBgColor = $GLOBALS['browseColor2'];
            }
            $totItem++;
            $linkBase = 'main.php?dbsel=' . $GLOBALS['dbsel'] . '&amp;' . strtolower($item) . '=' . $itemName;
            if ($item == 'Table' || $item == 'View') {
                if ($workDb->getResId('SELECT count(*) FROM ' . brackets($itemName))) {
                    $nbEnr = $workDb->connId->fetch_single();
                } else {
                    $nbEnr = '&nbsp;';
                }
                $totEnr += $nbEnr;
            }
            echo "\t<tr bgcolor='" . $localBgColor . "' onMouseOver=\"setRowColor(this, {$totItem}, 'over', '" . $localBgColor . "', '" . $GLOBALS['browseColorOver'] . "', '" . $GLOBALS["browseColorClick"] . "')\" \n\t\t\t\t\t\t\t\t\tonMouseOut=\"setRowColor(this, {$totItem}, 'out', '" . $localBgColor . "', '" . $GLOBALS["browseColorOver"] . "', '" . $GLOBALS['browseColorClick'] . "')\">\n";
            echo "\t\t<td class=\"tabprop\" align='left'><a href=\"" . $linkBase . "\" class=\"PropItemTitle\"><span style=\"font-size: 12px\">&nbsp;" . $itemName . "</span></a></td>\n";
            if (isset($nbEnr) && $nbEnr && ($item == 'Table' || $item == 'View')) {
                echo "\t\t<td class=\"tabprop\" align='center'><a href=\"" . $linkBase . "&amp;action=browseItem\" class=\"propItem\">" . displayPics("browse2.png", $traduct->get(73)) . "</a></td>\n";
            } elseif ($item == 'Table' || $item == 'View') {
                echo "\t\t<td class=\"tabprop\" align='center'><span style='color: gray'>" . displayPics("browse_off.png", $traduct->get(73)) . "</span></td>\n";
            }
            if ($item == 'Table') {
                if (!$workDb->isReadOnly() && displayCondition("data")) {
コード例 #10
0
 /**
  * Generate SQL query for 'select'
  * @author Maurício M. Maia <*****@*****.**>
  *
  * @param string $table
  */
 function selectElement($view)
 {
     $showField = $_REQUEST['showField'];
     $valField = $_REQUEST['valField'];
     $operats = $_REQUEST['operats'];
     $error = false;
     $selectQuery = 'SELECT ';
     $condQuery = '';
     if (is_array($_REQUEST['showField']) && !empty($_REQUEST['showField'])) {
         $selectQuery .= implode(", ", array_keys($_REQUEST['showField']));
     } else {
         $selectQuery .= '*';
     }
     $selectQuery .= ' FROM ' . brackets($view) . ' ';
     if (is_array($_REQUEST['valField']) && !empty($_REQUEST['valField'])) {
         foreach ($valField as $key => $value) {
             if (isset($value) && !empty($value) || isset($operats[$key]) && !empty($operats[$key])) {
                 if ($operats[$key] == 'ISNULL' || $operats[$key] == 'NOTNULL') {
                     $condQuery .= $key . ' ' . $operats[$key];
                 } else {
                     $condQuery .= $key . ' ' . $operats[$key] . ' ' . quotes($value);
                 }
             }
         }
     }
     if (!empty($_REQUEST['CondSuppl'])) {
         if ($condQuery) {
             $condQuery .= ' ' . $_REQUEST['operSuppl'] . ' ';
         }
         $condQuery .= $_REQUEST['CondSuppl'];
     }
     return $selectQuery . ($condQuery ? 'WHERE ' . $condQuery : '');
 }
コード例 #11
0
 /**
  *
  */
 function copyTable($source, $destination, $copy = true)
 {
     if (strpos($source, ".")) {
         list($srcDb, $srcTable) = explode('.', $source);
     } else {
         $srcDb = "";
         $srcTable = $source;
     }
     if (strpos($destination, ".")) {
         list($dstDb, $dstable) = explode('.', $destination);
     } else {
         $dstDb = "";
         $dstable = $destination;
     }
     $res = $GLOBALS['workDb']->getResId('PRAGMA table_info(' . brackets($srcTable) . ');');
     $infoTable = $GLOBALS['workDb']->getArray();
     foreach ($infoTable as $iT) {
         $listField[$iT["cid"]] = $iT["name"];
     }
     // backup table schema
     $backupSchema = $GLOBALS['workDb']->connId->array_query("SELECT sql FROM sqlite_master WHERE tbl_name LIKE '" . $srcTable . "' ORDER BY ROWID", SQLITE_ASSOC);
     if ($dstDb) {
         // create an instance on this
         $GLOBALS["db"]->query("SELECT location FROM database WHERE name='" . $dstDb . "'");
         $dbLocation = $GLOBALS["db"]->fetch_single();
         if (dirname($dbLocation) == '.') {
             $dbLocation = DEFAULT_DB_PATH . $dbLocation;
         }
         $tempDb =& new SQLiteDbConnect($dbLocation);
         $query[] = "ATTACH DATABASE \"" . $dbLocation . "\" AS \"" . $dstDb . "\";\n";
     }
     $query[] = "BEGIN TRANSACTION;\n";
     $query[] = "CREATE TABLE SQLIteManager_backup AS SELECT * FROM " . brackets($srcTable) . ";\n";
     if (isset($_REQUEST["dropTable"]) && $_REQUEST["dropTable"] == "true") {
         $res = $GLOBALS["workDb"]->connId->query("SELECT count(*) FROM sqlite_master WHERE name='" . brackets($dstable) . "'");
         if ($exist = $GLOBALS["workDb"]->connId->fetch_single()) {
             $query[] = "DROP TABLE " . brackets($dstable) . ";\n";
         }
     }
     if (!$copy) {
         $query[] = "DROP TABLE " . brackets($srcTable) . ";\n";
     }
     if (!$copy || $copy && ($_REQUEST["whatToDo"] == "structure" || $_REQUEST["whatToDo"] == "data")) {
         foreach ($backupSchema as $schema) {
             $tempQuery = $schema["sql"];
             if (isset($tempQuery) && eregi("CREATE[[:space:]]TABLE", $tempQuery)) {
                 $tempQuery = ereg_replace("CREATE[[:space:]]TABLE[[:space:]]" . $srcTable, "CREATE TABLE " . brackets($dstable), $tempQuery);
                 if ($dstDb) {
                     if (isset($_REQUEST["dropTable"]) && $_REQUEST["dropTable"] == "true") {
                         // check if table exist and drop it
                         $res = $tempDb->connId->query("SELECT count(*) FROM sqlite_master WHERE name='" . brackets($dstable) . "'");
                         $exist = $tempDb->connId->fetch_single();
                         if ($exist) {
                             $query[] = "DROP TABLE " . brackets($dstable);
                         }
                     }
                     $tempDb->connId->query($tempQuery);
                     print_r($tempDb->connId);
                     unset($tempQuery);
                 }
             }
             if (isset($tempQuery) && eregi("[[:space:]]INTO[[:space:]]", $tempQuery)) {
                 $tempQuery = eregi_replace("^[[:space:]]INTO[[:space:]]" . $srcTable, " INTO " . $destination, $tempQuery);
             }
             if (isset($tempQuery) && eregi("CREATE[[:space:]]TRIGGER[[:space:]]", $tempQuery)) {
                 unset($tempQuery);
             }
             if (isset($tempQuery) && $tempQuery) {
                 $query[] = $tempQuery;
             }
         }
     }
     if (!$copy || $copy && ($_REQUEST["whatToDo"] == "data" || $_REQUEST["whatToDo"] == "dataonly")) {
         $query[] = "INSERT INTO " . brackets($destination) . " (" . implode(", ", $listField) . ") SELECT " . implode(", ", $listField) . " FROM SQLIteManager_backup;\n";
     }
     $query[] = "DROP TABLE SQLIteManager_backup;\n";
     $query[] = "COMMIT TRANSACTION;\n";
     $noerror = false;
     foreach ($query as $req) {
         if (!$noerror) {
             if (!$this->connId->query($req) && !$this->connId->getError()) {
                 $noerror = true;
             }
         }
     }
     return $noerror;
 }
コード例 #12
0
ファイル: browse.php プロジェクト: jaketay/raspberry_pi
* Show result query with paginate, sort, modify/delete links
* @package SQLiteManager
* @author Frédéric HENNINOT
* @version $Id: browse.php,v 1.45 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.45 $
*/
include_once INCLUDE_LIB . 'ParsingQuery.class.php';
include_once INCLUDE_LIB . 'sql.class.php';
if (!isset($withForm)) {
    $withForm = true;
}
if (!isset($DisplayQuery) || empty($DisplayQuery)) {
    if ($action == 'sql') {
        $displayResult = false;
    }
    if (!empty($table) || !empty($view)) {
        $DisplayQuery = 'SELECT * FROM ' . quotes(brackets($table, false) . brackets($view, false));
    } else {
        $DisplayQuery = '';
    }
} else {
    if (!isset($_FILES)) {
        $DisplayQuery = urldecode($GLOBALS['DisplayQuery']);
    } elseif (!empty($_POST['DisplayQuery']) || !empty($_GET['DisplayQuery'])) {
        $DisplayQuery = SQLiteStripSlashes($DisplayQuery);
    }
}
if (!isset($displayResult)) {
    $displayResult = true;
}
if (!isset($sql_action)) {
    $sql_action = '';
コード例 #13
0
 /**
  * Return the index list
  */
 function getIndexList()
 {
     if (is_array($this->tableInfo)) {
         foreach ($this->tableInfo as $propTable) {
             if (isset($propTable['primary'])) {
                 $temp['name'] = $temp['type'] = 'PRIMARY';
                 $temp['champ'][] = $propTable['name'];
                 $this->indexInfo['primary'] = $temp;
             }
         }
     }
     $tabIndexList = $GLOBALS['workDb']->connId->array_query('PRAGMA index_list(' . brackets($this->table) . ');', SQLITE_ASSOC);
     if (is_array($tabIndexList)) {
         foreach ($tabIndexList as $indexInfo) {
             if (preg_match('#autoindex#i', $indexInfo['name'])) {
                 continue;
             }
             if (!empty($indexInfo)) {
                 $tabInfoIndex = $GLOBALS['workDb']->connId->array_query('PRAGMA index_info(' . brackets($indexInfo['name']) . ');', SQLITE_ASSOC);
                 if (is_array($tabInfoIndex)) {
                     $indexNum = $indexInfo['seq'];
                     foreach ($tabInfoIndex as $indexChamp) {
                         $this->indexInfo[$indexNum]['champ'][] = $indexChamp['name'];
                     }
                     $this->indexInfo[$indexNum]['name'] = $indexInfo['name'];
                     $this->indexInfo[$indexNum]['type'] = $indexInfo['unique'] ? 'UNIQUE' : 'KEY';
                 }
             }
         }
     }
     return $this->indexInfo;
 }
コード例 #14
0
 /**
  * Return an array with the data to send
  *
  * @access private
  * @return array
  */
 function _getRecord()
 {
     if (isset($GLOBALS['TableListImpact'])) {
         $tableList = explode(',', $GLOBALS['TableListImpact']);
         if (count($tableList) > 1) {
             $withTableName = true;
         } else {
             $withTableName = false;
         }
         foreach ($tableList as $tableImpact) {
             if (!empty($tableImpact) && !preg_match('#\\.#', $tableImpact)) {
                 $tempInfoTable = $this->SQLiteConnId->array_query('PRAGMA table_info(' . brackets(trim($tableImpact)) . ');');
                 if (is_array($tempInfoTable)) {
                     foreach ($tempInfoTable as $infoTable) {
                         if ($withTableName) {
                             $this->NullInfo[trim($tableImpact) . '.' . $infoTable['name']] = $infoTable['notnull'];
                         } else {
                             $this->NullInfo[$infoTable['name']] = $infoTable['notnull'];
                         }
                     }
                 }
             }
         }
     }
     if (strpos(trim($this->order), ' ')) {
         $order = '"' . $this->order . '"';
     } else {
         $order = $this->order;
     }
     $query = $this->query . ($this->order ? ' ORDER BY ' . $order . ' ' . $this->orderSens : '');
     if (!preg_match('#pragma#i', $this->query) && !preg_match('#limit#i', $this->query)) {
         $query .= ' LIMIT ' . $this->indexStart . ', ' . $this->recordPerPage;
     }
     if ($this->SQLiteConnId->query($query)) {
         unset($tabRecord);
         $tabRecord = array();
         while ($ligne = $this->SQLiteConnId->fetch_array(null, SQLITE_NUM)) {
             $tabRecord[] = $ligne;
         }
     }
     $this->realQuery = $query;
     return $tabRecord;
 }
コード例 #15
0
ファイル: Macro.php プロジェクト: assertchris/yay
 private function compilePattern(int $line, array $tokens) : Parser
 {
     if (!$tokens) {
         $this->fail(self::E_EMPTY_PATTERN, $line);
     }
     $ts = TokenStream::fromSlice($tokens);
     traverse(either(consume(chain(token(T_NS_SEPARATOR), token(T_NS_SEPARATOR), parentheses()->as('cloaked')))->onCommit(function (Ast $result) use($ts) {
         $ts->inject(TokenStream::fromSequence(...$result->cloaked));
         $ts->skip(...TokenStream::SKIPPABLE);
     }), rtoken('/^(T_\\w+)·(\\w+)$/')->onCommit(function (Ast $result) {
         $token = $result->token();
         $id = $this->lookupCapture($token);
         $type = $this->lookupTokenType($token);
         $this->parsers[] = token($type)->as($id);
     }), ($parser = chain(rtoken('/^·\\w+$/')->as('parser_type'), token('('), optional(ls(either(future($parser)->as('parser'), string()->as('string'), rtoken('/^T_\\w+·\\w+$/')->as('token'), rtoken('/^T_\\w+$/')->as('constant'), word()->as('word')), token(',')))->as('args'), commit(token(')')), optional(rtoken('/^·\\w+$/')->as('label'))))->onCommit(function (Ast $result) {
         $this->parsers[] = $this->compileParser($result->array());
     }), $this->layer('{', '}', braces()), $this->layer('[', ']', brackets()), $this->layer('(', ')', parentheses()), rtoken('/^···(\\w+)$/')->onCommit(function (Ast $result) {
         $id = $this->lookupCapture($result->token());
         $this->parsers[] = layer()->as($id);
     }), token(T_STRING, '·')->onCommit(function (Ast $result) use($ts) {
         $offset = \count($this->parsers);
         if (0 !== $this->dominance || 0 === $offset) {
             $this->fail(self::E_BAD_DOMINANCE, $offset, $result->token()->line());
         }
         $this->dominance = $offset;
     }), rtoken('/·/')->onCommit(function (Ast $result) {
         $token = $result->token();
         $this->fail(self::E_BAD_CAPTURE, $token, $token->line());
     }), any()->onCommit(function (Ast $result) {
         $this->parsers[] = token($result->token());
     })))->parse($ts);
     // check if macro dominance '·' is last token
     if ($this->dominance === \count($this->parsers)) {
         $this->fail(self::E_BAD_DOMINANCE, $this->dominance, $ts->last()->line());
     }
     $this->specificity = \count($this->parsers);
     if ($this->specificity > 1) {
         if (0 === $this->dominance) {
             $pattern = chain(...$this->parsers);
         } else {
             /*
               dominat macros are partially wrapped in commit()s and dominance
               is the offset used as the 'event horizon' point... once the entry
               point is matched, there is no way back and a parser error arises
             */
             $prefix = array_slice($this->parsers, 0, $this->dominance);
             $suffix = array_slice($this->parsers, $this->dominance);
             $pattern = chain(...array_merge($prefix, array_map(commit::class, $suffix)));
         }
     } else {
         /*
           micro optimization to save one function call for every token on the subject
           token stream whenever the macro pattern consists of a single parser
         */
         $pattern = $this->parsers[0];
     }
     return $pattern;
 }
コード例 #16
0
ファイル: sql.class.php プロジェクト: jaketay/raspberry_pi
 /**
  * Get column of table select for SQL
  *
  * @access private
  */
 function GetColumnSelect()
 {
     $query = 'PRAGMA table_info(' . brackets($GLOBALS['table']) . ');';
     $tableInfoTable = array();
     $out = '';
     if ($this->connId->getResId($query)) {
         $tableInfoTable = $this->connId->getArray();
     }
     if (!empty($tableInfoTable)) {
         $optionList = array();
         foreach ($tableInfoTable as $columnInfo) {
             $optionList[] = '<option value="' . brackets($GLOBALS['table']) . '.' . brackets($columnInfo['name']) . '">' . brackets($GLOBALS['table']) . '.' . brackets($columnInfo['name']) . '</option>';
         }
         $out = '<div><select name="columnTable" size="' . TEXAREA_NB_ROWS . '" multiple="multiple">' . "\n" . implode("\n", $optionList) . '</select></div>' . "\n";
         $out .= '<div><input name="insertButton" class="button" type="button" value="' . $GLOBALS['traduct']->get(75) . '" onClick="insertColumn();"></div>';
     }
     return $out;
 }
コード例 #17
0
    /**
     * Display the current TRIGGER properties
     *
     * @access public
     */
    function propView()
    {
        $tabTrigInfo = $this->extractProperties($this->triggerProperties);
        $triggView = 'CREATE TRIGGER ' . brackets($this->trigger) . ' ' . $tabTrigInfo['TriggerMoment'];
        if ($tabTrigInfo['TriggerMoment'] != '') {
            $triggView .= ' ';
        }
        $triggView .= $tabTrigInfo['TriggerEvent'] . $tabTrigInfo['ColumnList'] . ' ';
        $triggView .= 'ON ' . brackets($tabTrigInfo['TriggerOn']) . ' ' . $tabTrigInfo['TriggerAction'];
        if ($tabTrigInfo['TriggerAction'] != '') {
            $triggView .= ' ';
        }
        if ($tabTrigInfo['TriggerCondition'] == 'WHEN ') {
            $triggView .= 'WHEN ' . $tabTrigInfo['ConditionList'] . ' ';
        }
        $triggView .= "\n" . 'BEGIN ' . "\n" . $tabTrigInfo["TriggerStep"] . "\n" . ' END;' . "\n";
        echo '<br>';
        echo '	<table cellpadding="2" cellspacing="0" width="90%" class="viewProp">
					<tr class="viewPropTitle"><td align="right" width="20%" class="viewPropTitle">' . $GLOBALS['traduct']->get(19) . " :&nbsp;</td><td align='center' class='viewPropTitle'>" . $this->trigger . "</td></tr>\n\t\t\t\t\t<tr><td align='right' class='viewProp'>" . $GLOBALS['traduct']->get(53) . " :&nbsp;</td><td class='viewProp'>" . nl2br($triggView) . "</td></tr>";
        echo '		</table>';
        echo '<div align="center">';
        if (!$GLOBALS['workDb']->isReadOnly() && displayCondition('properties')) {
            echo "<a href=\"main.php?dbsel=" . $GLOBALS["dbsel"] . "&amp;trigger=" . $this->trigger . "&amp;action=modify\" class='base' target=\"main\">" . $GLOBALS['traduct']->get(14) . '</a>';
        } else {
            echo '<span class="base"><i>' . $GLOBALS['traduct']->get(14) . '</i></span>';
        }
        echo str_repeat('&nbsp;', 10);
        if (!$GLOBALS['workDb']->isReadOnly() && displayCondition('del')) {
            echo '<a href="main.php?dbsel=' . $GLOBALS['dbsel'] . '&amp;trigger=' . $this->trigger . '&amp;action=delete" class="base" target="main">' . $GLOBALS['traduct']->get(15) . '</a>';
        } else {
            echo '<span class="base"><i>' . $GLOBALS['traduct']->get(15) . '</i></span>';
        }
        echo '</div>';
    }
コード例 #18
0
ファイル: browse.php プロジェクト: racontemoi/mamp
* Show result query with paginate, sort, modify/delete links
* @package SQLiteManager
* @author Frédéric HENNINOT
* @version $Id: browse.php,v 1.45 2006/04/14 15:16:52 freddy78 Exp $ $Revision: 1.45 $
*/
include_once INCLUDE_LIB . 'ParsingQuery.class.php';
include_once INCLUDE_LIB . 'sql.class.php';
if (!isset($withForm)) {
    $withForm = true;
}
if (!isset($DisplayQuery) || empty($DisplayQuery)) {
    if ($action == 'sql') {
        $displayResult = false;
    }
    if (!empty($table) || !empty($view)) {
        $DisplayQuery = 'SELECT * FROM ' . brackets($table) . brackets($view);
    } else {
        $DisplayQuery = '';
    }
} else {
    if (!isset($_FILES)) {
        $DisplayQuery = urldecode($GLOBALS['DisplayQuery']);
    } elseif (!empty($_POST['DisplayQuery']) || !empty($_GET['DisplayQuery'])) {
        $DisplayQuery = stripslashes($DisplayQuery);
    }
}
if (!isset($displayResult)) {
    $displayResult = true;
}
if (!isset($sql_action)) {
    $sql_action = '';
コード例 #19
0
 /**
  * return View properties
  *
  * @access public
  * @param string $table table name
  */
 function viewProperties($view)
 {
     $out = '#%BREAK%###%BREAK%#';
     $out .= '# ' . $GLOBALS['traduct']->getdirect(134) . ': ' . $view . '#%BREAK%#';
     $out .= '##%BREAK%#';
     $query = "SELECT sql FROM sqlite_master WHERE type='view' AND tbl_name=" . quotes($view) . " ORDER BY rootpage";
     $this->connId->getResId($query);
     if (isset($_POST['drop']) && $_POST['drop']) {
         $out .= 'DROP VIEW ' . brackets($table) . ';#%BREAK%#';
     }
     foreach ($this->connId->getArray() as $sqlProp) {
         $out .= $sqlProp['sql'] . ';#%BREAK%#';
     }
     $this->exportContent .= $out;
     return;
 }