0

How can I conditionally parametrize a SQLite database in AIR? For example this query:

//selectedID is the ID I want to select
query.text = "select * from table where id=@ID";
query.parameters['@ID']=selectedID;

But I want the where statement to appear only if selectedID is greater than 0.

What I would normally do is:

query.text = "select * from table"+(selectedID>0?" where id="+selectedID:'');

However, I read on the LiveDocs performance-wise it is better to use parameters.

Is it possible to parametrize a whole statement or that's only possible for values? Or maybe this is good-enough:

query.text = "select * from table"+(selectedID>0?" where id=@ID":'');
query.parameters['@ID']=selectedID;
Francisc
  • 77,430
  • 63
  • 180
  • 276

1 Answers1

0
            if (selectedID > 0)
            {
                 query.text = .....
                 query.parameters['@ID'] = ...
            } 
            else
            {
                 query.text = .....
            {
Tim
  • 8,669
  • 31
  • 105
  • 183
  • Yeah, I know, I was wondering if you can parameterize the statement. – Francisc Sep 06 '11 at 20:09
  • Also, it's basically the same thing as with the short version of if-else only I have to change the text property twice when I do... – Francisc Sep 06 '11 at 20:09