如何处理PhoneGap sql存储结果?
在 PhoneGap API http://docs.phonegap.com/en /1.1.0/phonegap_storage_storage.md.html#存储 有一个 SQLResultSet 示例说明如何处理 sql SELECT 结果..现在
在我的代码中我有类似这样的
id=17
if(recordExists(id)){
.. do something
}
recordExists 函数正在本地数据库中检查以查看记录是否存在。如何从此函数返回真/假结果?以便可以在条件内使用
function recordExists(id){
try {
mydb.transaction(
function(transaction) {
transaction.executeSql(
'SELECT id FROM mytable WHERE id='+id, [],null,null);
});
} catch(e) {
alert("Problem : " + e.message);
return;
}
}
通常在PG示例中都有回调函数。显然我无法从回调函数返回结果。有没有一种方法可以像在 PHP 中一样使用它,
$result = recordExists();
我认为一种可能的解决方案是在应用程序初始化时选择所有记录到一个变量,然后 recordExists 函数将对其进行操作。但我更愿意在这个表上使用 sql 进行操作..
请告知
In the PhoneGap API http://docs.phonegap.com/en/1.1.0/phonegap_storage_storage.md.html#Storage
There is a SQLResultSet example of how to handle sql SELECT results.. now
In my code I have something like this
id=17
if(recordExists(id)){
.. do something
}
recordExists function is checking within local db to see if the record exists. How can I return a true/false result from this function? so that it can be used within condition
function recordExists(id){
try {
mydb.transaction(
function(transaction) {
transaction.executeSql(
'SELECT id FROM mytable WHERE id='+id, [],null,null);
});
} catch(e) {
alert("Problem : " + e.message);
return;
}
}
Normally in PG examples there are callback functions. Obviously I can't return a result from the callback function. Is there a way to use it as in PHP where you would have something like
$result = recordExists();
One possible solution i see as a workaround is on app initialization select all records to a variable and recordExists function would operate on it. But i would prefer to operate with sql on this table instead..
Please advise
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理论上你可以将“做某事”放在回调函数中。
You could theoretically put the "do something" in the callback function.