Skip to content

Commit cca471a

Browse files
committed
feat: getFieldData() returns nullable data on PostgreSQL
1 parent d7c8f04 commit cca471a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

system/Database/Postgre/Connection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ protected function _listColumns(string $table = ''): string
234234
*/
235235
protected function _fieldData(string $table): array
236236
{
237-
$sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default"
238-
FROM "information_schema"."columns"
239-
WHERE LOWER("table_name") = '
237+
$sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default", "is_nullable"
238+
FROM "information_schema"."columns"
239+
WHERE LOWER("table_name") = '
240240
. $this->escape(strtolower($table))
241241
. ' ORDER BY "ordinal_position"';
242242

@@ -252,6 +252,7 @@ protected function _fieldData(string $table): array
252252

253253
$retVal[$i]->name = $query[$i]->column_name;
254254
$retVal[$i]->type = $query[$i]->data_type;
255+
$retVal[$i]->nullable = $query[$i]->is_nullable === 'YES';
255256
$retVal[$i]->default = $query[$i]->column_default;
256257
$retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
257258
}

tests/system/Database/Live/ForgeTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ public function testAddFields()
843843
$this->assertSame('integer', $fieldsData[0]->type);
844844
$this->assertSame('character varying', $fieldsData[1]->type);
845845

846+
$this->assertFalse($fieldsData[0]->nullable);
847+
$this->assertFalse($fieldsData[1]->nullable);
848+
846849
$this->assertSame(32, (int) $fieldsData[0]->max_length);
847850
$this->assertSame(255, (int) $fieldsData[1]->max_length);
848851

0 commit comments

Comments
 (0)