Commit d7032199 authored by Lars Strojny's avatar Lars Strojny Committed by Benjamin Eberlei

Fixing issue when number of positional parameters != number of given types

parent 17c1ee56
......@@ -80,7 +80,7 @@ class SQLParserUtils
* @param string $query The SQL query to execute.
* @param array $params The parameters to bind to the query.
* @param array $types The types the previous parameters are in.
*
*
* @return array
*/
static public function expandListParameters($query, $params, $types)
......@@ -103,7 +103,7 @@ class SQLParserUtils
$arrayPositions[$name] = false;
}
if (( ! $arrayPositions && $isPositional) || (count($params) != count($types))) {
if (( ! $arrayPositions && $isPositional)) {
return array($query, $params, $types);
}
......@@ -130,7 +130,9 @@ class SQLParserUtils
$types = array_merge(
array_slice($types, 0, $needle),
array_fill(0, $count, $types[$needle] - Connection::ARRAY_PARAM_OFFSET), // array needles are at PDO::PARAM_* + 100
$count ?
array_fill(0, $count, $types[$needle] - Connection::ARRAY_PARAM_OFFSET) : // array needles are at PDO::PARAM_* + 100
array(),
array_slice($types, $needle + 1)
);
......@@ -157,9 +159,9 @@ class SQLParserUtils
$pos += $queryOffset;
$queryOffset -= ($paramLen - 1);
$paramsOrd[] = $value;
$typesOrd[] = $types[$paramName];
$typesOrd[] = isset($types[$paramName]) ? $types[$paramName] : \PDO::PARAM_STR;
$query = substr($query, 0, $pos) . '?' . substr($query, ($pos + $paramLen));
continue;
}
......@@ -197,4 +199,4 @@ class SQLParserUtils
return $fragments[1];
}
}
\ No newline at end of file
}
......@@ -237,6 +237,22 @@ SQLDATA
array(),
array()
),
array(
"SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar OR baz = :baz",
array('foo' => array(1, 2), 'bar' => 'bar', 'baz' => 'baz'),
array('foo' => Connection::PARAM_INT_ARRAY, 'baz' => 'string'),
'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ? OR baz = ?',
array(1, 2, 'bar', 'baz'),
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR, 'string')
),
array(
"SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar",
array('foo' => array(1, 2), 'bar' => 'bar'),
array('foo' => Connection::PARAM_INT_ARRAY),
'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?',
array(1, 2, 'bar'),
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_STR)
),
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment