How to catch all exceptions?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
stlcours
Posts: 33
Joined: Wed 14 Sep 2011 20:22

How to catch all exceptions?

Post by stlcours » Wed 01 Jan 2014 20:23

Query1 := TUniQuery.Create(Owner);
Query1.Connection:=DM.Connection;
MainForm.ds1.DataSet:=Query1;
try
with Query1 do
begin
SpecificOptions.Values['MySQL.FetchAll'] := 'True';
SQL.Clear;
SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=sssss'); // u_name is string
Execute;
end
except
on E:Exception do begin
// raise EDatabaseError.Create(E.Message);
ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
end;
end;

// unidac 5.1.4
--------------------------------------------------------------
But the result is not stable, there are three different windows like these cases if I always execute the same SQL above. Why?
Image
Image
Image
Attention, the last picture is so strange. It cover the whole sreen, including the statusbar of windows(not statusbar of my application).
I hope the error window always like the first one.

Help me, thanks.
Last edited by stlcours on Fri 03 Jan 2014 10:46, edited 1 time in total.

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

Re: How to catch all exceptions?

Post by AlexP » Thu 02 Jan 2014 10:51

Hello,

Please send us the error messages as text, because the links to pictures cannot be opened.

stlcours
Posts: 33
Joined: Wed 14 Sep 2011 20:22

Re: How to catch all exceptions?

Post by stlcours » Fri 03 Jan 2014 11:06

I have send you mail. Please look at it when you are free. thanks..

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

Re: How to catch all exceptions?

Post by AlexP » Fri 03 Jan 2014 12:04

Hello,

If you use a string in a where condition, you need to put it in the quotation marks.

Code: Select all

SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=''sssss''');
If this is a string variable, use the code like the following:

Code: Select all

sssss := 'sssss';
SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=''' + sssss + '''');
If this is a parameter, use the following:

Code: Select all

SQL.Add('update users set u_pass=''xxxxxxx'' where u_name=:sssss');
ParamByName('sssss').asString := 'sssss';

stlcours
Posts: 33
Joined: Wed 14 Sep 2011 20:22

Re: How to catch all exceptions?

Post by stlcours » Fri 03 Jan 2014 15:50

Thanks Alex, I know well how to add the quote to the sql code of delphi. But my question is how to catch all the errors? The error above is designed by me to learn how can I catch all the errors correctly.
If possible, Even I want to get the index/number of this error of database(mysql).

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

Re: How to catch all exceptions?

Post by AlexP » Sat 11 Jan 2014 11:23

Hello,

You can use the UniConnection.onError event to process all the exceptions that occur when working with databases. When any error occurs, this event is triggered. You can analyze ErrorCode, Message, and other properties of the EDAError class and the SQL property for examining the SQL that caused the error.

Post Reply