4

I am trying to programmatically execute the VACUUM command in C++ using the Sqlite3 library for C++. See reference at C-language Interface Specification for SQLite.

Can someone give a code snippet of how to do this? I tried calling this but it gives an exception:

This code is in my SqliteDb.cpp helper class.

void SqliteDb::executeSql(const string& sqlStatement) {
  char* errMsg = NULL;
  sqlite3_exec(db, sqlStatement.c_str(), NULL, NULL, &errMsg);
  if (errMsg != NULL) {
    string reason = string("Error in") + sqlStatement + " " + errMsg;
    sqlite3_free(errMsg);
    __throw_sqlitedb(reason);
  }
}

In my main class I did:

try{
    db = new SqliteDb(filepath);
    db->executeSql("VACUUM;");
} catch (std::exception e) {
    printf("EXCEPTION occurred %s", e.what());
}

The output is

EXCEPTION occurred std::exception

The SqliteDb.cpp is a tested class and works well for other components that use this class.

3

2 Answers 2

1

you can use sqlite3_exec() api from sqlite3.

sqlite3_exec(db, "VACUUM", 0, 0, 0);

-3
PRAGMA auto_vacuum = FULL;

Then you won't have to worry about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.