diff --git a/DataStorage/Database/BuilderAbstract.php b/DataStorage/Database/BuilderAbstract.php index e74806314..780b5fd2a 100755 --- a/DataStorage/Database/BuilderAbstract.php +++ b/DataStorage/Database/BuilderAbstract.php @@ -27,6 +27,14 @@ use phpOMS\DataStorage\Database\Query\QueryType; */ abstract class BuilderAbstract { + /** + * Log queries. + * + * @var bool + * @since 1.0.0 + */ + public static bool $log = false; + /** * Is read only. * diff --git a/DataStorage/Database/Query/Builder.php b/DataStorage/Database/Query/Builder.php index c8b491c99..ab2ee08e7 100755 --- a/DataStorage/Database/Query/Builder.php +++ b/DataStorage/Database/Query/Builder.php @@ -43,14 +43,6 @@ class Builder extends BuilderAbstract */ protected Grammar $grammar; - /** - * Log queries. - * - * @var bool - * @since 1.0.0 - */ - public static bool $log = false; - /** * Columns. * diff --git a/DataStorage/Database/Schema/Builder.php b/DataStorage/Database/Schema/Builder.php index 4616f1955..6d4dc5e4d 100755 --- a/DataStorage/Database/Schema/Builder.php +++ b/DataStorage/Database/Schema/Builder.php @@ -479,6 +479,12 @@ class Builder extends BuilderAbstract } } - return \substr($queryString, 0, -1) . ';'; + $query = \substr($queryString, 0, -1) . ';'; + + if (self::$log) { + \phpOMS\Log\FileLogger::getInstance()->debug($query); + } + + return $query; } } diff --git a/tests/DataStorage/Database/Schema/BuilderTest.php b/tests/DataStorage/Database/Schema/BuilderTest.php index 14ef7397c..fda96873d 100755 --- a/tests/DataStorage/Database/Schema/BuilderTest.php +++ b/tests/DataStorage/Database/Schema/BuilderTest.php @@ -108,7 +108,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase } elseif ($con instanceof SqlServerConnection) { $sql = 'SELECT [table_name] FROM [sys].[tables] INNER JOIN [sys].[schemas] ON [sys].[tables.schema_id] = [sys].[schemas.schema_id];'; } elseif ($con instanceof SQLiteConnection) { - $sql = 'SELECT `name` FROM `sqlite_master` WHERE `type` = \'table\';'; + $sql = 'SELECT `name` FROM `sqlite_master` WHERE `type` = ?;'; } $sql = \strtr($sql, '[]', $iS . $iE); @@ -139,7 +139,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase } elseif ($con instanceof SqlServerConnection) { $sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = ? AND [table_name] = ?;'; } elseif ($con instanceof SQLiteConnection) { - $sql = 'SELECT * FROM pragma_table_info(?) WHERE pragma_table_info(?) = ?;'; + $sql = 'SELECT * FROM pragma_table_info(?) WHERE pragma_table_info(\'test\') = ?;'; } $sql = \strtr($sql, '[]', $iS . $iE); @@ -170,7 +170,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase } elseif ($con instanceof SqlServerConnection) { $sql = 'CREATE TABLE IF NOT EXISTS [user_roles] ([user_id] INT AUTO_INCREMENT, [role_id] VARCHAR(10) DEFAULT ? NULL, PRIMARY KEY ([user_id]), FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id]));'; } elseif ($con instanceof SQLiteConnection) { - $sql = 'CREATE TABLE [user_roles] ([user_id] INTEGER AUTOINCREMENT PRIMARY KEY, [role_id] TEXT DEFAULT ? NULL, FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id]));'; + $sql = 'CREATE TABLE [user_roles] ([user_id] INTEGER PRIMARY KEY AUTOINCREMENT, [role_id] TEXT DEFAULT ? NULL, FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id]));'; } $sql = \strtr($sql, '[]', $iS . $iE); diff --git a/tests/Stdlib/Base/AddressTest.php b/tests/Stdlib/Base/AddressTest.php index bd5dc5696..34308009a 100755 --- a/tests/Stdlib/Base/AddressTest.php +++ b/tests/Stdlib/Base/AddressTest.php @@ -47,6 +47,8 @@ final class AddressTest extends \PHPUnit\Framework\TestCase 'state' => '', 'lat' => 0.0, 'lon' => 0.0, + 'id' => 0, + 'type' => 1, ]; self::assertEquals('', $this->address->fao); @@ -77,6 +79,8 @@ final class AddressTest extends \PHPUnit\Framework\TestCase 'state' => '', 'lat' => 0.0, 'lon' => 0.0, + 'id' => 0, + 'type' => 1, ]; $this->address->fao = 'fao'; @@ -98,6 +102,8 @@ final class AddressTest extends \PHPUnit\Framework\TestCase 'state' => '', 'lat' => 0.0, 'lon' => 0.0, + 'id' => 0, + 'type' => 1, ]; $this->address->fao = 'fao'; diff --git a/tests/Stdlib/Base/LocationTest.php b/tests/Stdlib/Base/LocationTest.php index eb646f5f5..e7d0a77f9 100755 --- a/tests/Stdlib/Base/LocationTest.php +++ b/tests/Stdlib/Base/LocationTest.php @@ -47,7 +47,7 @@ final class LocationTest extends \PHPUnit\Framework\TestCase 'lat' => 0.0, 'lon' => 0.0, 'id' => 0, - 'type' => 2, + 'type' => 1, ]; self::assertEquals('', $this->location->postal); @@ -163,6 +163,8 @@ final class LocationTest extends \PHPUnit\Framework\TestCase public function testUnserialize() : void { $expected = [ + 'id' => 0, + 'type' => 1, 'postal' => '0123456789', 'city' => 'city', 'country' => 'Country', @@ -170,8 +172,6 @@ final class LocationTest extends \PHPUnit\Framework\TestCase 'state' => 'This is a state 123', 'lat' => 12.1, 'lon' => 11.2, - 'id' => 0, - 'type' => 2, ]; $this->location->unserialize(\json_encode($expected));