Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Sources/Db/APIs/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,30 +468,30 @@ public function insert(string $method, string $table, array $columns, array $dat
}
// the inserted value already exists we need to find the pk
else {
$where_string = '';
$where_string = [];

$count2 = count($keys);

for ($x = 0; $x < $count2; $x++) {
$keyPos = array_search($keys[$x], array_keys($columns));

$where_string .= $keys[$x] . ' = ' . $data[$i][$keyPos];

if (($x + 1) < $count2) {
$where_string .= ' AND ';
foreach ($columns as $column_name => $type) {
if (str_contains($type, 'string-')) {
$where_string[] = $column_name . ' = ' . sprintf('SUBSTRING({string:%1$s}, 1, ' . substr($type, 7) . ')', $column_name);
} else {
$where_string[] = $column_name . ' = ' . sprintf('{%1$s:%2$s}', $type, $column_name);
}
}

$where_string = implode(' AND ', $where_string);

$request = $this->query(
'',
'SELECT `' . $keys[0] . '` FROM ' . $table . '
WHERE ' . $where_string . ' LIMIT 1',
[],
'SELECT ' . $keys[0] . '
FROM ' . $table . '
WHERE ' . $where_string . '
LIMIT 1',
array_combine($indexed_columns, $data[$i]),
);

if ($request !== false && $this->num_rows($request) == 1) {
$row = $this->fetch_assoc($request);
$ai = $row[$keys[0]];
$ai = (int) $row[$keys[0]];
}
}

Expand Down
Loading