dblayeroo: in isert, return the primary key if the provided value is not autoincrement field with valid value
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3920 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -2765,12 +2765,6 @@ class dblayeroo
|
||||
}
|
||||
$this->debugLog ("Entering createRequest ()");
|
||||
$sql = $this->createRequest ();
|
||||
if ($this->driver === "pgsql" && $this->command === "INSERT")
|
||||
{
|
||||
// PgSQL doesn't support the lastInsertId if there is no autoincrement
|
||||
// field. Will return the primary key
|
||||
$sql .= " RETURNING ".$this->sep.$this->primary.$this->sep;
|
||||
}
|
||||
$this->debugLog ("Entering prepareRequest (XXX, ",false,")");
|
||||
$st = $this->prepareRequest ($sql, false);
|
||||
$this->debugLog ("'",$this->getDisplayQuery (),"'");
|
||||
@@ -2851,8 +2845,22 @@ class dblayeroo
|
||||
}
|
||||
return $result;
|
||||
case "INSERT":
|
||||
// If the primary key is not autoincrement, return the provided value if
|
||||
// exists
|
||||
if (! in_array ("autoincrement", $this->fields[$this->primary]) &&
|
||||
key_exists ($this->primary, $this->setValues))
|
||||
return $this->setValues[$this->primary];
|
||||
|
||||
// If the primary key is autoincrement and the provided value is not null
|
||||
// Return it
|
||||
if (in_array ("autoincrement", $this->fields[$this->primary]) &&
|
||||
key_exists ($this->primary, $this->setValues) &&
|
||||
$this->setValues[$this->primary] !== null)
|
||||
return $this->setValues[$this->primary];
|
||||
|
||||
// If the primary key is autoincrement and the provided value is null or
|
||||
// not provided, return the autoincremented value
|
||||
// PostGres need the name of the column autoincrement to return something
|
||||
// If there is no autoincrement column, do not request the lastInsertId
|
||||
$autoInc = null;
|
||||
if ($this->driver === "pgsql")
|
||||
{
|
||||
@@ -2866,13 +2874,6 @@ class dblayeroo
|
||||
}
|
||||
if ($autoInc !== null)
|
||||
$autoInc = $this->table."_${col}_seq";
|
||||
else
|
||||
{
|
||||
$this->debugLog ("INSERT: PgSQL INSERT without Autoincrement. ".
|
||||
"Return the PK value defined in RETURN part");
|
||||
$result = $st->fetch (PDO::FETCH_ASSOC);
|
||||
return $result[$this->primary];
|
||||
}
|
||||
}
|
||||
$this->debugLog ("INSERT: lastInsertId=",
|
||||
self::$instance[$this->dsn]->lastInsertId ($autoInc));
|
||||
|
||||
Reference in New Issue
Block a user