Skip to content

Commit

Permalink
explicit columns
Browse files Browse the repository at this point in the history
Fix #160
  • Loading branch information
garak committed Mar 7, 2015
1 parent 8f7f225 commit 03768b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Ddeboer/DataImport/Writer/PdoWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function writeItem(array $item)
if (!$this->statement) {

$this->statement = $this->pdo->prepare(
'INSERT INTO '.$this->tableName.' VALUES ('.substr(str_repeat('?,', count($item)), 0, -1).')'
'INSERT INTO '.$this->tableName.'('.implode(',', array_keys($item)).') VALUES ('.substr(str_repeat('?,', count($item)), 0, -1).')'
);

//for PDO objects that do not have exceptions enabled
Expand Down
10 changes: 5 additions & 5 deletions tests/Ddeboer/DataImport/Tests/Writer/PdoWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testValidWriteItem()
{
$writer = new PdoWriter($this->pdo, 'example');
$writer->prepare();
$writer->writeItem(array('foo', 'bar'));
$writer->writeItem(array('a' => 'foo', 'b' => 'bar'));
$writer->finish();

$stmnt = $this->pdo->query('SELECT * FROM `example`');
Expand All @@ -38,9 +38,9 @@ public function testValidWriteMultiple()
{
$writer = new PdoWriter($this->pdo, 'example');
$writer->prepare();
$writer->writeItem(array('foo', 'bar'));
$writer->writeItem(array('cat', 'dog'));
$writer->writeItem(array('ac', 'dc'));
$writer->writeItem(array('a' => 'foo', 'b' => 'bar'));
$writer->writeItem(array('a' => 'cat', 'b' => 'dog'));
$writer->writeItem(array('a' => 'ac', 'b' => 'dc'));
$writer->finish();

$stmnt = $this->pdo->query('SELECT * FROM `example`');
Expand Down Expand Up @@ -110,7 +110,7 @@ public function testFluentInterface()
$writer = new PdoWriter($this->pdo, 'example');

$this->assertSame($writer, $writer->prepare());
$this->assertSame($writer, $writer->writeItem(array('foo', 'bar')));
$this->assertSame($writer, $writer->writeItem(array('a' => 'foo', 'b' => 'bar')));
$this->assertSame($writer, $writer->finish());
}
}

0 comments on commit 03768b1

Please sign in to comment.