From 77697340a42be91777c5a183b9efd7becdaa0b6d Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 23 Jan 2011 20:24:17 +0000 Subject: [PATCH] add DB escape methods for lists git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@711 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- phpbase/db.php | 30 ++++++++++++++++++++++++++++++ 1 files changed, 30 insertions(+), 0 deletions(-) diff --git a/phpbase/db.php b/phpbase/db.php index 628ca7b..879bb55 100644 --- a/phpbase/db.php +++ b/phpbase/db.php @@ -308,6 +308,36 @@ abstract class DbEngine return $r; } + /**escapes a list of strings; uses escapeInt for each element; automatically adds parentheses*/ + public function escapeStringList(array $il) + { + if(count($il)==0)return "(NULL)"; + $r="("; + $b=false; + foreach($il as $i){ + if($b)$r.=","; + else $b=true; + $r.=$this->escapeString($i); + } + $r.=")"; + return $r; + } + + /**escapes a list of values for a specific column; uses escapeInt for each element; automatically adds parentheses*/ + public function escapeListColumn(array $il,$table,$col) + { + if(count($il)==0)return "(NULL)"; + $r="("; + $b=false; + foreach($il as $i){ + if($b)$r.=","; + else $b=true; + $r.=$this->escapeColumn($table,$col,$i); + } + $r.=")"; + return $r; + } + /**escapes strings; the default uses addslashes and encloses the value in ''; it is recommended to overwrite this with the proper escaping procedure for the target DB (false and null are translated to NULL)*/ public function escapeString($s) { -- 1.7.2.5