TMyStoredProc, set null strings to empty string?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
docH
Posts: 59
Joined: Sun 22 Dec 2013 15:18

TMyStoredProc, set null strings to empty string?

Post by docH » Mon 17 Mar 2014 12:12

I have ver 8.2.6 of TmyStoredProc.
I have a stored procedure in the database that returns two Varchars, one or both of which might be null.

The code below gives an exception in Delphi if the the parameter is null

Code: Select all

...
 MyStoredproc1.Execute;
 MyStringVar:= MyStoredproc1.ParamByName('MyParamName').AsString;
...
end;
Is there an easy way in TMyStoredProc to automatically convert null varchars to an empty string or do I have to alter my SQL with IFNULL(FieldName,"") and do it all in the procedure before returning any values?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: TMyStoredProc, set null strings to empty string?

Post by AlexP » Thu 20 Mar 2014 14:20

Hello,

Please specify when the exception is raised (and provide the error message text): on method execution or when calling the parameter. In addition, if you use SELECT in your procedure and want to call fields of the generated ResultSet, then you should use FieldByName instead of ParamByName.
If the parameter value is NULL, then, when calling the AsString property, the Null value will be mapped to an empty string.

Post Reply