Web SQL insert data into multiple rows

拈花ヽ惹草 提交于 2019-12-24 04:09:31

问题


I've tried to insert variables into multiple rows at once in Web SQL database but with all known to me methods I'm getting errors:

("INSERT INTO tab (a,b) VALUES (?,?),(?,?)",[v1,v2,v3,v4])
>> could not prepare statement (1 near ",": syntax error)

("INSERT INTO tab (a,b) VALUES (?,?,?,?)",[v1,v2,v3,v4])
>> could not prepare statement (1 4 values for 2 columns)

("INSERT INTO tab (a,b) VALUES (?,?)",[v1,v2,v3,v4])
>> number of '?' does not match arguments count

Which one is correct for Web SQL and where is my mistake?


回答1:


As table tab has two columns you can specify only two values to be inserted as a row not 4. Following query will work:

("INSERT INTO tab (a,b) VALUES (?,?)",[v1,v2])

You can execute this query multiple times in a single transaction to add multiple rows to improve performance of overall query and ensure integrity. Hope this helps!!!



来源:https://stackoverflow.com/questions/19477840/web-sql-insert-data-into-multiple-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!