コード例 #1
5
// ========================================================================== //
// Select.
// ========================================================================== //
bool AStatisticSqlTableController::select() {
    if(!_model) {
        QSqlDatabase db = QSqlDatabase::database(connectionName());
        if(!db.tables().contains(QStringLiteral("statistic"))) {
            const QString query_str
                = QLatin1String("CREATE TABLE IF NOT EXISTS statistic(" \
                    "statistic_id INTEGER PRIMARY KEY AUTOINCREMENT" \
                    ", username TEXT" \
                    ", period_from INTEGER" \
                    ", period_to INTEGER" \
                    ", is_extra_time INTEGER" \
                    ", is_synced INTEGER)");

            QSqlQuery query(db);
            if(!query.exec(query_str)) {
                QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, "database")
                    .warning() << qPrintable(ASqlTableController::tr(
                        "Query: \"%1\"; error: \"%2\"")
                        .arg(query_str).arg(query.lastError().text()));

                return false;
            }
        }

        _model = new QSqlTableModel(this, db);
        _model->setTable(QStringLiteral("statistic"));
        _model->setEditStrategy(QSqlTableModel::OnManualSubmit);

        _model->setHeaderData(
            _model->fieldIndex(QStringLiteral("statistic_id"))
            , Qt::Horizontal, AStatisticSqlTableController::tr("ID"));

        _model->setHeaderData(
            _model->fieldIndex(QStringLiteral("username"))
            , Qt::Horizontal, AStatisticSqlTableController::tr("Username"));

        _model->setHeaderData(
            _model->fieldIndex(QStringLiteral("period_from"))
            , Qt::Horizontal, AStatisticSqlTableController::tr("Period from"));

        _model->setHeaderData(
            _model->fieldIndex(QStringLiteral("period_to"))
            , Qt::Horizontal, AStatisticSqlTableController::tr("Period to"));

        _model->setHeaderData(
            _model->fieldIndex(QStringLiteral("is_extra_time"))
            , Qt::Horizontal
            , AStatisticSqlTableController::tr("Is extra time"));

        _model->setHeaderData(
            _model->fieldIndex(QStringLiteral("is_synced"))
            , Qt::Horizontal, AStatisticSqlTableController::tr("Is synced"));

        _model->setSort(_model->fieldIndex(QStringLiteral("period_from"))
            , Qt::DescendingOrder);
    }

    return _model->select();
}
コード例 #2
0
void CWizardIrcConnection::accept()
{
	if ( !quazaaSettings.Chat.NickNames.contains( nickName(), Qt::CaseInsensitive ) )
	{
		quazaaSettings.Chat.NickNames << nickName();
	}
	if ( !quazaaSettings.Chat.RealNames.contains( realName(), Qt::CaseInsensitive ) )
	{
		quazaaSettings.Chat.RealNames << realName();
	}
	if ( !quazaaSettings.Chat.Hosts.contains( hostName(), Qt::CaseInsensitive ) )
	{
		quazaaSettings.Chat.Hosts << hostName();
	}
	if ( !quazaaSettings.Chat.UserNames.contains( userName(), Qt::CaseInsensitive ) )
	{
		quazaaSettings.Chat.UserNames << userName();
	}
	if ( !quazaaSettings.Chat.ConnectionNames.contains( connectionName(), Qt::CaseInsensitive ) )
	{
		quazaaSettings.Chat.ConnectionNames << connectionName();
	}
	quazaaSettings.saveChatConnectionWizard();

	QDialog::accept();
}
コード例 #3
0
ファイル: QueryThread.cpp プロジェクト: gitcommit/geologist
void QueryThread::open(const ConnectionData& cd) {
    if (!isRunning()) {
        start(LowPriority);
    }
    emit message(tr("Sending Connect Request to Database Connection..."));
    emit connectRequest(cd, connectionName());
}
コード例 #4
0
    void ExplorerReplicaSetFolderItem::on_repSetStatus()
    {
        if (!_server->replicaSetInfo()->primary.empty()) {
            openCurrentServerShell(_server, "rs.status()");
        }
        else // primary is unreachable
        {
            // Todo: do this before 
            // Run rs.status only if there is a reachable secondary
            mongo::HostAndPort onlineMember;
            for (auto const& member : _server->replicaSetInfo()->membersAndHealths) {
                if (member.second) {
                    onlineMember = mongo::HostAndPort(member.first);
                    break;
                }
            }
            if (onlineMember.empty())   // todo: throw error
                return;

            auto connSetting = _server->connectionRecord()->clone();    // todo: unique_ptr
            // Set connection settings of this replica member
            connSetting->setConnectionName(onlineMember.toString() + 
                                           " [member of " + connSetting->connectionName() + "]");
            connSetting->setServerHost(onlineMember.host());
            connSetting->setServerPort(onlineMember.port());
            connSetting->setReplicaSet(false);
            connSetting->replicaSetSettings()->setMembers(std::vector<std::string>()); 

            openCurrentServerShell(_server, connSetting, "rs.status()");
        }
    }
