コード例 #1
0
// Remove privileges for $username from the entire database.
void Database_Privileges::removeUser (string username)
{
  SqliteDatabase sql (database ());
  sql.add ("DELETE FROM bibles WHERE username ="******";");
  sql.execute ();
  sql.clear ();
  sql.add ("DELETE FROM features WHERE username ="******";");
  sql.execute ();
}
コード例 #2
0
void TagDatabaseInMemoryTest::loadEmpty()
{
	QTemporaryFile file;
	QVERIFY(file.open());

	TagDatabaseInMemory database("tests/resources/tag-types.txt", file.fileName());
	QVERIFY(database.load());

	QMap<QString, TagType> types = database.getTagTypes(QStringList() << "tag1" << "tag3");

	QCOMPARE(types.count(), 0);
	QCOMPARE(database.count(), 0);
}
コード例 #3
0
//////////////////////////////////////////////////////////////////////
// ProjectTable implementation
//////////////////////////////////////////////////////////////////////
ProjectRecord	ProjectTable::get(const std::string& name) {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "retrieve project '%s'", name.c_str());
	std::string	condition = stringprintf("name = '%s'",
		database()->escape(name).c_str());
	std::list<ProjectRecord>	l = select(condition);
	if (0 == l.size()) {
		std::string	msg = stringprintf("no project '%s'",
			name.c_str());
		debug(LOG_DEBUG, DEBUG_LOG, 0, "%s", msg.c_str());
		throw std::runtime_error(msg);
	}
	return *(l.begin());
}
コード例 #4
0
/**
 * @fn tryGetTask
 */
