这是PhoneGap android的表格:
tx.executeSql("如果不存在则创建表 user_prayers('id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,'prayer_id' TEXT ,'user_id' INTEGER,'date' DATETIME,'status' INTEGER)",[],successCB,错误CB);
并使用循环插入行:
function insertInUserPrayerTable() {
db.transaction(function(tx)
{for(var i = 0;i<5;i++)
{checkedValueofCheckboxInsertArray.push('INSERT INTO user_prayers '
+ '(prayer_id,user_id,date,status)'
+ ' VALUES("'
+ checkedValueofCheckbox[i]
+ '","'
+ window.localStorage
.getItem("userid") + '","'
+ $('#datepicker').val() + '","'
+ statusofNamaz[i] + '");');
console.log("array values:"+checkedValueofCheckboxInsertArray);
}
},errorCB,successCB);
runInsertQuery();
}
function runInsertQuery() {
db
.transaction(
function(tx) {
for (var i = 0; i < checkedValueofCheckboxInsertArray.length; i++) {
tx
.executeSql(
checkedValueofCheckboxInsertArray[i],
[],
successCBrunInsertQuery,
errorCBrunInsertQuery);
}
},errorCB,successCB);
}
$('#showbtn')
.off('click')
.on('click',
function() {
//getRecord();
db
.transaction(
function(tx) {
tx.executeSql("SELECT a.date, COALESCE(a.status,'') AS 'fajr', COALESCE((SELECT b.status FROM user_prayers b WHERE b.date = a.date AND b.id != a.id LIMIT 1),'') AS 'zohar' FROM user_prayers a WHERE user_id='"+window.localStorage.getItem("userid")+"' GROUP BY a.date",[],successCBofselect,errorCBofselect);},errorCB,successCB);
但它没有返回我的状态,而相同的查询在 sql fiddle 中工作正常: