Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Adding schema for Postgres #378

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions src/TableGateway/Feature/SequenceFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Zend\Db\Sql\Insert;
use Zend\Db\Adapter\Driver\ResultInterface;
use Zend\Db\Adapter\Driver\StatementInterface;
use Zend\Db\Sql\TableIdentifier;

class SequenceFeature extends AbstractFeature
{
Expand All @@ -25,6 +26,11 @@ class SequenceFeature extends AbstractFeature
*/
protected $sequenceName;

/**
* @var string
*/
protected $schemaName = null;

/**
* @var int
*/
Expand All @@ -39,6 +45,11 @@ public function __construct($primaryKeyField, $sequenceName)
{
$this->primaryKeyField = $primaryKeyField;
$this->sequenceName = $sequenceName;

if ($sequenceName instanceof TableIdentifier) {
$this->sequenceName = $sequenceName->getTable();
$this->schemaName = $sequenceName->getSchema();
}
}

/**
Expand Down Expand Up @@ -90,6 +101,9 @@ public function nextSequenceId()
break;
case 'PostgreSQL':
$sql = 'SELECT NEXTVAL(\'"' . $this->sequenceName . '"\')';
if ($this->schemaName !== null) {
$sql = 'SELECT NEXTVAL(\'"' . $this->schemaName . '"."' . $this->sequenceName . '"\')';
}
break;
default:
return;
Expand Down Expand Up @@ -118,6 +132,9 @@ public function lastSequenceId()
break;
case 'PostgreSQL':
$sql = 'SELECT CURRVAL(\'' . $this->sequenceName . '\')';
if ($this->schemaName !== null) {
$sql = 'SELECT CURRVAL(\'"' . $this->schemaName . '"."' . $this->sequenceName . '"\')';
}
break;
default:
return;
Expand Down