Page 1 of 1

parameters wrongly in the sql's beginning

Posted: 23.10.2022, 11:47
by dcoun
After an exception in a previous query I am getting the following error using Zeos8.0-fixes last trunk and mormot2 with Delphi 11.2 win32:

Code: Select all

Exception: 20221023 07461843  * EXC   EZSQLException {Message:"SQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '100804359select pid as ID from table where iid=? limit 1' at line 1
Code: 1064 SQL: select pid as ID from table where iid=? limit 1"} 
[Pool9-TEslave] at 01f194c0 ZDbcMySql.pas TZMySQLConnection.HandleErrorOrWarning (1271)  
ZDbcMySql.pas TZMySQLConnection.HandleErrorOrWarning (1271) 
ZDbcMySqlStatement.pas ExecuteEmulated (1040) 
ZDbcMySqlStatement.pas TZAbstractMySQLPreparedStatement.ExecuteQueryPrepared (1052) 
mormot.db.sql.zeos.pas TSqlDBZeosStatement.ExecutePrepared (1180) 
mormot.db.sql.pas TSqlDBStatement.ExecutePreparedAndFetchAllAsJson (6664) 
mormot.orm.sql.pas TRestStorageExternal.EngineList (1380) 
mormot.orm.server.pas TRestOrmServer.EngineList (1073) 
mormot.orm.rest.pas TRestOrm.ExecuteList (1676) 
mormot.orm.rest.pas TRestOrm.MultiFieldValue (977) ...... 
It seems that the parameter of the query exists in the beginning of the SQL query.
I have put a log point to see where the sql is created like than and the sql squery return from ComposeRawSQLQuery in TZAbstractMySQLPreparedStatement.ExecuteQueryPrepared is returned as

Code: Select all

100804359select pid as ID from table where iid=? limit 1


Before that in TSqlDBZeosStatement.ExecutePrepared from mormot.db.sql.zeos the fStatement.GetSQL returns the correct query:

Code: Select all

select pid as ID from patient where amka=? limit 1
What do you propose to log in order to debug it more?
I can reproduce that in an example and for the moment I just log such a problem when it happens.
Thank you in advance

Re: parameters wrongly in the sql's beginning

Posted: 25.10.2022, 09:53
by marsupilami
Hello,

that sounds strange to me because on MariaDB Zeos has no reason to chenge the SQL statements and try to insert parameters there. Did you already check if this also happens without mormot? For example something like this:

Code: Select all

  ZQuery.Close;
  ZQuery.SQL.Text := 'select pid as ID from table where iid=:iid limit 1';
  ZQuery.ParamByName('iid').AsInteger := 100804359;
  ZQuery.Open;
Just to see if this isn't introduced by mORMot in any way?

Best regards,

Jan

Re: parameters wrongly in the sql's beginning

Posted: 25.10.2022, 20:20
by dcoun
The problem is that this seldom happens and usually after an other exception (like a duplicate primary index or a field insert with out of range value).
Do you propose to add somewhere in the source a log point to find more info?