From 58540955e6f72190723f8c6299ffcdeee8074729 Mon Sep 17 00:00:00 2001 From: git Date: Sat, 21 Jun 2025 18:40:37 +0100 Subject: [PATCH] Handle another edge case, where table being handled doesn't have a primary key --- plt/index.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plt/index.php b/plt/index.php index e160364..8f7e3c3 100755 --- a/plt/index.php +++ b/plt/index.php @@ -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()); } }