From 58e644c453a8258ab9c2643cb7c88656a0244dbf Mon Sep 17 00:00:00 2001 From: Loki Date: Fri, 16 Mar 2018 14:01:39 +0300 Subject: [PATCH] fix insert Array into table --- src/Query/Grammar.php | 2 +- tests/ClientTest.php | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Query/Grammar.php b/src/Query/Grammar.php index e0f3178..5257a34 100644 --- a/src/Query/Grammar.php +++ b/src/Query/Grammar.php @@ -34,7 +34,7 @@ public function quote($value) return "'" . $value . "'"; if (is_array($value)) - return "'" . implode("','", $value) . "'"; + return "[" . implode(",", array_map([$this,'quote'], $value)) . "]"; if (null === $value) return ''; diff --git a/tests/ClientTest.php b/tests/ClientTest.php index d8c1404..3826395 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -126,10 +126,10 @@ public function testCreateDropTable() public function testInsertFormatValues() { $faker = Faker\Factory::create(); - $columns = ['RowId', 'RowDate', 'RowString']; + $columns = ['RowId', 'RowDate', 'RowString','RowStringArray']; $data = [ - [$id1 = $faker->randomDigitNotNull, $date1 = $faker->date, $string1 = $faker->word], - [$id2 = $faker->randomDigitNotNull, $date2 = $faker->date, $string2 = $faker->word], + [$id1 = $faker->randomDigitNotNull, $date1 = $faker->date, $string1 = $faker->word, $words1 = [$faker->word,$faker->word]], + [$id2 = $faker->randomDigitNotNull, $date2 = $faker->date, $string2 = $faker->word, $words2 = [$faker->word,$faker->word]], ]; $this->client->insert($this->tablename, $columns, $data); @@ -140,11 +140,10 @@ public function testInsertFormatValues() $all = $statement->fetchAll(); $first = current($all); $this->assertEquals($id1, $first->RowId); - + $this->assertEquals($words1, $first->RowStringArray); $last = end($all); $this->assertEquals($id2, $last->RowId); - - + $this->assertEquals($words2, $last->RowStringArray); }