Joakim Engstrom
Joakim Engstrom

Reputation: 6403

SQLite in a webapp with jQtouch

I'm treying to create a simple todo webapp with jQtouch but I'm having some time creating a SQLite database. Or the database is created with no tables, and when I refresh Safari the database is created again, resulting in many datbases with diffrent names.

$(function() {

var db;


//DATABASE
var shortName = 'todosDB';
var version = '1.0';
var displayName = 'todosDB';
var maxSize = 65536;
db = openDatabase(shortName, version, displayName, maxSize);
db.transaction(
    function(transaction) {
        transaction.executeSql(
            'IF NOT EXISTS CREATE TABLE  todos ' +
            '(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' +
            'todo TEXT NOT NULL, description TEXT NOT NULL' +
            'date DATE);'
        );
    }
);

And when I finally create it nothing happens when I try to put some data in the db.

db.transaction(
        function(transaction) {
                transaction.executeSql(
                    'INSERT INTO todos (todo, description) VALUES (' +  $('#todo').val()  + ', ' +  $('#description').val()  + ' );'
                );
            }
        );

Any help would be appreciated. I don't know if the problem is because of how jQtouch handles the initial function? It seems like the transaction does not even execute which leads me to believe there is something with the opening lines that is the problem.

EDIT: The biggest trouble I have is duplicating databases, every time I refresh the browser it creates another database. The table are created now but since it creates a new database every time it makes a new table every time and so on.

Upvotes: 0

Views: 312

Answers (1)

Derrick
Derrick

Reputation: 46

Use phonegap, it uses native api for phones and put the code in the ready function for phonegap. Also if you still have problems start putting alerts in spots of the code and see when the last one comes up. The line before after the last alert will be your problem

Upvotes: 3

Related Questions