Update DB IO classes with better RETURNING data handle
Dropped old insert_id and insert_id_ext and only kepy insert_id_arr. Added insert_id_pk_name to get the inserted pk name. Insert RETURNING also works on non set pk name with RETURNING set Moved the get insert (RETURNING) into method so it can be called from both dbExec and dbExecute flow. Error code 31 is only thrown if no returning is set and insert flow cannot find a primary key for this table Update all old insert_id calls from other classes
This commit is contained in:
@@ -262,10 +262,10 @@ class PgSQL
|
||||
* this only works if db schema is after "no plural names. and pk name is table name + _id
|
||||
* detects schema prefix in table name
|
||||
* @param string $query query string
|
||||
* @param string $pk_name primary key name, if '' then auto detect
|
||||
* @param string|null $pk_name primary key name, if '' then auto detect
|
||||
* @return string|int|false primary key value
|
||||
*/
|
||||
public function __dbInsertId(string $query, string $pk_name)
|
||||
public function __dbInsertId(string $query, ?string $pk_name)
|
||||
{
|
||||
// only if an insert has been done
|
||||
if (preg_match("/^insert /i", $query)) {
|
||||
@@ -280,7 +280,7 @@ class PgSQL
|
||||
$table = $_table;
|
||||
}
|
||||
// no PK name given at all
|
||||
if (!$pk_name) {
|
||||
if (empty($pk_name)) {
|
||||
// if name is plurar, make it singular
|
||||
// if (preg_match("/.*s$/i", $table))
|
||||
// $table = substr($table, 0, -1);
|
||||
|
||||
Reference in New Issue
Block a user