//插入Note方法 int NoteDAO::create(string pDate, string pContent) { //初始化数据库 initDB(); sqlite3* db= NULL; string path = dbDirectoryFile(); if (sqlite3_open(path.c_str(), &db) != SQLITE_OK) { sqlite3_close(db); CCASSERT(false, "DB open failure."); } else { string sqlStr = "INSERT OR REPLACE INTO note (cdate, content) VALUES (?,?)"; sqlite3_stmt *statement; //预处理过程 if (sqlite3_prepare_v2(db, sqlStr.c_str(), -1, &statement, NULL) == SQLITE_OK) { //绑定参数开始 sqlite3_bind_text(statement, 1, pDate.c_str(), -1, NULL); sqlite3_bind_text(statement, 2, pContent.c_str(), -1, NULL); //执行插入 if (sqlite3_step(statement) != SQLITE_DONE) { CCASSERT(false, "Insert Data failure."); } } sqlite3_finalize(statement); sqlite3_close(db); } return 0; }
/*! Constructs the log engine with the given \a parent. */ LogEngine::LogEngine(QObject *parent): QObject(parent) { m_db = QSqlDatabase::addDatabase("QSQLITE"); m_db.setDatabaseName(GuhSettings::logPath()); m_dbMaxSize = 8000; if (QCoreApplication::instance()->organizationName() == "guh-test") { m_dbMaxSize = 20; qCDebug(dcLogEngine) << "Set logging dab max size to" << m_dbMaxSize << "for testing."; } qCDebug(dcLogEngine) << "Opening logging database" << m_db.databaseName(); if (!m_db.isValid()) { qCWarning(dcLogEngine) << "Database not valid:" << m_db.lastError().driverText() << m_db.lastError().databaseText(); return; } if (!m_db.open()) { qCWarning(dcLogEngine) << "Error opening log database:" << m_db.lastError().driverText() << m_db.lastError().databaseText(); return; } initDB(); }
//删除Note方法 int NoteDAO::remove(string pDate) { //初始化数据库 initDB(); sqlite3* db= NULL; string path = dbDirectoryFile(); if (sqlite3_open(path.c_str(), &db) != SQLITE_OK) { sqlite3_close(db); CCASSERT(false, "DB open failure."); } else { string sqlStr = "DELETE from note where cdate =?"; sqlite3_stmt *statement; //预处理过程 if (sqlite3_prepare_v2(db, sqlStr.c_str(), -1, &statement, NULL) == SQLITE_OK) { //绑定参数开始 sqlite3_bind_text(statement, 1, pDate.c_str(), -1, NULL); //执行删除 if (sqlite3_step(statement) != SQLITE_DONE) { CCASSERT(false, "Delete Data failure."); } } sqlite3_finalize(statement); sqlite3_close(db); } return 0; }
int main() { struct sOneWireDevice *devices, *device; pthread_t poll_thread; struct timeval tick; unsigned long last_tick; #ifdef DEBUG fprintf(stderr, "Debug mode\r\n"); #endif log_entry("Starting up", LOG_NO_EXIT); KEEP_RUNNING = 1; zExitCode = 0; signal(SIGINT, intHandler); initDB(); initGPIO(); if (pthread_create(&poll_thread, NULL, cPoll, NULL)) { log_entry("Error creating thread", EXIT_FAILURE); } gettimeofday(&tick, NULL); last_tick = tick.tv_sec; devices = list_devices(); while (KEEP_RUNNING == 1) { gettimeofday(&tick, NULL); if ((tick.tv_sec - last_tick) >= LOG_INTERVAL) { last_tick = tick.tv_sec; device = devices; while (device != NULL) { if (updateValue(device) != NULL) log_device(device); device = device->next; } power = 0; elapsedTicks = 0; } sleep(1); } if (pthread_join(poll_thread, NULL)) { log_entry("Error joining thread\n", EXIT_FAILURE); } device = devices; while (device != NULL) { devices = device->next; free(device); device = devices; } restoreGPIO(); log_entry("Cleanup finished, exiting", LOG_NO_EXIT); return (0); }
void Contest::init() { logMsg("Initialize Database..."); initDB(); logMsg("done\n"); /* logMsg("Load codes into RAM..."); loadCodes(); logMsg("done\n");*/ logMsg("Initialize Prizes..."); if (SetupPrizes == true) { setupPrizes(); logMsg("done\n"); } else logMsg("Already initialized.\n"); logMsg("Started signal handler..."); initSignal(); logMsg("done\n"); logMsg("Started thread engine..."); initThreads(iaddr); logMsg("done\n"); current_day = 0; current_week = 0; current_month = 0; return; }
int main(int argc , char **argv){ DB *db = initDB(); int i; Reference *ref ; for (i = 0; i < 3 ; i++){ ref = malloc(sizeof(Reference)); ref->citKey = teste[i].citKey; ref->autores = teste[i].autores; ref->title = teste[i].title; addCitation(db, teste[i].categoria, ref); } if (argc == 3) { dump_dot_file(db,argv[1], argv[2]); return 0; } if (argc == 2){ dump_html_file(db, argv[1]); return 0; } printf("%s FILE_NAME <- gerar html\n",argv[0]); printf("%s FILE_NAME AUTHOR <- gerar dot\n",argv[0]); return 0; }
int PointSqlQueryModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QSqlQueryModel::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: setQuery((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QSqlDatabase(*)>(_a[2]))); break; case 1: setQuery((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 2: setQuery((*reinterpret_cast< const QSqlQuery(*)>(_a[1]))); break; case 3: { QVariant _r = data((*reinterpret_cast< const QModelIndex(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< QVariant*>(_a[0]) = _r; } break; case 4: refresh((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2])),(*reinterpret_cast< double(*)>(_a[3]))); break; case 5: refreshSearch((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 6: { QVariant _r = datasingle((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< QVariant*>(_a[0]) = _r; } break; case 7: { bool _r = openDB(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 8: initDB(); break; case 9: closeDB(); break; case 10: { double _r = distance((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2])),(*reinterpret_cast< double(*)>(_a[3])),(*reinterpret_cast< double(*)>(_a[4]))); if (_a[0]) *reinterpret_cast< double*>(_a[0]) = _r; } break; default: ; } _id -= 11; } return _id; }
//修改Note方法 int NoteDAO::modify(string pDate, string pContent) { //初始化数据库 initDB(); sqlite3* db= NULL; string path = dbDirectoryFile(); if (sqlite3_open(path.c_str(), &db) != SQLITE_OK) { sqlite3_close(db); CCASSERT(false, "DB open failure."); } else { string sqlStr = "UPDATE note set content=? where cdate =?"; sqlite3_stmt *statement; //预处理过程 if (sqlite3_prepare_v2(db, sqlStr.c_str(), -1, &statement, NULL) == SQLITE_OK) { //绑定参数开始 sqlite3_bind_text(statement, 1, pContent.c_str(), -1, NULL); sqlite3_bind_text(statement, 2, pDate.c_str(), -1, NULL); //执行修改数据 if (sqlite3_step(statement) != SQLITE_DONE) { CCASSERT(false, "Upate Data failure."); } } sqlite3_finalize(statement); sqlite3_close(db); } return 0; }
//查询所有数据方法 ValueVector NoteDAO::findAll() { //初始化数据库 initDB(); sqlite3* db= NULL; string path = dbDirectoryFile(); ValueVector listData; if (sqlite3_open(path.c_str(), &db) != SQLITE_OK) { sqlite3_close(db); CCASSERT(false, "DB open failure."); } else { string qsql = "SELECT cdate,content FROM Note"; sqlite3_stmt *statement; //预处理过程 if (sqlite3_prepare_v2(db, qsql.c_str(), -1, &statement, NULL) == SQLITE_OK) { //执行 while (sqlite3_step(statement) == SQLITE_ROW) { char *cdate = (char *)sqlite3_column_text(statement, 0); char *content = (char *)sqlite3_column_text(statement, 1); ValueMap dict ; dict["date"] = Value(cdate); dict["content"] = Value(content); listData.push_back(Value(dict)); } } sqlite3_finalize(statement); sqlite3_close(db); } return listData; }
void LoginServer::run() { auto logger = el::Loggers::getLogger("ServPG"); processMaps(logger); logger->info("Running login server on port %v.", serverDetails.port); logger->info("\"%v\", version %v (%v)", serverDetails.friendlyName, Version::versionString, Version::gitHash); processingThread = std::thread([this]() {this->processIncoming();}); connectedThread = std::thread([this]() {this->processConnected();}); initDB(logger); while (!done) { auto newPlayerSocket = playerAcceptor->acceptSocket(); if (newPlayerSocket != nullptr) { logger->verbose(9, "Accepted a connection from: %v. Sending to processing thread.", newPlayerSocket->remoteHost); std::lock_guard<std::mutex> incomingGuard(incomingConnectionsMutex); incomingConnections.emplace_back(std::move(newPlayerSocket)); } else { if (playerAcceptor->hasError()) { logger->error("Error in playerAcceptor, exiting."); break; } } } processingThread.join(); connectedThread.join(); }
AccountingForm::AccountingForm(const int& pat_id) : m_patient(pat_id) { createLayout(); makeConnections(); initDB(); initialUpdate(); }
//------------------------------------------------------------------------------------- bool Interfaces::initializeEnd() { PythonApp::initializeEnd(); mainProcessTimer_ = this->dispatcher().addTimer(1000000 / g_kbeSrvConfig.gameUpdateHertz(), this, reinterpret_cast<void *>(TIMEOUT_TICK)); // 不做频道超时检查 CLOSE_CHANNEL_INACTIVITIY_DETECTION(); if (!initDB()) return false; SCOPED_PROFILE(SCRIPTCALL_PROFILE); // 所有脚本都加载完毕 PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), const_cast<char*>("onInterfaceAppReady"), const_cast<char*>("")); if(pyResult != NULL) Py_DECREF(pyResult); else SCRIPT_ERROR_CHECK(); pTelnetServer_ = new TelnetServer(&this->dispatcher(), &this->networkInterface()); pTelnetServer_->pScript(&this->getScript()); bool ret = pTelnetServer_->start(g_kbeSrvConfig.getInterfaces().telnet_passwd, g_kbeSrvConfig.getInterfaces().telnet_deflayer, g_kbeSrvConfig.getInterfaces().telnet_port); Components::getSingleton().extraData4(pTelnetServer_->port()); return ret; }
bool SessionManager::init(int argc, char *argv[]) { srand(time(&curTime)); option.load(argc, argv); if (!initDB()) return false; s2s->connect(option.s2s_ip, option.s2s_port, 30); if (!createSocket(SOCK_STREAM)) return false; if (!bindAddress(option.sm_ip, option.sm_port)) { ICQ_LOG("Can not bind on port %d\n", option.sm_port); return false; } listen(sockfd, 5); addEvent(SOCKET_READ); ICQ_LOG("sm is now started\n"); return true; }
Server::Server(std::string con_info) : accepting_clients(sf::Socket::Disconnected), max_connected_players(1), current_connected_players(0), port(14000), turn_count(1), max_turns(1000), active_player(0) { /* * We will need to have a socket instantiated * to accept the first player */ players.push_back(new RemotePlayer()); try { packetF = new PacketFactory(con_info); } catch(std::exception &e){ std::cerr << e.what() << std::endl; } try { troopDAO = new TroopDAO(con_info); cityDAO = new CityDAO(con_info); } catch(std::exception &e){ std::cerr << e.what() << std::endl; } initDB(); }
int main(int argc, char *argv[]) { initDB(); QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
bool MySqlAdapter::createDatabase(const QString &name) { m_lastQuery = QString("CREATE DATABASE %1;") .arg(name); bool result = m_query.exec(m_lastQuery); if(result) initDB(name); return result; }
YipDirectory::YipDirectory(const std::string & prjPath, const Project * project) : m_Path(pathConcat(prjPath, ".yip")), m_Project(project) { pathCreate(m_Path); m_Path = pathMakeCanonical(m_Path); m_DB = std::make_shared<SQLiteDatabase>(pathConcat(m_Path, "db")); initDB(); }
DBClass::DBClass( QString _dbName, QString _host, QString _user, QString _pass ): dbName( _dbName ), host ( _host ), user( _user ), pass ( _pass ) { if ( !QSqlDatabase::database().isOpen() ) { initDB (); } isOpened (); }
//------------------------------------------------------------------------------------- bool BillingSystem::initializeEnd() { mainProcessTimer_ = this->getMainDispatcher().addTimer(1000000 / g_kbeSrvConfig.gameUpdateHertz(), this, reinterpret_cast<void *>(TIMEOUT_TICK)); // 不做频道超时检查 CLOSE_CHANNEL_INACTIVITIY_DETECTION(); this->threadPool().addTask(new AnonymousChannel()); return initDB(); }
LogEngine::LogEngine(QObject *parent): QObject(parent) { m_db = QSqlDatabase::addDatabase("QSQLITE"); m_db.setDatabaseName("/tmp/guhd-logs.sqlite"); if (!m_db.open()) { qCWarning(dcLogEngine) << "Error opening log database:" << m_db.lastError().driverText() << m_db.lastError().databaseText(); return; } initDB(); }
int main(void){ //Declara e inicia database database_t db; initDB(&db); //Loop do Menu Principal while(menu_principal(&db)); //Encerra database, liberando todas as estruturas closeDB(&db); return 0; }
objsearch_pi::objsearch_pi ( void *ppimgr ) : opencpn_plugin_112 ( ppimgr ) { // Create the PlugIn icons initialize_images(); m_db_thread_running = false; m_bDBUsable = true; m_bWaitForDB = true; finishing = false; m_db = initDB(); wxSQLite3ResultSet set; if (m_bDBUsable) { set = SelectFromDB( m_db, wxT("SELECT id, chartname, scale, nativescale FROM chart") ); if (m_bDBUsable) { while (set.NextRow()) { Chart ch; ch.id = set.GetInt(0); ch.name = set.GetAsString(1); ch.scale = set.GetDouble(2); ch.nativescale = set.GetInt(3); m_chartsInDb[ch.name] = ch; } } set.Finalize(); } if (m_bDBUsable) { set = SelectFromDB( m_db, wxT("SELECT id, featurename FROM feature")); if (m_bDBUsable) { while (set.NextRow()) { m_featuresInDb[set.GetAsString(1)] = set.GetInt(0); } } set.Finalize(); } m_bWaitForDB = false; }
bool CGameWorld::init() { m_iTime = Sys_GetTime(); const char* pFilePath = "setup.xml"; TiXmlDocument xmlDoc(pFilePath); if (!xmlDoc.LoadFile()) { CORE("init:","load setup.xml error"); return false; } TiXmlElement *root = xmlDoc.RootElement(); if (root==NULL) { CORE("init:","init error RootElement"); return false; } if (!initConfig(root->FirstChildElement("config"))) { CORE("init:","initConfig error"); return false; } if (!initNet(root->FirstChildElement("net"))) { CORE("init:","initNet error"); return false; } if (!initDB(root->FirstChildElement("db"))) { CORE("init:","initDB error"); return false; } if (!initData()) { return false; } return true; }
SyncStore::SyncStore() : Store::Store() { try { initDB(DB_COUNT, m_countDB, DB_INDEXTYPE, DB_INDEXFLAG); } catch (DbException &e) { std::cerr << "Error opening database environment: " << DB_HOME << std::endl; std::cerr << e.what() << std::endl; exit(-1); } catch (std::exception &e) { std::cerr << "Error opening database environment: " << DB_HOME << std::endl; std::cerr << e.what() << std::endl; exit(-1); } }
//------------------------------------------------------------------------------------- bool Dbmgr::initializeEnd() { // 添加一个timer, 每秒检查一些状态 loopCheckTimerHandle_ = this->dispatcher().addTimer(1000000, this, reinterpret_cast<void *>(TIMEOUT_CHECK_STATUS)); mainProcessTimer_ = this->dispatcher().addTimer(1000000 / 50, this, reinterpret_cast<void *>(TIMEOUT_TICK)); // 添加globalData, baseAppData, cellAppData支持 pGlobalData_ = new GlobalDataServer(GlobalDataServer::GLOBAL_DATA); pBaseAppData_ = new GlobalDataServer(GlobalDataServer::BASEAPP_DATA); pCellAppData_ = new GlobalDataServer(GlobalDataServer::CELLAPP_DATA); pGlobalData_->addConcernComponentType(CELLAPP_TYPE); pGlobalData_->addConcernComponentType(BASEAPP_TYPE); pBaseAppData_->addConcernComponentType(BASEAPP_TYPE); pCellAppData_->addConcernComponentType(CELLAPP_TYPE); INFO_MSG(fmt::format("Dbmgr::initializeEnd: digest({})\n", EntityDef::md5().getDigestStr())); SCOPED_PROFILE(SCRIPTCALL_PROFILE); // 所有脚本都加载完毕 PyObject* pyResult = PyObject_CallMethod(getEntryScript().get(), const_cast<char*>("onDBMgrReady"), const_cast<char*>("")); if(pyResult != NULL) Py_DECREF(pyResult); else SCRIPT_ERROR_CHECK(); pTelnetServer_ = new TelnetServer(&this->dispatcher(), &this->networkInterface()); pTelnetServer_->pScript(&this->getScript()); bool ret = pTelnetServer_->start(g_kbeSrvConfig.getDBMgr().telnet_passwd, g_kbeSrvConfig.getDBMgr().telnet_deflayer, g_kbeSrvConfig.getDBMgr().telnet_port); Components::getSingleton().extraData4(pTelnetServer_->port()); return ret && initInterfacesHandler() && initDB(); }
QvernoteStorage::QvernoteStorage() : m_bStorageEnabled(false) { db = QSqlDatabase::addDatabase("QSQLITE"); QString path(QDir::home().path()); path.append(QDir::separator()).append(QVERNOTE_DB); path = QDir::toNativeSeparators(path); db.setDatabaseName(path); qDebug() << __FUNCTION__ << "Database path set to: " << path; if(!db.isValid()) { qDebug() << __FUNCTION__ << "No valid driver for SQLITE"; m_bStorageEnabled = false; return; } if(!db.open()) { qDebug() << __FUNCTION__ << "Error opening db"; m_bStorageEnabled = false; return; } if(db.tables().size() == 0) { if(initDB() == false) { m_bStorageEnabled = false; return; } } // check if thumbnail table exists: if(db.tables().indexOf("thumbnails") == -1) { QSqlQuery query(db); query.exec(PREPARE_NOTE_THUMBNAIL_SCRIPT); } enableForeignKeys(); m_bStorageEnabled = true; }
//------------------------------------------------------------------------------------- bool Dbmgr::initializeEnd() { // 添加一个timer, 每秒检查一些状态 loopCheckTimerHandle_ = this->getMainDispatcher().addTimer(1000000, this, reinterpret_cast<void *>(TIMEOUT_CHECK_STATUS)); mainProcessTimer_ = this->getMainDispatcher().addTimer(1000000 / g_kbeSrvConfig.gameUpdateHertz(), this, reinterpret_cast<void *>(TIMEOUT_TICK)); // 添加globalData, globalBases, cellAppData支持 pGlobalData_ = new GlobalDataServer(GlobalDataServer::GLOBAL_DATA); pGlobalBases_ = new GlobalDataServer(GlobalDataServer::GLOBAL_BASES); pCellAppData_ = new GlobalDataServer(GlobalDataServer::CELLAPP_DATA); pGlobalData_->addConcernComponentType(CELLAPP_TYPE); pGlobalData_->addConcernComponentType(BASEAPP_TYPE); pGlobalBases_->addConcernComponentType(BASEAPP_TYPE); pCellAppData_->addConcernComponentType(CELLAPP_TYPE); return initBillingHandler() && initDB(); }
bool ICQMain::init(int argc, char *argv[]) { srand(time(&curTime)); option.load(argc, argv); // Open logger logger->open(option.log_ip, option.log_port, option.log_level, "linqd"); if (!initDB() || !c2s->init()) return false; // Enumerate all of the modules ConfigParser parser(LINQ_CONFIG_DIR"/modules.conf"); parser.start(this); // Start all event threads startThreads(); logger->log(LOG_INFORMATION, "linqd is now started"); return true; }
bool DB::dumpFlow(time_t when, Flow *f) { const char *create_flows_db = "BEGIN; CREATE TABLE IF NOT EXISTS flows (vlan_id number, cli_ip string KEY, cli_port number, " "srv_ip string KEY, srv_port number, proto number, bytes number, duration number, json string);"; char sql[4096], cli_str[64], srv_str[64], *json; initDB(when, create_flows_db); json = f->serialize(); snprintf(sql, sizeof(sql), "INSERT INTO flows VALUES (%u, '%s', %u, '%s', %u, %lu, %u, %u, '%s');", f->get_vlan_id(), f->get_cli_host()->get_ip()->print(cli_str, sizeof(cli_str)), f->get_cli_port(), f->get_srv_host()->get_ip()->print(srv_str, sizeof(srv_str)), f->get_srv_port(), (unsigned long)f->get_bytes(), f->get_duration(), f->get_protocol(), json ? json : ""); if(json) free(json); execSQL(db, sql); return(true); }
//------------------------------------------------------------------------------------- bool Dbmgr::initializeEnd() { // 添加一个timer, 每秒检查一些状态 loopCheckTimerHandle_ = this->getMainDispatcher().addTimer(1000000, this, reinterpret_cast<void *>(TIMEOUT_CHECK_STATUS)); mainProcessTimer_ = this->getMainDispatcher().addTimer(1000000 / g_kbeSrvConfig.gameUpdateHertz(), this, reinterpret_cast<void *>(TIMEOUT_TICK)); // 添加globalData, baseAppData, cellAppData支持 pGlobalData_ = new GlobalDataServer(GlobalDataServer::GLOBAL_DATA); pBaseAppData_ = new GlobalDataServer(GlobalDataServer::BASEAPP_DATA); pCellAppData_ = new GlobalDataServer(GlobalDataServer::CELLAPP_DATA); pGlobalData_->addConcernComponentType(CELLAPP_TYPE); pGlobalData_->addConcernComponentType(BASEAPP_TYPE); pBaseAppData_->addConcernComponentType(BASEAPP_TYPE); pCellAppData_->addConcernComponentType(CELLAPP_TYPE); INFO_MSG(boost::format("Dbmgr::initializeEnd: digest(%1%)\n") % EntityDef::md5().getDigestStr()); return initBillingHandler() && initDB(); }