0

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?

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@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-binding thnx!
Even better: use the insert() method on SQLiteDatabase, so you are not generating any of your own SQL.
0

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.

Comments

0

wrap your double quotes with single quotes?

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.