summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2009-08-25 17:53:16 +0000
committerChristian Schneider2009-08-25 17:53:16 +0000
commita04073131d35ba78af4a009c4699cc4895c96f7f (patch)
tree3b7237165e8f067042f8f3b3f38253a59ae1d834
parent21aae88fc189bc2672ef563f6ed7ae42a3b8634e (diff)
downloaditools-a04073131d35ba78af4a009c4699cc4895c96f7f.tar.gz
itools-a04073131d35ba78af4a009c4699cc4895c96f7f.tar.bz2
itools-a04073131d35ba78af4a009c4699cc4895c96f7f.zip
Added array support to NI operator
-rw-r--r--it_dbi.class22
-rwxr-xr-xtests/it_dbi.t7
2 files changed, 21 insertions, 8 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 9e4ca74..c9f2bbb 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -237,7 +237,7 @@ function _set($tags, $allfields = false)
if (substr($field, 0, 1) == '-') # Unquoted value (always added)
$r[] = substr($field, 1)."=$value";
else if ($allfields || ($value !== $this->_data[$field]))
- $r[] = "$field=".(isset($value) ? "'".$this->escape_string($value)."'" : 'NULL');
+ $r[] = "$field=".(isset($value) ? $this->escape_string($value) : 'NULL');
}
return $r ? 'SET '.implode(', ', $r) : '';
@@ -304,18 +304,26 @@ function _where($params = "", $dummy_link = null, $omit_where = false)
$qval = $value;
}
else if (!is_array($value))
- $qval = "'" . $this->escape_string((string)$value) . "'";
+ $qval = $this->escape_string((string)$value);
}
switch ($op)
{
case 'NI':
- $query .= $sep."CONCAT(',',$field,',') LIKE '%,$value,%'";
+ if ($value)
+ {
+ foreach ((array)$value as $val)
+ $parts[] = "CONCAT(',',$field,',') LIKE " . $this->escape_string("%,$val,%");
+
+ $query .= $sep . "(" . join(" OR ", $parts) . ")";
+ }
+ else
+ $query .= $sep . "1";
break;
case 'MATCH':
- $qval = is_array($value) ? join(' ', $value) : $value;
- $query .= $sep . "MATCH ($field) AGAINST ('" . $this->escape_string($qval) . "' IN BOOLEAN MODE)";
+ $qval = join(' ', (array)$value);
+ $query .= "$sep$op ($field) AGAINST (" . $this->escape_string($qval) . " IN BOOLEAN MODE)";
break;
case 'IN':
@@ -329,7 +337,7 @@ function _where($params = "", $dummy_link = null, $omit_where = false)
foreach ($value as $val)
$qvals[] = $this->escape_string($val);
- $query .= "$sep$field $op ('" . join("','", $qvals) . "')"; # null is mapped to ''
+ $query .= "$sep$field $op (" . join(",", $qvals) . ")"; # null is mapped to ''
}
else
$query .= $sep . (($op == 'IN') ? "0" : "1");
@@ -697,7 +705,7 @@ function delete($query = null)
function escape_string($str)
{
$this->_connect();
- return mysql_real_escape_string($str, $this->_link);
+ return "'" . mysql_real_escape_string($str, $this->_link) . "'";
}
diff --git a/tests/it_dbi.t b/tests/it_dbi.t
index faf243d..4404247 100755
--- a/tests/it_dbi.t
+++ b/tests/it_dbi.t
@@ -54,6 +54,11 @@ is(
"select with IN"
);
is(
+ $record->select(array('ID NI' => array(2,3))),
+ 2,
+ "select with NI"
+);
+is(
$record->select(array('ID NOT IN' => array(2,3))),
1,
"select with NOT IN"
@@ -131,7 +136,7 @@ $record->update(array('-x' => 'RAND() * 10'));
isnt(
array($record->_key, $record->x, $record->foo),
array(3, 17, "q'uux"),
- "update"
+ "update with function"
);
$rand = $record->x;