Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ PHP Sqlite
Hello Everyone:
 
I am trying to delete a SQLite database(file) through C++, which is created using php file. I am getting the SQLITE_BUSY error and was not able to solve it.
 
Creating the database in PHP:
$dir = 'sqlite:C:/Program Files/x/'.$DataBaseName.'.sqlite';
$database  = new PDO($dir) or die("cannot open the database"); //Database is always created sucessfully here
 
Accessing and Deleting the database in C++:
function1()
{
   bool delete = false;
   delete = HandleDataBase(name);
   if(delete)
      remove(filename);//C++ error 32, file is under use.
}
 
HandleDataBase(name)
{
    sqlite3 *database;
    if(sqlite3_open(name, &database) == SQLITE_OK)//database exists
    {
	const char *pSQL[6];
        pSQL[0] = "select * from Table1";
        sqlite3_stmt *statement1;
		
        if ( sqlite3_prepare(database, pSQL[0], -1, &statement1, 0 ) == SQLITE_OK )//i believe this makes the database busy, but how to meake it nonbusy after performing operations 
        {
        }
 
        int rc = sqlite3_close(database);//failing since the database is busy
	if ( rc == SQLITE_BUSY)
	{
	     bool busy = true;//true, the database here is always busy.
	}
        return true;//delete the database if it exists.
    }
    return false;
}
 
How do i solve my issue, how should i close the database after reading and updating information(using sqlite3_prepare) so that i can delete it?
Posted 2-Jul-12 10:40am
amarasat1.3K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use sqlite3_finalize[^] on the prepared statement.
  Permalink  
Comments
amarasat at 5-Jul-12 11:59am
   
Thanks a lot, using sqlite3_finalize has solved my issue!!
abhishekgour at 30-May-13 9:07am
   
It's solved my iphone sqlite_busy error thanks a lot....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100