You are not logged in.
Pages: 1
I am having a strange error when using TrestBatch. I am getting an exception error when batch is send that happens the same way in the same part of the code and I can not find a solution:
Bind^.indicators is null and gives exception in line 3201 in ZDBcMysqlStatement:
procedure TZMariaDBBatchDMLPreparedStatement.SetNullArray(
ParameterIndex: Integer; const SQLType: TZSQLType; const Value;
const VariantType: TZVariantType);
var
Bind: PMYSQL_aligned_BIND;
aArray: PZArray;
I: Integer;
begin
inherited SetNullArray(ParameterIndex, SQLType, Value, VariantType);
{$IFNDEF GENERIC_INDEX}
ParameterIndex := ParameterIndex - 1;
{$ENDIF}
{$R-}
Bind := @FMYSQL_aligned_BINDs[ParameterIndex];
{$IFDEF RangeCheckEnabled}{$R+}{$ENDIF}
if (FMYSQL_STMT = nil) then
InternalRealPrepare;
if (FMYSQL_STMT = nil) then
raise EZSQLException.Create(SFailedtoPrepareStmt);
aArray := BindList[ParameterIndex].Value;
if Pointer(Value) = nil
then FillChar(Bind^.indicators^, BatchDMLArrayCount, Char(MySQLNullIndicatorMatrix[False, FUseDefaults]))
else for i := 0 to BatchDMLArrayCount -1 do
{$R-}
{3201 line} Bind^.indicators[I] := MySQLNullIndicatorMatrix[(Bind^.indicators[i] = Ord(STMT_INDICATOR_NULL)) or IsNullFromArray(aArray, I), FUseDefaults];
{$IFDEF RangeCheckEnabled}{$R+}{$ENDIF}
end;ParameterIndex is 0 as it is called from TZeosArrayBinding.Create line 1091 of mormot.db.sql.zeos where fStatement does not seem to have something unsual.
I am using Delphi 12.3 64bit, with mariadb 10.6.7 and 10.6.24 dll
This problem does not happen in 32bit with mariadb 3.1.24 dll but it gives an error in function TZAbstractMySQLPreparedStatement.GetUpdateCount in line 1314 (LastUpdateCount := FPlainDriver.mysql_stmt_affected_rows(FMYSQL_STMT);)
Also this happens with only 3 Torms that they do not have something special. And all this happens exactly the same in any case for these torms
One of the them is:
TormEhfymdIcd=class(Torm)
private
Fdescr, Fcod: rawutf8; Fsdat, Fedat: tdatetime;
public
class procedure InitializeTable(const Server: IRestOrmServer; const FieldName: RawUtf8; Options: TOrmInitializeTableOptions); override;
published
property cod: rawutf8 index 25 read Fcod write Fcod;
property descr: rawutf8 index 1500 read Fdescr write Fdescr;
property sdat: tdatetime read Fsdat write Fsdat;
property edat: tdatetime read Fedat write Fedat;
end;
Any help? I really can not understand what happens. Thank you in advance
Last edited by dcoun (2026-01-22 18:24:38)
Offline
Looking the logs probably I have find the problem:
Mormot creates a query to update a Torm where the datetime field "approved" is 0 and in the query is shown as '', producing the error:
update pinakas set vid=295,abnorm=0,monas=0,timi='6 , 13:45',sim='',parentbcode=74272047418,approved='' where ID=959894
The above query does not run in mariadb
Last edited by dcoun (2026-01-22 23:49:29)
Offline
ThreadId=3080
ProcessId=9
ThreadName="pool10-TepresSlave"
ExceptionMessage="Access violation at address 0000000000BC119E. Read of address 0000000000000000"
ExceptionName="EAccessViolation"
ExceptionDisplayName="$C0000005"
ExceptionAddress=00BC119E
FileName="C:\DG\zeoslib\src\dbc\ZDbcMySqlStatement.pas"
LineNumber=3201
I delete the table and left mormot to recreate it, but the same exception happened again
Entering 0 in a Tdatetime field in a Torm is allowed?
How can I debug it more?
Last edited by dcoun (2026-01-23 08:50:41)
Offline
I removed the updates from trestbatch and now it seems that everything works with updates
Now I have again a problem with Trestbatch in the same zeos file in TZAbstractMySQLPreparedStatement.GetUpdateCount: Integer; line 1314
LastUpdateCount := FPlainDriver.mysql_stmt_affected_rows(FMYSQL_STMT);
That gives Range Check Error when called from TSqlDBZeosStatement.UpdateCount
What do you recommend to use as alternative to zeos for mariab and mormot2?
For windows and linux
Offline
I also found in the logs the following error that it is not connected with zeos:
20260123 10355947 5 EXC ESqlite3Exception {Message:"Error SQLITE_ERROR (1) [Step] using 3.51.2 - SQL logic error",ErrorCode:1,SQLite3ErrorCode:"secERROR"} [pool15-TepresSlave] at 01232ca2 {6 2.57 65532.92 8 5GB/7.7GB 66581b01}
20260123 10355947 5 ERROR mormot.rest.sqlite3.TRestServerDB(02187594f480) {"ESqlite3Exception(02182f9aab20)":{Message:"Error SQLITE_ERROR (1) [Step] using 3.51.2 - SQL logic error",ErrorCode:1,SQLite3ErrorCode:"secERROR"}} for update EhfyResult set exid=:(4674): where RowID in (:(112150186198810):,:(112150186198811):) // update EhfyResult set exid=? where RowID in (?,?)
20260123 10355947 5 EXC EZUnsupportedException {Message:"Unsupported operation"} [pool15-TepresSlave] at e58408 {6 2.57 65532.92 8 5GB/7.7GB 66581b01}
Offline
I removed the updates from trestbatch and now it seems that everything works with updates
Now I have again a problem with Trestbatch in the same zeos file in TZAbstractMySQLPreparedStatement.GetUpdateCount: Integer; line 1314
LastUpdateCount := FPlainDriver.mysql_stmt_affected_rows(FMYSQL_STMT);
That gives Range Check Error when called from TSqlDBZeosStatement.UpdateCount
The above was fixed by adding a LastUpdateCount := Integer(FPlainDriver.mysql_stmt_affected_rows(FMYSQL_STMT)); it was my compiler running in debug mode
My initial problem was resolved by adding to check if it is null
else if Bind^.indicators <> nil then for i := 0 to BatchDMLArrayCount -1 do ....Sometimes, I feel I am the only person in earth that uses mariadb with zeos and mormot. All updates in zeos is for other bindings.....
Offline
I tried to asked gemini what it thinks about my solution. And I got that the above change is not safe plus the following:
The Root Cause: Batch DML Synchronization
The issue stems from a "state mismatch" between the mORMot 2 batching logic and the Zeos internal buffer allocation.
Zeos Side: In ZDbcMySqlStatement.pas, the indicators array (used for NULL values) is only allocated when the driver is explicitly told it is performing a batch operation via AllocateBuffers.
mORMot Side: In mormot.db.sql.zeos.pas, the ExecutePrepared method detects a batch when fParamsArrayCount > 0. It then creates a TZeosArrayBinding to bind the data.
The Conflict: If mORMot reuses a statement that was previously used for a single row (common in the ORM's InternalProcess or ExecutePrepared calls), the Zeos statement object may not have re-run the allocation logic for the indicators pointer, leading to the nil access at line 3201.
The solution is to disable the cache from mormot, in connection with: usecache:=false; After that Bind^.indicators=nil error disappears when I removed the check "if Bind^.indicators<>nil"
I also noticed, that SupportsArrayBindings=false even when using a recent version of libmariadb.dll and zeos 8.0-paches trunk.
This solution is less fast as cache is not used, but at least in my senario, it is reliable.
Offline
Pages: 1