mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
Adding the sql_in_set function which should give us a bit of a performance improvement for queries using IN with just one value
git-svn-id: file:///svn/phpbb/trunk@6261 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
7508b00978
commit
d8af8223cd
1 changed files with 43 additions and 0 deletions
|
@ -285,6 +285,49 @@ class dbal
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sql_in_set($field, $array)
|
||||||
|
{
|
||||||
|
if (!sizeof($array))
|
||||||
|
{
|
||||||
|
trigger_error('No values specified for SQL IN comparison', E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bitfield = (strpos($field, 'bitfield') !== false);
|
||||||
|
|
||||||
|
$values = array();
|
||||||
|
foreach ($array as $var)
|
||||||
|
{
|
||||||
|
if (is_null($var))
|
||||||
|
{
|
||||||
|
$values[] = 'NULL';
|
||||||
|
}
|
||||||
|
else if (is_string($var))
|
||||||
|
{
|
||||||
|
if (!$bitfield)
|
||||||
|
{
|
||||||
|
$values[] = "'" . $this->sql_escape($var) . "'";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$values[] = $this->sql_escape_binary($var);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$values[] = (is_bool($var)) ? intval($var) : $var;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sizeof($values) == 1)
|
||||||
|
{
|
||||||
|
return $field . ' = ' . $values[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $field . ' IN (' . implode(',', $values) . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function sql_escape_binary($msg)
|
function sql_escape_binary($msg)
|
||||||
{
|
{
|
||||||
return "'" . $this->sql_escape($msg) . "'";
|
return "'" . $this->sql_escape($msg) . "'";
|
||||||
|
|
Loading…
Add table
Reference in a new issue