Page 1 of 1

TZSQLProcessor .RowsAffected

Posted: 30.07.2023, 21:23
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 :)

Re: TZSQLProcessor .RowsAffected

Posted: 02.08.2023, 12:55
by aehimself
Well, the code-breaking but more elegant solution is waiting on GitHub to be applied :)