From 15e86875f37d24a6cdcc42698cc858449b43f503 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 10 Apr 2013 20:45:38 +0200 Subject: [PATCH] Fix: sql syntax error --- htdocs/core/lib/admin.lib.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 978f0896f65..f70d3e846cc 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -252,18 +252,20 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker // Ajout trace sur requete (eventuellement a commenter si beaucoup de requetes) if (! $silent) print ''.$langs->trans("Request").' '.($i+1)." sql='".dol_htmlentities($newsql,ENT_NOQUOTES)."'\n"; dol_syslog('Admin.lib::run_sql Request '.($i+1).' sql='.$newsql, LOG_DEBUG); + $sqlmodified=0; // Replace for encrypt data - if (preg_match_all('/__ENCRYPT\(\'([A-Za-z0-9_\"\[\]]+)\'\)__/i',$newsql,$reg)) + if (preg_match_all('/__ENCRYPT\(\'([^\']+)\'\)__/i',$newsql,$reg)) { $num=count($reg[0]); - for($i=0;$i<$num;$i++) + for($j=0;$j<$num;$j++) { - $from = $reg[0][$i]; - $to = $db->encrypt($reg[1][$i],1); + $from = $reg[0][$j]; + $to = $db->encrypt($reg[1][$j],1); $newsql = str_replace($from,$to,$newsql); } + $sqlmodified++; } // Replace for decrypt data @@ -271,12 +273,13 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker { $num=count($reg[0]); - for($i=0;$i<$num;$i++) + for($j=0;$j<$num;$j++) { - $from = $reg[0][$i]; - $to = $db->decrypt($reg[1][$i]); + $from = $reg[0][$j]; + $to = $db->decrypt($reg[1][$j]); $newsql = str_replace($from,$to,$newsql); } + $sqlmodified++; } // Replace __x__ with rowid of insert nb x @@ -294,9 +297,11 @@ function run_sql($sqlfile,$silent=1,$entity='',$usesavepoint=1,$handler='',$oker $from='__'.$cursor.'__'; $to=$listofinsertedrowid[$cursor]; $newsql=str_replace($from,$to,$newsql); - dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG); + $sqlmodified++; } + if ($sqlmodified) dol_syslog('Admin.lib::run_sql New Request '.($i+1).' (replacing '.$from.' to '.$to.') sql='.$newsql, LOG_DEBUG); + $result=$db->query($newsql,$usesavepoint); if ($result) {