Example #1
0
bool medDatabaseController::createConnection(void)
{
    medStorage::mkpath(medStorage::dataLocation() + "/");

    if (this->m_database.databaseName().isEmpty())
        this->m_database = QSqlDatabase::addDatabase("QSQLITE");
    this->m_database.setDatabaseName(medStorage::dataLocation() + "/" + "db");

    if (!m_database.open()) {
        dtkDebug() << DTK_COLOR_FG_RED << "Cannot open database: Unable to establish a database connection." << DTK_NO_COLOR;
        return false;
    }
    else
    {
        dtkDebug() << "Database opened at: " << m_database.databaseName();
        d->isConnected = true;
    }

    createPatientTable();
    createStudyTable();
    createSeriesTable();
    createImageTable();

    // optimize speed of sqlite db
    QSqlQuery query(m_database);
    if ( !query.exec( QLatin1String( "PRAGMA synchronous = 0" ) ) ) {
        dtkDebug() << "Could not set sqlite synchronous mode to asynchronous mode.";
    }
    if ( !query.exec( QLatin1String( "PRAGMA journal_mode=wal" ) ) ) {
        dtkDebug() << "Could not set sqlite write-ahead-log journal mode";
    }


    return true;
}
bool DatabaseManager::createDB()
{    
    if (m_db.isOpen()) {
        
        if (initializeInfoTable()) {
            qDebug() << "information table created";
        }
        
        if (createSeriesTable() && createEpisodeTable() && createBannerTable()) {
            
            qDebug() << "Tables created";
            
            updateInfoTable(2.0);
        }
    }

    return true;
}