TZSQLProcessor .RowsAffected

The offical for ZeosLib 7.3 Report problems, ask for help, post proposals for the new version of Zeoslib 7.3/v8
Quick Info:
-We made two new drivers: odbc(raw and unicode version) and oledb
-GUID domain/field-defined support for FB
-extended error infos of Firebird
-performance ups are still in queue
In future some more feature will arrive, so stay tuned and don't hassitate to help
Post Reply
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 765
Joined: 18.11.2018, 17:37
Location: Hungary

TZSQLProcessor .RowsAffected

Post by aehimself »

Hello,

I recently got a request (of course when I should be on vacation, whenever else...) if I can implement multiple command execution in my tool. Zeos has me covered with TZSQLProcessor but I have to keep a standardized output... for one query it was simply "x record(s) affected", now I need to have as many of these as the user entered, separated by sLineBreak.

Checking the statement count is easy, having If-Else-s is still easy but I cannot seem to find out if it's possible in TZSQLProcessor to get the affected row count after each executed statement. This seems to be backed up by ZSQLProcessor.pas : 395 (TZSQLProcessor.Execute) where we simply ignore this value:

Code: Select all

            Statement := CreateStatement(SQL.Statements[0].SQL, nil);
            try
              SetStatementParams(Statement, SQL.Statements[0].ParamNamesArray,
                FParams);
              Statement.ExecuteUpdatePrepared; // <-- return value holding affected rows is simple discarded here
            finally
              Statement.Close; //see test Test1049821: if LastResultSet is assigned
              Statement := nil;
            end;
The fix is easy and I'm more than happy to create a pull request with it, just want to confirm a couple of things first:
1, Did I overlook something? Can the count of affected rows be extracted for each successful statement execution?
2, If no, how exactly should it be implemented?
2.1, Add a .RowsAffected property to TZSQLProcessor which changes after each statement or
2.2, Create a new TZProcessorNotifyEvent method to include the count of affected rows and use this as the .AfterExecute event handler

I personally prefer 2.2, however it is a code-breaking change.

More ways to accomplish this is also welcome :)
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 765
Joined: 18.11.2018, 17:37
Location: Hungary

Re: TZSQLProcessor .RowsAffected

Post by aehimself »

Well, the code-breaking but more elegant solution is waiting on GitHub to be applied :)
Delphi 12.1, Zeos 8 from latest GIT snapshot
Using:
- MySQL server 8.0.18; libmariadb.dll 3.3.8
- Oracle server 11.2.0, 12.1.0, 19.0.0; oci.dll 21.13
- MSSQL 2012, 2019; sybdb.dll FreeTDS_2435
- SQLite 3.45.2
Post Reply