TZQuery events - when they're running ?

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
PetyaMaster
Fresh Boarder
Fresh Boarder
Posts: 19
Joined: 22.04.2010, 13:09

TZQuery events - when they're running ?

Post by PetyaMaster »

I've just tried to implement a TZQuery event, it looks to work fine when calling Open, to retrieve resultsets.
I wonder what if running the query by ExecSql, for SQL statements that have no resultsets.
I've done it this way :

[font=Courier New]
  • type
    TMyZQuery = class(TZQuery)
    private
    procedure BeforeOpenHandler(DataSet: TDataSet);
    public
    constructor Create(AOwner: TComponent); override;
    end;

    ...

    constructor TMyZQuery.Create(AOwner: TComponent);
    begin
    inherited Create(AOwner);
    BeforeOpen:=BeforeOpenHandler;
    end;

    {$B-}
    procedure TMyZQuery.BeforeOpenHandler(DataSet: TDataSet);
    begin
    if IniParams.Log.Database and (DataSet.ClassName='TMyZQuery') then
    FileLog(DatabaseAll,(DataSet as TZQuery).SQL.Text);
    end;
[/font]

I also wonder if Delphi F1 key usable .hlp help files are being planned or not.
Any suggestions are welcome.

THX :
Peter
PetyaMaster
Fresh Boarder
Fresh Boarder
Posts: 19
Joined: 22.04.2010, 13:09

Post by PetyaMaster »

I've done some testing and assume that ExecSql does not call BeforeOpen.
Can someone confirm that ?
If yes, is there an event that's called both times, before executing any kind of queries ?
(As you can see, I wanna log any and all SQL statements to a text file automatically)
Isn't there a manual that describes when the TZQuery events are called, I didn't find this info on test.bravecobra.com .

THX & Cheers

btw. what if I Open an UPDATE or INSERT statement ?
EDatabaseError ?
PetyaMaster
Fresh Boarder
Fresh Boarder
Posts: 19
Joined: 22.04.2010, 13:09

Post by PetyaMaster »

I'm afraid it was a bad idea to give more details and partially answer my own question.
PetyaMaster
Fresh Boarder
Fresh Boarder
Posts: 19
Joined: 22.04.2010, 13:09

Post by PetyaMaster »

[font=Courier New] TMyZQuery = class(TZQuery)
private
procedure BeforeOpenHandler(DataSet: TDataSet);
public
constructor Create(AOwner: TComponent); override;
procedure ExecSQL; override;
end;

procedure TMyZQuery.ExecSQL;
begin
if Assigned(BeforeOpen) then BeforeOpen(Self);
inherited ExecSQL;
end;[/font]
Solves the original problem.

Gotta find another stuff you maybe interested in.
Try to set a datetime column to 2010.04.31 00:00 using TZQuery.
No Exception raised (run through IDE), statement simply thrown away.
Database not changed.
ZeosDBO 6.6.0 stable

Does Zeos have something like bug tracker publicly visible ?
guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Post by guidoaerts »

In any case there must be a conversion of string to datetime that will raise an exception...
guido
PetyaMaster
Fresh Boarder
Fresh Boarder
Posts: 19
Joined: 22.04.2010, 13:09

Post by PetyaMaster »

Conversion ?
Sorry, but I must contradict that.
I give the SQL statement as a string.
SQL server accepts the statement as a string.
There's no need for Zeos to convert anything.
Zeos is not in the position to be able to convert.

What you probably point occurs inside the database server, but that place it cannot raise anything or cause any and all event or any change to happen in the client.
If I run the same query in a database manager, it correctly answers :
"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated."
This is what Zeos does not catch, I suppose.

ps. Have you tried it ?
guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Post by guidoaerts »

well, you're right, it happens on the server, but zeos checks for errors an passes them through ; I tried it ( zeos 6.6.5; lazarus 0.9.26.2, xp)
i get a dialog with :
SQL error : conversion error from string "31/04/2010". Error code : -413. Overflow occured during data type conversion. (...and then my sql string)
the field value in the table remains unchanged of course.

guido
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

Image
Post Reply