D7 E - Stored procedur ewith datetime parameters

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for MySQL in Delphi and C++Builder
Post Reply
zzzato
Posts: 12
Joined: Mon 20 Aug 2012 08:47

D7 E - Stored procedur ewith datetime parameters

Post by zzzato » Sat 20 Apr 2013 15:23

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

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: D7 E - Stored procedur ewith datetime parameters

Post by DemetrionQ » Mon 22 Apr 2013 16:53

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;

zzzato
Posts: 12
Joined: Mon 20 Aug 2012 08:47

Re: D7 E - Stored procedur ewith datetime parameters

Post by zzzato » Tue 23 Apr 2013 07:01

Hi.
Thanks for your answer.I'll try.
Best.

zzzato
Posts: 12
Joined: Mon 20 Aug 2012 08:47

Re: D7 E - Stored procedur ewith datetime parameters

Post by zzzato » Mon 29 Apr 2013 07:19

Hi, DemetrionQ..
Param.value := now: doesn't work.
Param.AsSqlTimeStamp := DateTimeToSqlTimeStamp(Now): works.

See u.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: D7 E - Stored procedur ewith datetime parameters

Post by DemetrionQ » Mon 29 Apr 2013 16:31

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.

zzzato
Posts: 12
Joined: Mon 20 Aug 2012 08:47

Re: D7 E - Stored procedur ewith datetime parameters

Post by zzzato » Wed 01 May 2013 09:05

Sorry. Paramater was ftDatetime insthead ftTimeStamp.
Now, param.Value := now works.
Many thanks.
See u.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: D7 E - Stored procedur ewith datetime parameters

Post by DemetrionQ » Fri 10 May 2013 17:38

Hello.

If any other questions come up, please contact us.

Post Reply