/* ============================================================================= * main * ============================================================================= */ MAIN(argc, argv) { manager_t* managerPtr; client_t** clients; TIMER_T start; TIMER_T stop; /* Initialization */ parseArgs(argc, (char** const)argv); SIM_GET_NUM_CPU(global_params[PARAM_CLIENTS]); managerPtr = initializeManager(); assert(managerPtr != NULL); clients = initializeClients(managerPtr); assert(clients != NULL); long numThread = global_params[PARAM_CLIENTS]; TM_STARTUP(numThread); P_MEMORY_STARTUP(numThread); thread_startup(numThread); /* Run transactions */ printf("Running clients... "); fflush(stdout); GOTO_SIM(); TIMER_READ(start); #ifdef OTM #pragma omp parallel { client_run(clients); } #else thread_start(client_run, (void*)clients); #endif TIMER_READ(stop); GOTO_REAL(); puts("done."); printf("Time = %0.6lf\n", TIMER_DIFF_SECONDS(start, stop)); fflush(stdout); checkTables(managerPtr); /* Clean up */ printf("Deallocating memory... "); fflush(stdout); freeClients(clients); /* * TODO: The contents of the manager's table need to be deallocated. */ manager_free(managerPtr); puts("done."); fflush(stdout); TM_SHUTDOWN(); P_MEMORY_SHUTDOWN(); thread_shutdown(); MAIN_RETURN(0); }
//---------------------------------------------------------------------------- void ctkPluginStorageSQL::open() { createDatabaseDirectory(); QSqlDatabase database = getConnection(); //Check if the sqlite version supports foreign key constraints QSqlQuery query(database); if (!query.exec("PRAGMA foreign_keys")) { close(); throw ctkPluginDatabaseException(QString("Check for foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } if (!query.next()) { close(); throw ctkPluginDatabaseException(QString("SQLite db does not support foreign keys. It is either older than 3.6.19 or was compiled with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER"), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); query.clear(); //Enable foreign key support if (!query.exec("PRAGMA foreign_keys = ON")) { close(); throw ctkPluginDatabaseException(QString("Enabling foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); //Check database structure (tables) and recreate tables if neccessary //If one of the tables is missing remove all tables and recreate them //This operation is required in order to avoid data coruption if (!checkTables()) { if (dropTables()) { createTables(); } else { //dropTables() should've handled error message //and warning close(); } } // silently remove any plugin marked as uninstalled cleanupDB(); //Update database based on the recorded timestamps updateDB(); initNextFreeIds(); }
/*! Verify the database Returns true if the correct tables are present and the schema is the correct version. \pre The database referred to by \e dbFilename exists and is a valid database. */ bool MainDbSchema::verify(const QString* dbFilename, QStringList* missingTablesList) { return checkTables(*dbFilename, missingTablesList) && schemaVersionOk(); }
//---------------------------------------------------------------------------- void ctkPluginStorageSQL::open() { if (m_isDatabaseOpen) return; QString path; //Create full path to database if(m_databasePath.isEmpty ()) m_databasePath = getDatabasePath(); path = m_databasePath; QFileInfo dbFileInfo(path); if (!dbFileInfo.dir().exists()) { if(!QDir::root().mkpath(dbFileInfo.path())) { close(); QString errorText("Could not create database directory: %1"); throw ctkPluginDatabaseException(errorText.arg(dbFileInfo.path()), ctkPluginDatabaseException::DB_CREATE_DIR_ERROR); } } m_connectionName = dbFileInfo.completeBaseName(); QSqlDatabase database; if (QSqlDatabase::contains(m_connectionName)) { database = QSqlDatabase::database(m_connectionName); } else { database = QSqlDatabase::addDatabase("QSQLITE", m_connectionName); database.setDatabaseName(path); } if (!database.isValid()) { close(); throw ctkPluginDatabaseException(QString("Invalid database connection: %1").arg(m_connectionName), ctkPluginDatabaseException::DB_CONNECTION_INVALID); } //Create or open database if (!database.isOpen()) { if (!database.open()) { close(); throw ctkPluginDatabaseException(QString("Could not open database. ") + database.lastError().text(), ctkPluginDatabaseException::DB_SQL_ERROR); } } m_isDatabaseOpen = true; //Check if the sqlite version supports foreign key constraints QSqlQuery query(database); if (!query.exec("PRAGMA foreign_keys")) { close(); throw ctkPluginDatabaseException(QString("Check for foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } if (!query.next()) { close(); throw ctkPluginDatabaseException(QString("SQLite db does not support foreign keys. It is either older than 3.6.19 or was compiled with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER"), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); query.clear(); //Enable foreign key support if (!query.exec("PRAGMA foreign_keys = ON")) { close(); throw ctkPluginDatabaseException(QString("Enabling foreign key support failed."), ctkPluginDatabaseException::DB_SQL_ERROR); } query.finish(); //Check database structure (tables) and recreate tables if neccessary //If one of the tables is missing remove all tables and recreate them //This operation is required in order to avoid data coruption if (!checkTables()) { if (dropTables()) { createTables(); } else { //dropTables() should've handled error message //and warning close(); } } // silently remove any plugin marked as uninstalled cleanupDB(); //Update database based on the recorded timestamps updateDB(); initNextFreeIds(); }