Skip to content

Commit

Permalink
fix: check against correct identity flags when using IDENTITY_INSERT …
Browse files Browse the repository at this point in the history
…for sql server
  • Loading branch information
ikkez committed Feb 19, 2022
1 parent cdd878d commit 8db6bfe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ final class Base extends Prefab implements ArrayAccess {
//@{ Framework details
const
PACKAGE='Fat-Free Framework',
VERSION='3.8.0-Release';
VERSION='3.8.1-Dev';
//@}

//@{ HTTP status codes (RFC 2616)
Expand Down
8 changes: 6 additions & 2 deletions db/sql/mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ function insert() {
$values='';
$filter='';
$pkeys=[];
$aikeys=[];
$nkeys=[];
$ckeys=[];
$inc=NULL;
Expand All @@ -449,6 +450,9 @@ function insert() {
unset($field);
}
foreach ($this->fields as $key=>&$field) {
if ($field['auto_inc']) {
$aikeys[] = $key;
}
if ($field['pkey']) {
$field['previous']=$field['value'];
if (!$inc && empty($field['value']) &&
Expand All @@ -469,7 +473,7 @@ function insert() {
}
unset($field);
}
if ($fields) {
if ($fields) {
$add=$aik='';
if ($this->engine=='pgsql' && !empty($pkeys)) {
$names=array_keys($pkeys);
Expand All @@ -478,7 +482,7 @@ function insert() {
}
$lID=$this->db->exec(
(preg_match('/mssql|dblib|sqlsrv/',$this->engine) &&
array_intersect(array_keys($pkeys),$ckeys)?
array_intersect(array_keys($aikeys),$ckeys)?
'SET IDENTITY_INSERT '.$this->table.' ON;':'').
'INSERT INTO '.$this->table.' ('.$fields.') '.
'VALUES ('.$values.')'.$add,$args
Expand Down

0 comments on commit 8db6bfe

Please sign in to comment.