I'm "trying" to create a Safari Extension that adds links to a local sqlite database.
In the global.html file, I can create the database, but I can't create a table unless I refer to a non-existant variable, which makes the rest of the script fail.
// Global Variable to hold my database
var my_DB;
// Make A Database
init_DB();
// Make A Table
createTable(my_DB);
// Rest of the code
alert("Database and Table have been created!");
// Initialise the Database
function init_DB() {
try {
// Check for Database Support
if (!window.openDatabase) {
alert("Database functionality is NOT Supported!");
} else {
// Setup the database
var shortName = "imp_DB";
var version = '1.0';
var displayName = "My Important Database";
var maxSize = 65536; // in bytes
var theDB = openDatabase(shortName, version, displayName, maxSize);
}
} catch(e) {
// Error Handling
if (e == "INVALID_STATE_ERR") {
// We have a version number mismatch
alert("Invalid database version");
} else {
// Unknown error
alert("Unknown error: " + e);
}
return;
}
// Assign the database to the global variable
my_DB = theDB;
}
// Create The Table
function createTable(thisDB) {
thisDB.transaction(function(txn) {
txn.executeSql('CREATE TABLE IF NOT EXISTS people (id unique, name, age)');
});
// The following line is the problem
someVar = txn;
}
Calling init_DB() works fine, and the database is created. However, calling createTable(my_DB) just fails silently, (No Errors, or Warnings) and the rest of the code completes, UNLESS I refer to "txn" somehow.
So adding the "SomeVar = txn;" line allows the Table to be created, but unfortunately, it causes "ReferenceError: Can't find variable: txn" to appear in the console, and stops the rest of the code from running.
Does anyone have any ideas? I've been trying to get this to work for over a week, and I'm at my wit's end.
Thanks in advance for any suggestions ;-)
N.B. Declaring "txn" before attempting to create a Table also causes a silent fail.