开发者

Conditionally parameterize SQLite query in AIR

开发者 https://www.devze.com 2023-04-02 22:55 出处:网络
How can I conditionally parametrize a SQLite database in AIR? For example this query: //selectedID is the ID I want to select

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 paramet开发者_运维知识库ers.

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;


            if (selectedID > 0)
            {
                 query.text = .....
                 query.parameters['@ID'] = ...
            } 
            else
            {
                 query.text = .....
            {
0

精彩评论

暂无评论...
验证码 换一张
取 消