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
13 changes: 13 additions & 0 deletions lib/Adapter/PgsqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ private function get_sequence_name(string $table, string $column_name): string
return "{$table}_{$column_name}_seq";
}

public function buildInsert(string $table, string $keys, array $sequence): string
{
if ($sequence) {
$sql =
"INSERT INTO $table($keys," . $this->quote_name($sequence[0]) .
') VALUES(?,' . $this->next_sequence_value($sequence[1]) . ')';
} else {
$sql = parent::buildInsert($table, $keys, $sequence);
}

return $sql;
}

public function init_sequence_name(Table $table): string
{
$table->sequence = $table->class->getStaticPropertyValue('sequence') ??
Expand Down
8 changes: 8 additions & 0 deletions lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ public function next_sequence_value(string $sequence_name): ?string
return null;
}

/**
* @param array<string> $sequence
*/
public function buildInsert(string $table, string $keys, array $sequence): string
{
return "INSERT INTO $table($keys) VALUES(?)";
}

/**
* Quote a name like table names and field names.
*
Expand Down
9 changes: 1 addition & 8 deletions lib/SQLBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,7 @@ private function build_delete(): string
private function build_insert(): string
{
$keys = join(',', $this->quoted_key_names());

if ($this->sequence) {
$sql =
"INSERT INTO $this->table($keys," . $this->connection->quote_name($this->sequence[0]) .
') VALUES(?,' . $this->connection->next_sequence_value($this->sequence[1]) . ')';
} else {
$sql = "INSERT INTO $this->table($keys) VALUES(?)";
}
$sql = $this->connection->buildInsert($this->table, $keys, $this->sequence);

$e = new WhereClause($sql, [array_values($this->data)]);

Expand Down