Page 1 of 1

D7 E - Stored procedur ewith datetime parameters

Posted: Sat 20 Apr 2013 15:23
by zzzato
Hi, All.
I've a strange delphi exception calling a stored procedure with datetime parameters.
I tried a lot of different cases without any positive result.
See examples below:

CREATE PROCEDURE `JNTEST`(
in ASTARTDATE DATETIME,
OUT ASLADATETIME DATETIME)
BEGIN
SET ASLADATETIME = SYSDATE();

END$$

CREATE PROCEDURE `JNTEST2`(
in ASTARTDATE DATETIME)
BEGIN
declare x int;
set x = 0;
END$$

When I try to call it using this delphi sintax:

proc.Params.ParamByName('ADateStart').AsDateTime := Now;
proc.execproc;

delphi raises an exception "invalid value to datetime encode".
Using debugger, I saw that something in dbx crashes when application tries to set parameters value. If I don't set value or write a code like this:

proc.Params.ParamByName('ADateStart').Clear;
proc.execproc;

I've not exceptions.

Note that mysql database version is 5.1 and server is running on debian virtual machine.

Thanks for any suggestion.

Best

Re: D7 E - Stored procedur ewith datetime parameters

Posted: Mon 22 Apr 2013 16:53
by DemetrionQ
Hello.

This problem occurs due to that Delphi doesn't allow distinguish the DateTime and SQLTimeStamp types. Unfortunately, we cannot influence this behaviour in any way.
As a workaround, you can transfer the value to the parameter via TParam.Value or TParam.AsSQLTimeStamp, for example:

Code: Select all

  proc.Params.ParamByName('ADateStart').Value := Now;

Re: D7 E - Stored procedur ewith datetime parameters

Posted: Tue 23 Apr 2013 07:01
by zzzato
Hi.
Thanks for your answer.I'll try.
Best.

Re: D7 E - Stored procedur ewith datetime parameters

Posted: Mon 29 Apr 2013 07:19
by zzzato
Hi, DemetrionQ..
Param.value := now: doesn't work.
Param.AsSqlTimeStamp := DateTimeToSqlTimeStamp(Now): works.

See u.

Re: D7 E - Stored procedur ewith datetime parameters

Posted: Mon 29 Apr 2013 16:31
by DemetrionQ
Hello.

Please verify what did you mean by "Param.value := now: doesn't work"?
If when using Param.value := now you get an error "invalid value to datetime encode", make sure that Param.DataType is not set to ftDateTime. It must have the ftTimeStamp value.

Re: D7 E - Stored procedur ewith datetime parameters

Posted: Wed 01 May 2013 09:05
by zzzato
Sorry. Paramater was ftDatetime insthead ftTimeStamp.
Now, param.Value := now works.
Many thanks.
See u.

Re: D7 E - Stored procedur ewith datetime parameters

Posted: Fri 10 May 2013 17:38
by DemetrionQ
Hello.

If any other questions come up, please contact us.