Skip to content

Commit

Permalink
fix pgsql for name /w schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jul 11, 2022
1 parent 900887b commit e493d0c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Persistence/Sql/Postgresql/PlatformTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ protected function getCreateAutoincrementSql(Table $table, Column $pkColumn): ar
// else branch should be maybe (because of concurrency) put into after update trigger
// with pure nextval instead of setval with a loop like in Oracle trigger
str_replace('[pk_seq]', '\'' . $pkSeqName . '\'', <<<'EOF'
CREATE OR REPLACE FUNCTION {trigger_func}()
CREATE OR REPLACE FUNCTION {{trigger_func}}()
RETURNS trigger AS $$
DECLARE
atk4__pk_seq_last__ {table}.{pk}%TYPE;
BEGIN
IF (NEW.{pk} IS NULL) THEN
NEW.{pk} := nextval([pk_seq]);
ELSE
SELECT COALESCE(last_value, 0) INTO atk4__pk_seq_last__ FROM {pk_seq};
SELECT COALESCE(last_value, 0) INTO atk4__pk_seq_last__ FROM {{pk_seq}};
IF (atk4__pk_seq_last__ <= NEW.{pk}) THEN
atk4__pk_seq_last__ := setval([pk_seq], NEW.{pk}, true);
END IF;
Expand All @@ -92,7 +92,7 @@ protected function getCreateAutoincrementSql(Table $table, Column $pkColumn): ar
$$ LANGUAGE plpgsql
EOF),
[
'table' => $table->getName(),
'table' => $table->getShortestName($table->getNamespaceName()), // TODO should be schema-qualified
'pk' => $pkColumn->getName(),
'pk_seq' => $pkSeqName,
'trigger_func' => $table->getName() . '_AI_FUNC', // TODO create only one function per schema
Expand All @@ -103,13 +103,13 @@ protected function getCreateAutoincrementSql(Table $table, Column $pkColumn): ar
<<<'EOF'
CREATE TRIGGER {trigger}
BEFORE INSERT OR UPDATE
ON {table}
ON {{table}}
FOR EACH ROW
EXECUTE PROCEDURE {trigger_func}()
EXECUTE PROCEDURE {{trigger_func}}()
EOF,
[
'table' => $table->getName(),
'trigger' => $table->getName() . '_AI_PK',
'trigger' => $table->getShortestName($table->getNamespaceName()) . '_AI_PK',
'trigger_func' => $table->getName() . '_AI_FUNC',
]
)->render()[0];
Expand Down

0 comments on commit e493d0c

Please sign in to comment.