QueuedProcess *QueuedCorePrivateHelper::tryGetTask(const long long _id)
{
    qCDebug(LOG_LIB) << "Search for task" << _id;

    auto task = processes()->process(_id);
    if (!task) {
        qCInfo(LOG_LIB) << "Try to get information about task" << _id << "from database";
        auto data = database()->get(QueuedDB::TASKS_TABLE, _id);
        if (data.isEmpty()) {
            qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
            return nullptr;
        }
        qCInfo(LOG_LIB) << "Try to get task" << _id << "modifications from database";
        auto mods
            = database()->get(QueuedDB::TASKS_MODS_TABLE, "WHERE task=:task", {{"task", _id}});

        auto defs = QueuedProcessManager::parseDefinitions(data, mods);
        task = new QueuedProcess(this, defs, _id);
    }

    return task;
}
コード例 #5
0
void debug_node_plugin::plugin_startup()
{
   ilog("debug_node_plugin::plugin_startup() begin");
   chain::database& db = database();

   // connect needed signals

   _applied_block_conn  = db.applied_block.connect([this](const chain::signed_block& b){ on_applied_block(b); });
   _changed_objects_conn = db.changed_objects.connect([this](const std::vector<graphene::db::object_id_type>& ids){ on_changed_objects(ids); });
   _removed_objects_conn = db.removed_objects.connect([this](const std::vector<const graphene::db::object*>& objs){ on_removed_objects(objs); });

   app().register_api_factory< debug_node_api >( "debug_node_api" );
}
コード例 #6
0
void elasticsearch_plugin::plugin_initialize(const boost::program_options::variables_map& options)
{
   database().applied_block.connect( [&]( const signed_block& b){ my->update_account_histories(b); } );
   my->_oho_index = database().add_index< primary_index< operation_history_index > >();
   database().add_index< primary_index< account_transaction_history_index > >();

   if (options.count("elasticsearch-node-url")) {
      my->_elasticsearch_node_url = options["elasticsearch-node-url"].as<std::string>();
   }
   if (options.count("elasticsearch-bulk-replay")) {
      my->_elasticsearch_bulk_replay = options["elasticsearch-bulk-replay"].as<uint32_t>();
   }
   if (options.count("elasticsearch-bulk-sync")) {
      my->_elasticsearch_bulk_sync = options["elasticsearch-bulk-sync"].as<uint32_t>();
   }
   if (options.count("elasticsearch-logs")) {
      my->_elasticsearch_logs = options["elasticsearch-logs"].as<bool>();
   }
   if (options.count("elasticsearch-visitor")) {
      my->_elasticsearch_visitor = options["elasticsearch-visitor"].as<bool>();
   }
}
コード例 #7
0
void SQLTransactionBackend::doCleanup()
{
    if (!m_frontend)
        return;
    m_frontend = 0; // Break the reference cycle. See comment about the life-cycle above.

    ASSERT(currentThread() == database()->databaseContext()->databaseThread()->getThreadID());

    releaseOriginLockIfNeeded();

    MutexLocker locker(m_statementMutex);
    m_statementQueue.clear();

    if (m_sqliteTransaction) {
        // In the event we got here because of an interruption or error (i.e. if
        // the transaction is in progress), we should roll it back here. Clearing
        // m_sqliteTransaction invokes SQLiteTransaction's destructor which does
        // just that. We might as well do this unconditionally and free up its
        // resources because we're already terminating.
        m_sqliteTransaction.clear();
    }

    // Release the lock on this database
    if (m_lockAcquired)
        m_database->transactionCoordinator()->releaseLock(this);

    // Do some aggresive clean up here except for m_database.
    //
    // We can't clear m_database here because the frontend may asynchronously
    // invoke SQLTransactionBackend::requestTransitToState(), and that function
    // uses m_database to schedule a state transition. This may occur because
    // the frontend (being in another thread) may already be on the way to
    // requesting our next state before it detects an interruption.
    //
    // There is no harm in letting it finish making the request. It'll set
    // m_requestedState, but we won't execute a transition to that state because
    // we've already shut down the transaction.
    //
    // We also can't clear m_currentStatementBackend and m_transactionError.
    // m_currentStatementBackend may be accessed asynchronously by the
    // frontend's deliverStatementCallback() state. Similarly,
    // m_transactionError may be accessed by deliverTransactionErrorCallback().
    // This occurs if requests for transition to those states have already been
    // registered with the frontend just prior to a clean up request arriving.
    //
    // So instead, let our destructor handle their clean up since this
    // SQLTransactionBackend is guaranteed to not destruct until the frontend
    // is also destructing.

    m_wrapper = 0;
}
コード例 #8
0
ファイル: MySqlStorage.cpp プロジェクト: hefee/Charm
bool MySqlStorage::createDatabaseTables()
{
        Q_ASSERT_X(database().open(), Q_FUNC_INFO,
                        "Connection to database must be established first");

        bool error = false;
        // create tables:
        for (int i = 0; i < NumberOfTables; ++i)
        {
                if (!database().tables().contains(Tables[i]))
                {
                        QString statement;
                        QTextStream stream(&statement, QIODevice::WriteOnly);

                        stream << "CREATE table  `" << Tables[i] << "` (";
                        const Field* field = Database_Fields[i];
                        while (field->name != QString::null )
                        {
                                stream << " `" << field->name << "` "
                                << field->type;
                                ++field;
                                if ( field->name != QString::null ) stream << ", ";
                        }
                        stream << ");";

                        QSqlQuery query( database() );
                        qDebug() << statement;
                        query.prepare( statement );
                        if ( ! runQuery( query ) )
                        {
                                error = true;
                        }
                }
        }

        error = error || ! setMetaData(CHARM_DATABASE_VERSION_DESCRIPTOR, QString().setNum( CHARM_DATABASE_VERSION) );
        return ! error;
}
コード例 #9
0
TKvsDatabase TKvsDatabase::addDatabase(const QString &driver, const QString &connectionName)
{
    QMutexLocker lock(&mutex);

    // Removes it if exists
    if (databaseMap.contains(connectionName))
        removeDatabase(connectionName);

    TKvsDatabaseData data;
    data.connectionName = connectionName;
    data.driver = createDriver(driver);  // creates a driver
    databaseMap.insert(connectionName, data);
    return database(connectionName);
}
コード例 #10
0
// Remove the privilege of a $username to have access to $bible $book.
// Removing the privilege for $book 0 removes them for all possible books.
void Database_Privileges::removeBibleBook (string username, string bible, int book)
{
  SqliteDatabase sql (database ());
  sql.add ("DELETE FROM bibles WHERE username ="******"AND bible =");
  sql.add (bible);
  if (book) {
    sql.add ("AND book =");
    sql.add (book);
  }
  sql.add (";");
  sql.execute ();
}
コード例 #11
0
ファイル: login.cpp プロジェクト: bibledit/bibledit-windows
void Database_Login::create ()
{
  SqliteDatabase sql (database ());
  sql.add ("CREATE TABLE IF NOT EXISTS logins ("
           " username text,"
           " address text,"
           " agent text,"
           " fingerprint text,"
           " cookie text,"
           " touch boolean,"
           " timestamp integer"
           ");");
  sql.execute ();
}
コード例 #12
0
void elasticsearch_plugin_impl::update_account_histories( const signed_block& b )
{
   graphene::chain::database& db = database();
   const vector<optional< operation_history_object > >& hist = db.get_applied_operations();
   for( const optional< operation_history_object >& o_op : hist ) {
      optional <operation_history_object> oho;

      auto create_oho = [&]() {
         return optional<operation_history_object>(
               db.create<operation_history_object>([&](operation_history_object &h) {
                  if (o_op.valid())
                  {
                     h.op           = o_op->op;
                     h.result       = o_op->result;
                     h.block_num    = o_op->block_num;
                     h.trx_in_block = o_op->trx_in_block;
                     h.op_in_trx    = o_op->op_in_trx;
                     h.virtual_op   = o_op->virtual_op;
                  }
               }));
      };

      if( !o_op.valid() ) {
         _oho_index->use_next_id();
         continue;
      }
      oho = create_oho();

      const operation_history_object& op = *o_op;

      // get the set of accounts this operation applies to
      flat_set<account_id_type> impacted;
      vector<authority> other;
      operation_get_required_authorities( op.op, impacted, impacted, other ); // fee_payer is added here

      if( op.op.which() == operation::tag< account_create_operation >::value )
         impacted.insert( op.result.get<object_id_type>() );
      else
         graphene::app::operation_get_impacted_accounts( op.op, impacted );

      for( auto& a : other )
         for( auto& item : a.account_auths )
            impacted.insert( item.first );

      for( auto& account_id : impacted )
      {
         add_elasticsearch( account_id, oho, b );
      }
   }
}
コード例 #13
0
//Create new SQLite journal (6/9/13)
bool NewJournalCreator::Create_SQLite_Database(){

    QFile database(sqlite_journal_path + QDir::separator() + sqlite_journal_name);
    QString path=database.fileName();
    path=QDir::toNativeSeparators(path);
    bool proceed=true;

    if(database.exists()){
        QMessageBox j;
        int choice=j.question(this,"RoboJournal","SQLite database <b>" + path + "</b> already exists. "
                              "Do you want to replace it? <br><br><b>Warning:</b> If you choose to replace the "
                              "database, the current contents will be overwritten. This action cannot be undone!",
                              QMessageBox::Yes | QMessageBox::No, QMessageBox::No);

        switch(choice){
        case QMessageBox::Yes:
            proceed=true;
            break;

        case QMessageBox::No:
            proceed=false;
            break;
        }
    }

    bool success;

    if(proceed){
        SQLiteCore sqlite;
        success=sqlite.CreateDB(path);
    }
    else{
        return false;
    }

    QMessageBox m;
    FavoriteCore f;

    if(success){

        m.information(this,"RoboJournal","The new journal was successfully created at <b>" + path + "</b>.");
        f.SQLite_Add_to_DB(path,sqlite_is_favorite);

    }
    else{
        m.critical(this,"RoboJournal","Journal creation attempt failed.");
    }

    return success;
}
コード例 #14
0
ファイル: WebResourceProvider.cpp プロジェクト: Orpheon/lmms
void WebResourceProvider::updateDatabase()
{
	QBuffer indexBuffer;
	indexBuffer.open( QBuffer::ReadWrite );
	download( url() + "/WebResources/Index", &indexBuffer );

	indexBuffer.seek( 0 );

	QDomDocument doc;
	doc.setContent( &indexBuffer );

	importNodeIntoDB( doc.firstChildElement( "webresources" ),
						database()->topLevelNode() );
}
コード例 #15
0
TEST( TestMySQL_Database, TestQExecute )
{
        const ::configFile::Database    &dbb = Core::Config::getInstance("test.ini").database();
        std::string host = dbb.host();
        std::string _database = dbb.database();
        std::string user = dbb.user();
        std::string pass = dbb.password();

	Core::CMySQL_Database database(host.c_str(), _database.c_str(), user.c_str(), pass.c_str());
	EXPECT_NO_FATAL_FAILURE( database.QExecute("DROP TABLE IF EXISTS test_table;"));
	EXPECT_NO_FATAL_FAILURE(database.QExecute("CREATE TABLE test_table(id INT);"));
	EXPECT_NO_FATAL_FAILURE(database.QExecute("DROP TABLE test_table;") );
	EXPECT_THROW(database.QExecute("use table test_table;"), std::exception);
}
コード例 #16
0
void SQLTransaction::postflightAndCommit()
{
    ASSERT(m_lockAcquired);

    // Transaction Step 7 - Peform postflight steps, jumping to the error callback if they fail
    if (m_wrapper && !m_wrapper->performPostflight(this)) {
        m_transactionError = m_wrapper->sqlError();
        if (!m_transactionError)
            m_transactionError = SQLError::create(SQLError::UNKNOWN_ERR, "unknown error occured setting up transaction");
        handleTransactionError(false);
        return;
    }

    // Transacton Step 8+9 - Commit the transaction, jumping to the error callback if that fails
    ASSERT(m_sqliteTransaction);

    m_database->disableAuthorizer();
    m_sqliteTransaction->commit();
    m_database->enableAuthorizer();

    // If the commit failed, the transaction will still be marked as "in progress"
    if (m_sqliteTransaction->inProgress()) {
        if (m_wrapper)
            m_wrapper->handleCommitFailedAfterPostflight(this);
        m_successCallbackWrapper.clear();
        m_transactionError = SQLError::create(SQLError::DATABASE_ERR, "failed to commit the transaction");
        handleTransactionError(false);
        return;
    }

    // Vacuum the database if anything was deleted.
    if (m_database->hadDeletes())
        m_database->incrementalVacuumIfNeeded();

    // The commit was successful. If the transaction modified this database, notify the delegates.
    if (m_modifiedDatabase)
        m_database->transactionClient()->didCommitWriteTransaction(database());

    // Now release our unneeded callbacks, to break reference cycles.
    m_errorCallbackWrapper.clear();

    // Transaction Step 10 - Deliver success callback, if there is one
    if (m_successCallbackWrapper.hasCallback()) {
        m_nextStep = &SQLTransaction::deliverSuccessCallback;
        LOG(StorageAPI, "Scheduling deliverSuccessCallback for transaction %p\n", this);
        m_database->scheduleTransactionCallback(this);
    } else
        cleanupAfterSuccessCallback();
}
コード例 #17
0
ファイル: qejdbclient.cpp プロジェクト: gitter-badger/qtejdb
/**
 * @brief QEjdbClientPrivate::load load a Json from database stored in collection
 * identified by collectionName. If nothing found en empty Json is returned.
 *
 * @param collectionName name of collection
 * @param uid Bson uid
 *
 * @return Json Object or empty Json if noting found
 */
