Calling Prepare raise an exception in Firemonkey iOS and Android

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
2mrezaee
Posts: 4
Joined: Tue 22 Nov 2016 23:49

Calling Prepare raise an exception in Firemonkey iOS and Android

Post by 2mrezaee » Mon 05 Dec 2016 22:28

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.

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: Calling Prepare raise an exception in Firemonkey iOS and Android

Post by ertank » Tue 06 Dec 2016 21:00

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;

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Calling Prepare raise an exception in Firemonkey iOS and Android

Post by azyk » Wed 07 Dec 2016 13:54

Please provide us a full error code you get and CREATE-script of the stored procedure which the error is reproduced.

2mrezaee
Posts: 4
Joined: Tue 22 Nov 2016 23:49

Re: Calling Prepare raise an exception in Firemonkey iOS and Android

Post by 2mrezaee » Wed 07 Dec 2016 18:45

Thanks for the reply
Database is MS-SQL and when I trace the app as soon as calling Prepare procedure the error will raise.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Calling Prepare raise an exception in Firemonkey iOS and Android

Post by azyk » Fri 09 Dec 2016 15:02

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

Code: Select all

ShowMessage('Error');
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).

2mrezaee
Posts: 4
Joined: Tue 22 Nov 2016 23:49

Re: Calling Prepare raise an exception in Firemonkey iOS and Android

Post by 2mrezaee » Mon 12 Dec 2016 20:03

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

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Calling Prepare raise an exception in Firemonkey iOS and Android

Post by azyk » Wed 14 Dec 2016 10:39

Thank you for the information. We have reproduced the described behavior and are investigating it. We will inform you about the results.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Calling Prepare raise an exception in Firemonkey iOS and Android

Post by azyk » Mon 06 Mar 2017 10:56

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.

Post Reply