admin管理员组文章数量:1333427
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.
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.
Share Improve this question edited Jul 27, 2011 at 11:30 diagonalbatman 18k3 gold badges33 silver badges31 bronze badges asked Jul 26, 2011 at 14:35 levilevi 25.2k18 gold badges63 silver badges75 bronze badges 7- 3 What abomination of a javascript library lets you perform datbase inserts? – Jamiec Commented Jul 26, 2011 at 14:43
- This is within HP WebOs Enyo framework, Inserting into a local SQLite DB – levi Commented Jul 26, 2011 at 14:46
- Is this websql? If not this is the biggest security risk I have ever seen on stackoverflow. – Caimen Commented Jul 26, 2011 at 14:46
- inserts look like this: INSERT INTO tasks ( task, task_date, remark ) VALUES ( ?,?,? ) – Randy Commented Jul 26, 2011 at 14:46
- @Jamiec, JavaScript is used for more than just client-side web development. Node.js, for example, is a server-side usage of JavaScript. As a language it's very powerful, but you do have to remember to notify people as to what context it's being called in. – zzzzBov Commented Jul 26, 2011 at 14:51
3 Answers
Reset to default 2I am assuming you didn't mean to tag this MySQL....
However - a useful class for helping out with Enyo DB queries is:
https://github./onecrayon/database-webos
One crayon's implementation. Works very nicely for Enyo.
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
db.transaction(
function (transaction) {
transaction.executeSql(
"INSERT OR IGNORE INTO contact (contactId, nameG, nameF, orgContactId, accountId) VALUES (?, ?, ?, ?, ?)",
[contact.contactId, contact.nameG, contact.nameF, contactContactId, contact.accountId],
function (transaction, resultSet) { // SQL INSERT statement success
// do something now that the item has been saved
}, // end statement success callback
function (transaction, sqlError) { // statement fail
// report failed operation
return true; // abort transaction
}
);
} // end transaction function
// no transaction callbacks
); // end transaction call
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
this.$.db.query( 'INSERT INTO tasks ( task, some_other_field ) VALUES ( ?,? )', { values: [ item, some_other_input ] } );
for each "?" in your sql query, you will need another parameter in the values
array.
本文标签: sqliteHelp with Javascript SQL INSERTStack Overflow
版权声明:本文标题:sqlite - Help with Javascript SQL INSERT - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742314473a2451537.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论