Page 1 of 1

Problem with date query parameters

Posted: Mon 25 May 2009 12:53
by pwatel
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

Posted: Tue 26 May 2009 06:46
by Plash
Try to use the AsDate or AsDateTime property:

Code: Select all

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

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

Posted: Tue 26 May 2009 08:54
by pwatel
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

Posted: Wed 27 May 2009 07:33
by Plash
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.