This commit is contained in:
Dennis Eichhorn 2024-05-18 00:53:22 +00:00
parent e78031906e
commit a5ee11721f
6 changed files with 27 additions and 15 deletions

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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';

View File

@ -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));