11 require_once(dirname(dirname(dirname(dirname(__FILE__)))) .
"/vendor/autoload.php");
14 use Monolog\Handler\StreamHandler;
25 function __construct($dbFileName =
null)
27 if (! class_exists(
'Sqlite3')) {
28 throw new \Exception(
"Class SQLite3 not found");
31 date_default_timezone_set(
"UTC");
32 if (! isset($dbFileName)) {
33 $dbFileName =
":memory:";
35 if (file_exists($dbFileName)) {
39 $this->dbFileName = $dbFileName;
41 require (dirname(dirname(__FILE__)).
'/common-container.php');
44 $logger = $container->get(
'logger');
45 $this->logFileName = dirname(dirname(dirname(dirname(dirname(__FILE__))))) .
'/db.sqlite.log';
46 $logger->pushHandler(
new StreamHandler($this->logFileName, Logger::DEBUG));
48 $sqlite3Connection =
new SQLite3($this->dbFileName, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
50 $liteDb =
new SqliteE($sqlite3Connection);
51 $container->get(
'db.manager')->setDriver($liteDb);
52 $this->
dbManager = $container->get(
'db.manager');
57 if (file_exists($this->logFileName)) {
58 unlink($this->logFileName);
69 $coreSchemaFile = $this->dirnameRec(__FILE__, 4) .
'/www/ui/core-schema.dat';
71 require($coreSchemaFile);
72 foreach ($Schema[
'TABLE'] as $tableName=>$tableCols) {
73 if ($invert^!in_array($tableName, $tableList) || array_key_exists($tableName, $Schema[
'INHERITS'])) {
78 foreach ($tableCols as $attributes) {
79 $sql = preg_replace(
'/ DEFAULT .*/',
'', $attributes[
"ADD"]);
80 $alterSql = explode(
'"', $sql);
81 $columns[$alterSql[3]] =
"$alterSql[3] " . $alterSql[4];
83 $createSql =
"CREATE TABLE $tableName (" . implode(
',', $columns) .
')';
95 $sql = str_replace(
' false,',
" 'false',", $sql);
96 $sql = str_replace(
' true,',
" 'true',", $sql);
97 $sql = str_replace(
' false)',
" 'false')", $sql);
98 $sql = str_replace(
' true)',
" 'true')", $sql);
queryConverter($sql)
convert sql string to something the drive understands
createPlainTables($tableList, $invert=FALSE)
fo_dbManager * dbManager
fo_dbManager object