trying to set the pragma from a query will not work because it cannot be set when there is a pending transaction in SQLite:
SQLite PRAGMA foreign_keys documentation wrote:This pragma is a no-op within a transaction; foreign key constraint enforcement may only be enabled or disabled when there is no pending BEGIN or SAVEPOINT.
TZQueries always operate within a transaction.
I wrote a small patch to enable setting the pragma from the TZConnection properties. So doing ZConnection->Properties->Add("foreign_keys=1") will enable the foreign_keys pragma, whereas ZConnection->Properties->Add("foreign_keys=0") will disable the pragma. Having no foreign_keys line will leave SQLite to its default behaviour where the pragma can be set at compile time.
Could you please apply the patch and see if it solves your problems?
Best regards,
Jan
You do not have the required permissions to view the files attached to this post.
As a matter of fact I am not whitin a transaction, I have just connected to the SQLite database.
The TZConnection::AutoCommit is set to false and I have not started an explicit transaction, so I can not undrstand why the SQL commando does not work.
it seems to be a Zeos decision - at least for SQLite - but when you open a connection, transaction support is started immediately. Have a look at the file ZDbcSqLite.pas. One of the last things, the procedure TZSQLiteConnection.Open does, is a call to the procedure StartTransactionSupport. Similar things happen for PostgeSQL and Firebird. I would not be surprised if it were true for all DBC drivers. So I think this has been a design decision by the Zeos developers - as soon as you open a connection, you are in a transaction.
This is why my patch modifies TZSQLiteConnection.Open to check for a parameter foreign_keys and executes the corresponding pragma before transaction support has ben started.
So - to get back to my original question - does the patch solve your problem?
Best regards,
the patch cannot be directly applied to 7.1. But I will supply a similar patch for 7.1 in the upcoming week :-)
I have an Idea on how to support this kind of parameters in a more generic way but it will take some more time to work this out in a way that I can present here ;o)
Best regards,
I unexpectedly had some time to do the patch for Zeos 7.0. I think 7.0 should be modified too because otherwise it will not easily be possible to migrate from 6.6 to 7.0 if anybody chooses to do so.
Best regards,
Jan
You do not have the required permissions to view the files attached to this post.
this is strange because as far as I understand the source code, Zeos should behave exactly the opposite way. ON is not a defined value for a boolean parameter.
Hmmm - I will have to check this...
I added the expected behaviour to the driver parameters Wiki page nonetheless and added a reference to your post. See https://sourceforge.net/p/zeoslib/wiki/ ... arameters/
I was testing a "ON DELETE CASCADE" and with "foreign_keys=ON" seemed to be working, but I think I misleading something when checking it with sqlite3.exe command line tool.
I've just retested again and "foreign_keys=1" works.
On the other hand, maybe these parameters ask some standardization, e.g., the "AutoEncodeStrings=ON " when setting AutoEncodeStrings to True into Object Inspector.