Рефакторинг
This commit is contained in:
parent
1b5852cc43
commit
981a1d0f0f
11 changed files with 626 additions and 270 deletions
26
src/Database/IdGenerator.php
Normal file
26
src/Database/IdGenerator.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
class Database_IdGenerator {
|
||||
private $db;
|
||||
|
||||
function __construct(Database $db) {
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
function isBeforeInsert() {
|
||||
return $this->db->isPostgres();
|
||||
}
|
||||
|
||||
function isAfterInsert() {
|
||||
return !$this->db->isPostgres();
|
||||
}
|
||||
|
||||
function getId($seq) {
|
||||
if ($this->db->isPostgres()) {
|
||||
$result = $this->db->fetchOneArray("SELECT nextval('$seq') AS nextval");
|
||||
} else {
|
||||
$result = $this->db->fetchOneArray("SELECT last_insert_rowid() AS nextval");
|
||||
}
|
||||
return intval($result['nextval']);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue