#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    52
    Rep Power
    6

    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    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

    • Jacques1 disagrees : Did you even read the post? We're talking about *SQLite* here.
  4. #3
  5. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4124
    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
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    52
    Rep Power
    6
    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:
    PHP Code:
    $select->getSqlString($this->getAdapter()->getPlatform()) 
    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

    Originally Posted by jimmyg999
    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.
    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...
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    189
    Rep Power
    0
    You're so right! I skipped right over that title. My bad on missing the SQLite reference....
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    52
    Rep Power
    6
    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 03:13 PM.

IMN logo majestic logo threadwatch logo seochat tools logo