Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

javascript - Access pre-populate SQL Lite DB in Phonegap

I created a pre-populate SQL Lite DB an added it to my app as described in my other question.

Now, how can I use this DB?

I guess I need to use openDatabase but how do i make it open my DB in /assets/data.db?

I tried this:

        var shortName = 'data'; 
        var version = '1.0'; 
        var displayName = 'data'; 
        var maxSize = 65535;

        var db = openDatabase(shortName, version, displayName, maxSize); 

        function errorHandler(transaction, error)
        {
            // error.message is a human-readable string.
            // error.code is a numeric error code
            alert('DB Error: '+error.message+' (Code '+error.code+')');
        }

        db.transaction(
            function(tx) {
                tx.executeSql('SELECT street, numbers FROM streets', [], function(tx, results) {
                    // do some more stuff
                    alert("My first database query finished executing!");
                }, errorHandler);
            }
        );

But get sqlite returned: error code = 1, msg = no such table: streets.

I used the SQLite Database Browser to make sure the table exists. BTW: I don't have a 0000000000000001.db file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...