Commit 7f7a425c authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-435'

parents 89c3e54c 512f0018
......@@ -130,11 +130,13 @@ 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)
);
$expandStr = implode(", ", array_fill(0, $count, "?"));
$expandStr = $count ? implode(", ", array_fill(0, $count, "?")) : 'NULL';
$query = substr($query, 0, $needlePos) . $expandStr . substr($query, $needlePos + 1);
$paramOffset += ($count - 1); // Grows larger by number of parameters minus the replaced needle.
......@@ -164,7 +166,7 @@ class SQLParserUtils
}
$count = count($value);
$expandStr = $count > 0 ? implode(', ', array_fill(0, $count, '?')) : '?';
$expandStr = $count > 0 ? implode(', ', array_fill(0, $count, '?')) : 'NULL';
foreach ($value as $val) {
$paramsOrd[] = $val;
......@@ -197,4 +199,4 @@ class SQLParserUtils
return $fragments[1];
}
}
\ No newline at end of file
}
......@@ -548,6 +548,18 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
}
/**
* @group DBAL-435
*/
public function testEmptyParameters()
{
$sql = "SELECT * FROM fetch_table WHERE test_int IN (?)";
$stmt = $this->_conn->executeQuery($sql, array(array()), array(\Doctrine\DBAL\Connection::PARAM_INT_ARRAY));
$rows = $stmt->fetchAll();
$this->assertEquals(array(), $rows);
}
private function setupFixture()
{
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
......
......@@ -108,21 +108,21 @@ SQLDATA
array(1, 2, 3, 4, 5),
array(\PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT, \PDO::PARAM_INT)
),
// Positional : Empty "integer" array DDC-1978
// Positional: Empty "integer" array DDC-1978
array(
"SELECT * FROM Foo WHERE foo IN (?)",
array('foo'=>array()),
array('foo'=>Connection::PARAM_INT_ARRAY),
'SELECT * FROM Foo WHERE foo IN (?)',
array(array()),
array(Connection::PARAM_INT_ARRAY),
'SELECT * FROM Foo WHERE foo IN (NULL)',
array(),
array()
),
// Positional : Empty "str" array DDC-1978
// Positional: Empty "str" array DDC-1978
array(
"SELECT * FROM Foo WHERE foo IN (?)",
array('foo'=>array()),
array('foo'=>Connection::PARAM_STR_ARRAY),
'SELECT * FROM Foo WHERE foo IN (?)',
array(array()),
array(Connection::PARAM_STR_ARRAY),
'SELECT * FROM Foo WHERE foo IN (NULL)',
array(),
array()
),
......@@ -145,7 +145,6 @@ SQLDATA
array(1,'Some String'),
array(\PDO::PARAM_INT, \PDO::PARAM_STR)
),
// Named parameters : Very simple with one needle
array(
"SELECT * FROM Foo WHERE foo IN (:foo)",
......@@ -224,7 +223,7 @@ SQLDATA
"SELECT * FROM Foo WHERE foo IN (:foo)",
array('foo'=>array()),
array('foo'=>Connection::PARAM_INT_ARRAY),
'SELECT * FROM Foo WHERE foo IN (?)',
'SELECT * FROM Foo WHERE foo IN (NULL)',
array(),
array()
),
......@@ -233,7 +232,7 @@ SQLDATA
"SELECT * FROM Foo WHERE foo IN (:foo) OR bar IN (:bar)",
array('foo'=>array(), 'bar'=>array()),
array('foo'=>Connection::PARAM_STR_ARRAY, 'bar'=>Connection::PARAM_STR_ARRAY),
'SELECT * FROM Foo WHERE foo IN (?) OR bar IN (?)',
'SELECT * FROM Foo WHERE foo IN (NULL) OR bar IN (NULL)',
array(),
array()
),
......
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