您可以使用 JavaScript 从 SQLite 数据库返回 SQLResultSet 吗?

发布于 2024-10-01 19:06:53 字数 630 浏览 5 评论 0原文

我正在尝试创建一个小插件,使使用 SQLite 数据库变得更加容易。除了从数据库中选择数据之外,我已经有了基本的 CRUD 功能。

我想从executeSql函数返回选定的数据,但似乎我所能做的就是调用另一个方法,而不仅仅是返回数据。

所以我想做的是:

var data = $(window).dbPlugin( 'select', '*', 'tableName', 'conditions' );

然后我想使用“data”变量作为查询中的 SQLResultSet。但是,该事务似乎只允许我调用数据处理程序方法,而不仅仅是返回结果。

testDB.transaction(  
    function ( transaction ) {  
        transaction.executeSql( sql, [], dataHandler, errorHandler);  
    }  
);

function dataHandler( transaction, results ) {
    // Now I can work with the "results" as the SQLResultSet
}

有什么想法如何返回选定的数据或者是否可能?

I'm trying to create a little plugin that will make working with SQLite databases a little easier. I've got the basic CRUD functions except for selecting data from the database.

I would like to return the selected data from the executeSql function, but it seems all I can do is call another method and not just return the data.

So what I'd like to do is:

var data = $(window).dbPlugin( 'select', '*', 'tableName', 'conditions' );

Then I would like to work with the "data" variable as the SQLResultSet from the query. However, the transaction seems to only allow me to call a data handler method and not just return the result.

testDB.transaction(  
    function ( transaction ) {  
        transaction.executeSql( sql, [], dataHandler, errorHandler);  
    }  
);

function dataHandler( transaction, results ) {
    // Now I can work with the "results" as the SQLResultSet
}

Any ideas how to just return the selected data or if it's even possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半夏半凉 2024-10-08 19:06:53

SQLlite 是异步的,没有任何方法可以避免这种情况。您可以将要作为回调调用的函数传递到 .dbPlugin 方法中。 After 条件传递另一个值,该值是在查询运行后调用的函数。然后在回调函数中设置数据。

这很烦人,我最近写了一些像你在我的上一个项目中写的东西。我使用了一个名为 blockUI 的 jQuery 插件,它本质上会在 SQL 调用期间阻塞接口,这使得它看起来更加“同步”,

祝你好运。

SQLlite is asynchronous, and there isn't any way to avoid that. You could pass in the function you want to be called as your callback into your .dbPlugin method. After conditions pass another value which is a function to be called after the query is run. Then set data in your callback function.

It's pretty annoying, I recently wrote something like you are writing on my last project. I used a jQuery plugin called blockUI that would essentially block the interface during SQL calls which made it appear a little more 'synchronous'

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文