Problem with date query parameters

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
pwatel
Posts: 39
Joined: Wed 11 Feb 2009 09:42

Problem with date query parameters

Post by pwatel » Mon 25 May 2009 12:53

sql := INSERT INTO FUNDSHISTPRICES (SYMBOL,ADATE, CLOSEV)
VALUES (:SYMBOL,:ADATE,:CLOSEV);

var
q : TIBCSQL;
q.SQL.Clear;
q.SQL.Text := sql;
q.AutoCommit := true
q.Prepare;

for each parameters I do that
q.ParamByName('SYMBOL').Value := 'IBM';// example
q.ParamByName('ADATE').Value := Date(); // today
q.ParamByName('CLOSEV').Value := 65.45; // any value
q.execute;

CRASH ON THE DATE FIELD
ALL PARAMETERS WORK OK BUT THE DATE CRASHES IT DOES NOT CONVERT IT IS SHOWN AS A REAL BEING CONVERTED AS STRING
LIKE 37879.000000 (whic is the date value as float)
I AM MISSING SOMETHING ?
IF I HAVE TO INPUT EACH TIME THE PARAMETER DATATYPE IT IS VERY CLUMSY BESIDES IT WORKS WITH ALL OTHER DATATYPES SO????
Thanks
PW
ps the caps is to diffrenciate the code from my message no sign of bad temper

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 26 May 2009 06:46

Try to use the AsDate or AsDateTime property:

Code: Select all

q.ParamByName('ADATE').AsDate := Date();

pwatel
Posts: 39
Joined: Wed 11 Feb 2009 09:42

ok it works if..................

Post by pwatel » Tue 26 May 2009 08:54

I have a procedure
so using your tip I modified it as such

procedure TDBFirebirdIBDAC.SetQueryParameter(fQuery: TComponent;
const ParamName: string; aValue: Variant; const fISBlob: Boolean = false);
begin
bla bla..

if VarIsType(aValue, varDate) then
q.ParamByName(ParamName).AsDate := aValue

else
q.ParamByName(ParamName).Value := aValue;

end;

However if works only if I call it by forcing the datetype on the variant
var
Zdate : Tdate
zdate := date();
THAT DOES NOT WORK
SetQueryParameter(aquery,'ADATEPARAM',zdate)
THIS DOES
SetQueryParameter(aquery,'ADATEPARAM',Tdatetime(zdate) );

Why no idea....

thanks
PW

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Wed 27 May 2009 07:33

You are using incorrect data type for the ZDate variable. You should declare this variable as TDateTime. In this case you don't need the workaround, and can use the Value property.

Post Reply