views:

94

answers:

3

the old query works, the new on doesnt. the android logcat gives me error as: Failure 1: no such column abcname. abcname is the value of a editview that im trying to get from a popup in android.

i know that the first query will insert those values in the fields, as they are given in single inverted commas. the same query, i typed in the adb shell, works. so i copied the query, and just removed the data corresponding to the field names, and inserted the variable names. on trying to run, i get the above said error.

OLD QUERY:

MapsActivity.myDB.execSQL("INSERT INTO "
    +MapsActivity.TableName
    + " (name, user_comment, latitude, longitude) "
    + " VALUES ('tagName','tagComment','tagLatitude','tagLongitude');");

NEW QUERY:

MapsActivity.myDB.execSQL("INSERT INTO "
    +MapsActivity.TableName
    + " (name, user_comment, latitude, longitude) "
    + " VALUES ("+tagName +",'tagComment','tagLatitude','tagLongitude');");

what is the problem?

+1  A: 

If tagName has, e.g., the value "abc", your query will expand to ... VALUE (abc,'tagComment',.... It's missing the single quotes.

Building SQL like this give bad karma. Use SQLite's parameter-binding mechanism instead.

Marcelo Cantos
@1 the old query works fine. its the second query that doesnt work. i have to take the value from a varible, hence i cant use a single quote. i need to substitute the value oftagName.@2 looking into parameter-bindingthnx!
Kaustubh
Even better: use the `insert()` method on `SQLiteDatabase`, so you are not generating any of your own SQL.
CommonsWare
A: 

I recommend creating a simple active record db implementation. here is a great tutorial for a simple sqlite active record for android. This adds some extra time up front but saves you time while you develop.

Dave.B
ohkay, looking into it :)thanks!
Kaustubh
A: 

wrap your double quotes with single quotes?

...('"+tagName +"',....

searchMaker
nope, pretty confusing. im trying to declare the queries, fields, and the values, as a string, with value substitution. lets see where that take me.
Kaustubh