I am trying to create a table in my db with a name dependent on a variable
var db = Ti.Database.install('areas.sqlite','templates'); Titanium.API.log(currentWin.tableName); db.execute('CREATE TABLE IF NOT EXISTS ? (id INTEGER, area TEXT, comment TEXT, img TEXT)', currentWin.tableName); db.close();the log spits out the variable text to be _adb
the error I get is
[INFO] _adf 2012-07-23 14:39:49.760 propinspect[7833:9f03] [ERROR] A SQLite database error occurred on database '/Users/tightflks/Library/Application Support/iPhone Simulator/4.3/Applications/BBEDD433-DB5B-4589-81AD-07980A506DD6/Library/Private Documents/templates.sql': Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x6b69b00 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=CREATE TABLE IF NOT EXISTS ? (id INTEGER, area TEXT, comment TEXT, img TEXT), com.plausiblelabs.pldatabase.error.vendor.string=near "?": syntax error} (SQLite #1: near "?": syntax error) (query: 'CREATE TABLE IF NOT EXISTS ? (id INTEGER, area TEXT, comment TEXT, img TEXT)') [ERROR] invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3 "An error occured parsing the provided SQL statement." UserInfo=0x6b69b00 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=CREATE TABLE IF NOT EXISTS ? (id INTEGER, area TEXT, comment TEXT, img TEXT), com.plausiblelabs.pldatabase.error.vendor.string=near "?": syntax error} in -[TiDatabaseProxy execute:] (TiDatabaseProxy.m:186) [WARN] Exception in event callback. { line = 57; message = "invalid SQL statement. Error Domain=com.plausiblelabs.pldatabase Code=3 \"An error occured parsing the provided SQL statement.\" UserInfo=0x6b69b00 {com.plausiblelabs.pldatabase.error.vendor.code=1, NSLocalizedDescription=An error occured parsing the provided SQL statement., com.plausiblelabs.pldatabase.error.query.string=CREATE TABLE IF NOT EXISTS ? (id INTEGER, area TEXT, comment TEXT, img TEXT), com.plausiblelabs.pldatabase.error.vendor.string=near \"?\": syntax error} in -[TiDatabaseProxy execute:] (TiDatabaseProxy.m:186)"; sourceId = 196303648; sourceURL = "file://localhost/Users/tightflks/Library/Application%20Support/iPhone%20Simulator/4.3/Applications/BBEDD433-DB5B-4589-81AD-07980A506DD6/propinspect.app/template.js"; }I really do not understand why this is happening. I am running the latest iPhone sdk, any help would be much appreciated. thanks
1 Answer
Accepted Answer
Do this instead:
db.execute('CREATE TABLE IF NOT EXISTS ' + currentWin.tableName + ' (id INTEGER, area TEXT, comment TEXT, img TEXT)');
Your Answer
Think you can help? Login to answer this question!