I'm trying to build a database, I'm really struggling though, I keep getting the following error:
[ERROR] invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x99567d0 {com.plausiblelabs.pldatabase.error.vendor.code=26, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=CREATE TABLE IF NOT EXISTS menus (menu_id INTEGER,section VARCHAR(255),dish VARCHAR(255),price NUMERIC NOT NULL,original_id INTEGER,PRIMARY KEY (menu_id));CREATE TABLE IF NOT EXISTS pubs (pub_id INTEGER,name VARCHAR(255),location VARCHAR(255),distance NUMERIC,geoX NUMERIC,geoY NUMERIC,original_id INTEGER,PRIMARY KEY (pub_id));CREATE TABLE IF NOT EXISTS staff (staff_id INTEGER,name VARCHAR(255),job VARCHAR(255),desc TEXT(1000),original_id INTEGER,section VARCHAR(255),PRIMARY KEY (staff_id));, com.plausiblelabs.pldatabase.error.vendor.string=file is encrypted or is not a database} in -[TiDatabaseProxy execute:] (TiDatabaseProxy.m:186) [ERROR] Script Error = invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x99567d0 {com.plausiblelabs.pldatabase.error.vendor.code=26, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=CREATE TABLE IF NOT EXISTS menus (menu_id INTEGER,section VARCHAR(255),dish VARCHAR(255),price NUMERIC NOT NULL,original_id INTEGER,PRIMARY KEY (menu_id));CREATE TABLE IF NOT EXISTS pubs (pub_id INTEGER,name VARCHAR(255),location VARCHAR(255),distance NUMERIC,geoX NUMERIC,geoY NUMERIC,original_id INTEGER,PRIMARY KEY (pub_id));CREATE TABLE IF NOT EXISTS staff (staff_id INTEGER,name VARCHAR(255),job VARCHAR(255),desc TEXT(1000),original_id INTEGER,section VARCHAR(255),PRIMARY KEY (staff_id));, com.plausiblelabs.pldatabase.error.vendor.string=file is encrypted or is not a database} in -[TiDatabaseProxy execute:] (TiDatabaseProxy.m:186) (unknown file)The code I'm using to do this is:
db = Titanium.Database.open('db'); db.execute('CREATE TABLE IF NOT EXISTS menus ('+ 'menu_id INTEGER,'+ 'section VARCHAR(255),'+ 'dish VARCHAR(255),'+ 'price NUMERIC NOT NULL,'+ 'original_id INTEGER,'+ 'PRIMARY KEY (menu_id)'+ ');'+ ''+ 'CREATE TABLE IF NOT EXISTS pubs ('+ 'pub_id INTEGER,'+ 'name VARCHAR(255),'+ 'location VARCHAR(255),'+ 'distance NUMERIC,'+ 'geoX NUMERIC,'+ 'geoY NUMERIC,'+ 'original_id INTEGER,'+ 'PRIMARY KEY (pub_id)'+ ');'+ ''+ 'CREATE TABLE IF NOT EXISTS staff ('+ 'staff_id INTEGER,'+ 'name VARCHAR(255),'+ 'job VARCHAR(255),'+ 'desc TEXT(1000),'+ 'original_id INTEGER,'+ 'section VARCHAR(255),'+ 'PRIMARY KEY (staff_id)'+ ');');Any help is greatly appreciated. Been running about in circles with this for a while now.
Thanks
3 Answers
Separate your CREATE statements into individual db.execute() commands. Also, some of these data types do not exist in SQLite, such as VARCHAR, NUMERIC, etc.
Check out the Working with SQLite Databases Guide to get more info on data types and how to structure your statements.
I have fixed the issue. This is caused by a old erroneous database being present on the device. Previously I had tried loading a db and called it 'db', so when creating a new database Appcelerator/SQLite reports errors withe SQL statements, when in reality the issue is with the database itself rather than the code.
I have just renamed the database and everything works as expected.
I have fixed the issue. This is caused by a old erroneous database being present on the device. Previously I had tried loading a db and called it 'db', so when creating a new database Appcelerator/SQLite reports errors withe SQL statements, when in reality the issue is with the database itself rather than the code.
I have just renamed the database and everything works as expected.
Your Answer
Think you can help? Login to answer this question!