// TODO: should be renamed to r_syscall_use(); R_API bool r_syscall_setup(RSyscall *s, const char *arch, int bits, const char *cpu, const char *os) { if (!os || !*os) { os = R_SYS_OS; } if (!arch) { arch = R_SYS_ARCH; } free (s->os); s->os = strdup (os); if (!strcmp (os, "any")) { // ignored return true; } if (!strcmp (arch, "mips")) { s->regs = fastcall_mips; } else if (!strcmp (arch, "avr")) { s->sysport = sysport_avr; } else if (!strcmp (os, "osx") || !strcmp (os, "macos")) { os = "darwin"; } else if (!strcmp (arch,"sh")) { s->regs = fastcall_sh; } else if (!strcmp (arch, "arm")) { switch (bits) { case 16: case 32: s->regs = fastcall_arm; break; case 64: s->regs = fastcall_arm64; break; } } else if (!strcmp (arch, "x86")) { s->sysport = sysport_x86; switch (bits) { case 8: s->regs = fastcall_x86_8; break; case 32: s->regs = fastcall_x86_32; break; case 64: s->regs = fastcall_x86_64; break; } } char *dbName = r_str_newf ("syscall/%s-%s-%d", os, arch, bits); s->db = openDatabase (s->db, dbName); free (dbName); dbName = r_str_newf ("sysregs/%s-%d-%s", arch, bits, cpu ? cpu: arch); s->srdb = openDatabase (s->srdb, dbName); free (dbName); if (s->fd) { fclose (s->fd); } s->fd = NULL; return true; }
void LocalStorageDatabase::importItems(StorageMap& storageMap) { // FIXME: If it can't import, then the default WebKit behavior should be that of private browsing, // not silently ignoring it. https://bugs.webkit.org/show_bug.cgi?id=25894 openDatabase(SkipIfNonExistent); if (!m_database.isOpen()) return; SQLiteStatement query(m_database, "SELECT key, value FROM ItemTable"); if (query.prepare() != SQLResultOk) { LOG_ERROR("Unable to select items from ItemTable for local storage"); return; } HashMap<String, String> items; int result = query.step(); while (result == SQLResultRow) { items.set(query.getColumnText(0), query.getColumnBlobAsString(1)); result = query.step(); } if (result != SQLResultDone) { LOG_ERROR("Error reading items from ItemTable for local storage"); return; } storageMap.importItems(items); }
TableSchema::TableSchema(const QString &table, const QString &env) : tablename(table) { if (!dbSettings) { QString path = QLatin1String("config") + QDir::separator() + "database.ini"; if (!QFile::exists(path)) { qCritical("not found, %s", qPrintable(path)); } dbSettings = new QSettings(path, QSettings::IniFormat); } if (openDatabase(env)) { if (!tablename.isEmpty()) { QSqlTableModel model; model.setTable(tablename); tableFields = model.record(); if (model.database().driverName().toUpper() == "QPSQL") { // QPSQLResult doesn't call QSqlField::setAutoValue(), fix it for (int i = 0; i < tableFields.count(); ++i) { QSqlField f = tableFields.field(i); if (f.defaultValue().toString().startsWith(QLatin1String("nextval"))) { f.setAutoValue(true); tableFields.replace(i, f); } } } } else { qCritical("Empty table name"); } } }
DbModel::DbModel(QQuickItem *parent) : QAbstractListModel(parent), m_status(Null), m_schema(QJsonObject()), m_mapDepth(0), m_jsonDbPath("") { DEBUG; // QFile db(DBPATH); // if(!db.open(QIODevice::ReadOnly)) // { // qDebug() << "db does not exist! creating/copying..."; // QFile file("assets:/qml/MyCollections/db/store.db"); // file.copy(DBPATH); // } else // { // qDebug() << "Successfully opened db, hash is below:"; // QByteArray hashData = QCryptographicHash::hash(db.readAll(),QCryptographicHash::Md5); // qDebug() << hashData.toHex(); // } // db.close(); connect(this, SIGNAL(nameChanged(QString)), this, SLOT(openDatabase())); connect(this, SIGNAL(schemaChanged(QJsonObject)), this, SLOT(buildDataTables(QJsonObject))); }
DatabaseOpenWidget::DatabaseOpenWidget(QWidget* parent) : DialogyWidget(parent) , m_ui(new Ui::DatabaseOpenWidget()) , m_db(Q_NULLPTR) { m_ui->setupUi(this); QFont font = m_ui->labelHeadline->font(); font.setBold(true); font.setPointSize(font.pointSize() + 2); m_ui->labelHeadline->setFont(font); m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); m_ui->buttonTogglePassword->setIcon(filePath()->onOffIcon("actions", "password-show")); connect(m_ui->buttonTogglePassword, SIGNAL(toggled(bool)), m_ui->editPassword, SLOT(setShowPassword(bool))); connect(m_ui->buttonBrowseFile, SIGNAL(clicked()), SLOT(browseKeyFile())); connect(m_ui->editPassword, SIGNAL(textChanged(QString)), SLOT(activatePassword())); connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(activateKeyFile())); connect(m_ui->checkPassword, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled())); connect(m_ui->checkKeyFile, SIGNAL(toggled(bool)), SLOT(setOkButtonEnabled())); connect(m_ui->comboKeyFile, SIGNAL(editTextChanged(QString)), SLOT(setOkButtonEnabled())); connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(openDatabase())); connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject())); }
SqliteDatabaseConnector::SqliteDatabaseConnector(const std::string database_name, const size_t cardinality, const bool read_write) : DatabaseConnector(database_name, cardinality, read_write) { openDatabase(); }
char dbDelete(const char *id) { char query[strlen(QUERY_DELETE) + strlen(id)]; int result = 0; sqlite3_stmt *statement; sqlite3 *db; sprintf(query, "%s%s", QUERY_DELETE, id); db = openDatabase(); if(!db) return 0; result = sqlite3_prepare_v2(db, query, -1, &statement, 0); if(result != SQLITE_OK) { sqlite3_close(db); return 0; } result = sqlite3_step(statement); if(result != SQLITE_DONE && result != SQLITE_ROW) { sqlite3_close(db); return 0; } sqlite3_finalize(statement); sqlite3_close(db); return 1; }
/* ** Open a new database handle. */ EXPORT_C int sqlite3_open( const char *zFilename, sqlite3 **ppDb ){ return openDatabase(zFilename, ppDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0); }
bool DatabaseController::loadTableData(const QString& szTableName, const QString& szFilter, QSqlDisplayTableModel* pTableModel) { bool bRes; QStringList listRowHeader; bRes = openDatabase(); if(bRes){ listRowHeader = listColumnNames(szTableName); pTableModel->setTable(szTableName); pTableModel->setEditStrategy(QSqlTableModel::OnFieldChange); if (!szFilter.isEmpty()) { pTableModel->setFilter(szFilter); } //Set the headers for (int i = 0; i < listRowHeader.size(); i++) { pTableModel->setHeaderData(i , Qt::Horizontal, listRowHeader.at(i), Qt::TextAlignmentRole); } bRes = pTableModel->select(); } else { qCritical("[DatabaseController] Cannot open database for table data loading"); } return bRes; }
bool CChinesePinyinTable::initTable() { bool value_ret = false; int num_records = sizeof(p2h)/sizeof(p2h[0]); int i=0; if(!openDatabase()) { value_ret = DataBaseNotOpen; } else { QSqlQuery query(db); QString strSqlDelete = "delete * from "+ m_TableName; query.exec(strSqlDelete); for(i=0;i<num_records;i++) { pyhz_tab tempRecord = p2h[i]; QChar firstAlphabet = tempRecord.py.at(0); QChar lowFirstAlphabet = firstAlphabet.toLower(); tempRecord.py.replace(0,1,lowFirstAlphabet); QString strSQL = "insert into " + m_TableName + " (pinyin,pinyin_shengdiao,shengdiao,ChineseCharactor,First_Alphabet) values (\'" + tempRecord.py + "\',\'" + tempRecord.py_shengdiao + "\'," + QString::number(tempRecord.shengdiao) + ",\'" + tempRecord.hz + "\',\'" + lowFirstAlphabet + "\')"; /*QString strSQL = "insert into " + m_TableName + " (pinyin,pinyin_shengdiao) values (\'" + tempRecord.py + "\',\'" + tempRecord.py_shengdiao + "\')";*/ // strSQL = "select * from " + m_TableName; //qDebug()<<strSQL; if(query.exec(strSQL)) { value_ret = true; } else { value_ret = false; } } } return value_ret; }
QStringList QgsMssqlConnection::schemas( const QString &uri, QString *errorMessage ) { QgsDataSourceUri dsUri( uri ); // connect to database QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() ); if ( !openDatabase( db ) ) { if ( errorMessage ) *errorMessage = db.lastError().text(); return QStringList(); } const QString sql = QStringLiteral( "select s.name as schema_name from sys.schemas s" ); QSqlQuery q = QSqlQuery( db ); q.setForwardOnly( true ); if ( !q.exec( sql ) ) { if ( errorMessage ) *errorMessage = q.lastError().text(); return QStringList(); } QStringList result; while ( q.next() ) { const QString schemaName = q.value( 0 ).toString(); result << schemaName; } return result; }
bool QgsMssqlConnection::createSchema( const QString &uri, const QString &schemaName, QString *errorMessage ) { QgsDataSourceUri dsUri( uri ); // connect to database QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() ); if ( !openDatabase( db ) ) { if ( errorMessage ) *errorMessage = db.lastError().text(); return false; } QSqlQuery q = QSqlQuery( db ); q.setForwardOnly( true ); const QString sql = QStringLiteral( "CREATE SCHEMA [%1]" ).arg( schemaName ); if ( !q.exec( sql ) ) { if ( errorMessage ) *errorMessage = q.lastError().text(); return false; } return true; }
bool QgsMssqlConnection::truncateTable( const QString &uri, QString *errorMessage ) { QgsDataSourceUri dsUri( uri ); // connect to database QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() ); const QString schema = dsUri.schema(); const QString table = dsUri.table(); if ( !openDatabase( db ) ) { if ( errorMessage ) *errorMessage = db.lastError().text(); return false; } QSqlQuery q = QSqlQuery( db ); q.setForwardOnly( true ); const QString sql = QStringLiteral( "TRUNCATE TABLE [%1].[%2]" ).arg( schema, table ); if ( !q.exec( sql ) ) { if ( errorMessage ) *errorMessage = q.lastError().text(); return false; } return true; }
bool QgsMssqlConnection::dropTable( const QString &uri, QString *errorMessage ) { QgsDataSourceUri dsUri( uri ); // connect to database QSqlDatabase db = getDatabase( dsUri.service(), dsUri.host(), dsUri.database(), dsUri.username(), dsUri.password() ); const QString schema = dsUri.schema(); const QString table = dsUri.table(); if ( !openDatabase( db ) ) { if ( errorMessage ) *errorMessage = db.lastError().text(); return false; } QSqlQuery q = QSqlQuery( db ); q.setForwardOnly( true ); const QString sql = QString( "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[%1].[%2]') AND type in (N'U')) DROP TABLE [%1].[%2]\n" "DELETE FROM geometry_columns WHERE f_table_schema = '%1' AND f_table_name = '%2'" ) .arg( schema, table ); if ( !q.exec( sql ) ) { if ( errorMessage ) *errorMessage = q.lastError().text(); return false; } return true; }
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; }
bool DatabaseController::loadWorksheetQueryResults(QString& szWorksheetQuery, QSqlDisplayQueryModel** ppQueryModel) { bool bRes; QStringList listRowHeader; QStringList listRowData; QString szRequest; bRes = openDatabase(); if(bRes && !szWorksheetQuery.isEmpty()){ szRequest = szWorksheetQuery.section(QRegExp("\\s+"), 0, 0, QString::SectionSkipEmpty); if (szRequest.toLower() == "select") { *ppQueryModel = new QSqlDisplayQueryModel(); (*ppQueryModel)->setQuery(szWorksheetQuery, m_db); if ((*ppQueryModel)->query().lastError().text()!=" ") { bRes = false; } m_szResultString = makeQueryResultString((*ppQueryModel)->query()); } else { QSqlQuery query(m_db); query.exec(szWorksheetQuery); bRes = false; //No results to display in this case m_szResultString = makeQueryResultString(query); } closeDataBase(); } else { qCritical("[DatabaseController] Cannot open database for new query loading"); } return bRes; }
void GeolocationPermissions::maybeLoadPermanentPermissions() { if (s_permanentPermissionsLoaded) return; s_permanentPermissionsLoaded = true; SQLiteDatabase database; if (!openDatabase(&database)) return; // Create the table here, such that even if we've just created the DB, the // commands below should succeed. if (!database.executeCommand("CREATE TABLE IF NOT EXISTS Permissions (origin TEXT UNIQUE NOT NULL, allow INTEGER NOT NULL)")) { database.close(); return; } SQLiteStatement statement(database, "SELECT * FROM Permissions"); if (statement.prepare() != SQLResultOk) { database.close(); return; } ASSERT(s_permanentPermissions.size() == 0); while (statement.step() == SQLResultRow) s_permanentPermissions.set(statement.getColumnText(0), statement.getColumnInt64(1)); database.close(); }
bool DatabaseController::loadViewsTables(DbLoadTableCB func, void* user_data) { bool bRes; bRes = openDatabase(); if(bRes){ QStringList listItem = m_db.tables(QSql::Views); // Sort by name listItem.sort(); QList<QString>::const_iterator iter = listItem.begin(); while(iter != listItem.end()) { if(func){ func(*iter, user_data); } iter++; } closeDataBase(); }else{ qCritical("[DatabaseController] Cannot open database for views loading"); } return bRes; }
/* ** Open a new database handle. */ EXPORT_C int sqlite3_open16( const void *zFilename, sqlite3 **ppDb ){ char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ sqlite3_value *pVal; int rc = SQLITE_NOMEM; assert( zFilename ); assert( ppDb ); *ppDb = 0; pVal = sqlite3ValueNew(0); sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); zFilename8 = (const char*)sqlite3ValueText(pVal, SQLITE_UTF8); if( zFilename8 ){ rc = openDatabase(zFilename8, ppDb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0); if( rc==SQLITE_OK && *ppDb ){ rc = sqlite3_exec(*ppDb, "PRAGMA encoding = 'UTF-16'", 0, 0, 0); if( rc!=SQLITE_OK ){ sqlite3_close(*ppDb); *ppDb = 0; } } } sqlite3ValueFree(pVal); return sqlite3ApiExit(0, rc); }
void NotificationPresenterImpl::maybeStorePermanentPermissions() { // If the permanent permissions haven't been modified, there's no need to // save them to the DB. (If we haven't even loaded them, writing them now // would overwrite the stored permissions with the empty set.) SQLiteDatabase database; if (!openDatabase(&database)) return; SQLiteTransaction transaction(database); // The number of entries should be small enough that it's not worth trying // to perform a diff. Simply clear the table and repopulate it. if (!database.executeCommand("DELETE FROM NotifyPermissions")) { database.close(); return; } PermissionsMap::const_iterator end = s_notificationPermissions.end(); for (PermissionsMap::const_iterator iter = s_notificationPermissions.begin(); iter != end; ++iter) { SQLiteStatement statement(database, "INSERT INTO NotifyPermissions (origin, allow) VALUES (?, ?)"); if (statement.prepare() != SQLResultOk) continue; statement.bindText(1, iter->first); statement.bindInt64(2, iter->second); statement.executeCommand(); } transaction.commit(); database.close(); }
void Servatrice_DatabaseInterface::initDatabase(const QSqlDatabase &_sqlDatabase) { if (_sqlDatabase.isValid()) { sqlDatabase = QSqlDatabase::cloneDatabase(_sqlDatabase, "pool_" + QString::number(instanceId)); openDatabase(); } }
void ApplicationCacheStorage::storeNewestCache(ApplicationCacheGroup* group) { openDatabase(true); SQLiteTransaction storeCacheTransaction(m_database); storeCacheTransaction.begin(); if (!group->storageID()) { // Store the group if (!store(group)) return; } ASSERT(group->newestCache()); ASSERT(!group->newestCache()->storageID()); // Store the newest cache if (!store(group->newestCache())) return; // Update the newest cache in the group. SQLiteStatement statement(m_database, "UPDATE CacheGroups SET newestCache=? WHERE id=?"); if (statement.prepare() != SQLResultOk) return; statement.bindInt64(1, group->newestCache()->storageID()); statement.bindInt64(2, group->storageID()); if (!executeStatement(statement)) return; storeCacheTransaction.commit(); }
/*************************************************************************** Desc: Does most of the actual work of opening an existing database, but doesn't provide COM interfaces... ****************************************************************************/ RCODE F_DbSystem::openDb( const char * pszDbFileName, const char * pszDataDir, const char * pszRflDir, const char * pszPassword, FLMUINT uiOpenFlags, IF_Db ** ppDb) { RCODE rc = NE_XFLM_OK; *ppDb = NULL; if (!pszDbFileName || *pszDbFileName == 0) { rc = RC_SET( NE_FLM_IO_INVALID_FILENAME); goto Exit; } // Open the file if (RC_BAD( rc = openDatabase( NULL, pszDbFileName, pszDataDir, pszRflDir, pszPassword, uiOpenFlags, FALSE, NULL, NULL, NULL, ppDb))) { goto Exit; } Exit: return( rc); }
ApplicationCacheGroup* ApplicationCacheStorage::loadCacheGroup(const KURL& manifestURL) { openDatabase(false); if (!m_database.isOpen()) return 0; SQLiteStatement statement(m_database, "SELECT id, manifestURL, newestCache FROM CacheGroups WHERE newestCache IS NOT NULL AND manifestURL=?"); if (statement.prepare() != SQLResultOk) return 0; statement.bindText(1, manifestURL); int result = statement.step(); if (result == SQLResultDone) return 0; if (result != SQLResultRow) { LOG_ERROR("Could not load cache group, error \"%s\"", m_database.lastErrorMsg()); return 0; } unsigned newestCacheStorageID = (unsigned)statement.getColumnInt64(2); RefPtr<ApplicationCache> cache = loadCache(newestCacheStorageID); if (!cache) return 0; ApplicationCacheGroup* group = new ApplicationCacheGroup(manifestURL); group->setStorageID((unsigned)statement.getColumnInt64(0)); group->setNewestCache(cache.release()); return group; }
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; }
bool ASQLiteDatabase::checkDatabase () { if (ADatabase::isOpen() == true) return true; return openDatabase(); }
/* ** Open a new database handle. */ int sqlite3_open16( const void *zFilename, sqlite3 **ppDb ){ char const *zFilename8; /* zFilename encoded in UTF-8 instead of UTF-16 */ int rc = SQLITE_NOMEM; sqlite3_value *pVal; assert( ppDb ); *ppDb = 0; pVal = sqlite3ValueNew(); sqlite3ValueSetStr(pVal, -1, zFilename, SQLITE_UTF16NATIVE, SQLITE_STATIC); zFilename8 = sqlite3ValueText(pVal, SQLITE_UTF8); if( zFilename8 ){ rc = openDatabase(zFilename8, ppDb); if( rc==SQLITE_OK && *ppDb ){ sqlite3_exec(*ppDb, "PRAGMA encoding = 'UTF-16'", 0, 0, 0); } } if( pVal ){ sqlite3ValueFree(pVal); } return rc; }
void DatabaseOpenWidget::enterKey(const CompositeKey& masterKey) { if (masterKey.isEmpty()) { return; } openDatabase(masterKey); }
void QgsOSMExportDialog::onLoadTags() { if ( !openDatabase() ) return; QApplication::setOverrideCursor( Qt::WaitCursor ); QList<QgsOSMTagCountPair> pairs = mDatabase->usedTags( !radPoints->isChecked() ); mDatabase->close(); mTagsModel->setColumnCount( 3 ); mTagsModel->setRowCount( pairs.count() ); for ( int i = 0; i < pairs.count(); ++i ) { const QgsOSMTagCountPair& p = pairs[i]; QStandardItem* item = new QStandardItem( p.first ); item->setCheckable( true ); mTagsModel->setItem( i, 0, item ); QStandardItem* item2 = new QStandardItem(); item2->setData( p.second, Qt::DisplayRole ); mTagsModel->setItem( i, 1, item2 ); QStandardItem* item3 = new QStandardItem(); item3->setData( "Not null", Qt::DisplayRole ); item3->setCheckable( true ); mTagsModel->setItem( i, 2, item3 ); } viewTags->resizeColumnToContents( 0 ); viewTags->sortByColumn( 1, Qt::DescendingOrder ); QApplication::restoreOverrideCursor(); }
void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, String>& changedItems) { if (!m_database.isOpen()) openDatabase(CreateIfNonExistent); if (!m_database.isOpen()) return; if (m_shouldClearItems) { m_shouldClearItems = false; SQLiteStatement clearStatement(m_database, "DELETE FROM ItemTable"); if (clearStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare clear statement - cannot write to local storage database"); return; } int result = clearStatement.step(); if (result != SQLITE_DONE) { LOG_ERROR("Failed to clear all items in the local storage database - %i", result); return; } } SQLiteStatement insertStatement(m_database, "INSERT INTO ItemTable VALUES (?, ?)"); if (insertStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare insert statement - cannot write to local storage database"); return; } SQLiteStatement deleteStatement(m_database, "DELETE FROM ItemTable WHERE key=?"); if (deleteStatement.prepare() != SQLITE_OK) { LOG_ERROR("Failed to prepare delete statement - cannot write to local storage database"); return; } SQLiteTransaction transaction(m_database); transaction.begin(); for (auto it = changedItems.begin(), end = changedItems.end(); it != end; ++it) { // A null value means that the key/value pair should be deleted. SQLiteStatement& statement = it->value.isNull() ? deleteStatement : insertStatement; statement.bindText(1, it->key); // If we're inserting a key/value pair, bind the value as well. if (!it->value.isNull()) statement.bindBlob(2, it->value); int result = statement.step(); if (result != SQLITE_DONE) { LOG_ERROR("Failed to update item in the local storage database - %i", result); break; } statement.reset(); } transaction.commit(); }