From cca471a014d763d607a8f2bdc540e4059e7ff7e6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 9 May 2022 16:38:45 +0900 Subject: [PATCH] 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);