RE: [sqlite] Query generation
Pusedo code: set s.sql = 'select a from mytable where (b=0)'; if got.more then set s.sql = s.sql + ' and ' + s.userinput; ... set s.sql = s.sql + ';'; > -Original Message- > From: Lloyd [mailto:[EMAIL PROTECTED] > Sent: Thursday, December 07, 2006 2:46 AM > To: sqlite-users@sqlite.org > Subject: [sqlite] Query generation > > > Hi, > I am generating queries dynamically from my program based on > the input. > The primary part of the query is always > > select a from mytable where (b=0) and > > based on the user input I add more where clauses to my query like > > select a from mytable where (b=0) and (x=10) > > but in one case there in no where clause to add, so my final query > become > > select a from mytable where (b=0) and > > and this is a syntax error. > > Is there any option to add a null clause after the 'and' ? > > Thanks, > Lloyd > > > __ > Scanned and protected by Email scanner > > -- > --- > To unsubscribe, send email to [EMAIL PROTECTED] > -- > --- > - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Query generation
At 2:15 PM +0530 12/7/06, Lloyd wrote: Hi, I am generating queries dynamically from my program based on the input. The primary part of the query is always select a from mytable where (b=0) and based on the user input I add more where clauses to my query like select a from mytable where (b=0) and (x=10) but in one case there in no where clause to add, so my final query become select a from mytable where (b=0) and and this is a syntax error. Is there any option to add a null clause after the 'and' ? Thanks, Lloyd A better solution is to use leading 'and' rather than trailing 'and', so you should start off with: select a from mytable where (b=0) ... which is already valid syntax, and only add a bunch of "and " when you actually have the "". -- Darren Duncan - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Query generation
Thanks, 0=0 works well enough for me. (This hint is what I wanted) Thanks again, Lloyd On Wed, 2006-12-06 at 10:00 +0100, Mario Frasca wrote: > Lloyd wrote: > > >select a from mytable where (b=0) and > > > >and this is a syntax error. > > > > > you're not saying which language you're using. > > in Python a common solution looks like this: > clauses = [] > # add strings to the clauses list, like > clauses.append('(b=0)') > # join the parts using appropriate glue > where = ' AND '.join(clauses) > > sometimes I do need something like what you call "an empty clause"... > some engines accept 'TRUE', others don't know that literal. > I find this quite convenient: > '0=0' > > hth... > > - > To unsubscribe, send email to [EMAIL PROTECTED] > - __ Scanned and protected by Email scanner - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Query generation
Lloyd wrote: select a from mytable where (b=0) and and this is a syntax error. you're not saying which language you're using. in Python a common solution looks like this: clauses = [] # add strings to the clauses list, like clauses.append('(b=0)') # join the parts using appropriate glue where = ' AND '.join(clauses) sometimes I do need something like what you call "an empty clause"... some engines accept 'TRUE', others don't know that literal. I find this quite convenient: '0=0' hth... - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] Query generation
Hi, I am generating queries dynamically from my program based on the input. The primary part of the query is always select a from mytable where (b=0) and based on the user input I add more where clauses to my query like select a from mytable where (b=0) and (x=10) but in one case there in no where clause to add, so my final query become select a from mytable where (b=0) and and this is a syntax error. Is there any option to add a null clause after the 'and' ? Thanks, Lloyd __ Scanned and protected by Email scanner - To unsubscribe, send email to [EMAIL PROTECTED] -