0

I am new to sqlite and android, my question is simple, in visual studio if you want to make a query from local variable it is done by "'localvariable'" like wise but how on sqlite is possible?

for eg..

String local;
local = column1;

sqlite query

SELECT "'local'" FROM table 

Table structure

table: column1 column2

in the above i cannot use the assigned local variable? what would be the syntax i am not able to figure out. i use raw query.

any help is highly appreciated

2 Answers 2

2
String column1 = "NameOfMyFirstColumn";
String column2 = "NameOfMySecondColumn";
String sql = "SELECT "+ column1 +","+ column2 +" FROM table";
Cursor c = db.rawQuery(sql, null); 
Sign up to request clarification or add additional context in comments.

Comments

0

try this

Cursor cursor = db.rawQuery("SELECT ? FROM table", new String[] { local });

? will be replaced by local.

Comments

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.