Click here to Skip to main content
15,885,757 members

SQLite, sqlite_busy: Unable to delete the database

amarasat asked:

Open original thread
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?
Tags: C++, Sqlite, PHP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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