void sendAprs(struct gpsCoordinates gpsData, int radioId, struct repeater repeater){ char toSend[300]; char timeString[7]; char SQLQUERY[200]; int sockfd; struct idInfo radioIdent = {0}; sqlite3 *dbase; sqlite3_stmt *stmt; unsigned char aprsCor[30]; dbase = openDatabase(); sprintf(SQLQUERY,"SELECT callsign,aprsSuffix,aprsBeacon,aprsSymbol,lastAprsTime FROM callsigns WHERE radioId = %i",radioId); if (sqlite3_prepare_v2(dbase,SQLQUERY,-1,&stmt,0) == 0){ if (sqlite3_step(stmt) == SQLITE_ROW){ sprintf(radioIdent.callsign,"%s",sqlite3_column_text(stmt,0)); sprintf(radioIdent.aprsSuffix,"%s",sqlite3_column_text(stmt,1)); sprintf(radioIdent.aprsBeacon,"%s",sqlite3_column_text(stmt,2)); radioIdent.aprsSymbol = sqlite3_column_int(stmt,3); radioIdent.aprsTimeStamp = sqlite3_column_int(stmt,4); sqlite3_finalize(stmt); } else{ sqlite3_finalize(stmt); syslog(LOG_NOTICE,"[%s]DMR ID %i not found in database, not sending to aprs.fi",repeater.callsign,radioId); closeDatabase(dbase); return; } } else{ syslog(LOG_NOTICE,"[%s]Bad query %s",repeater.callsign,SQLQUERY); closeDatabase(dbase); return; } if (time(NULL) - radioIdent.aprsTimeStamp < 5){ syslog(LOG_NOTICE,"[%s]Preventing aprs.fi flooding for %s",repeater.callsign,radioIdent.callsign); closeDatabase(dbase); return; } sprintf(SQLQUERY,"UPDATE callsigns SET hasSendAprs = 1, lastAprsTime = %lu where radioId = %i",time(NULL),radioId); sqlite3_exec(dbase,SQLQUERY,0,0,0); closeDatabase(dbase); sprintf(aprsCor,"%s/%s>%s/%s",gpsData.latitude,gpsData.longitude,gpsData.heading,gpsData.speed); aprsCor[18] = radioIdent.aprsSymbol; sprintf(toSend,"user %s pass %s vers DMRgate 1.0\n%s%s>APRS,%s,qAR,%s:!%s %s\n",repeater.callsign,repeater.aprsPass,radioIdent.callsign,radioIdent.aprsSuffix,repeater.callsign,repeater.callsign,aprsCor,radioIdent.aprsBeacon); //sockfd = openAprsSock(); //send(sockfd,toSend,strlen(toSend),0); //close(sockfd); syslog(LOG_NOTICE,"[%s]Would send info to APRS network for %s [%s]",repeater.callsign,radioIdent.callsign,toSend); }
bool Buffer::quitProc(string& dbName){ closeDatabase(dbName); delete fileHead; return true; }
void Database::close() { ASSERT(databaseContext()->databaseThread()); ASSERT(currentThread() == databaseContext()->databaseThread()->getThreadID()); { MutexLocker locker(m_transactionInProgressMutex); // Clean up transactions that have not been scheduled yet: // Transaction phase 1 cleanup. See comment on "What happens if a // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. RefPtr<SQLTransactionBackend> transaction; while (!m_transactionQueue.isEmpty()) { transaction = m_transactionQueue.takeFirst(); transaction->notifyDatabaseThreadIsShuttingDown(); } m_isTransactionQueueEnabled = false; m_transactionInProgress = false; } closeDatabase(); // DatabaseThread keeps databases alive by referencing them in its // m_openDatabaseSet. DatabaseThread::recordDatabaseClose() will remove // this database from that set (which effectively deref's it). We hold on // to it with a local pointer here for a liitle longer, so that we can // unschedule any DatabaseTasks that refer to it before the database gets // deleted. Ref<DatabaseBackend> protect(*this); databaseContext()->databaseThread()->recordDatabaseClosed(this); databaseContext()->databaseThread()->unscheduleDatabaseTasks(this); }
int main(int argc, char *argv[]) { sqlite3 *db; int64 count; parseArgs(argc, argv); db = openDatabase(); if (rebuild) { dropGlueTables(db); } makeTables(db); fillGlueTables(db); count = writeEventsToSQL(db); evlog(LOG_ALWAYS, "Imported %llu events from %s to %s, serial %lu.", count, logFileName, databaseName, logSerial); if (runTests) { /* TODO: more unit tests in here */ testTableExists(db); } closeDatabase(db); return 0; }
DatabaseSync::~DatabaseSync() { ASSERT(m_scriptExecutionContext->isContextThread()); if (opened()) { DatabaseTracker::tracker().removeOpenDatabase(this); closeDatabase(); } }
void DatabaseTabWidget::closeDatabaseFromSender() { Q_ASSERT(sender()); DatabaseWidget* dbWidget = static_cast<DatabaseWidget*>(sender()); Database* db = databaseFromDatabaseWidget(dbWidget); int index = databaseIndex(db); setCurrentIndex(index); closeDatabase(db); }
bool DatabaseTabWidget::closeAllDatabases() { while (!m_dbList.isEmpty()) { if (!closeDatabase()) { return false; } } return true; }
bool DatabaseTabWidget::closeDatabase(int index) { if (index == -1) { index = currentIndex(); } setCurrentIndex(index); return closeDatabase(indexDatabase(index)); }
void DatabaseSync::closeImmediately() { ASSERT(m_scriptExecutionContext->isContextThread()); if (!opened()) return; logErrorMessage("forcibly closing database"); closeDatabase(); }
MainWindow::~MainWindow() { lib->clearDB(); lib->exportDB(); closeDatabase(); lib->erase(); delete lib; delete tableWidgetLibrary; delete ui; }
void SqliteMerge::mergeFiles() { // If there is only one file, we are done. if (m_files.size() == 1) { sqlite3 *main_db = openDatabase(m_files[0]); createABUPS(main_db); closeDatabase(main_db); renameFinalDatabase( m_files[0]); } else { // Otherwise, there are more files.. sqlite3 *main_db = openDatabase(m_files[0]); //summary(main_db); //m_primaryKeyBase = sqlite3_last_insert_rowid(main_db); //std::sort(m_files.begin(),m_files.end()); for (size_t i = 1; i < m_files.size(); ++i) { //m_primaryKeyBase = i*1000; //m_primaryKeyBase = sqlite3_last_insert_rowid(main_db); mergeDatabases(main_db,m_files[i]); } //summary(main_db); //printMeterData(main_db); //CreateView //CreateView(main_db); //for testing purposes // create ABUPS table in main database // begin(main_db); //meaningless is the tabular data now dropTabularData(main_db); createABUPS(main_db); commit(main_db); closeDatabase(main_db); renameFinalDatabase( m_files[0]); } }
void Logger::terminate() { Debug(1, "Terminating Logger" ); if ( mFileLevel > NOLOG ) closeFile(); if ( mSyslogLevel > NOLOG ) closeSyslog(); if ( mDatabaseLevel > NOLOG ) closeDatabase(); }
DatabaseBackendSync::~DatabaseBackendSync() { // SQLite is "multi-thread safe", but each database handle can only be used // on a single thread at a time. // // For DatabaseBackendSync, we open the SQLite database on the script context // thread. And hence we should also close it on that same thread. This means // that the SQLite database need to be closed here in the destructor. ASSERT(m_databaseContext->isContextThread()); if (opened()) closeDatabase(); }
void DatabaseSync::closeImmediately() { if (!m_scriptExecutionContext->isContextThread()) { m_scriptExecutionContext->postTask(CloseSyncDatabaseOnContextThreadTask::create(this)); return; } if (!opened()) return; DatabaseTracker::tracker().removeOpenDatabase(this); closeDatabase(); }
bool databaseSqlite::createDatabase(QWidget *parent,QString *path) { if (!path) {//show dialog and get a newPath qDebug()<<"no hay path"<<*path; QString newPath = QFileDialog::getSaveFileName(parent, QObject::tr("Create Database"), misc::filesPath(), "SQLite3 (*.sqlite3)", 0, QFileDialog::DontConfirmOverwrite); if (newPath.isEmpty()) return false; path=&newPath; } //create a copy of the database in the *path QString oldDb = QSqlDatabase::database().databaseName(); closeDatabase(); if (QFile::exists(*path)) { QMessageBox::critical(0, QObject::tr("Database Error"), QObject::tr("Database exists already.")); if (!oldDb.isEmpty()) connectDatabase(oldDb); return false; } if(!QFile::copy(":/sqlite/todoro.db",*path)) { QString msg =QString("Copying database to %1 failed").arg(*path); QMessageBox::critical(0,"Error",msg); if (!oldDb.isEmpty()) connectDatabase(oldDb); return false; } QFile::setPermissions(*path, QFile::ReadUser | QFile::WriteUser | QFile::WriteOwner | QFile::ReadOwner); if (!connectDatabase(*path)) { if (!oldDb.isEmpty()) connectDatabase(oldDb); return false; } else { return true; } }
int main(int argc,char **argv) { sqlite3 *db; BriefInfo *info; FinalPhoneList *phonelist; db = openDatabase(); phonelist = getPhone("233231","2010-04-14",db); while(phonelist != NULL) { puts(phonelist->telephone); phonelist = phonelist->next; } closeDatabase(db); return 0; }
void Database::close() { ASSERT(m_scriptExecutionContext->databaseThread()); ASSERT(currentThread() == m_scriptExecutionContext->databaseThread()->getThreadID()); { MutexLocker locker(m_transactionInProgressMutex); m_isTransactionQueueEnabled = false; m_transactionInProgress = false; } closeDatabase(); // Must ref() before calling databaseThread()->recordDatabaseClosed(). RefPtr<Database> protect = this; m_scriptExecutionContext->databaseThread()->recordDatabaseClosed(this); m_scriptExecutionContext->databaseThread()->unscheduleDatabaseTasks(this); DatabaseTracker::tracker().removeOpenDatabase(this); }
// // delete all collections, their metadata, then the database // Status BLTreeEngine::dropDatabase( OperationContext* ctx, const StringData& db ) { const string prefix = db.toString() + "."; boost::mutex::scoped_lock lk( _entryMapMutex ); vector<string> toDrop; for (EntryMap::const_iterator i = _entryMap.begin(); i != _entryMap.end(); ++i ) { const StringData& ns = i->first; if ( ns.startsWith( prefix ) ) { toDrop.push_back( ns.toString() ); } } for (vector<string>::const_iterator j = toDrop.begin(); j != toDrop.end(); ++j ) { _dropCollection_inlock( ctx, *j ); } return closeDatabase( ctx, db ); }
void Register::on_register_registerPushButton_clicked() { QString lastName = ui->register_lnameLineEdit->text(); QString firstName = ui->register_fnameLineEdit->text(); QString email = ui->register_emailLineEdit->text(); QString username = ui->register_usernameLineEdit->text(); QString password = ui->register_pwdLineEdit->text(); QString verifyPwd = ui->register_verifypwdLineEdit->text(); if(password==verifyPwd) { if(connectToDatabase()) { if(checkUserExists(email)) { QMessageBox::warning(this, "warning", "The user already exists"); } else { User newUser; newUser.setFirstName(firstName); newUser.setLastName(lastName); newUser.setUserName(username); newUser.setEmail(email); newUser.setPassword(password); if(addNewUser(newUser)) { QMessageBox::about(this,"Register","The new account created!"); } close(); } } } else { QMessageBox::warning(this,"Waring","The passwords are not matched."); } closeDatabase(); }
bool databaseSqlite::openDatabase(QWidget *parent) { QString oldPath = QFileInfo(QSqlDatabase::database().databaseName()).absolutePath(); QString path = QFileDialog::getOpenFileName(parent, "Open Database", (oldPath.isEmpty()) ? misc::filesPath() : oldPath, "SQLite3 (*.sqlite3)"); if (path.isEmpty()) return false; QString oldDb = QSqlDatabase::database().databaseName(); closeDatabase(); if(!connectDatabase(path)) { if (!oldDb.isEmpty()) return connectDatabase(oldDb); return false; } return true; }
void DatabaseBackend::close() { ASSERT(databaseContext()->databaseThread()); ASSERT(databaseContext()->databaseThread()->isDatabaseThread()); { MutexLocker locker(m_transactionInProgressMutex); // Clean up transactions that have not been scheduled yet: // Transaction phase 1 cleanup. See comment on "What happens if a // transaction is interrupted?" at the top of SQLTransactionBackend.cpp. RefPtrWillBeRawPtr<SQLTransactionBackend> transaction = nullptr; while (!m_transactionQueue.isEmpty()) { transaction = m_transactionQueue.takeFirst(); transaction->notifyDatabaseThreadIsShuttingDown(); } m_isTransactionQueueEnabled = false; m_transactionInProgress = false; } closeDatabase(); databaseContext()->databaseThread()->recordDatabaseClosed(this); }
bool QgsOSMXmlImport::import() { mError.clear(); // open input mInputFile.setFileName( mXmlFileName ); if ( !mInputFile.open( QIODevice::ReadOnly ) ) { mError = QString( "Cannot open input file: %1" ).arg( mXmlFileName ); return false; } // open output if ( QFile::exists( mDbFileName ) ) { if ( !QFile( mDbFileName ).remove() ) { mError = QString( "Database file cannot be overwritten: %1" ).arg( mDbFileName ); return false; } } if ( !createDatabase() ) { // mError is set in createDatabase() return false; } qDebug( "starting import" ); int retX = sqlite3_exec( mDatabase, "BEGIN", NULL, NULL, 0 ); Q_ASSERT( retX == SQLITE_OK ); Q_UNUSED( retX ); // start parsing QXmlStreamReader xml( &mInputFile ); while ( !xml.atEnd() ) { xml.readNext(); if ( xml.isEndDocument() ) break; if ( xml.isStartElement() ) { if ( xml.name() == "osm" ) readRoot( xml ); else xml.raiseError( "Invalid root tag" ); } } int retY = sqlite3_exec( mDatabase, "COMMIT", NULL, NULL, 0 ); Q_ASSERT( retY == SQLITE_OK ); Q_UNUSED( retY ); createIndexes(); if ( xml.hasError() ) { mError = QString( "XML error: %1" ).arg( xml.errorString() ); return false; } closeDatabase(); return true; }
ossimVpfDatabase::~ossimVpfDatabase() { deleteLibraryList(); closeDatabase(); }
ClientConnection::~ClientConnection() { closeDatabase(); }
void databaseSqlite::removeDatabase(QString path) { closeDatabase(); QFile::remove(path); }
void MainWindow::createActions() { m_newAction = new QAction(this); m_newAction->setText(tr("&New")); m_newAction->setShortcut(QKeySequence::New); m_newAction->setIcon(QIcon(":/images/document-new.png")); m_newAction->setStatusTip(tr("Create a new, in memory, SQLite database")); connect(m_newAction, SIGNAL(triggered()), this, SLOT(openMemoryDatabase())); m_openAction = new QAction(this); m_openAction->setText(tr("&Open")); m_openAction->setShortcut(QKeySequence::Open); m_openAction->setIcon(QIcon(":/images/document-open.png")); m_openAction->setStatusTip(tr("Open an existing SQLite database")); connect(m_openAction, SIGNAL(triggered()), this, SLOT(openDatabase())); m_saveAction = new QAction(this); m_saveAction->setText(tr("&Save")); m_saveAction->setShortcut(QKeySequence::Save); m_saveAction->setStatusTip(tr("Save the database")); connect(m_saveAction, SIGNAL(triggered()), m_dbWidget, SIGNAL(commit())); m_saveAsAction = new QAction(this); m_saveAsAction->setText(tr("Save &As...")); m_saveAsAction->setShortcut(QKeySequence::SaveAs); m_saveAsAction->setStatusTip(tr("Save this database under a new name")); connect(m_saveAsAction, SIGNAL(triggered()), this, SLOT(saveAsDatabase())); m_closeAction = new QAction(this); m_closeAction->setText(tr("Close")); m_closeAction->setShortcut(QKeySequence::Close); m_closeAction->setStatusTip(tr("Close the currently opened database")); connect(m_closeAction, SIGNAL(triggered()), this, SLOT(closeDatabase())); for (int i = 0; i < MaxRecentFiles; ++i) { m_recentFileActions[i] = new QAction(this); m_recentFileActions[i]->setVisible(false); connect(m_recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); } m_exitAction = new QAction(this); m_exitAction->setText(tr("E&xit")); m_exitAction->setShortcut(QKeySequence::Quit); m_exitAction->setStatusTip(tr("Quits sbuilder")); connect(m_exitAction, SIGNAL(triggered()), this, SLOT(close())); m_undoAction = new QAction(this); m_undoAction->setText(tr("&Undo")); m_undoAction->setShortcut(QKeySequence::Undo); connect(m_undoAction, SIGNAL(triggered()), m_dbWidget, SLOT(undo())); m_redoAction = new QAction(this); m_redoAction->setText(tr("&Redo")); m_redoAction->setShortcut(QKeySequence::Redo); connect(m_redoAction, SIGNAL(triggered()), m_dbWidget, SLOT(redo())); m_cutAction = new QAction(this); m_cutAction->setText(tr("Cu&t")); m_cutAction->setShortcut(QKeySequence::Cut); m_cutAction->setIcon(QIcon(":/images/edit-cut.png")); connect(m_cutAction, SIGNAL(triggered()), m_dbWidget, SLOT(cut())); m_copyAction = new QAction(this); m_copyAction->setText(tr("&Copy")); m_copyAction->setShortcut(QKeySequence::Copy); m_copyAction->setIcon(QIcon(":/images/edit-copy.png")); connect(m_copyAction, SIGNAL(triggered()), m_dbWidget, SLOT(copy())); m_pasteAction = new QAction(this); m_pasteAction->setText(tr("&Paste")); m_pasteAction->setShortcut(QKeySequence::Paste); m_pasteAction->setIcon(QIcon(":/images/edit-paste.png")); connect(m_pasteAction, SIGNAL(triggered()), m_dbWidget, SLOT(paste())); m_selectAllAction = new QAction(this); m_selectAllAction->setText(tr("&Select All")); m_selectAllAction->setShortcut(QKeySequence::SelectAll); connect(m_selectAllAction, SIGNAL(triggered()), m_dbWidget, SLOT(selectAll())); m_runAction = new QAction(this); m_runAction->setText(tr("&Run")); // TODO: a better name m_runAction->setIcon(QIcon(":/images/media-playback-start.png")); m_runAction->setShortcut(QKeySequence(tr("F5"))); connect(m_runAction, SIGNAL(triggered()), m_dbWidget, SLOT(execute())); m_commitAction = new QAction(this); m_commitAction->setText(tr("&Commit")); connect(m_commitAction, SIGNAL(triggered()), m_dbWidget, SIGNAL(commit())); m_rollbackAction = new QAction(this); m_rollbackAction->setText(tr("Roll&back")); connect(m_rollbackAction, SIGNAL(triggered()), m_dbWidget, SIGNAL(rollback())); m_logAction = new QAction(this); m_logAction->setText(tr("Show Log")); connect(m_logAction, SIGNAL(triggered()), m_log, SLOT(show())); m_pragmaAction = new QAction(this); m_pragmaAction->setText(tr("Show &Pragmas")); connect(m_pragmaAction, SIGNAL(triggered()), m_pragmaDialog, SLOT(show())); m_memoryAction = new QAction(this); m_memoryAction->setText(tr("Show &Memory Stats")); connect(m_memoryAction, SIGNAL(triggered()), m_memoryDialog, SLOT(show())); m_aboutAction = new QAction(this); m_aboutAction->setText(tr("&About")); m_aboutAction->setStatusTip(tr("About the wonderful maker of sbuilder")); connect(m_aboutAction, SIGNAL(triggered()), this, SLOT(about())); }
DatabaseEditorActions::DatabaseEditorActions(DatabaseEditorController *controller) : QObject(controller), m_controller(controller) { connect(controller, SIGNAL(currentDatabaseChanged(::LBDatabase::Database*)), this, SLOT(updateActions())); connect(controller, SIGNAL(currentTableChanged(::LBDatabase::Table*)), this, SLOT(updateActions())); connect(controller, SIGNAL(currentContextChanged(::LBDatabase::Context*)), this, SLOT(updateActions())); m_openDatabaseAction = new Action(this); m_openDatabaseAction->setText(tr("&Open...")); m_openDatabaseAction->setShortcut(QKeySequence::Open); connect(m_openDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(openFile())); m_importDatabaseAction = new Action(this); m_importDatabaseAction->setText(tr("&Import database...")); connect(m_importDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(importDatabase())); m_closeDatabaseAction = new Action(this); m_closeDatabaseAction->setText(tr("C&lose database")); m_closeDatabaseAction->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_W); m_closeDatabaseAction->setEnabled(false); connect(m_closeDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(closeDatabase())); m_saveDatabaseAction = new Action(this); m_saveDatabaseAction->setText(tr("&Save")); m_saveDatabaseAction->setShortcut(QKeySequence::Save); m_saveDatabaseAction->setEnabled(false); connect(m_saveDatabaseAction, SIGNAL(triggered()), m_controller, SLOT(saveDatabase())); m_insertRowAction = new Action(this); m_insertRowAction->setText(tr("&Insert Row...")); m_insertRowAction->setEnabled(false); connect(m_insertRowAction, SIGNAL(triggered()), m_controller, SLOT(appendRow())); m_deleteRowAction = new Action(this); m_deleteRowAction->setText(tr("&Delete Row...")); m_deleteRowAction->setEnabled(false); connect(m_deleteRowAction, SIGNAL(triggered()), m_controller, SLOT(deleteRow())); m_createTableAction = new Action(this); m_createTableAction->setText(tr("&Create Table...")); m_createTableAction->setEnabled(false); connect(m_createTableAction, SIGNAL(triggered()), m_controller, SLOT(createTable())); m_editTableAction = new Action(this); m_editTableAction->setText(tr("&Edit Table...")); m_editTableAction->setEnabled(false); connect(m_editTableAction, SIGNAL(triggered()), m_controller, SLOT(editTable())); m_createContextAction = new Action(this); m_createContextAction->setText(tr("&Create Context...")); m_createContextAction->setEnabled(false); connect(m_createContextAction, SIGNAL(triggered()), m_controller, SLOT(createContext())); m_addEntityTypeAction = new Action(this); m_addEntityTypeAction->setText(tr("&Add EntityType...")); m_addEntityTypeAction->setEnabled(false); connect(m_addEntityTypeAction, SIGNAL(triggered()), m_controller, SLOT(addEntityType())); m_editEntityTypesAction = new Action(this); m_editEntityTypesAction->setText(tr("&Edit EntityTypes...")); m_editEntityTypesAction->setEnabled(false); connect(m_editEntityTypesAction, SIGNAL(triggered()), m_controller, SLOT(editEntityTypes())); m_exportUmlGraphvizAction = new Action(this); m_exportUmlGraphvizAction->setText(tr("&UML Graphviz *.dot document...")); m_exportUmlGraphvizAction->setEnabled(true); connect(m_exportUmlGraphvizAction, SIGNAL(triggered()), m_controller, SLOT(exportGraphviz())); m_exportCppAction = new Action(this); m_exportCppAction->setText(tr("&C++ Entity Storage...")); m_exportCppAction->setEnabled(true); connect(m_exportCppAction, SIGNAL(triggered()), m_controller, SLOT(exportCpp())); }
TActionProcess::~TActionProcess() { closeDatabase(); }
rlBussignalDatabase::~rlBussignalDatabase() { closeDatabase(); if(databaseName != NULL) delete [] databaseName; if(tableName != NULL) delete [] tableName; }
SqliteDatabaseConnector::~SqliteDatabaseConnector() { closeDatabase(); }