Exemplo n.º 1
0
void getOutDatedDatabase()
{
    qDebug() <<"Fetching Outdated Database..." << endl;

    //Filename - We need to different datatypes for the same file becuse you can't static cast them
    QString path = "Outdated/drc_db.db3";
    char * pathChar = "Outdated/drc_db.db3";

    //Make sure that the database exists
    if (databaseExists(pathChar))
    {
        qDebug() << "Database found." << endl;
    }
    else
    {
        qDebug() << "ERROR: Database not found!!!!" << endl;
        exit(1);
    }

    //Open the database
    QSqlDatabase database;
    if (openDatabase(path, database))
    {
        qDebug() << "Database Opened Successfully." << endl;
    }
    else
    {
        qDebug() << "ERROR: Database not opened correctly!!!!" << endl;
        exit(1);
    }

    qDebug() << "DONE!" << endl;
}
Exemplo n.º 2
0
void DatabaseManager::openDatabase()
{
    bool db_exists = databaseExists();

    //if already open
    if (QSqlDatabase::database("main").isValid())
        return;

    QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE", "main");
    database.setDatabaseName(m_databasePath);

    bool open = database.open();

    if (!open) {
        QString err = database.lastError().text();
        QMessageBox::critical(0, QObject::tr("Database Error"),
                              QObject::tr("Failed to open the database file: %1")
                              .arg(err));
        return;
    }

    if (!db_exists && open) {
        initDatabase(database);
    }

    //TODO: on next db version
    //on open database check db version, if higher don't open it
    //and how error message
}
Exemplo n.º 3
0
void dropUserTable(char *host, char *user, char *password, char *database)
/* Drop database if it exists. */
{
if (databaseExists(host, user, password, database))
    {
    struct sqlConnection *conn = sqlConnectRemote(host, user, password, database);
    if (sqlTableExists(conn, userTable))
	{
	char query[512];
	sqlSafef(query, sizeof(query), "drop table %s", userTable);
	sqlUpdate(conn, query);
	}
    sqlDisconnect(&conn);
    }
}
Exemplo n.º 4
0
void createNewFakeDatabase(char *host, char *user, char *password, char *database)
/* Create a fake database with empty fake useDb table. */
{
dropUserTable(host, user, password, database);
if (!databaseExists(host, user, password, database))
    createEmptyDatabase(host, user, password, database);
struct sqlConnection *conn = sqlConnectRemote(host, user, password, database);
char query[1024];
sqlSafef(query, sizeof(query), 
"CREATE TABLE %s  (\n"
"    id integer unsigned not null auto_increment,	# Cart ID\n"
"    contents longblob not null,	# Contents - encoded variables\n"
"    reserved tinyint not null,	# always 0\n"
"    firstUse DATETIME not null,	# First time this was used\n"
"    lastUse DATETIME not null,	# Last time this was used\n"
"    useCount int not null,	# Number of times used\n"
"              #Indices\n"
"    PRIMARY KEY(id)\n"
") ENGINE = %s\n", userTable, engine);
sqlUpdate(conn, query);
sqlDisconnect(&conn);
}