Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
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++:
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

1 solution

Use sqlite3_finalize[^] on the prepared statement.
 
Share this answer
 
Comments
amarasat 5-Jul-12 11:59am    
Thanks a lot, using sqlite3_finalize has solved my issue!!
abhishekgour 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900