开发者

Android Accessing embedded sql lite database from HTML5

Running into a major brick wall here. I have a database of data that I need to package in a sql lite database. I also need to be able to query this database from a webview in javascript. When trying to query the database in javascript, sql lite is returning an error code 1 with a message of "no such table". Any ideas?

Here's the js code

    var database = window.openDatabase("testdb5", "", "main total", 1024 * 1024);

        if (database)
            document.write('got');

        database.transaction(function (tx) {
            tx.executeSql("SELECT * FROM testtable", [], function (tx, result) {
                for (var i = 0, item = null; i < result.rows.length; i++) {
                    item = result.rows.item(i);
                    document.write(item.name);
                }
            });
        });

Here's the relevant java :

    WebSettings settings = myWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);

    //String databasePath = this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    String databasePath ="/data/data/com.example.helloandroid/databases/";
    settings.setDatabasePath(databasePath);

    myWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize,
                    long totalUsedQuota, WebStorage.开发者_JS百科QuotaUpdater quotaUpdater) {
                    quotaUpdater.updateQuota(estimatedSize * 2);
            }
    });

Sucks that there's no documentation on this! Any help is much appreciated.


This is hopeless. For posterity's sake, I decided to simply create a javascript interface and call methods that would natively interact with the sql lite database.

The only problem with this solution is that my code won't be as portable. I will have to figure out some hacky solution to put it on IOS... Such is life.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