[Solved] ZSQLProcessor Commit problem with temporary table

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
naumov13
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 19.09.2019, 14:33

[Solved] ZSQLProcessor Commit problem with temporary table

Post by naumov13 »

Hello.

I found a problem with ZSQLProcessor (7.2.4-stable) and SQLite when I execute some sql-script with creating temporary table .
Without "create temporary table" all works fine. ZEOS 7.2.1-rc not reproduce this problem.

My environment:
Windows 8.1 x64
Lazarus 1.8.0 x32
FPC: 3.0.4
ZEOS version: 7.2.4-stable
Database driver: SQLite (sqlite3.dll v3.18.0 in attachment)

In the attachment is a project demonstrating that problem.
There is simple application with 1 buttons and 3 radiobuttons.
1 radiobutton - reproduce problem
2 and 3 - variants avoid problem

Database creates at button click, and deletes at application starts.
So you need restart application in order to try other radiobutton variants.

Some comments in code.
You do not have the required permissions to view the files attached to this post.
Last edited by naumov13 on 27.03.2021, 08:12, edited 1 time in total.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: ZSQLProcessor Commit problem with temporary table

Post by marsupilami »

Hello,

I am sorry, I didn't respond more early. Could you ckeck if the problem still exists on Zeos 7.2.6?
Best regards,

Jan
naumov13
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 19.09.2019, 14:33

Re: ZSQLProcessor Commit problem with temporary table

Post by naumov13 »

Hello,
Yes, I did checked it. The problem still exists on Zeos 7.2.6-stable
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: ZSQLProcessor Commit problem with temporary table

Post by marsupilami »

Ok - the problem is strange. It happens when starting the next transaction. Note: you should not use start transaction and commit in scripts. This can interfere with the Zeos transaction logic. Most probably strange things would happen if you encounter an error and cannot commit or rollback your transaction. Zeos still might think it is in AutoCommit mode, while there is a transaction giong on...

So - the strange thing about thi error is - when checking the extended error information, we get the messagt that this isn't an error:
[Window Title]
commitbug

[Content]
SQL Error: Error: SQL logic error or missing database
Message: not an error.

Press OK to ignore and risk data corruption.
Press Abort to kill the program.

[OK] [Abort]
I will open a ticket and see to it that I create a test in the test suites...

Edit: The ticket is: https://sourceforge.net/p/zeoslib/tickets/405/
naumov13
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 19.09.2019, 14:33

Re: ZSQLProcessor Commit problem with temporary table

Post by naumov13 »

Hello.

This problem still persists.
Checked with current stable version zeos-7.2.10

When I looked under the debugger, I saw the following comment in the method TZAbstractConnection.Commit

Code: Select all

 { TODO -oEgonHugeist : Change this code sequence on 7.3! My automation idea simply is wrong! A commit vs. commitupdate(clear the cache) shouldn't be same! }
      //See: http://zeoslib.sourceforge.net/viewtopic.php?f=38&t=19800 
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: ZSQLProcessor Commit problem with temporary table

Post by marsupilami »

I reopened the ticket. Please keep an eye on that.

Best regards,

Jan
naumov13
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 19.09.2019, 14:33

Re: ZSQLProcessor Commit problem with temporary table

Post by naumov13 »

I reread the entire thread more closely.
My apologies, it looks like I jumped to conclusions.

The error remains due to the fact that I am still using starting a transaction before calling TZSQLProcessor.Execute

Please explain in a little more detail why, when using TZSQLProcessor, you do not recommend opening a transaction?
Maybe TZSQLProcessor always does it itself?
User avatar
aehimself
Zeos Dev Team
Zeos Dev Team
Posts: 766
Joined: 18.11.2018, 17:37
Location: Hungary

Re: ZSQLProcessor Commit problem with temporary table

Post by aehimself »

You can use transactions with SQLProcessor, the main point is:
marsupilami wrote: 14.01.2020, 14:24in scripts
When you start a transcation, Zeos "translates" that to an SQL command and sends it to the server, e.g. "START TRANSACTION". Same goes when you do a commit, e.g. "COMMIT TRANSACTION". Now imagine it from the server side:

ZConnection.StartTransaction; // START TRANSACTION arrives to server

SQLProcessor.Execute; // Here, COMMIT TRANSACTION is included is in the script, so SQL server commits everything

At this stage, ZConnection still thinks that it is in a transaction as there was no ZConnection.Commit / .Rollback, but because the script commited the database server thinks otherwise. This just gets worse with nested transactions, as ZConnection has an internal counter on how "deep" we are in currently which can completely be messed up:

ZConnection.StartTransaction; // Zeos depth: 1

Script:
START TRANSACTION // SQL server depth: 2, Zeos depth: 1
START TRANSACTION // SQL server depth: 3, Zeos depth: 1
START TRANSACTION // SQL server depth: 4, Zeos depth: 1
START TRANSACTION // SQL server depth: 5, Zeos depth: 1

Either Remove all transactions from your scripts and use ZConnection, or set AutoCommit to True and handle all transactions from within the script. Mixing the two will disalign Zeos and the RDBMS.
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
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: ZSQLProcessor Commit problem with temporary table

Post by marsupilami »

I suggest handling all transactions from the Zeos side: If there is an error in the script we most probably stop processing it and don't know how many transcations were started. So if the script executes a "start transaction" and raises an error afterwards, Zeos will not know that there is an open transaction...
naumov13
Fresh Boarder
Fresh Boarder
Posts: 16
Joined: 19.09.2019, 14:33

Re: ZSQLProcessor Commit problem with temporary table

Post by naumov13 »

Got it.
Thanks a lot for the detailed clarification!
Post Reply