[DUG] firebird query parameters behaving oddly

Todd Martin toddm at kol.co.nz
Fri Jul 6 14:11:06 NZST 2007


The date string is probably not being escaped correctly.
Perhaps try

ParamByName(‘from’).AsDate = FromDat;
ParamByName(‘to).AsDate = ToDat;

Tracey wrote:
> Hi all
> 
>  
> 
> I have in my code many areas where queries are “strung” together then 
> executed.  These queries are parameterized.  However I am having 
> problems with my date parameters.
> 
>  
> 
> If I have my sql string looking like this:
> 
>  
> 
> SQL.Add('Select stuff');
> 
> SQL.Add('From tables ');
> 
> SQL.Add('Join more tables on keys');
> 
> SQL.Add('Where DataDate >= :from');
> 
> SQL.Add('And DataDate <= :to');
> 
> ParamByName(‘from’).AsString = sFromDat;  (previously checked valid date 
> loaded into string)
> 
> ParamByName(‘to).AsString = sToDat;  (previously checked valid date 
> loaded into string)
> 
>  
> 
>  
> 
> These queries work, however I seem to be missing records. 
> 
>  
> 
> If I do the unthinkable and string the date values in with the query:
> 
>  
> 
> SQL.Add('Select stuff');
> 
> SQL.Add('From tables ');
> 
> SQL.Add('Join more tables on keys');
> 
> SQL.Add('Where DataDate >= ‘’’ + sFromDat + ‘’’’);
> 
> SQL.Add('And DataDate <= ‘’’ + sToDat + ‘’’’);
> 
>  
> 
> I get the correct amount of records
> 
>  
> 
> I wouldn’t even know where to start on this one, I am leaving the params 
> as they are in the working code, but not happy about it.
> 
>  
> 
> Any revelations?
> 
>  
> 
> Tracey
> 
>  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: delphi at delphi.org.nz
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject: unsubscribe
> 
> 
> ------------------------------------------------------------------------
> 
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.476 / Virus Database: 269.10.0/887 - Release Date: 5/07/2007 1:55 p.m.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5143 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.adventureeducation.co.nz/pipermail/delphi/attachments/20070706/edbde59b/smime.bin


More information about the Delphi mailing list