October 4th, 2013, 07:09 AM
Cannot unlink SQLite database file
I have some unit tests set up for a php library built on top of ZF2 and some of the components require a database for testing. For each test the database must be created then deleted. The issue is that although the connection to the database is closed, the script cannot delete the file (trying to rename it confirms it is used by another process).
The code can be found here: https://github.com/brian978/ZF2-Comm...aseCreator.php
Does anyone know how to fix this?
October 4th, 2013, 08:29 AM
I imagine you cannot 'delete' a database with php, but rather have to use sql to do it. It is not a 'file' in the 'file system' per se, but rather a structure that is completely managed by your database system, ie, MySQL, etc.
Comments on this post
October 4th, 2013, 10:55 AM
even MySQL stores its data in 'real' files on the file system which can be deleted (with often confusing consequences) but can be moved from one server to another and copied/pasted
October 4th, 2013, 02:12 PM
The OP indicated he was getting an error message about the file being in use. Assuming the db manager is the culprit I was merely telling him that he would have to use the db manager to effect a database delete.
And to others, the post did NOT mention SQLite. Maybe the link did, but I never go to links here.
October 4th, 2013, 02:22 PM
After some digging through the code I found out what was causing the "file in use" issue. Somewhere in the library, for logging purposes, I call the getSqlString() method from Zend\Db\Sql\Select like so:
I've done some digging in Zend this time but for now I couldn't find was is actually still using the file (a clone of the \PDO object maybe?) since the method returns a string. Any ideas are welcome
The database manager was mentioned in the title and I didn't see the need to mention it in the post, but maybe I was wrong...
Originally Posted by jimmyg999
October 4th, 2013, 02:29 PM
You're so right! I skipped right over that title. My bad on missing the SQLite reference....
October 4th, 2013, 04:37 PM
Figured out what the issue was: in the Adapter object there are 2 other objects that contain the PDO object (which, of course, is used to connect to the database). Because of this even though the disconnect() method is called on the Connection object, a reference still remains in the second object (Platform object) which isn't destroyed until the end of the script.
Considering this, is there any way to destroy all the references of the PDO object once the disconnect() method is called?
LE: best way I found to work around this was to clone the Platform object in the method were I log the info so it gets destroyed after the method call and not at the end of the script
Last edited by dbrian; October 14th, 2013 at 04:13 PM.