Skip to content

Commit b0eb45d

Browse files
committed
- Fixed: FS#2165 - Function missing in mysql lib in SVN
- Improved datalog functions.
1 parent 4369ab9 commit b0eb45d

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public function nextRecord() {
143143
public function numRows() {
144144
return $this->queryId->num_rows;
145145
}
146+
147+
public function affectedRows() {
148+
return $this->queryId->affected_rows;
149+
}
146150

147151
// returns mySQL insert id
148152
public function insertID() {
@@ -206,7 +210,7 @@ public function diffrec($record_old, $record_new) {
206210
}
207211

208212
//** Function to fill the datalog with a full differential record.
209-
public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new) {
213+
public function datalogSave($db_table, $action, $primary_field, $primary_id, $record_old, $record_new, $force_update = false) {
210214
global $app,$conf;
211215

212216
// Insert backticks only for incomplete table names.
@@ -216,10 +220,17 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
216220
$escape = '`';
217221
}
218222

219-
$tmp = $this->diffrec($record_old, $record_new);
220-
$diffrec_full = $tmp['diff_rec'];
221-
$diff_num = $tmp['diff_num'];
222-
unset($tmp);
223+
if($force_update == true) {
224+
//* We force a update even if no record has changed
225+
$diffrec_full = array('new' => $record_new,'old' => $record_old);
226+
$diff_num = count($record_new);
227+
} else {
228+
//* get the difference record between old and new record
229+
$tmp = $this->diffrec($record_old, $record_new);
230+
$diffrec_full = $tmp['diff_rec'];
231+
$diff_num = $tmp['diff_num'];
232+
unset($tmp);
233+
}
223234

224235
// Insert the server_id, if the record has a server_id
225236
$server_id = (isset($record_old['server_id']) && $record_old['server_id'] > 0)?$record_old['server_id']:0;
@@ -254,6 +265,8 @@ public function datalogInsert($tablename, $insert_data, $index_field) {
254265
$key_str .= "`".$key ."`,";
255266
$val_str .= "'".$this->quote($val)."',";
256267
}
268+
$key_str = substr($key_str,0,-1);
269+
$val_str = substr($val_str,0,-1);
257270
$insert_data_str = '('.$key_str.') VALUES ('.$val_str.')';
258271
} else {
259272
$insert_data_str = $insert_data;
@@ -272,24 +285,21 @@ public function datalogInsert($tablename, $insert_data, $index_field) {
272285
public function datalogUpdate($tablename, $update_data, $index_field, $index_value, $force_update = false) {
273286
global $app;
274287

275-
if($force_update == true) {
276-
$old_rec = array();
277-
} else {
278-
$old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
279-
}
288+
$old_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
280289

281290
if(is_array($update_data)) {
282291
$update_data_str = '';
283292
foreach($update_data as $key => $val) {
284293
$update_data_str .= "`".$key ."` = '".$this->quote($val)."',";
285294
}
295+
$update_data_str = substr($update_data_str,0,-1);
286296
} else {
287297
$update_data_str = $update_data;
288298
}
289299

290300
$this->query("UPDATE $tablename SET $update_data WHERE $index_field = '$index_value'");
291301
$new_rec = $this->queryOneRecord("SELECT * FROM $tablename WHERE $index_field = '$index_value'");
292-
$this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec);
302+
$this->datalogSave($tablename, 'UPDATE', $index_field, $index_value, $old_rec, $new_rec, $force_update);
293303

294304
return true;
295305
}

0 commit comments

Comments
 (0)