From eeadef2b59d64523a3629f25abf63a52dc05a615 Mon Sep 17 00:00:00 2001 From: michalsn Date: Mon, 23 Dec 2024 09:46:17 +0100 Subject: [PATCH] fix tests --- system/Database/BasePreparedQuery.php | 2 +- system/Database/SQLSRV/Connection.php | 6 +++++- system/Database/SQLSRV/Forge.php | 2 +- .../Migrations/20160428212500_Create_test_tables.php | 2 +- .../Database/Live/AbstractGetFieldDataTestCase.php | 10 ++++------ .../Database/Live/Postgre/GetFieldDataTestCase.php | 7 +++++++ .../Database/Live/SQLSRV/GetFieldDataTestCase.php | 7 +++++++ 7 files changed, 26 insertions(+), 10 deletions(-) diff --git a/system/Database/BasePreparedQuery.php b/system/Database/BasePreparedQuery.php index fd84535bc2d5..6ba2f6eb5a43 100644 --- a/system/Database/BasePreparedQuery.php +++ b/system/Database/BasePreparedQuery.php @@ -263,7 +263,7 @@ public function getErrorMessage(): string /** * Whether the input contain binary data. */ - protected function isBinary($input): bool + protected function isBinary(string $input): bool { return mb_detect_encoding($input, 'UTF-8', true) === false; } diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index 7d60ad1cabd1..8ded4cd02098 100644 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -368,7 +368,11 @@ protected function _fieldData(string $table): array $retVal[$i]->max_length = $query[$i]->CHARACTER_MAXIMUM_LENGTH > 0 ? $query[$i]->CHARACTER_MAXIMUM_LENGTH - : $query[$i]->NUMERIC_PRECISION; + : ( + $query[$i]->CHARACTER_MAXIMUM_LENGTH === -1 + ? 'max' + : $query[$i]->NUMERIC_PRECISION + ); $retVal[$i]->nullable = $query[$i]->IS_NULLABLE !== 'NO'; $retVal[$i]->default = $query[$i]->COLUMN_DEFAULT; diff --git a/system/Database/SQLSRV/Forge.php b/system/Database/SQLSRV/Forge.php index fff528d3f12f..df3d55c779c4 100644 --- a/system/Database/SQLSRV/Forge.php +++ b/system/Database/SQLSRV/Forge.php @@ -398,7 +398,7 @@ protected function _attributeType(array &$attributes) break; case 'BLOB': - $attributes['TYPE'] = 'VARBINARY'; + $attributes['TYPE'] = 'VARBINARY'; $attributes['CONSTRAINT'] ??= 'MAX'; break; diff --git a/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php b/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php index 3753fb49ffa7..434644bef280 100644 --- a/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php +++ b/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php @@ -91,7 +91,7 @@ public function up(): void } if ($this->db->DBDriver === 'SQLSRV') { - unset($dataTypeFields['type_timestamp'], $dataTypeFields['type_blob']); + unset($dataTypeFields['type_timestamp']); $dataTypeFields['type_text'] = ['type' => 'NVARCHAR(max)', 'null' => true]; } diff --git a/tests/system/Database/Live/AbstractGetFieldDataTestCase.php b/tests/system/Database/Live/AbstractGetFieldDataTestCase.php index 60413acc784f..011564992922 100644 --- a/tests/system/Database/Live/AbstractGetFieldDataTestCase.php +++ b/tests/system/Database/Live/AbstractGetFieldDataTestCase.php @@ -104,8 +104,8 @@ protected function createTableForType(): void $this->forge->dropTable($this->table, true); // missing types: - // TINYINT,MEDIUMINT,BIT,YEAR,BINARY,VARBINARY,TINYTEXT,LONGTEXT, - // JSON,Spatial data types + // TINYINT,MEDIUMINT,BIT,YEAR,BINARY,VARBINARY (BLOB more or less handles these two), + // TINYTEXT,LONGTEXT,JSON,Spatial data types // `id` must be INTEGER else SQLite3 error on not null for autoincrement field. $fields = [ 'id' => ['type' => 'INTEGER', 'constraint' => 20, 'auto_increment' => true], @@ -138,8 +138,7 @@ protected function createTableForType(): void $fields['type_enum'], $fields['type_set'], $fields['type_mediumtext'], - $fields['type_double'], - $fields['type_blob'] + $fields['type_double'] ); } @@ -147,8 +146,7 @@ protected function createTableForType(): void unset( $fields['type_set'], $fields['type_mediumtext'], - $fields['type_double'], - $fields['type_blob'] + $fields['type_double'] ); } diff --git a/tests/system/Database/Live/Postgre/GetFieldDataTestCase.php b/tests/system/Database/Live/Postgre/GetFieldDataTestCase.php index 42e823397926..0adfc036c4c3 100644 --- a/tests/system/Database/Live/Postgre/GetFieldDataTestCase.php +++ b/tests/system/Database/Live/Postgre/GetFieldDataTestCase.php @@ -212,6 +212,13 @@ public function testGetFieldDataType(): void 'default' => null, ], 15 => (object) [ + 'name' => 'type_blob', + 'type' => 'bytea', + 'max_length' => null, + 'nullable' => true, + 'default' => null, + ], + 16 => (object) [ 'name' => 'type_boolean', 'type' => 'boolean', 'max_length' => null, diff --git a/tests/system/Database/Live/SQLSRV/GetFieldDataTestCase.php b/tests/system/Database/Live/SQLSRV/GetFieldDataTestCase.php index bf00175c4fab..47aa8d108972 100644 --- a/tests/system/Database/Live/SQLSRV/GetFieldDataTestCase.php +++ b/tests/system/Database/Live/SQLSRV/GetFieldDataTestCase.php @@ -219,6 +219,13 @@ public function testGetFieldDataType(): void 'default' => null, ], 16 => (object) [ + 'name' => 'type_blob', + 'type' => 'varbinary', + 'max_length' => 'max', + 'nullable' => true, + 'default' => null, + ], + 17 => (object) [ 'name' => 'type_boolean', 'type' => 'bit', 'max_length' => null,