This also crashes on me at sqlite3_backup_init. To isolate the problem I have created a small test program. sqlite3.h & .c are taken from the Qt 4.7.1. archive (the version I am developing with), somehow those files were missing in the OpenSUSE 11.4 Qt Source package.
This code tries to do an online backup of an opened database, so it's not from memory.
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlDriver>
#include <QString>
#include <QVariant>
#include "sqlite3/sqlite3.h"
sqlDb.setDatabaseName(src);
sqlDb.open();
sqlite3* pSource = *static_cast<sqlite3 **>(v.data());
int rc;
sqlite3 *pDest;
sqlite3_backup *pBackup;
rc = sqlite3_open(dst.toLocal8Bit().data(), &pDest);
if(rc == SQLITE_OK) {
pBackup = sqlite3_backup_init(pDest, "main", pSource, "main");
if (pBackup) {
do {
rc = sqlite3_backup_step(pBackup, 5);
if (rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
sqlite3_sleep(250);
}
} while(rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED );
/* Release resources allocated by backup_init(). */
sqlite3_backup_finish(pBackup);
}
sqlite3_close(pDest);
}
sqlDb.close();
}
int main(int argc, char *argv[]) {
backup("/home/arkay/Projects/QtWebApp/database/Current/architektur.db",
"/home/arkay/Projects/QtWebApp/database/Backup/architektur.db");
}
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlDriver>
#include <QString>
#include <QVariant>
#include "sqlite3/sqlite3.h"
void backup(QString src, QString dst) {
QSqlDatabase sqlDb = QSqlDatabase::addDatabase("QSQLITE");
sqlDb.setDatabaseName(src);
sqlDb.open();
QVariant v = sqlDb.driver()->handle();
sqlite3* pSource = *static_cast<sqlite3 **>(v.data());
int rc;
sqlite3 *pDest;
sqlite3_backup *pBackup;
rc = sqlite3_open(dst.toLocal8Bit().data(), &pDest);
if(rc == SQLITE_OK) {
pBackup = sqlite3_backup_init(pDest, "main", pSource, "main");
if (pBackup) {
do {
rc = sqlite3_backup_step(pBackup, 5);
if (rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED) {
sqlite3_sleep(250);
}
} while(rc == SQLITE_OK || rc == SQLITE_BUSY || rc == SQLITE_LOCKED );
/* Release resources allocated by backup_init(). */
sqlite3_backup_finish(pBackup);
}
sqlite3_close(pDest);
}
sqlDb.close();
}
int main(int argc, char *argv[]) {
backup("/home/arkay/Projects/QtWebApp/database/Current/architektur.db",
"/home/arkay/Projects/QtWebApp/database/Backup/architektur.db");
}
To copy to clipboard, switch view to plain text mode
Bookmarks