mardi 6 janvier 2015

Android SQLite no such column, passed columns are ignored

I'm new to SQLite and not experienced in SQL in general. I keep getting the message "no such column: value (code 1)" without understanding why.


I am trying to store persons with indexes so I can uniquely identify them and retrieve more complex data that doesn't need to be queried as json, for which I use Gson to convert to and from Json from an object.



//Creation query
private static final String CREATE_PERSON_TABLE = "CREATE TABLE IF NOT EXISTS
"+PERSON_TABLE_NAME+" (id INTEGER PRIMARY KEY, firstname VARCHAR, lastname VARCHAR,
zipcode VARCHAR, birthdate VARCHAR, json VARCHAR);";

//Create unique combination
private static final String CREATE_PERSON_UNIQUE_INDEX = "CREATE UNIQUE INDEX
person_unique ON "+PERSON_TABLE_NAME+" (firstname, lastname, zipcode, birthdate);";

//Insert or replace query execution
getWritableDatabase().execSQL("INSERT OR REPLACE INTO "+PERSON_TABLE_NAME+"
(firstname, lastname, zipcode, birthdate, json) VALUES
("+person.getFirstname()+","+person.getLastName()+","+person.getZipcode()+",
'"+person.getBirthdate+"','"+person.getLifestoryJson()+"')");


Stacktrace



android.database.sqlite.SQLiteException: no such column: Hank (code 1): , while compiling: INSERT OR REPLACE INTO person (firstname,
lastname, zipcode, birthdate, json) VALUES (Hank,Hairy,8888HH,'06-01-1966','{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}')
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)


I've been staring and comparing with tutorials for hours now, I'm just not seeing what is going wrong. It appears that for some reason the columns I pass are ignored and the values are used as columns instead. Any help or explanation as to what can cause this error is very appreciated.


Aucun commentaire:

Enregistrer un commentaire