Handle another edge case, where table being handled doesn't have a primary key
This commit is contained in:
parent
0224ccd4cb
commit
58540955e6
@ -182,6 +182,7 @@ function runJavascriptCodeTrigger($functionName, $activeTable, $row) {
|
|||||||
function updateDatabaseRow($tableName, $originalRow, $newRowValue) {
|
function updateDatabaseRow($tableName, $originalRow, $newRowValue) {
|
||||||
if (empty($originalRow) || empty($newRowValue)) return;
|
if (empty($originalRow) || empty($newRowValue)) return;
|
||||||
$pkColsName = getTblPrimaryKeyColName($tableName);
|
$pkColsName = getTblPrimaryKeyColName($tableName);
|
||||||
|
if (empty($pkColsName)) {echo redText("ERROR: No PRIMARY KEY foudn for table: $tableName\n"); return;}
|
||||||
$pkColsValues = array_map(fn($cName) => $originalRow[$cName], $pkColsName);
|
$pkColsValues = array_map(fn($cName) => $originalRow[$cName], $pkColsName);
|
||||||
|
|
||||||
$setStatements = [];
|
$setStatements = [];
|
||||||
@ -199,7 +200,7 @@ function updateDatabaseRow($tableName, $originalRow, $newRowValue) {
|
|||||||
$sql_instruction = "UPDATE $tableName SET " . implode(", ", $setStatements) . " WHERE " . implode(" AND ", $whereStatements);
|
$sql_instruction = "UPDATE $tableName SET " . implode(", ", $setStatements) . " WHERE " . implode(" AND ", $whereStatements);
|
||||||
try {sql($sql_instruction);}
|
try {sql($sql_instruction);}
|
||||||
catch (Exception $e) {
|
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