Skip to content

Commit 52700df

Browse files
authored
Merge pull request #104 from alpha0010/master
Enable calling set() multiple times for multi inserts
2 parents 5e0a9d3 + 54e2b6d commit 52700df

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/SphinxQL.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,8 +1180,12 @@ public function value($column, $value)
11801180
*/
11811181
public function set($array)
11821182
{
1183-
foreach ($array as $key => $item) {
1184-
$this->value($key, $item);
1183+
if ($this->columns === array_keys($array)) {
1184+
$this->values($array);
1185+
} else {
1186+
foreach ($array as $key => $item) {
1187+
$this->value($key, $item);
1188+
}
11851189
}
11861190

11871191
return $this;

tests/SphinxQL/SphinxQLTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,30 @@ public function testInsert()
201201
->getStored();
202202

203203
$this->assertCount(8, $result);
204+
205+
SphinxQL::create(self::$conn)->insert()
206+
->into('rt')
207+
->set(array(
208+
'id' => 18,
209+
'title' => 'a multi set test',
210+
'content' => 'has text',
211+
'gid' => 9002
212+
))
213+
->set(array(
214+
'id' => 19,
215+
'title' => 'and a',
216+
'content' => 'second set call',
217+
'gid' => 9003
218+
))
219+
->execute();
220+
221+
$result = SphinxQL::create(self::$conn)->select()
222+
->from('rt')
223+
->execute()
224+
->getStored();
225+
226+
$this->assertCount(10, $result);
227+
204228
}
205229

206230
/**

0 commit comments

Comments
 (0)