and ! file_exists('/opt/local/var/run/mysql5/mysqld.sock')
) ? true : false;
-# Look for sqlite db path
+#
+# Search existing DIR_SQLITE
+#
$DIR_SQLITE = '';
foreach ([
'~nico/ownCloud',
}
if ($DIR_SQLITE) $DIR_SQLITE .= '/var/lib/sqlite';
-# Includes
+#
+# Includes dbs/*php
+#
$dir = dirname(__FILE__).'/dbs';
foreach (nb::ls_dir($dir,'\.php$') as $file) {
require_once("$dir/$file");
}
#
-# Db All
+# Create *-sqlite databases
+#
+$host_already_exists = [];
+foreach ($CONF as $id => $db) {
+ if (1
+ and !empty($db['type']) and $db['type'] == 'sqlite'
+ and !empty($db['host'])
+ ) $host_already_exists[$db['host']] = $id;
+}
+if ($DIR_SQLITE) {
+ foreach (nb::ls_dir($DIR_SQLITE,'\.db$') as $file) {
+
+ if (isset($host_already_exists["$DIR_SQLITE/$file"])) {
+ $CONF[$host_already_exists["$DIR_SQLITE/$file"]]['exec'][] = 'PRAGMA journal_mode=OFF';
+ continue;
+ }
+
+ $id = 'sqlite-'.basename($file,'.db');
+
+ $CONF[$id] = [
+ 'host' => "$DIR_SQLITE/$file",
+ 'type' => 'sqlite',
+ 'title' => 'created by dbs.php',
+ ];
+ }
+}
+
+#
+# Sqlite all Attach db type=sqlite
#
#return;
$CONF['all'] = [
'types' => [
'exec' => [
'PRAGMA busy_timeout = 1000',
- 'PRAGMA synchronous=NORMAL',
+ #'PRAGMA synchronous=NORMAL',
'PRAGMA journal_mode=MEMORY',
],
],
];
+
+#debug($CONF['postfix']);
foreach ($CONF as $id => $db) {
+ #debug($db);
if (0
or empty($db['type'] )
or $db['type']!='sqlite'
or empty($db['host'] )
+ #or !is_readable($fname=basename($db['host'],'.db'))
+ #or !is_readable($fname)
or !is_readable($db['host'])
) continue;
#debug(basename($db['host'],'.db'));
- $CONF['all']['types']['exec'][] = "ATTACH DATABASE '".$db['host']."' as ".basename($db['host'],'.db')."";
+ $fname = basename($db['host'],'.db');
+ $CONF['all']['types']['exec'][] = "ATTACH DATABASE '".$db['host']."' as ".$fname."";
conf_merge($CONF[$id],$CONF['all']);
}
public $conf = [];
public $row_parse; # Function to call in rows()
+ # Params
+ protected static $paliases = [
+ 'd' => 'db',
+ 't' => 'table',
+ 'l' => 'limit',
+ 'a' => 'action',
+ 'h' => 'header',
+
+ 'f' => 'format',
+ 'out' => 'format',
+ 'o' => 'format',
+ ];
+
+ protected static $action_aliases = [
+ 'ls' => 'db.ls',
+ 'databases' => 'db.databases',
+
+ 'tables' => 'db.tables',
+ 'fields' => 'table.fields',
+ 'rows' => 'table.rows',
+ 'insert' => 'table.insert',
+ 'replace' => 'table.replace',
+ 'update' => 'table.update',
+ 'delete' => 'table.delete',
+ ];
+
# Web
public $default_table;
public $sort;
}
public function __destruct() {
- foreach (array_keys((array)$this) as $k) { if (isset($this->$k)) unset($this->$k); };
$this->disconnect();
+ foreach (array_keys((array)$this) as $k) { if (isset($this->$k)) unset($this->$k); };
}
function connect_init() {
function disconnect() {
if (empty($this->conn)) return null;
#$this->conn->exec('COMMIT');
- return $this->conn->close();
+ $this->method('disconnect');
+# NB 09.09.16 return $this->conn->close();
}
function connect() {
foreach ($this->sql_exec() as $s) {
$this->conn->exec($s);
}
- #$this->conn->exec('BEGIN');
+ #$this->conn->exec('BEGIN TRANSACTION');
# Create functions
if ($this->type('sqliteCreateFunction')) {
#if (!isset($this->tables)) {
$this->_tables = true;
- $sql = $this->type('tables',true,$this->type);
- if (is_callable($sql)) $sql = $sql($this);
- $sql = $this->unvar($sql);
+# NB 09.09.16 $sql = $this->type('tables',true,$this->type);
+# NB 09.09.16 if (is_callable($sql)) $sql = $sql($this);
+# NB 09.09.16 $sql = $this->unvar($sql);
$sql = $this->method('tables');
foreach ($this->conn->query($sql,PDO::FETCH_ASSOC) as $row) {
}
public static function pinit() {
- self::paliases([
- 'd' => 'db',
- 't' => 'table',
- 'l' => 'limit',
- 'a' => 'action',
- 'h' => 'header',
-
- 'f' => 'format',
- 'out' => 'format',
- 'o' => 'format',
- ]);
-
- if ($action=self::p('action')) {
- foreach ([
-
- 'ls' => 'db.ls',
- 'tables' => 'db.tables',
-
- 'fields' => 'table.fields',
- 'rows' => 'table.rows',
- 'insert' => 'table.insert',
- 'replace' => 'table.replace',
- 'update' => 'table.update',
- 'delete' => 'table.delete',
-
- ] as $src => $dest) {
+ if (!empty(self::$paliases)) self::paliases(self::$paliases);
+
+ if ($action=self::p('action') and !empty(self::$action_aliases)) {
+ foreach (self::$action_aliases
+ as $src => $dest) {
if ($action === $src) {
$action = $dest;
}
exit;
}
$DB_TYPES['sqlite'] = array (
+'dump.pre' => [
+ 'PRAGMA foreign_keys=OFF',
+],
+'_disconnect' => function($db) {
+ #$table->db()->exec("COMMIT");
+ $db->conn->commit();
+},
'exec' => [
#'PRAGMA journal_mode = MEMORY',
#'PRAGMA journal_mode = WAL',
'PRAGMA encoding = "'.strtoupper(Db::$encoding).'"',
#'PRAGMA temp_store = 2',
#'PRAGMA read_uncommitted = false',
+ #'BEGIN TRANSACTION',
],
'use_path' => true,
'extra_where' => 'denorm',