Class DB IO, fix for trailing ; with RETURNING
If an INSERT query has no RETURNING but ; at the end, the RETURNING was added after the ; The ; is now stripped before adding RETURNING
This commit is contained in:
@@ -85,6 +85,9 @@
|
|||||||
// $status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id");
|
// $status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id");
|
||||||
$status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id, test");
|
$status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id, test");
|
||||||
print "DIRECT MULTIPLE INSERT STATUS: $status | PRIMARY KEYS: ".print_r($basic->insert_id, 1)." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
|
print "DIRECT MULTIPLE INSERT STATUS: $status | PRIMARY KEYS: ".print_r($basic->insert_id, 1)." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
|
||||||
|
// no returning, but not needed ;
|
||||||
|
$status = $basic->db_exec("INSERT INTO foo (test) VALUES ('FOO; TEST ".time()."');");
|
||||||
|
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, 1)."<br>";
|
||||||
|
|
||||||
# db write class test
|
# db write class test
|
||||||
$table = 'foo';
|
$table = 'foo';
|
||||||
|
|||||||
@@ -663,6 +663,8 @@
|
|||||||
}
|
}
|
||||||
if (!preg_match("/ returning /i", $this->query) && $this->pk_name && $this->pk_name != 'NULL')
|
if (!preg_match("/ returning /i", $this->query) && $this->pk_name && $this->pk_name != 'NULL')
|
||||||
{
|
{
|
||||||
|
// check if this query has a ; at the end and remove it
|
||||||
|
$this->query = preg_replace("/(;\s*)$/", '', $this->query);
|
||||||
$this->query .= " RETURNING ".$this->pk_name;
|
$this->query .= " RETURNING ".$this->pk_name;
|
||||||
$this->returning_id = true;
|
$this->returning_id = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user