This method inquires if the table exist in the database.
// inquire if table exist
if (SQLDatabase.tableExists("SAMPLE_TABLE", ""))
{
// table does exist, let's confirm it's up to date
var version = SQLDatabase.getTableVersion("SAMPLE_TABLE");
if (version == 1)
{ / / table is out of date, run query to update table to version 2
// this SQL demonstrates adding two columns, 'deleted' and 'removed', to SAMPLE_TABLE
SQLDatabase.executeSQL("begin; create table SAMPLE_TEMP (ID integer, TYPE text, FILENAME text); \
insert into SAMPLE_TEMP select ID, TYPE, FILENAME from SAMPLE_TABLE; \
drop table SAMPLE_TABLE; \
create table SAMPLE_TABLE(ID integer not null, DELETED integer default 0, \
REMOVED integer default 0, TYPE text, FILENAME text, primary key(ID)); \
insert into SAMPLE_TABLE (ID, TYPE, FILENAME) select ID, TYPE, FILENAME from SAMPLE_TEMP; \
drop table SAMPLE_TEMP; commit;");
SQLDatabase.setTableVersion("SAMPLE_TABLE", 2);
logpane.document.writeln("...updated table version<br>");
}
}
else
{ // table does not exist, create version 2
SQLDatabase.executeSQL("begin; create table SAMPLE_TABLE (ID integer not null, DELETED integer default 0, \
REMOVED integer default 0, TYPE text, FILENAME text, primary key(ID))");
SQLDatabase.setTableVersion("SAMPLE_TABLE", 2);
SQLDatabase.executeSQL("commit;");
}