Handle another edge case, where table being handled doesn't have a primary key

This commit is contained in:
git 2025-06-21 18:40:37 +01:00
parent 0224ccd4cb
commit 58540955e6

View File

@ -182,6 +182,7 @@ function runJavascriptCodeTrigger($functionName, $activeTable, $row) {
function updateDatabaseRow($tableName, $originalRow, $newRowValue) {
if (empty($originalRow) || empty($newRowValue)) return;
$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);
$setStatements = [];
@ -199,7 +200,7 @@ function updateDatabaseRow($tableName, $originalRow, $newRowValue) {
$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());
}
}