Skip to content

Commit ee260d7

Browse files
committed
Extended datalogUpdate and datalogInsert function in mysql library so that insert_data and update_data arguments can be passed as array too.
1 parent b673442 commit ee260d7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,21 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
286286
//** Inserts a record and saves the changes into the datalog
287287
public function datalogInsert($tablename, $insert_data, $index_field) {
288288
global $app;
289+
290+
if(is_array($insert_data)) {
291+
$key_str = '';
292+
$val_str = '';
293+
foreach($insert_data as $key => $val) {
294+
$key_str .= "`".$key ."`,";
295+
$val_str .= "'".$this->quote($val)."',";
296+
}
297+
$insert_data_str = '('.$key_str.') VALUES ('.$val_str.')';
298+
} else {
299+
$insert_data_str = $insert_data;
300+
}
289301

290302
$old_rec = array();
291-
$this->query("INSERT INTO $tablename $insert_data");
303+
$this->query("INSERT INTO $tablename $insert_data_str");
292304
$index_value = $this->insertID();
293305
$new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
294306
$this->datalogSave($tablename, 'INSERT', $index_field, $index_value, $old_rec, $new_rec);
@@ -298,13 +310,23 @@ public function datalogInsert($tablename, $insert_data, $index_field) {
298310

299311
//** Updates a record and saves the changes into the datalog
300312
public function datalogUpdate($tablename, $update_data, $index_field, $index_value, $force_update = false) {
301-
global $app;
313+
global $app;
302314

303315
if($force_update == true) {
304316
$old_rec = array();
305317
} else {
306318
$old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
307319
}
320+
321+
if(is_array($update_data)) {
322+
$update_data_str = '';
323+
foreach($update_data as $key => $val) {
324+
$update_data_str .= "`".$key ."` = '".$this->quote($val)."',";
325+
}
326+
} else {
327+
$update_data_str = $update_data;
328+
}
329+
308330
$this->query("UPDATE $tablename SET $update_data WHERE $index_field = '$index_value'");
309331
$new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
310332
$this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec);

0 commit comments

Comments
 (0)