QJSValue QEjdbClientPrivate::load(QString collectionName, QJSValue uid)
{
    QEjdbDatabase db = database();
    if (db.containsCollection(collectionName)) {
        QBsonOid oid = QBsonOid(uid.toString());
        if (oid.isValid()) {
            QBsonObject bso = db.load(collectionName, uid.toString());
            if (bso.isEmpty()) {
                return QJSValue(QJSValue::NullValue);
            }
            return QJSValue(convert(bso));
        }
    }
    return QJSValue(QJSValue::NullValue);
}
コード例 #18
0
ファイル: qejdbclient.cpp プロジェクト: gitter-badger/qtejdb
/**
 * @brief QEjdbClientPrivate::save Saves a Json in database. If autoCreateCollection is true
 * colleciton will created.
 *
 * @param collectionName name of collection
 *
 * @param jsValue
 *
 * @return created Json with id parameter
 */
QJSValue QEjdbClientPrivate::save(QString collectionName, const QJSValue &jsValue)
{
    qDebug() << "save value" << jsValue.toVariant() << "in" << collectionName;

    QBsonObject bsonObj = convert(jsValue);

    QEjdbDatabase db = database();
    checkCollection(db, collectionName);
    db.save(collectionName, bsonObj);

    QJSValue resultJs(jsValue);
    resultJs.setProperty("_id", QJSValue(bsonObj.oid().toString()));

    return resultJs;
}
コード例 #19
0
// Returns true if a record for $username / $bible / $book exists in the database.
// When the $book = 0, it takes any book.
bool Database_Privileges::getBibleBookExists (string username, string bible, int book)
{
  SqliteDatabase sql (database ());
  sql.add ("SELECT rowid FROM bibles WHERE username ="******"AND bible =");
  sql.add (bible);
  if (book) {
    sql.add ("AND book =");
    sql.add (book);
  }
  sql.add (";");
  vector <string> result = sql.query () ["rowid"];
  return !result.empty();
}
コード例 #20
0
void DatabaseManager::slotTables(QString connection, TableProcess process, ErrorProcess error){
    QSqlDatabase database(QSqlDatabase::database(connection));

    if(database.lastError().isValid()){
        error(database.lastError().text());
    }else{
        QStringList tables(database.tables());

        if(database.lastError().isValid()){
            error(database.lastError().text());
        }else{
            process(tables);
        }
    }
}
コード例 #21
0
void TagDatabaseInMemoryTest::saveEmpty()
{
	QString filename = "test_tmp_tags_file.txt";

	TagDatabaseInMemory database("tests/resources/tag-types.txt", filename);
	QVERIFY(database.load());

	database.setTags(QList<Tag>());
	QVERIFY(database.save());

	QFile f(filename);
	QVERIFY(f.open(QFile::ReadOnly | QFile::Text));
	QString content = f.readAll();
	QVERIFY(content.isEmpty());
	QVERIFY(f.remove());
}
コード例 #22
0
void DatabaseManager::slotAddConnection(QString connection, DatabaseMySQL db, ErrorProcess error){
    QSqlDatabase database(db.loadDatabase(connection));

    if(database.lastError().isValid()){
        QString message(database.lastError().text());

        if(db.getHostName() == "localhost"){
            message += "\n\nTip: Try using 127.0.0.1 instead of localhost";
        }

        error(message);
    }else{
        connections.push_back(connection);
        error("");
    }
}
コード例 #23
0
bool SQLiteDocumentDAO::remove(Document::Ptr entity)
{
    if(!entity) {
        return false;
    }

    bool ret = QueryExecutor(database()).remove("document", makeQueryParameters("id", entity->id()));

    if(ret) {
        repository()->publications()->remove(entity->id());

        emit dataChanged();
    }

    return ret;
}
コード例 #24
0
ファイル: Entry.cpp プロジェクト: afontenot/keepassx
QPixmap Entry::iconPixmap() const
{
    if (m_data.customIcon.isNull()) {
        return databaseIcons()->iconPixmap(m_data.iconNumber);
    }
    else {
        QPixmap pixmap;
        if (!QPixmapCache::find(m_pixmapCacheKey, &pixmap)) {
            // TODO: check if database() is 0
            pixmap = QPixmap::fromImage(database()->metadata()->customIcon(m_data.customIcon));
            m_pixmapCacheKey = QPixmapCache::insert(pixmap);
        }

        return pixmap;
    }
}
コード例 #25
0
int	main(int argc, char *argv[]) {
	QCoreApplication::setOrganizationName("Forensics-Data-Extractor");
	QCoreApplication::setApplicationName("Extractor");

	QThreadPool	thread_pool;
	QString		db_file;
	zmq::context_t	zmq_context(1);

	if ( argc < 3 ) {
		usage();
		return EXIT_FAILURE;
	}

	if ( strcmp(argv[1], "-d" ) == 0 ) {
		db_file = argv[2];
	} else {
		usage();
		return EXIT_FAILURE;
	}

	Database	database(db_file);
	Receiver	receiver((void*)&zmq_context, ZMQ_INPROC_URL, &database);
	Worker		worker((void*) &zmq_context, &database, ZMQ_INPROC_URL);

	try {
		struct_file	file;

		receiver.start();

		while ( database.walk_files_to_extract(file) == true ) {
			worker.start();
			worker.wait();
		}
	} catch (std::exception& e) {
		std::cerr << e.what();
		return EXIT_FAILURE;
	}

	send_zmq(zmq_context, ZMQ_INPROC_URL, ZMQ_PUSH, "END;");
//	thread_pool.waitForDone();
	receiver.wait();

	std::cout << database.get_row_count("analysed_file") << " files analysed" << std::endl;
	std::cout << thread_pool.maxThreadCount() << " threads used" << std::endl;

	return EXIT_SUCCESS;
}
コード例 #26
0
TEST(TestMySQL_Database, TestMultipleResults)
{
	const ::configFile::Database    &dbb = Core::Config::getInstance("test.ini").database();
	std::string host = dbb.host();
	std::string _database = dbb.database();
	std::string user = dbb.user();
	std::string pass = dbb.password();

	Core::CMySQL_Database	database(host.c_str(), _database.c_str(), user.c_str(), pass.c_str());
	database.QExecute("DROP TABLE IF EXISTS test_table;");
	database.QExecute("CREATE TABLE test_table(id INT, value INT, str VARCHAR(64), data BLOB);");
	database.QExecute("insert into test_table(id, value, str, data) values(0, 12, 'plop', '\x08\x12\x24');");
	database.QExecute("insert into test_table(id, value, str, data) values(1, NULL, 'null values', NULL);");
	std::unique_ptr<Core::IResult>	res, res2;
	EXPECT_NO_FATAL_FAILURE(res = std::move(database.QStore("select * from test_table;")));
	EXPECT_NO_FATAL_FAILURE(res2 = std::move(database.QStore("select * from test_table;")));
}
コード例 #27
0
void DatabaseManager::slotAddConnection(QString connection, DatabaseSQLite db, ErrorProcess error){
    QString path(db.getDatabaseName());
    QFileInfo file(path);

    if(file.exists() && file.isFile()){
        QSqlDatabase database(db.loadDatabase(connection));

        if(database.lastError().isValid()){
            error(database.lastError().text());
        }else{
            connections.push_back(connection);
            error("");
        }
    }else{
        error("Cannot find file at " + path);
    }
}
コード例 #28
0
ファイル: BookmarkModel.cpp プロジェクト: dakerfp/snowshoe
void BookmarkModel::remove(const QString& url)
{
    if (!contains(url))
        return;
    QSqlQuery sqlQuery(database());
    sqlQuery.prepare(QString("SELECT id FROM bookmarks WHERE url = '%1'").arg(url));
    sqlQuery.exec();
    sqlQuery.first();
    int indexToDelete = -1;
    for (int row = 0; row < rowCount(); ++row) {
        if (index(row, 0).data(Qt::DisplayRole).toInt() == sqlQuery.value(0).toInt()) {
            indexToDelete = row;
            break;
        }
    }
    removeRow(indexToDelete);
}
コード例 #29
0
ファイル: main.cpp プロジェクト: julianandreou/pos
int main(int argc, char* argv[])
{
	QApplication app(argc, argv);
	std::string configFile = "PizzaShop.xml";
	Pos::Database database(configFile);

	MenusPtr menu = database.GetMenus();
	OrderHandler* orderHandler = new OrderHandler(menu);

	MainWindow* win = new MainWindow(orderHandler);

	LisenceDialog di;
	di.exec();

	win->show();
	return app.exec();
}
コード例 #30
0
ファイル: BookmarkModel.cpp プロジェクト: nezticle/snowshoe
void BookmarkModel::insert(const QString& name, const QString& url)
{
    if (url.isEmpty() || contains(url))
        return;
    QModelIndex index = QModelIndex();
    beginInsertRows(index, rowCount(index), rowCount(index));
    QSqlQuery sqlQuery(database());
    static QString insertStatement = QLatin1String("INSERT INTO bookmarks (name, url, dateAdded) VALUES (?, ?, ?)");
    sqlQuery.prepare(insertStatement);
    sqlQuery.addBindValue(name);
    sqlQuery.addBindValue(url);
    sqlQuery.addBindValue(QDateTime::currentDateTime().toTime_t());
    sqlQuery.exec();
    select();
    endInsertRows();
    submitAll();
}