-
-
Save fearphage/231331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Database = Class.create({ | |
initialize: function(tableName) { | |
this.tableName = tableName; | |
this.db = openDatabase("Database Name", "1.0", "Display Name", 10000); | |
}, | |
handleFirstTimers: function(firstTimeCallback, everyOtherTimeCallback) { | |
this.db.transaction(function(tx) { | |
tx.executeSql("CREATE TABLE IF NOT EXISTS " + this.tableName + " (flag REAL)",[], function(tx, result) { | |
tx.executeSql("SELECT flag FROM " + this.tableName, [], function(tx, result) { | |
if (result.rows.length == 0) { | |
tx.executeSql("INSERT INTO " + this.tableName + " (flag) VALUES (1)", [], function(tx, result) { | |
firstTimeCallback(); | |
}, function(tx, error) { | |
Mojo.Log.error("There was an error inserting into " + this.tableName + ": " + error.message); | |
}); | |
} else { | |
everyOtherTimeCallback(); | |
} | |
}, function(tx, error) { | |
Mojo.Log.error("There was a problem selecting the column from " + this.tableName + " table: " + error.message); | |
}); | |
}, function(tx, error) { | |
Mojo.Log.error("There was a problem creating the " + this.tableName + " table: " + error.message); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment