Skip to content

Commit

Permalink
Update on duplicate key; small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mc2contributor committed Jan 9, 2024
1 parent a844fac commit c7ce2bf
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions QuickBooks/Callbacks/SQL/Callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8097,8 +8097,8 @@ protected static function _deleteChildren($table, $user, $action, $ID, $object,
{
$deleted[$key][QUICKBOOKS_TXNLINEID][$arr[QUICKBOOKS_TXNLINEID]] = array(
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_ID],
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_USERNAME_ID],
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_EXTERNAL_ID] );
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_USERNAME_ID] ?? null,
$arr[QUICKBOOKS_DRIVER_SQL_FIELD_EXTERNAL_ID] ?? null);
}
}

Expand Down
12 changes: 4 additions & 8 deletions QuickBooks/Driver/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -3680,10 +3680,6 @@ public function insert($table, $object, $discov_and_resync = true)
if (!strncmp($field,'qbsql_',6)) {
$qbsql_fields[] = $field;
$qbsql_values[] = $this->fmtValue($field,$value);
if ($field == QUICKBOOKS_DRIVER_SQL_FIELD_ID) {
$fields[] = $field;
$values[] = $this->fmtValue($field,$value);
}
}
elseif (array_key_exists($field,$avail)) {
$fields[] = $field;
Expand All @@ -3702,13 +3698,13 @@ public function insert($table, $object, $discov_and_resync = true)
$errnum = 0;
$errmsg = '';

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

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

return $this->_query($sql, $errnum, $errmsg);
}
Expand Down
2 changes: 2 additions & 0 deletions QuickBooks/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ static public function actionToObject($action)
{
static $cache = array();

if ($action === null) return null;

if (isset($cache[$action]))
{
//print('returning cached [' . $action . ']' . "\n");
Expand Down

0 comments on commit c7ce2bf

Please sign in to comment.