Page 1 of 1
Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Mon 05 Dec 2016 22:28
by 2mrezaee
Hi there
I am talking about TStoredProc but it seems same problem exist in other components when you are working on iOS or Android application.
This is my code calling a stored procedure:
Code: Select all
procedure TUser.BreakfastCals;
var
ImConnected: Boolean;
begin
ImConnected := DM1.conSQL.Connected;
if not ImConnected then
DM1.conSQL.Open;
try
with DM1.sp_ThisDateLogedbreakfast do
begin
Close;
Prepare;
ParamByName('@CaloryDate').Value := TodayDate;
ParamByName('@UserId').Value := UserId;
ParamByName('@Sum').Value := 0;
Execute;
fBreakfastCals := ParamByName('@Sum').Value;
end;
except on E: Exception do
begin
ShowMessage('Error');
frmStartUp.AppClose;
end;
end;
frmToday.lblBreakfact.Text := IntToStr(fBreakfastCals) + ' kcal';
end;
So as you can see I'm looking for all exceptions may occur and not a specific one! when I run this code with Windows target platform it works fine but if I select iOS or Android as my target platform I always get the Error message inside the Except block.
Re: Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Tue 06 Dec 2016 21:00
by ertank
Hello,
Your database system is not known.
Just an idea, you can change exception block and see actual error message and maybe to have better information about whats going on.
Code: Select all
procedure TUser.BreakfastCals;
var
ImConnected: Boolean;
begin
ImConnected := DM1.conSQL.Connected;
if not ImConnected then
DM1.conSQL.Open;
try
with DM1.sp_ThisDateLogedbreakfast do
begin
Close;
Prepare;
ParamByName('@CaloryDate').Value := TodayDate;
ParamByName('@UserId').Value := UserId;
ParamByName('@Sum').Value := 0;
Execute;
fBreakfastCals := ParamByName('@Sum').Value;
end;
except on E: Exception do
begin
ShowMessage('Error:' + E.Message); // This line is what I suggest
frmStartUp.AppClose;
end;
end;
frmToday.lblBreakfact.Text := IntToStr(fBreakfastCals) + ' kcal';
end;
Re: Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Wed 07 Dec 2016 13:54
by azyk
Please provide us a full error code you get and CREATE-script of the stored procedure which the error is reproduced.
Re: Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Wed 07 Dec 2016 18:45
by 2mrezaee
Thanks for the reply
Database is MS-SQL and when I trace the app as soon as calling Prepare procedure the error will raise.
Re: Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Fri 09 Dec 2016 15:02
by azyk
Please provide us a full error code you get and CREATE-script of the stored procedure which the error is reproduced.
To get an error message:
1. In the provided code replace line
with
Code: Select all
ShowMessage('Error:' + E.Message);
2. Now when the error occurs, there will be an error message instead of the Error text in the dialogue.
To get CREATE-script:
3.Using SQL Server Management Studio in Object Explorer, connect to an instance of Database Engine and then expand that instance.
4.Expand Databases, expand the database in which the procedure belongs, and then expand Programmability.
5.Expand Stored Procedures, right-click the procedure and then click Script Stored Procedure as, and then click one of the Create To.
6.Select New Query Editor Window. This will display the procedure definition(CREATE-script).
Re: Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Mon 12 Dec 2016 20:03
by 2mrezaee
Hi there
Sorry for delay
Error message is:
Incorrect Syntax near '{'.
about the stored procedure it really does not matter what the procedure is I give this error after calling any stored procedure, but for your ref following is the stored procedure script
Code: Select all
ALTER PROCEDURE [sp_ThisDateLogedbreakfast]
@CaloryDate datetime,
@UserId bigint,
@Sum int output
AS
BEGIN
Select @Sum = Sum(Calories)
From CaloryLog
Where (UserId = @UserId) and
(CaloryDate = @CaloryDate) and
(Breakfast = 1)
Select Calories,
FoodName,
[Row],
(FoodDesc + ', ' + QTY) as FullDesc
From CaloryLog
Where (UserId = @UserId) and
(CaloryDate = @CaloryDate) and
(Breakfast = 1)
if @Sum is Null Set @Sum = 0
END
Re: Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Wed 14 Dec 2016 10:39
by azyk
Thank you for the information. We have reproduced the described behavior and are investigating it. We will inform you about the results.
Re: Calling Prepare raise an exception in Firemonkey iOS and Android
Posted: Mon 06 Mar 2017 10:56
by azyk
We fixed the bug. This fix will be included in the next UniDAC build.
If you want to get this change before the next UniDAC release, please send your license number to andreyz*devart*com and we will send you a night build.