From d7c8f04f5191e860ef6c24c285c399117ff5779c Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 9 May 2022 16:33:10 +0900 Subject: [PATCH 1/2] test: add empty lines or so --- tests/system/Database/Live/ForgeTest.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 28f40817ae15..99db3e51aa5c 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -835,31 +835,40 @@ public function testAddFields() $this->assertNull($fieldsData[0]->default); $this->assertNull($fieldsData[1]->default); + $this->assertSame(1, (int) $fieldsData[0]->primary_key); + $this->assertSame(255, (int) $fieldsData[1]->max_length); } elseif ($this->db->DBDriver === 'Postgre') { $this->assertSame('integer', $fieldsData[0]->type); $this->assertSame('character varying', $fieldsData[1]->type); + $this->assertSame(32, (int) $fieldsData[0]->max_length); - $this->assertNull($fieldsData[1]->default); $this->assertSame(255, (int) $fieldsData[1]->max_length); + + $this->assertNull($fieldsData[1]->default); } elseif ($this->db->DBDriver === 'SQLite3') { $this->assertSame('integer', strtolower($fieldsData[0]->type)); $this->assertSame('varchar', strtolower($fieldsData[1]->type)); + $this->assertNull($fieldsData[1]->default); } elseif ($this->db->DBDriver === 'SQLSRV') { $this->assertSame('int', $fieldsData[0]->type); - $this->assertSame(10, (int) $fieldsData[0]->max_length); $this->assertSame('varchar', $fieldsData[1]->type); - $this->assertNull($fieldsData[1]->default); + + $this->assertSame(10, (int) $fieldsData[0]->max_length); $this->assertSame(255, (int) $fieldsData[1]->max_length); + + $this->assertNull($fieldsData[1]->default); } elseif ($this->db->DBDriver === 'OCI8') { // Check types $this->assertSame('NUMBER', $fieldsData[0]->type); $this->assertSame('VARCHAR2', $fieldsData[1]->type); + $this->assertSame('11', $fieldsData[0]->max_length); - $this->assertSame('', $fieldsData[1]->default); $this->assertSame('255', $fieldsData[1]->max_length); + + $this->assertSame('', $fieldsData[1]->default); } else { $this->fail(sprintf('DB driver "%s" is not supported.', $this->db->DBDriver)); } From cca471a014d763d607a8f2bdc540e4059e7ff7e6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 9 May 2022 16:38:45 +0900 Subject: [PATCH 2/2] feat: getFieldData() returns nullable data on PostgreSQL --- system/Database/Postgre/Connection.php | 7 ++++--- tests/system/Database/Live/ForgeTest.php | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index bf78f379d1ef..6827ba70b54f 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -234,9 +234,9 @@ protected function _listColumns(string $table = ''): string */ protected function _fieldData(string $table): array { - $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default" - FROM "information_schema"."columns" - WHERE LOWER("table_name") = ' + $sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default", "is_nullable" + FROM "information_schema"."columns" + WHERE LOWER("table_name") = ' . $this->escape(strtolower($table)) . ' ORDER BY "ordinal_position"'; @@ -252,6 +252,7 @@ protected function _fieldData(string $table): array $retVal[$i]->name = $query[$i]->column_name; $retVal[$i]->type = $query[$i]->data_type; + $retVal[$i]->nullable = $query[$i]->is_nullable === 'YES'; $retVal[$i]->default = $query[$i]->column_default; $retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision; } diff --git a/tests/system/Database/Live/ForgeTest.php b/tests/system/Database/Live/ForgeTest.php index 99db3e51aa5c..2122afb36a45 100644 --- a/tests/system/Database/Live/ForgeTest.php +++ b/tests/system/Database/Live/ForgeTest.php @@ -843,6 +843,9 @@ public function testAddFields() $this->assertSame('integer', $fieldsData[0]->type); $this->assertSame('character varying', $fieldsData[1]->type); + $this->assertFalse($fieldsData[0]->nullable); + $this->assertFalse($fieldsData[1]->nullable); + $this->assertSame(32, (int) $fieldsData[0]->max_length); $this->assertSame(255, (int) $fieldsData[1]->max_length);