23 require_once(dirname(dirname(dirname(dirname(__FILE__)))) .
"/vendor/autoload.php");
37 function __construct($dbFileName = null)
39 if (! class_exists(
'Sqlite3')) {
40 throw new \Exception(
"Class SQLite3 not found");
43 date_default_timezone_set(
"UTC");
44 if (! isset($dbFileName)) {
45 $dbFileName =
":memory:";
47 if (file_exists($dbFileName)) {
51 $this->dbFileName = $dbFileName;
53 require (dirname(dirname(__FILE__)).
'/common-container.php');
56 $logger = $container->get(
'logger');
57 $this->logFileName = dirname(dirname(dirname(dirname(dirname(__FILE__))))) .
'/db.sqlite.log';
58 $logger->pushHandler(
new StreamHandler($this->logFileName, Logger::DEBUG));
60 $sqlite3Connection =
new SQLite3($this->dbFileName, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
62 $liteDb =
new SqliteE($sqlite3Connection);
63 $container->get(
'db.manager')->setDriver($liteDb);
64 $this->
dbManager = $container->get(
'db.manager');
69 if (file_exists($this->logFileName)) {
70 unlink($this->logFileName);
81 $coreSchemaFile = $this->dirnameRec(__FILE__, 4) .
'/www/ui/core-schema.dat';
83 require($coreSchemaFile);
84 foreach ($Schema[
'TABLE'] as $tableName=>$tableCols) {
85 if ($invert^!in_array($tableName, $tableList) || array_key_exists($tableName, $Schema[
'INHERITS'])) {
90 foreach ($tableCols as $attributes) {
91 $sql = preg_replace(
'/ DEFAULT .*/',
'', $attributes[
"ADD"]);
92 $alterSql = explode(
'"', $sql);
93 $columns[$alterSql[3]] =
"$alterSql[3] " . $alterSql[4];
95 $createSql =
"CREATE TABLE $tableName (" . implode(
',', $columns) .
')';
107 $sql = str_replace(
' false,',
" 'false',", $sql);
108 $sql = str_replace(
' true,',
" 'true',", $sql);
109 $sql = str_replace(
' false)',
" 'false')", $sql);
110 $sql = str_replace(
' true)',
" 'true')", $sql);
fo_dbManager * dbManager
fo_dbManager object
createPlainTables($tableList, $invert=FALSE)
queryConverter($sql)
convert sql string to something the drive understands