Handle another edge case, where table being handled doesn't have a primary key
This commit is contained in:
parent
0224ccd4cb
commit
58540955e6
@ -182,7 +182,8 @@ function runJavascriptCodeTrigger($functionName, $activeTable, $row) {
|
||||
function updateDatabaseRow($tableName, $originalRow, $newRowValue) {
|
||||
if (empty($originalRow) || empty($newRowValue)) return;
|
||||
$pkColsName = getTblPrimaryKeyColName($tableName);
|
||||
$pkColsValues = array_map(fn($cName) => $originalRow[$cName], $pkColsName);
|
||||
if (empty($pkColsName)) {echo redText("ERROR: No PRIMARY KEY foudn for table: $tableName\n"); return;}
|
||||
$pkColsValues = array_map(fn($cName) => $originalRow[$cName], $pkColsName);
|
||||
|
||||
$setStatements = [];
|
||||
foreach ($newRowValue as $k => $v) {
|
||||
@ -194,12 +195,12 @@ function updateDatabaseRow($tableName, $originalRow, $newRowValue) {
|
||||
foreach ($pkColsName as $k) {
|
||||
$val = is_numeric($originalRow[$k]) ? $originalRow[$k] : "'" . $originalRow[$k] . "'";
|
||||
$whereStatements[] = "$k = $val";
|
||||
}
|
||||
}
|
||||
|
||||
$sql_instruction = "UPDATE $tableName SET " . implode(", ", $setStatements) . " WHERE " . implode(" AND ", $whereStatements);
|
||||
try {sql($sql_instruction);}
|
||||
catch (Exception $e) {
|
||||
echo "ERROR: while trying $sql_instruction\n\n";print_r($e->getMessage());
|
||||
echo redText("ERROR: while trying $sql_instruction\n\n");print_r($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user