Skip to content

Commit

Permalink
feat: getFieldData() returns nullable data on PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed May 9, 2022
1 parent d7c8f04 commit cca471a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"';

Expand All @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit cca471a

Please sign in to comment.