Skip to content

Commit 32b0699

Browse files
Update on duplicate key; small fixes
1 parent 82742c5 commit 32b0699

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

QuickBooks/Callbacks/SQL/Callbacks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8097,8 +8097,8 @@ protected static function _deleteChildren($table, $user, $action, $ID, $object,
80978097
{
80988098
$deleted[$key][QUICKBOOKS_TXNLINEID][$arr[QUICKBOOKS_TXNLINEID]] = array(
80998099
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_ID],
8100-
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_USERNAME_ID],
8101-
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_EXTERNAL_ID] );
8100+
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_USERNAME_ID] ?? null,
8101+
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_EXTERNAL_ID] ?? null);
81028102
}
81038103
}
81048104

QuickBooks/Driver/Sql.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3680,10 +3680,6 @@ public function insert($table, $object, $discov_and_resync = true)
36803680
if (!strncmp($field,'qbsql_',6)) {
36813681
$qbsql_fields[] = $field;
36823682
$qbsql_values[] = $this->fmtValue($field,$value);
3683-
if ($field == QUICKBOOKS_DRIVER_SQL_FIELD_ID) {
3684-
$fields[] = $field;
3685-
$values[] = $this->fmtValue($field,$value);
3686-
}
36873683
}
36883684
elseif (array_key_exists($field,$avail)) {
36893685
$fields[] = $field;
@@ -3702,13 +3698,13 @@ public function insert($table, $object, $discov_and_resync = true)
37023698
$errnum = 0;
37033699
$errmsg = '';
37043700

3705-
$sql = "INSERT INTO quickbooks_qbsql (".implode(',',$qbsql_fields).") VALUES (".implode(',',$qbsql_values).")";
3701+
$updatesSql = implode(',',array_map(function($s){return "$s=values($s)";}, $qbsql_fields));
3702+
$sql = "INSERT INTO quickbooks_qbsql (".implode(',',$qbsql_fields).") VALUES (".implode(',',$qbsql_values).") ON DUPLICATE KEY UPDATE $updatesSql";
37063703
if (!$this->_query($sql, $errnum, $errmsg)) return false;
37073704
$qbsql_id = $this->last();
37083705

3709-
$fields[] = 'qbsql_id';
3710-
$values[] = $qbsql_id;
3711-
$sql = "INSERT INTO $table (".implode(',',$fields).") VALUES (".implode(',',$values).")";
3706+
$updatesSql = implode(',',array_map(function($s){return "$s=values($s)";}, $fields));
3707+
$sql = "INSERT INTO $table (".QUICKBOOKS_DRIVER_SQL_FIELD_ID.",".implode(',',$fields).") VALUES ($qbsql_id,".implode(',',$values).") ON DUPLICATE KEY UPDATE $updatesSql";
37123708

37133709
return $this->_query($sql, $errnum, $errmsg);
37143710
}

QuickBooks/Utilities.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static public function actionToObject($action)
762762
{
763763
static $cache = array();
764764

765+
if ($action === null) return null;
766+
765767
if (isset($cache[$action]))
766768
{
767769
//print('returning cached [' . $action . ']' . "\n");

0 commit comments

Comments
 (0)