]> git.joonet.de Git - adminer.git/commitdiff
Prepare for SQLite
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 16 Oct 2009 12:26:16 +0000 (12:26 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 16 Oct 2009 12:26:16 +0000 (12:26 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1192 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/create.inc.php
adminer/edit.inc.php
adminer/foreign.inc.php
adminer/include/adminer.inc.php
adminer/include/functions.inc.php
adminer/include/mysql.inc.php
adminer/table.inc.php
editor/include/adminer.inc.php

index abd9efc8cd1ad744db87df7e45dca81373adfa53..49ae7f92fcf0929d82c0cb3c289c3330be634784 100644 (file)
@@ -98,14 +98,6 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
 
 page_header((strlen($TABLE) ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE);
 
-$engines = array();
-$result = $connection->query("SHOW ENGINES");
-while ($row = $result->fetch_assoc()) {
-       if (ereg("YES|DEFAULT", $row["Support"])) {
-               $engines[] = $row["Engine"];
-       }
-}
-
 $row = array(
        "Engine" => $_COOKIE["adminer_engine"],
        "fields" => array(array("field" => "")),
@@ -148,6 +140,8 @@ $suhosin = floor(extension_loaded("suhosin") ? (min(ini_get("suhosin.request.max
 if ($suhosin && count($row["fields"]) > $suhosin) {
        echo "<p class='error'>" . h(lang('Maximum number of allowed fields exceeded. Please increase %s and %s.', 'suhosin.post.max_vars', 'suhosin.request.max_vars')) . "\n";
 }
+
+$engines = engines();
 // case of engine may differ
 foreach ($engines as $engine) {
        if (!strcasecmp($engine, $row["Engine"])) {
@@ -160,7 +154,7 @@ foreach ($engines as $engine) {
 <form action="" method="post" id="form">
 <p>
 <?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo h($row["name"]); ?>">
-<?php echo html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]); ?>
+<?php echo ($engines ? html_select("Engine", array("" => "(" . lang('engine') . ")") + $engines, $row["Engine"]) : ""); ?>
 <?php echo html_select("Collation", array("" => "(" . lang('collation') . ")") + $collations, $row["Collation"]); ?>
 <input type="submit" value="<?php echo lang('Save'); ?>">
 </p>
index 6aa40876221bbf8c6c0331bb9a2b68083edad3a3..a231e183e11552a39967fd86adc4465c5bc5d5cf 100644 (file)
@@ -22,8 +22,10 @@ if ($_POST && !$error && !isset($_GET["select"])) {
        $set = array();
        foreach ($fields as $name => $field) {
                $val = process_input($field);
-               if ($val !== false || !$update) {
-                       $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''");
+               if (!$update) {
+                       $set[idf_escape($name)] = ($val !== false ? $val : "''");
+               } elseif ($val !== false) {
+                       $set[] = "\n" . idf_escape($name) . " = $val";
                }
        }
        if (!$set) {
@@ -32,7 +34,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
        if ($update) {
                query_redirect("UPDATE " . idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.'));
        } else {
-               query_redirect("INSERT INTO " . idf_escape($TABLE) . " SET" . implode(",", $set), $location, lang('Item has been inserted.'));
+               query_redirect("INSERT INTO " . idf_escape($TABLE) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")", $location, lang('Item has been inserted.'));
        }
 }
 
index f3c54538087f4f5740cc97df184965be678ecbfc..f59a6552f75cb9d0e82b082903a79d6da537ff3d 100644 (file)
@@ -37,8 +37,8 @@ if ($_POST) {
        $row["source"][] = "";
 }
 
-$source = get_vals("SHOW COLUMNS FROM " . idf_escape($TABLE)); //! no text and blob
-$target = ($TABLE === $row["table"] ? $source : get_vals("SHOW COLUMNS FROM " . idf_escape($row["table"])));
+$source = array_keys(fields($TABLE)); //! no text and blob
+$target = ($TABLE === $row["table"] ? $source : array_keys(fields($row["table"])));
 ?>
 
 <form action="" method="post">
index bea746514d790e7bec8c2b2323d9955c7c6fe04a..2c618e6737c7df48288daf1eff4f220d199daffe 100644 (file)
@@ -491,7 +491,7 @@ class Adminer {
 </form>
 <?php
                        if ($missing != "db" && strlen(DB) && $connection->select_db(DB)) {
-                               $tables = get_vals("SHOW TABLES");
+                               $tables = tables_list();
                                if (!$tables) {
                                        echo "<p class='message'>" . lang('No tables.') . "\n";
                                } else {
index e53d798bf1f72d7baeb7c59adcdbcc193b81102e..dade066504597b766a5cb6af2682f3a166243a06 100644 (file)
@@ -24,6 +24,15 @@ function idf_unescape($idf) {
        return str_replace("``", "`", $idf);
 }
 
+/** Escape string to use inside ''
+* @param string
+* @return string
+*/
+function escape_string($val) {
+       global $connection;
+       return substr($connection->quote($val), 1, -1);
+}
+
 /** Escape or unescape string to use inside form []
 * @param string
 * @param bool
@@ -155,11 +164,10 @@ function unique_idf($row, $indexes) {
 * @return string
 */
 function where($where) {
-       global $connection;
        $return = array();
        foreach ((array) $where["where"] as $key => $val) {
                $key = bracket_escape($key, "back");
-               $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY " . $connection->quote($val); //! enum and set, columns looking like functions
+               $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = " . exact_value($val); //! enum and set, columns looking like functions
        }
        foreach ((array) $where["null"] as $key) {
                $key = bracket_escape($key, "back");
index eaf985121048ea3cfe8081c6e6141942f0e49550..8ddafdeda8349b67a54c3c874ef4637a2b70fdf9 100644 (file)
@@ -177,6 +177,25 @@ function get_databases($flush = true) {
        return $return;
 }
 
+function engines() {
+       global $connection;
+       $return = array();
+       $result = $connection->query("SHOW ENGINES");
+       while ($row = $result->fetch_assoc()) {
+               if (ereg("YES|DEFAULT", $row["Support"])) {
+                       $return[] = $row["Engine"];
+               }
+       }
+       return $return;
+}
+
+/** Get tables list
+* @return array
+*/
+function tables_list() {
+       return get_vals("SHOW TABLES");
+}
+
 /** Get table status
 * @param string
 * @return array
@@ -315,22 +334,22 @@ function collations() {
        return $return;
 }
 
-/** Escape string to use inside ''
+/** Find out if database is information_schema
 * @param string
-* @return string
+* @return bool
 */
-function escape_string($val) {
+function information_schema($db) {
        global $connection;
-       return substr($connection->quote($val), 1, -1);
+       return ($connection->server_info >= 5 && $db == "information_schema");
 }
 
-/** Find out if database is information_schema
+/** Return expression for binary comparison
 * @param string
-* @return bool
+* @return string
 */
-function information_schema($db) {
+function exact_value($val) {
        global $connection;
-       return ($connection->server_info >= 5 && $db == "information_schema");
+       return "BINARY " . $connection->quote($val);
 }
 
 // value means maximum unsigned length
index fd26dac430c4ba2490874383999c3cc7c3666142..034085d5c629c24147d357bb1eb993e44dd03f73 100644 (file)
@@ -1,22 +1,22 @@
 <?php
 $TABLE = $_GET["table"];
-$result = $connection->query("SHOW FULL COLUMNS FROM " . idf_escape($TABLE));
-if (!$result) {
+$fields = fields($TABLE);
+if (!$fields) {
        $error = h($connection->error);
 }
-$table_status = ($result ? table_status($TABLE) : array());
+$table_status = ($fields ? table_status($TABLE) : array());
 $is_view = !isset($table_status["Rows"]);
 
-page_header(($result && $is_view ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
+page_header(($fields && $is_view ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
 $adminer->selectLinks($table_status, $is_view ? null : "");
 
-if ($result) {
+if ($fields) {
        echo "<table cellspacing='0'>\n";
        echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . "<td>" . lang('Comment') . "</thead>\n";
-       while ($row = $result->fetch_assoc()) {
-               echo "<tr><th>" . h($row["Field"]);
-               echo "<td>" . h($row["Type"]) . ($row["Null"] == "YES" ? " <i>NULL</i>" : "") . ($row["Extra"] == "auto_increment" ? " <i>" . lang('Auto Increment') . "</i>" : "");
-               echo "<td>" . nbsp($row["Comment"]);
+       foreach ($fields as $field) {
+               echo "<tr><th>" . h($field["field"]);
+               echo "<td>" . h($field["full_type"]) . ($field["null"] ? " <i>NULL</i>" : "") . ($field["auto_increment"] ? " <i>" . lang('Auto Increment') . "</i>" : "");
+               echo "<td>" . nbsp($field["comment"]);
                echo "\n";
        }
        echo "</table>\n";
index bb8d9ec721e66ace03f867ac38381dce9b4b3df5..915e5d448c2a04140f2eec200a2d50ebe6750cdb 100644 (file)
@@ -116,7 +116,7 @@ ORDER BY ORDINAL_POSITION");
                                                // find all used ids
                                                $ids = array();
                                                foreach ($rows as $row) {
-                                                       $ids[$row[$key]] = "BINARY " . $connection->quote($row[$key]);
+                                                       $ids[$row[$key]] = exact_value($row[$key]);
                                                }
                                                // uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
                                                $descriptions = array();