catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

Sqlite - insert multiple items - correct sql query in debug but throws error on insert #658

Closed thureos closed 7 years ago

thureos commented 7 years ago

Hi,

I have this table on a sqlite db

CREATE TABLE "dependencies" ("sourcetype" VARCHAR NOT NULL , "sourceid" INTEGER NOT NULL , "targettype" VARCHAR NOT NULL , "targetid" INTEGER NOT NULL )

if I run this

        $sqlite = new Medoo([
            'database_type' => 'sqlite',
            'database_file' => 'db/db.sqlite',
        ]);

        $sqlite->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        //dumpJsonToFile('dependencies.json', $dependencies);
        $test = 
        [
            [
                'sourcetype' => '1',
                'sourceid' => '1',
                'targettype' => '1',
                'targetid' => '1',
            ],
            [
                'sourcetype' => '2',
                'sourceid' => '2',
                'targettype' => '2',
                'targetid' => '2',
            ],

        ];

        $sqlite->debug()->insert('dependencies', $test);
        $sqlite->insert('dependencies', $test);

I got this

INSERT INTO "dependencies" ("sourcetype", "sourceid", "targettype", "targetid") VALUES ('1', '1', '1', '1'), ('2', '2', '2', '2')
PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 near ",": syntax error' in /PATH/vendor/catfan/medoo/src/Medoo.php:299

If you run the command it works but when you run it directly it throws an error.

Thanks!

catfan commented 7 years ago

What's your SQLite version? If you using 3.7.11 or above, it should be supported.

thureos commented 7 years ago

3.6.20 turns out that the server I'm working on is pretty old so... Thanks!