2

If I try to execute the following sql command from Flex (ActionScript) code:

INSERT INTO table_name (field1, field2) VALUES (1, 0), (2, 1), (3, 1), (4, 0)

i'm getting the following error:

SQLError: 'Error #3115: SQL Error.', details:'near ',': syntax error', operation:'execute', detailID:'2003'
    at flash.data::SQLStatement/internalExecute()
    at flash.data::SQLStatement/execute()

If I try the same for only one value pair, it works fine:

INSERT INTO table_name (field1, field2) VALUES (15, 66)

SQLite was supposed to support multiple row inserts, right? I tried to copy 1st generated SQL statement to SQLite Expert and paste it into it's SQL tab and it also works fine, populating all the pairs to the table.

What am I doing wrong? Thanks.

bocko
  • 328
  • 6
  • 16
  • possible duplicate of [Is it possible to insert multiple rows at a time in an SQLite database?](http://stackoverflow.com/questions/1609637/is-it-possible-to-insert-multiple-rows-at-a-time-in-an-sqlite-database) – Raptor Aug 15 '13 at 09:55

1 Answers1

3

The syntax for SQL-lite is different then other "sql" syntax such as the one you have written above. The syntax for what you try to accomplish in SQL-lite is:

 INSERT INTO 'table_name'
      SELECT '1' AS 'field1', '0' AS 'field2'
UNION SELECT '2', '1'
UNION SELECT '3', '1'
UNION SELECT '4', '0'
John Snow
  • 4,954
  • 3
  • 31
  • 43
  • Worked like a charm. Thank you very much John Snow. (And beware - the winter is coming.) ;) – bocko Aug 15 '13 at 10:05
  • No problem, I've had this problem myself so recognized it :) glad I could help – John Snow Aug 15 '13 at 10:09
  • But still - my syntax WORKS in SQLite database - tried it in SQLite Expert, as I mentioned. It just doesn't work in AIR runtime version of SQLite... – bocko Aug 15 '13 at 10:15