Javascript SQL INSERT 帮助
我有以下代码,它将“任务”插入到具有“任务”值的表中。我正在尝试修改此语句以将多个值插入到多个列中,但由于我不熟悉该格式,因此我似乎无法使其工作。
有人可以告诉我如何修改以插入多个值吗?
var item = this.$.newItem.getValue();
this.$.db.query( 'INSERT INTO tasks ( task ) VALUES ( ? )', { values: [ item ] } );
多谢。
I have the following code which inserts a "task" into a table with a value for the "task". I am trying to modify this statement to insert multiple values into multiple columns, but I cant seem to get it to work since I am unfamiliar with the format.
Can sombody show me how the can be modified to insert multiple values?
var item = this.$.newItem.getValue();
this.$.db.query( 'INSERT INTO tasks ( task ) VALUES ( ? )', { values: [ item ] } );
Thanks alot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设你并不是故意标记这个 MySQL...
但是 - 一个帮助 Enyo DB 查询的有用类是:
https://github.com/onecrayon/database-webos
一种蜡笔的实现。非常适合 Enyo。
I am assuming you didn't mean to tag this MySQL....
However - a useful class for helping out with Enyo DB queries is:
https://github.com/onecrayon/database-webos
One crayon's implementation. Works very nicely for Enyo.
我不确定您是否使用某种库,但如果您使用 SQLite 的标准 Web SQL 接口,则第二个参数是值的数组,而不是像您这样的对象有。所以代码看起来更像
I'm not sure if you're using some kind of library, but if you're using the standard Web SQL interface to SQLite, the second argument is an array of values, not an object like you have. So code looks more like
不知道这个 javascript 实际在做什么使得很难回答这个问题,但足以说明将值插入到 sql 查询中的多个字段中的语法如下所示
INSERT INTO tableName ( col1,col2,coln)值(val1,val2,valn em>)
作为总有根据的猜测,我想说你正在寻找
每个“?”在您的 sql 查询中,您将需要
values
数组中的另一个参数。Not knowing what this javascript is actually doing makes it hard to answer this question, but suffice it to say the syntax for inserting values into multiple fields in a sql query is as follows
INSERT INTO tableName (col1, col2, coln) VALUES (val1, val2, valn)
As a total educated guess, I would say you're looking for
for each "?" in your sql query, you will need another parameter in the
values
array.