コード例 #5
0
    /**
     * @brief Converts to QVariantMap
     */
    QVariant ConnectionSettings::toVariant() const
    {
        QVariantMap map;
        map.insert("connectionName", QtUtils::toQString(connectionName()));
        map.insert("serverHost", QtUtils::toQString(serverHost()));
        map.insert("serverPort", serverPort());
        map.insert("defaultDatabase", QtUtils::toQString(defaultDatabase()));
        map.insert("isReplicaSet", isReplicaSet());
        if (isReplicaSet()) {
            map.insert("replicaSet", _replicaSetSettings->toVariant());
        }

#ifdef MONGO_SSL
        SSLInfo infl = _info.sslInfo();
        map.insert("sslEnabled", infl._sslSupport);
        map.insert("sslPemKeyFile", QtUtils::toQString(infl._sslPEMKeyFile));
#endif
        QVariantList list;
        for (QList<CredentialSettings *>::const_iterator it = _credentials.begin(); it != _credentials.end(); ++it) {
            CredentialSettings *credential = *it;
            list.append(credential->toVariant());
        }
        map.insert("credentials", list);

        map.insert("ssh", _sshSettings->toVariant());
        map.insert("ssl", _sslSettings->toVariant());
        map.insert("uuid", _uuid); 

        return map;
    }
