Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions Tests/Pgsql/PgsqlDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public function testGetTableColumns()
'id' => 'integer',
'title' => 'character varying',
'start_date' => 'timestamp without time zone',
'end_date' => 'timestamp without time zone',
'description' => 'text',
'data' => 'bytea',
);
Expand Down Expand Up @@ -371,6 +372,16 @@ public function testGetTableColumns()
$start_date->Default = null;
$start_date->comments = '';

$end_date = new \stdClass;
$end_date->column_name = 'end_date';
$end_date->Field = 'end_date';
$end_date->type = 'timestamp without time zone';
$end_date->Type = 'timestamp without time zone';
$end_date->null = 'NO';
$end_date->Null = 'NO';
$end_date->Default = '1970-01-01 00:00:00';
$end_date->comments = '';

$description = new \stdClass;
$description->column_name = 'description';
$description->Field = 'description';
Expand Down Expand Up @@ -398,6 +409,7 @@ public function testGetTableColumns()
'id' => $id,
'title' => $title,
'start_date' => $start_date,
'end_date' => $end_date,
'description' => $description,
'data' => $data,
)
Expand Down Expand Up @@ -702,6 +714,7 @@ public function testLoadObject()
$objCompare->id = 3;
$objCompare->title = 'Testing3';
$objCompare->start_date = '1980-04-18 00:00:00';
$objCompare->end_date = '1970-01-01 00:00:00';
$objCompare->description = 'three';
$objCompare->data = null;

Expand Down Expand Up @@ -730,6 +743,7 @@ public function testLoadObjectList()
$objCompare->id = 1;
$objCompare->title = 'Testing';
$objCompare->start_date = '1980-04-18 00:00:00';
$objCompare->end_date = '1970-01-01 00:00:00';
$objCompare->description = 'one';
$objCompare->data = null;

Expand All @@ -739,6 +753,7 @@ public function testLoadObjectList()
$objCompare->id = 2;
$objCompare->title = 'Testing2';
$objCompare->start_date = '1980-04-18 00:00:00';
$objCompare->end_date = '1970-01-01 00:00:00';
$objCompare->description = 'one';
$objCompare->data = null;

Expand All @@ -748,6 +763,7 @@ public function testLoadObjectList()
$objCompare->id = 3;
$objCompare->title = 'Testing3';
$objCompare->start_date = '1980-04-18 00:00:00';
$objCompare->end_date = '1970-01-01 00:00:00';
$objCompare->description = 'three';
$objCompare->data = null;

Expand All @@ -757,6 +773,7 @@ public function testLoadObjectList()
$objCompare->id = 4;
$objCompare->title = 'Testing4';
$objCompare->start_date = '1980-04-18 00:00:00';
$objCompare->end_date = '1970-01-01 00:00:00';
$objCompare->description = 'four';
$objCompare->data = null;

Expand Down Expand Up @@ -801,7 +818,7 @@ public function testLoadRow()
self::$driver->setQuery($query);
$result = self::$driver->loadRow();

$expected = array(3, 'Testing3', '1980-04-18 00:00:00', 'three', null);
$expected = array(3, 'Testing3', '1980-04-18 00:00:00', '1970-01-01 00:00:00', 'three', null);

$this->assertThat($result, $this->equalTo($expected), __LINE__);
}
Expand All @@ -823,8 +840,8 @@ public function testLoadRowList()
$result = self::$driver->loadRowList();

$expected = array(
array(1, 'Testing', '1980-04-18 00:00:00', 'one', null),
array(2, 'Testing2', '1980-04-18 00:00:00', 'one', null)
array(1, 'Testing', '1980-04-18 00:00:00', '1970-01-01 00:00:00', 'one', null),
array(2, 'Testing2', '1980-04-18 00:00:00', '1970-01-01 00:00:00', 'one', null)
);

$this->assertThat($result, $this->equalTo($expected), __LINE__);
Expand Down Expand Up @@ -1078,7 +1095,7 @@ public function testTransactionCommit()
self::$driver->setQuery($queryCheck);
$result = self::$driver->loadRow();

$expected = array(6, 'testTitle', '1970-01-01 00:00:00', 'testDescription', null);
$expected = array(6, 'testTitle', '1970-01-01 00:00:00', '1970-01-01 00:00:00', 'testDescription', null);

$this->assertThat($result, $this->equalTo($expected), __LINE__);
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Stubs/postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ CREATE TABLE "dbtest" (
"id" serial NOT NULL,
"title" character varying(50) NOT NULL,
"start_date" timestamp without time zone NOT NULL,
"end_date" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
"description" text NOT NULL,
"data" bytea,
PRIMARY KEY ("id")
Expand Down
22 changes: 13 additions & 9 deletions src/Pgsql/PgsqlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ public function getTableColumns($table, $typeOnly = true)
{
foreach ($fields as $field)
{
// Change Postgresql's NULL::* type with PHP's null one
if (preg_match('/^NULL::*/', $field->Default))
{
$field->Default = null;
}

// Normalise default values like datetime
if (preg_match('/^\'(.*)\'::.*/', $field->Default, $matches))
{
$field->Default = $matches[1];
}

// Do some dirty translation to MySQL output.
// @todo: Come up with and implement a standard across databases.
$result[$field->column_name] = (object) [
Expand All @@ -250,15 +262,6 @@ public function getTableColumns($table, $typeOnly = true)
}
}

// Change Postgresql's NULL::* type with PHP's null one
foreach ($fields as $field)
{
if (preg_match('/^NULL::*/', $field->Default))
{
$field->Default = null;
}
}

return $result;
}

Expand Down Expand Up @@ -588,6 +591,7 @@ public function sqlValue($columns, $field_name, $field_value)

break;

case 'timestamp without time zone':
case 'date':
case 'timestamp without time zone':
if (empty($field_value))
Expand Down