diff --git a/src/TableGateway/Feature/SequenceFeature.php b/src/TableGateway/Feature/SequenceFeature.php index 014171c24a..e77ec42507 100644 --- a/src/TableGateway/Feature/SequenceFeature.php +++ b/src/TableGateway/Feature/SequenceFeature.php @@ -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 { @@ -25,6 +26,11 @@ class SequenceFeature extends AbstractFeature */ protected $sequenceName; + /** + * @var string + */ + protected $schemaName = null; + /** * @var int */ @@ -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(); + } } /** @@ -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; @@ -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;