1.本人工做中的一點心得,就不整理了,直接拷貝在此,後面借鑑javascript
var offsetNumber; var db = openDatabase('users', '1.0', 'users', 1024 * 1024 * 1024); //db.transaction(function (context) { // //context.executeSql('DROP TABLE IF EXISTS messages'); // context.executeSql('CREATE TABLE IF NOT EXISTS messages (id unique, chat_type,timestamp,me,msg,other)'); // context.executeSql('INSERT INTO messages VALUES (?,?,?,?,?,?)',[now,type,now,$rootScope.User_Name_test,message,username]); //}); db.transaction(function (context) { //context.executeSql('DELETE FROM messages'); context.executeSql('SELECT count(id) AS CustomerNilsen FROM messages WHERE (other=? OR (me=? AND other=?)) ', [friendName,friendName,$rootScope.User_Name_test], function (context, results) { //console.log(results.rows.item(0).CustomerNilsen); offsetNumber = results.rows.item(0).CustomerNilsen-retNumber; console.log('number='+retNumber+'---offsetNumber=',offsetNumber); context.executeSql('SELECT * FROM messages WHERE (other=? OR (me=? AND other=?)) LIMIT ?,? ', [friendName,friendName,$rootScope.User_Name_test,offsetNumber,retNumber], function (context, results) { //context.executeSql('SELECT * FROM messages WHERE (other=? OR (me=? AND other=?)) AND id>?', [friendName,friendName,$rootScope.User_Name_test,time], function (context, results) { //console.log(context) console.log(results); var len = results.rows.length, i; //console.log('Got '+len+' rows.'); for (i = 0; i < len; i++){ //console.log('id: '+results.rows.item(i).id); //console.log('chat_type: '+results.rows.item(i).chat_type); //console.log('timestamp: '+results.rows.item(i).timestamp); //console.log('from: '+results.rows.item(i).me); //console.log('msg: '+results.rows.item(i).msg); //console.log('to: '+results.rows.item(i).other); }); }); });