Skip to content

Commit 1706a23

Browse files
author
Raphaël BERGINA
committed
Fixing quotes in array parameters
1 parent 5622f2f commit 1706a23

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/SQLParser/Node/Parameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function toSql(array $parameters = array(), Connection $dbConnection = nu
168168
} else {
169169
if(is_array($parameters[$this->name])){
170170
return '('.implode(',',array_map(function($item) {
171-
return addslashes($this->autoPrepend.$item.$this->autoAppend);
171+
return "'".addslashes($this->autoPrepend.$item.$this->autoAppend)."'";
172172
}, $parameters[$this->name])).')';
173173
} else{
174174
return "'".addslashes($this->autoPrepend.$parameters[$this->name].$this->autoAppend)."'";

tests/Mouf/Database/MagicQueryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public function testStandardSelect()
1818
$sql = 'SELECT * FROM users WHERE name LIKE :name AND company LIKE :company';
1919
$this->assertEquals("SELECT * FROM users WHERE (name LIKE 'foo')", self::simplifySql($magicQuery->build($sql, ['name' => 'foo'])));
2020
$this->assertEquals("SELECT * FROM users WHERE (name LIKE 'foo') AND (company LIKE 'bar')", self::simplifySql($magicQuery->build($sql, ['name' => 'foo', 'company' => 'bar'])));
21+
22+
$sql = 'SELECT * FROM users WHERE status in :status';
23+
$this->assertEquals("SELECT * FROM users WHERE status IN ('2','4')", self::simplifySql($magicQuery->build($sql, ['status' => [2,4]])));
2124
}
2225

2326
/**

0 commit comments

Comments
 (0)