コード例 #6
0
ファイル: database.cpp プロジェクト: fr33mind/SMTUC
Database::Database(QObject *parent) :
    QObject(parent)
{
    QSqlDatabase db = QSqlDatabase::database();
    if (! db.isValid())
        db = QSqlDatabase::addDatabase("QSQLITE");
    mSqlDatabase = db;
    mConnection = Database::connection(connectionName());
}
コード例 #7
0
void ConnectionClient::startProcess()
{
    TIME_SCOPE_DURATION("ConnectionClient::startProcess");

    if (!isProcessIsRunning()) {
        connectProcessFinished();
        connectStandardOutputAndError();
        process()->start(processPath(), {connectionName()});
        process()->waitForStarted();
        resetProcessAliveTimer();
    }
}
コード例 #8
0
ConnectionInfo CWizardIrcConnection::connection() const
{
	ConnectionInfo connection;
	connection.nick = nickName();
	connection.real = realName();
	connection.host = hostName();
	connection.port = port();
	connection.secure = isSecure();
	connection.user = userName();
	connection.pass = password();
	connection.name = connectionName();
	return connection;
}
コード例 #9
0
ファイル: loginfo.cpp プロジェクト: kthxbyte/KDE1-Linaro
void LogInfo::dump() {
  printf("LOGINFO %u\n", (unsigned)this);
  printf("\tconnection name : %s\n", connectionName().data());
  printf("\tcurrency symbol : %s\n", currency().data());
  printf("\tbegin           : %s", ctime(&_from));
  printf("\tend             : %s", ctime(&_until));
  printf("\tduration        : %d seconds\n", (int)_until - (int)_from);
  printf("\tsession cost    : %0.2e\n", sessionCosts());
  printf("\ttotal cost      : %0.2e\n", totalCosts());
  printf("\tbytes in        : %d\n", bytesIn());
  printf("\tbytes out       : %d\n", bytesOut());
  printf("\tbytes total     : %d\n", bytes());
  printf("\n");
}
コード例 #10
0
ファイル: qrsqldatabase.cpp プロジェクト: Qters/QrOrm
QSqlDatabase QrSqlDatabase::createDatabase(QSqlError &dbError)
{
    QString connectionName_ = connectionName();
    dbError = QSqlError();

    dbFileIsCreated = false;
    qDebug() << "create database:" << getDatabasePath () << "," << connectionName_;
    if (! QrFiler::fileExists (getDatabasePath ())) {
//        qDebug() << "database path is not exist:" << getDatabasePath ();
//        dbError = QSqlError("'database file is not exist!'", "", QSqlError::ConnectionError);
//        Q_ASSERT(false);
//        return QrSqlDatabase::null;
        dbFileIsCreated = true;
        qDebug() << "database file is not exist, ready to creating...";
    }

    const QrSqlDatabaseParams &params = getParams ();
    Q_ASSERT(!params.driverName.isEmpty () && !params.databaseName.isEmpty ());
    QSqlDatabase db = QSqlDatabase::addDatabase (params.driverName, connectionName_);
    db.setConnectOptions (params.connectOptions);
    db.setDatabaseName (getDatabasePath ());
    db.setUserName (params.username);
    db.setPassword (params.password);
    db.setHostName (params.hostname);
    if (-1 != params.port){
        db.setPort (params.port);
    }

    if (! db.open ()) {
        qDebug() << "fail to open database";
        QrSqlDatabaseError::displayLastError (db, "unable to open connection to database");
        dbError = db.lastError ();
        if (!dbError.isValid ()) {
            dbError = QSqlError("'unable to open connection to database'", "", QSqlError::UnknownError);
        }
        QSqlDatabase::removeDatabase (connectionName_);
        return QrSqlDatabase::null;
    }

    Qt::HANDLE curThreadIdHandle = QThread::currentThreadId ();
    listDbByThread.insert (curThreadIdHandle, connectionName_);

    QString curThreadId = QrStringCvter<Qt::HANDLE, QrIsPointer<Qt::HANDLE>::value>::toString (curThreadIdHandle);
    qDebug() << "create new database connection of " << params.databaseName
             << "in thread " << curThreadId << " with key " << connectionName_;

    return QSqlDatabase::database(connectionName_);
}
コード例 #11
0
bool ConnectionClient::connectToLocalSocket()
{
    for (int counter = 0; counter < 1000; counter++) {
        localSocket.connectToServer(connectionName());
        bool isConnected = localSocket.waitForConnected(20);

        if (isConnected)
            return isConnected;
        else
            QThread::msleep(30);
    }

    qDebug() << "Cannot connect:" <<localSocket.errorString();

    return false;
}
コード例 #12
0
core::IConnectionSettingsBase* ConnectionBaseWidget::createConnection() const {
  std::string conName = common::ConvertToString(connectionName());
  std::string conFolder = common::ConvertToString(UIFolderText());
  if (conFolder.empty()) {
    conFolder = defaultNameConnectionFolder;
  }

  core::connection_path_t path(common::file_system::stable_dir_path(conFolder) + conName);
  core::IConnectionSettingsBase* conn = createConnectionImpl(path);
  conn->SetNsSeparator(
      common::ConvertToString(toRawCommandLine(namespaceSeparator_->currentText())));
  conn->SetDelimiter(common::ConvertToString(toRawCommandLine(delimiter_->currentText())));
  if (isLogging()) {
    conn->SetLoggingMsTimeInterval(loggingInterval());
  }

  return conn;
}
コード例 #13
0
ClangPchManager::PchManagerConnectionClient::PchManagerConnectionClient(
        ClangBackEnd::PchManagerClientInterface *client)
    : ConnectionClient(Utils::TemporaryDirectory::masterDirectoryPath()
                       + QStringLiteral("/ClangPchManagerBackEnd-")
                       + currentProcessId()),
      m_serverProxy(client, ioDevice())
{
    m_processCreator.setTemporaryDirectoryPattern("clangpchmanagerbackend-XXXXXX");

    QDir pchsDirectory(Core::ICore::cacheResourcePath());
    pchsDirectory.mkdir("pchs");
    pchsDirectory.cd("pchs");
    m_processCreator.setArguments({connectionName(),
                                   Core::ICore::cacheResourcePath() + "/symbol-experimental-v1.db",
                                   pchsDirectory.absolutePath()});

    stdErrPrefixer().setPrefix("PchManagerConnectionClient.stderr: ");
    stdOutPrefixer().setPrefix("PchManagerConnectionClient.stdout: ");
}
コード例 #14
0
ファイル: database.cpp プロジェクト: fr33mind/SMTUC
void Database::componentComplete()
{
    Database::addDatabase(this);
    mConnection = Database::connection(connectionName());
}
コード例 #15
0
ファイル: AMDatabase.cpp プロジェクト: acquaman/acquaman
bool AMDatabase::ensureTable(const QString& tableName, const QStringList& columnNames, const QStringList& columnTypes, bool reuseDeletedIds) {

	if(columnNames.count() != columnTypes.count()) {
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -5, QString("could not create table: invalid structure. Different number of column names and types. Names: %1. Types:%2").arg(columnNames.join(",")).arg(columnTypes.join(","))));
		return false;
	}


	// todo: sanitize all inputs...
	QSqlQuery q(qdb());

	QString qs = "CREATE TABLE IF NOT EXISTS ";
	qs.append(tableName);
	if(reuseDeletedIds)
		qs.append("(id INTEGER PRIMARY KEY ASC, ");
	else
		qs.append("(id INTEGER PRIMARY KEY AUTOINCREMENT, ");
	for(int i=0; i<columnNames.count(); i++) {
		qs.append(columnNames.at(i));
		qs.append(" ");
		qs.append(columnTypes.at(i));
		qs.append(", ");
	}
	qs.chop(2);
	qs.append(")");

	q.prepare(qs);
	if(execQuery(q)) {
		return true;
	}
	else {
		q.finish();	// make sure that sqlite lock is released before emitting signals
		AMErrorMon::report(AMErrorReport(this, AMErrorReport::Alert, -6, QString("database table create failed on database %3 (%4). Could not execute query (%1). The SQL reply was: %2").arg(q.executedQuery()).arg(q.lastError().text()).arg(connectionName()).arg(dbAccessString())));
		return false;
	}
}