Permalink
Browse files

Improve SQLite

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1482 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent acf7a42 commit b649373e03b088f01701a2b09bcc79510f8f5c9d jakubvrana committed Apr 22, 2010
Showing with 91 additions and 47 deletions.
  1. +84 −42 adminer/drivers/sqlite.inc.php
  2. +3 −1 adminer/table.inc.php
  3. +4 −4 todo.txt
@@ -15,20 +15,24 @@
if (isset($_GET["sqlite2"])) {
class Min_SQLite {
- var $extension = "SQLite", $server_info, $affected_rows, $error, $_connection;
+ var $extension = "SQLite", $server_info, $affected_rows, $error, $_link;
function __construct() {
$this->server_info = sqlite_libversion();
- $this->_connection = new SQLiteDatabase(":memory:");
+ $this->_link = new SQLiteDatabase(":memory:");
}
function open($filename) {
- $this->_connection = new SQLiteDatabase($filename);
+ $this->_link = new SQLiteDatabase($filename);
+ }
+
+ function close() {
+ $this->_link = null;
}
function query($query, $unbuffered = false) {
$method = ($unbuffered ? "unbufferedQuery" : "query");
- $result = @$this->_connection->$method($query, SQLITE_BOTH, $error);
+ $result = @$this->_link->$method($query, SQLITE_BOTH, $error);
if (!$result) {
$this->error = $error;
return false;
@@ -98,32 +102,36 @@ function fetch_field() {
} else {
class Min_SQLite {
- var $extension = "SQLite3", $server_info, $affected_rows, $error, $_connection;
+ var $extension = "SQLite3", $server_info, $affected_rows, $error, $_link;
function __construct() {
- $this->_connection = new SQLite3(":memory:"); // required to display variables
- $version = $this->_connection->version();
+ $this->_link = new SQLite3(":memory:"); // required to display variables
+ $version = $this->_link->version();
$this->server_info = $version["versionString"];
}
function open($filename) {
- $this->_connection = new SQLite3($filename);
+ $this->_link = new SQLite3($filename);
+ }
+
+ function close() {
+ $this->_link->close();
}
function query($query) {
- $result = @$this->_connection->query($query);
+ $result = @$this->_link->query($query);
if (!$result) {
- $this->error = $this->_connection->lastErrorMsg();
+ $this->error = $this->_link->lastErrorMsg();
return false;
} elseif ($result->numColumns()) {
return new Min_Result($result);
}
- $this->affected_rows = $this->_connection->changes();
+ $this->affected_rows = $this->_link->changes();
return true;
}
function quote($string) {
- return "'" . $this->_connection->escapeString($string) . "'";
+ return "'" . $this->_link->escapeString($string) . "'";
}
function result($query, $field = 0) {
@@ -169,46 +177,56 @@ function __desctruct() {
}
- class Min_DB extends Min_SQLite {
-
- function select_db($filename) {
- set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
- $this->open($filename);
- restore_exception_handler();
- return true;
- }
-
- function multi_query($query) {
- return $this->_result = $this->query($query);
- }
-
- function store_result() {
- return $this->_result;
- }
-
- function next_result() {
- return false;
- }
- }
-
} elseif (extension_loaded("pdo_sqlite")) {
- class Min_DB extends Min_PDO {
+ class Min_SQLite extends Min_PDO {
var $extension = "PDO_SQLite";
- function select_db($filename) {
+ function __construct() {
+ $this->dsn(DRIVER . "::memory:", "", "");
+ }
+
+ function open($filename) {
static $connected = false;
if ($connected) {
return true;
}
$connected = true;
- $this->dsn(DRIVER . ":$filename", "", "", "connect_error");
- //! $this->server_info needs to be filled in __construct()
+ $this->dsn(DRIVER . ":$filename", "", "");
return true;
}
+
+ function close() {
+ // no known way
+ }
}
}
+ class Min_DB extends Min_SQLite {
+
+ function select_db($filename) {
+ if (!is_readable($filename)) { //! verify database format
+ return false;
+ }
+ set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
+ $this->open($filename);
+ restore_exception_handler();
+ return true;
+ }
+
+ function multi_query($query) {
+ return $this->_result = $this->query($query);
+ }
+
+ function store_result() {
+ return $this->_result;
+ }
+
+ function next_result() {
+ return false;
+ }
+ }
+
function idf_escape($idf) {
return '"' . str_replace('"', '""', $idf) . '"';
}
@@ -235,7 +253,8 @@ function limit1($query) {
}
function db_collation($db, $collations) {
- return null;
+ global $connection;
+ return $connection->result("PRAGMA encoding"); // there is no database list so $db == DB
}
function engines() {
@@ -332,6 +351,7 @@ function foreign_keys($table) {
if (is_object($result)) {
while ($row = $result->fetch_assoc()) {
$foreign_key = &$return[$row["id"]];
+ //! idf_unescape in SQLite2
if (!$foreign_key) {
$foreign_key = $row;
}
@@ -348,7 +368,7 @@ function view($name) {
}
function collations() {
- return get_vals("PRAGMA collation_list", 1);
+ return (isset($_GET["create"]) ? get_vals("PRAGMA collation_list", 1) : array());
}
function information_schema($db) {
@@ -365,9 +385,31 @@ function exact_value($val) {
return $connection->quote($val);
}
+ function create_database($db, $collation) {
+ global $connection;
+ // SQLITE3_OPEN_CREATE is not respected
+ // PRAGMA encoding = "UTF-8" is not respected
+ if (!file_exists($db) && touch($db)) {
+ return true;
+ }
+ $connection->error = lang('File can not be created.');
+ return false;
+ }
+
+ function drop_databases($databases) {
+ global $connection;
+ $connection->close();
+ foreach ($databases as $db) {
+ if (!unlink($db)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
function rename_database($name, $collation) {
global $connection;
- $connection->close(); //! not available with all extensions
+ $connection->close();
return rename(DB, $name);
}
@@ -395,7 +437,7 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
return false;
}
if ($auto_increment) {
- return queries("UPDATE sqlite_sequence SET seq = $auto_increment WHERE name = " . $connection->quote($name) . "");
+ queries("UPDATE sqlite_sequence SET seq = $auto_increment WHERE name = " . $connection->quote($name)); // ignores error
}
return true;
}
@@ -48,7 +48,9 @@
echo "<th><i>" . implode("</i>, <i>", array_map('h', $foreign_key["source"])) . "</i>";
echo "<td><a href='" . h($foreign_key["db"] != "" ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), ME) : ME) . "table=" . urlencode($foreign_key["table"]) . "'>$link</a>";
echo "(<em>" . implode("</em>, <em>", array_map('h', $foreign_key["target"])) . "</em>)";
- echo '<td><a href="' . h(ME . 'foreign=' . urlencode($TABLE) . '&name=' . urlencode($name)) . '">' . lang('Alter') . '</a>';
+ if ($driver != "sqlite") {
+ echo '<td><a href="' . h(ME . 'foreign=' . urlencode($TABLE) . '&name=' . urlencode($name)) . '">' . lang('Alter') . '</a>';
+ }
}
echo "</table>\n";
}
View
@@ -26,11 +26,9 @@ Rank, Tree structure
Add whisperer to fields with foreign key to big table
SQLite:
-CREATE DATABASE - PRAGMA encoding = "UTF-8"
-Detecion of non-existing database
-DROP DATABASE by file operations
CSV import - ON DUPLICATE KEY UPDATE
-Export - views, triggers
+Use ATTACH for select_db
+Export - triggers, CREATE DATABASE
Delimiter in export and SQL command
PostgreSQL:
@@ -40,8 +38,10 @@ Table schema
Export - http://www.postgresql.org/docs/8.4/static/functions-info.html
Table status - http://www.postgresql.org/docs/8.4/static/functions-admin.html
Column rights - http://www.postgresql.org/docs/8.4/static/functions-info.html
+Dollar terminated string in SQL command
Move table - ALTER TABLE SET SCHEMA
bool in Editor
+Check PDO driver
MS SQL:
Rename by sp_rename

0 comments on commit b649373

Please sign in to comment.