Simplify SQLite
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1483 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
b649373e03
commit
e780f9bb05
|
@ -17,19 +17,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
class Min_SQLite {
|
class Min_SQLite {
|
||||||
var $extension = "SQLite", $server_info, $affected_rows, $error, $_link;
|
var $extension = "SQLite", $server_info, $affected_rows, $error, $_link;
|
||||||
|
|
||||||
function __construct() {
|
function Min_SQLite($filename) {
|
||||||
$this->server_info = sqlite_libversion();
|
$this->server_info = sqlite_libversion();
|
||||||
$this->_link = new SQLiteDatabase(":memory:");
|
|
||||||
}
|
|
||||||
|
|
||||||
function open($filename) {
|
|
||||||
$this->_link = new SQLiteDatabase($filename);
|
$this->_link = new SQLiteDatabase($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
function close() {
|
|
||||||
$this->_link = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function query($query, $unbuffered = false) {
|
function query($query, $unbuffered = false) {
|
||||||
$method = ($unbuffered ? "unbufferedQuery" : "query");
|
$method = ($unbuffered ? "unbufferedQuery" : "query");
|
||||||
$result = @$this->_link->$method($query, SQLITE_BOTH, $error);
|
$result = @$this->_link->$method($query, SQLITE_BOTH, $error);
|
||||||
|
@ -60,7 +52,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
class Min_Result {
|
class Min_Result {
|
||||||
var $_result, $_offset = 0, $num_rows;
|
var $_result, $_offset = 0, $num_rows;
|
||||||
|
|
||||||
function __construct($result) {
|
function Min_Result($result) {
|
||||||
$this->_result = $result;
|
$this->_result = $result;
|
||||||
if (method_exists($result, 'numRows')) { // not available in unbuffered query
|
if (method_exists($result, 'numRows')) { // not available in unbuffered query
|
||||||
$this->num_rows = $result->numRows();
|
$this->num_rows = $result->numRows();
|
||||||
|
@ -104,20 +96,12 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
class Min_SQLite {
|
class Min_SQLite {
|
||||||
var $extension = "SQLite3", $server_info, $affected_rows, $error, $_link;
|
var $extension = "SQLite3", $server_info, $affected_rows, $error, $_link;
|
||||||
|
|
||||||
function __construct() {
|
function Min_SQLite($filename) {
|
||||||
$this->_link = new SQLite3(":memory:"); // required to display variables
|
$this->_link = new SQLite3($filename);
|
||||||
$version = $this->_link->version();
|
$version = $this->_link->version();
|
||||||
$this->server_info = $version["versionString"];
|
$this->server_info = $version["versionString"];
|
||||||
}
|
}
|
||||||
|
|
||||||
function open($filename) {
|
|
||||||
$this->_link = new SQLite3($filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
function close() {
|
|
||||||
$this->_link->close();
|
|
||||||
}
|
|
||||||
|
|
||||||
function query($query) {
|
function query($query) {
|
||||||
$result = @$this->_link->query($query);
|
$result = @$this->_link->query($query);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
|
@ -147,7 +131,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
class Min_Result {
|
class Min_Result {
|
||||||
var $_result, $_offset = 0, $num_rows;
|
var $_result, $_offset = 0, $num_rows;
|
||||||
|
|
||||||
function __construct($result) {
|
function Min_Result($result) {
|
||||||
$this->_result = $result;
|
$this->_result = $result;
|
||||||
$this->num_rows = 1; //!
|
$this->num_rows = 1; //!
|
||||||
}
|
}
|
||||||
|
@ -181,22 +165,8 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
class Min_SQLite extends Min_PDO {
|
class Min_SQLite extends Min_PDO {
|
||||||
var $extension = "PDO_SQLite";
|
var $extension = "PDO_SQLite";
|
||||||
|
|
||||||
function __construct() {
|
function Min_SQLite($filename) {
|
||||||
$this->dsn(DRIVER . "::memory:", "", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
function open($filename) {
|
|
||||||
static $connected = false;
|
|
||||||
if ($connected) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
$connected = true;
|
|
||||||
$this->dsn(DRIVER . ":$filename", "", "");
|
$this->dsn(DRIVER . ":$filename", "", "");
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function close() {
|
|
||||||
// no known way
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,14 +174,16 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
|
|
||||||
class Min_DB extends Min_SQLite {
|
class Min_DB extends Min_SQLite {
|
||||||
|
|
||||||
|
function Min_DB() {
|
||||||
|
$this->Min_SQLite(":memory:");
|
||||||
|
}
|
||||||
|
|
||||||
function select_db($filename) {
|
function select_db($filename) {
|
||||||
if (!is_readable($filename)) { //! verify database format
|
if (is_readable($filename) && $this->query("ATTACH " . $this->quote(ereg("(^[/\\]|:)", $filename) ? $filename : dirname($_SERVER["SCRIPT_FILENAME"]) . "/$filename") . " AS a")) { // is_readable - SQLite 3
|
||||||
return false;
|
$this->Min_SQLite($filename);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
set_exception_handler('connect_error'); // try/catch is not compatible with PHP 4
|
return false;
|
||||||
$this->open($filename);
|
|
||||||
restore_exception_handler();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function multi_query($query) {
|
function multi_query($query) {
|
||||||
|
@ -232,10 +204,6 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
global $connection;
|
|
||||||
if ($connection) {
|
|
||||||
return $connection; // can connect only once, function to get number of rows doesn't exist anyway
|
|
||||||
}
|
|
||||||
return new Min_DB;
|
return new Min_DB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,20 +355,23 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
|
|
||||||
function create_database($db, $collation) {
|
function create_database($db, $collation) {
|
||||||
global $connection;
|
global $connection;
|
||||||
// SQLITE3_OPEN_CREATE is not respected
|
if (file_exists($db)) {
|
||||||
// PRAGMA encoding = "UTF-8" is not respected
|
$connection->error = lang('File exists.');
|
||||||
if (!file_exists($db) && touch($db)) {
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
$connection->error = lang('File can not be created.');
|
$link = new Min_SQLite($db); //! exception handler
|
||||||
return false;
|
$link->query('PRAGMA encoding = "UTF-8"');
|
||||||
|
$link->query('CREATE TABLE adminer (i)'); // otherwise creates empty file
|
||||||
|
$link->query('DROP TABLE adminer');
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function drop_databases($databases) {
|
function drop_databases($databases) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$connection->close();
|
$connection->Min_SQLite(":memory:"); // to unlock file, doesn't work in PDO on Windows
|
||||||
foreach ($databases as $db) {
|
foreach ($databases as $db) {
|
||||||
if (!unlink($db)) {
|
if (!@unlink($db)) {
|
||||||
|
$connection->error = lang('File exists.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,8 +380,9 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
|
|
||||||
function rename_database($name, $collation) {
|
function rename_database($name, $collation) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$connection->close();
|
$connection->Min_SQLite(":memory:");
|
||||||
return rename(DB, $name);
|
$connection->error = lang('File exists.');
|
||||||
|
return @rename(DB, $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function auto_increment() {
|
function auto_increment() {
|
||||||
|
|
1
todo.txt
1
todo.txt
|
@ -27,7 +27,6 @@ Add whisperer to fields with foreign key to big table
|
||||||
|
|
||||||
SQLite:
|
SQLite:
|
||||||
CSV import - ON DUPLICATE KEY UPDATE
|
CSV import - ON DUPLICATE KEY UPDATE
|
||||||
Use ATTACH for select_db
|
|
||||||
Export - triggers, CREATE DATABASE
|
Export - triggers, CREATE DATABASE
|
||||||
Delimiter in export and SQL command
|
Delimiter in export and SQL command
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue