DROP TABLE IF EXISTS now available in mozStorage

This commit is contained in:
Dan Stillman 2006-03-22 16:42:22 +00:00
parent 6cad409813
commit 93c2b8c2ee
2 changed files with 13 additions and 31 deletions

View file

@ -375,21 +375,6 @@ Scholar.DB = new function(){
* Create new DB schema * Create new DB schema
*/ */
function _initializeSchema(){ function _initializeSchema(){
// Until DROP TABLE IF EXISTS works with the mozStorage extension
try { query('DROP TABLE version'); } catch(e){}
try { query('DROP TABLE objects'); } catch(e){}
try { query('DROP TABLE objectTypes'); } catch(e){}
try { query('DROP TABLE fieldFormats'); } catch(e){}
try { query('DROP TABLE fields'); } catch(e){}
try { query('DROP TABLE objectTypeFields'); } catch(e){}
try { query('DROP TABLE objectData'); } catch(e){}
try { query('DROP TABLE keywords'); } catch(e){}
try { query('DROP TABLE objectKeywords'); } catch(e){}
try { query('DROP TABLE creators'); } catch(e){}
try { query('DROP TABLE creatorTypes'); } catch(e){}
try { query('DROP TABLE objectCreators'); } catch(e){}
try { query('DROP TABLE folders'); } catch(e){}
try { try {
beginTransaction(); beginTransaction();
var sql = _getSchemaSQL(); var sql = _getSchemaSQL();

View file

@ -1,14 +1,11 @@
-- 2 -- 2
-- IF EXISTS not yet available in available mozStorage binaries, DROP TABLE IF EXISTS version;
-- so we fake it with a bunch of try/catches in the _initializeSchema()
-- DROP TABLE IF EXISTS version;
CREATE TABLE version ( CREATE TABLE version (
version INTEGER PRIMARY KEY version INTEGER PRIMARY KEY
); );
-- DROP TABLE IF EXISTS objects; DROP TABLE IF EXISTS objects;
CREATE TABLE objects ( CREATE TABLE objects (
objectID INTEGER PRIMARY KEY, objectID INTEGER PRIMARY KEY,
objectTypeID INT, objectTypeID INT,
@ -23,20 +20,20 @@
); );
CREATE INDEX folderID ON objects(folderID); CREATE INDEX folderID ON objects(folderID);
-- DROP TABLE IF EXISTS objectTypes; DROP TABLE IF EXISTS objectTypes;
CREATE TABLE objectTypes ( CREATE TABLE objectTypes (
objectTypeID INTEGER PRIMARY KEY, objectTypeID INTEGER PRIMARY KEY,
typeName TEXT typeName TEXT
); );
-- DROP TABLE IF EXISTS fieldFormats; DROP TABLE IF EXISTS fieldFormats;
CREATE TABLE fieldFormats ( CREATE TABLE fieldFormats (
fieldFormatID INTEGER PRIMARY KEY, fieldFormatID INTEGER PRIMARY KEY,
regex TEXT, regex TEXT,
isInteger INT isInteger INT
); );
-- DROP TABLE IF EXISTS fields; DROP TABLE IF EXISTS fields;
CREATE TABLE fields ( CREATE TABLE fields (
fieldID INTEGER PRIMARY KEY, fieldID INTEGER PRIMARY KEY,
fieldName TEXT, fieldName TEXT,
@ -44,7 +41,7 @@
FOREIGN KEY (fieldFormatID) REFERENCES fieldFormat(fieldFormatID) FOREIGN KEY (fieldFormatID) REFERENCES fieldFormat(fieldFormatID)
); );
-- DROP TABLE IF EXISTS objectTypeFields; DROP TABLE IF EXISTS objectTypeFields;
CREATE TABLE objectTypeFields ( CREATE TABLE objectTypeFields (
objectTypeID INT, objectTypeID INT,
fieldID INT, fieldID INT,
@ -54,7 +51,7 @@
FOREIGN KEY (fieldID) REFERENCES objectTypes(objectTypeID) FOREIGN KEY (fieldID) REFERENCES objectTypes(objectTypeID)
); );
-- DROP TABLE IF EXISTS objectData; DROP TABLE IF EXISTS objectData;
CREATE TABLE objectData ( CREATE TABLE objectData (
objectID INT, objectID INT,
fieldID INT, fieldID INT,
@ -65,13 +62,13 @@
); );
CREATE INDEX value ON objectData (value); CREATE INDEX value ON objectData (value);
-- DROP TABLE IF EXISTS keywords; DROP TABLE IF EXISTS keywords;
CREATE TABLE keywords ( CREATE TABLE keywords (
keywordID INTEGER PRIMARY KEY, keywordID INTEGER PRIMARY KEY,
keyword TEXT keyword TEXT
); );
-- DROP TABLE IF EXISTS objectKeywords; DROP TABLE IF EXISTS objectKeywords;
CREATE TABLE objectKeywords ( CREATE TABLE objectKeywords (
objectID INT, objectID INT,
keywordID INT, keywordID INT,
@ -80,7 +77,7 @@
FOREIGN KEY (keywordID) REFERENCES keywords(keywordID) FOREIGN KEY (keywordID) REFERENCES keywords(keywordID)
); );
-- DROP TABLE IF EXISTS creators; DROP TABLE IF EXISTS creators;
CREATE TABLE creators ( CREATE TABLE creators (
creatorID INT, creatorID INT,
creatorTypeID INT DEFAULT 1, creatorTypeID INT DEFAULT 1,
@ -90,13 +87,13 @@
FOREIGN KEY (creatorTypeID) REFERENCES creatorTypes(creatorTypeID) FOREIGN KEY (creatorTypeID) REFERENCES creatorTypes(creatorTypeID)
); );
-- DROP TABLE IF EXISTS creatorTypes; DROP TABLE IF EXISTS creatorTypes;
CREATE TABLE creatorTypes ( CREATE TABLE creatorTypes (
creatorTypeID INTEGER PRIMARY KEY, creatorTypeID INTEGER PRIMARY KEY,
creatorType TEXT creatorType TEXT
); );
-- DROP TABLE IF EXISTS objectCreators; DROP TABLE IF EXISTS objectCreators;
CREATE TABLE objectCreators ( CREATE TABLE objectCreators (
objectID INT, objectID INT,
creatorID INT, creatorID INT,
@ -106,7 +103,7 @@
FOREIGN KEY (creatorID) REFERENCES creators(creatorID) FOREIGN KEY (creatorID) REFERENCES creators(creatorID)
); );
-- DROP TABLE IF EXISTS folders; DROP TABLE IF EXISTS folders;
CREATE TABLE folders ( CREATE TABLE folders (
folderID INTEGER PRIMARY KEY, folderID INTEGER PRIMARY KEY,
folderName TEXT, folderName TEXT,