void ConnDlg::on_okButton_clicked() { if (ui.comboDriver->currentText().isEmpty()) { ui.status_label->setText(tr("请选择一个数据库驱动!")); ui.comboDriver->setFocus(); } else if(ui.comboDriver->currentText() =="QSQLITE") { addSqliteConnection(); //创建数据库表,如已存在则无须执行 creatDB(); accept(); } else { QSqlError err = addConnection(driverName(), databaseName(), hostName(),userName(), password(), port()); if (err.type() != QSqlError::NoError) ui.status_label->setText(err.text()); else ui.status_label->setText(tr("连接数据库成功!")); //创建数据库表,如已存在则无须执行 accept(); } }
// // This function will test ModifyDatabaseSettingsL method of CPosLmDatabaseManager class. // void CTestPosLmDatabaseManager::TestModifyDatabaseSettingsL() { CPosLmDatabaseManager* databaseManager= CPosLmDatabaseManager::NewL(); CleanupStack::PushL(databaseManager); _LIT(KDatabaseUri,"file://c:eposlm.ldb"); TBufC<40> databaseUri(KDatabaseUri); HPosLmDatabaseInfo* databaseInfo=HPosLmDatabaseInfo::NewLC(databaseUri); TPosLmDatabaseSettings databaseSettings=databaseInfo->Settings(); _LIT(KDatabaseName,"Nokia"); TPosLmDatabaseName databaseName(KDatabaseName); databaseSettings.SetDatabaseName(databaseName); databaseManager->ModifyDatabaseSettingsL(databaseUri,databaseSettings); TPtrC databaseNamePtr=databaseSettings.DatabaseName(); if(databaseNamePtr.Compare(databaseName)) { User::Leave(KErrGeneral); } CleanupStack::PopAndDestroy(databaseInfo); CleanupStack::PopAndDestroy(databaseManager); }
void CorePlugin::launchSqlTool() { qfLogFuncFrame(); QString program = QCoreApplication::applicationDirPath() + "/qsqlmon"; #ifdef Q_OS_WIN program += ".exe"; #endif qfDebug() << "launchnig" << program; QStringList otcs; { auto conn = qf::core::sql::Connection::forName(); otcs << "description=QuickEvent"; otcs << "driver=" + conn.driverName(); otcs << "host=" + conn.hostName(); otcs << "port=" + QString::number(conn.port()); otcs << "user="******"password="******"database=" + conn.databaseName(); } QStringList arguments; arguments << "--one-time-connection-settings" << otcs.join('&'); QProcess *process = new QProcess(this); process->start(program, arguments); }
// // This function will test the UnsetAttribute function of TPosLmDatabaseSettings class. // void TTestPosLmDataBaseSettings::TestUnsetAttributeL() { _LIT(KDatabaseUri,"file://c:eposlm.ldb"); TBufC<40> databaseUri(KDatabaseUri); HPosLmDatabaseInfo* databaseInfo=HPosLmDatabaseInfo::NewLC(databaseUri); TPosLmDatabaseSettings databaseSettings=databaseInfo->Settings(); _LIT(KDatabaseName,"Nokia"); TPosLmDatabaseName databaseName(KDatabaseName); databaseSettings.SetDatabaseName(databaseName); databaseSettings.UnsetAttribute(TPosLmDatabaseSettings::EName); CPosLmDatabaseManager* databasemanager= CPosLmDatabaseManager::NewL(); CleanupStack::PushL(databasemanager); databasemanager->ModifyDatabaseSettingsL(databaseUri,databaseSettings); if(databaseSettings.IsAttributeSet(TPosLmDatabaseSettings::EName)) { User::Leave(KErrGeneral); } CleanupStack::PopAndDestroy(databasemanager); CleanupStack::PopAndDestroy(databaseInfo); ReleaseLandmarkResources(); }
QVariant CredentialSettings::toVariant() const { QVariantMap map; map.insert("userName", QtUtils::toQString(userName())); map.insert("userPassword", QtUtils::toQString(userPassword())); map.insert("databaseName", QtUtils::toQString(databaseName())); map.insert("enabled", enabled()); return map; }
void MpdLibraryDb::connectionChanged(const MPDConnectionDetails &details) { QString dbFile=databaseName(details); DBUG << dbFileName << dbFile; if (dbFile!=dbFileName) { init(dbFile); } else { emit libraryUpdated(); } }
int main(int argc, char *argv[]) { QString databaseName(":memory:"); /* Create application */ QCoreApplication app(argc, argv); /* Parse command line arguments */ for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h")) { usage(); return EXIT_SUCCESS; } else if (!strcmp(argv[i], "-d")) { if (i == argc - 1 || !strlen(argv[i+1]) || argv[i+1][0] == '-') { fprintf(stderr, "Option -d requires an argument\n"); usage(); return EXIT_FAILURE; } databaseName = QString::fromLocal8Bit(argv[++i]); } else if (!strcmp(argv[i], "-p")) { if (i == argc - 1 || !strlen(argv[i+1]) || argv[i+1][0] == '-') { fprintf(stderr, "Option -p requires an argument\n"); usage(); return EXIT_FAILURE; } app.setLibraryPaths(app.libraryPaths() << QString::fromLocal8Bit(argv[++i])); } } /* Open database */ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(databaseName); if (!db.open()) { fprintf(stderr, "Could not access database '%s'\n", databaseName.toLocal8Bit().constData()); return EXIT_FAILURE; } QDjango::setDatabase(db); /* Run interactive shell */ QScriptEngine *engine = new QScriptEngine(); QDjangoScript::registerWhere(engine); QDjangoScript::registerModel<User>(engine); QDjangoScript::registerModel<Group>(engine); QDjangoScript::registerModel<Message>(engine); qDebug() << "Available extensions: " << engine->availableExtensions(); interactive(engine); return EXIT_SUCCESS; }
TESTCASE(SaveDatabase, DatabaseSave) { std::string databaseName(DataDir + "database1.csv"); Database database; std::remove(databaseName.c_str()); database.Scan(DataDir + "dir_with_files"); database.Save(databaseName); CHECK(fexists(databaseName)); }
QString KexiProjectData::infoString(bool nobr) const { if (d->connData.fileName().isEmpty()) { //server-based return QString(nobr ? "<nobr>" : "") + QString("\"%1\"").arg(databaseName()) + (nobr ? "</nobr>" : "") + (nobr ? " <nobr>" : " ") + i18nc("database connection", "(connection %1)", d->connData.serverInfoString()) + (nobr ? "</nobr>" : ""); } //file-based return QString(nobr ? "<nobr>" : "") + QString("\"%1\"").arg(d->connData.fileName()) + (nobr ? "</nobr>" : ""); }
QgsOracleConn::QgsOracleConn( QgsDataSourceURI uri ) : mRef( 1 ) , mCurrentUser( QString::null ) , mHasSpatial( -1 ) { QgsDebugMsg( QString( "New Oracle connection for " ) + uri.connectionInfo() ); QString database = databaseName( uri.database(), uri.host(), uri.port() ); QgsDebugMsg( QString( "New Oracle database " ) + database ); mDatabase = QSqlDatabase::addDatabase( "QOCISPATIAL", QString( "oracle%1" ).arg( snConnections++ ) ); mDatabase.setDatabaseName( database ); mDatabase.setConnectOptions( "OCI_ATTR_PREFETCH_ROWS=1000" ); mDatabase.setUserName( uri.username() ); mDatabase.setPassword( uri.password() ); if ( !mDatabase.open() ) { QString username = uri.username(); QString password = uri.password(); while ( !mDatabase.open() ) { bool ok = QgsCredentials::instance()->get( database, username, password, mDatabase.lastError().text() ); if ( !ok ) break; if ( !username.isEmpty() ) uri.setUsername( username ); if ( !password.isEmpty() ) uri.setPassword( password ); QgsDebugMsg( "Connecting to " + database ); mDatabase.setUserName( username ); mDatabase.setPassword( password ); } if ( mDatabase.isOpen() ) QgsCredentials::instance()->put( database, username, password ); } if ( !mDatabase.isOpen() ) { mDatabase.close(); QgsMessageLog::logMessage( tr( "Connection to database failed" ), tr( "Oracle" ) ); mRef = 0; return; } }
RestoreFrame::RestoreFrame(wxWindow* parent, DatabasePtr db) : BackupRestoreBaseFrame(parent, db) { setIdString(this, getFrameId(db)); wxString databaseName(db->getName_()); wxString serverName(db->getServer()->getName_()); SetTitle(wxString::Format(_("Restore Database \"%s:%s\""), serverName.c_str(), databaseName.c_str())); createControls(); layoutControls(); updateControls(); text_ctrl_filename->SetFocus(); }
void MpdLibraryDb::removeUnusedDbs() { QSet<QString> existing; QList<MPDConnectionDetails> connections=Settings::self()->allConnections(); QString dirPath=Utils::dataDir(constDirName, false); if (dirPath.isEmpty()) { return; } for (const MPDConnectionDetails &conn: connections) { existing.insert(databaseName(conn).mid(dirPath.length())); } QFileInfoList files=QDir(dirPath).entryInfoList(QStringList() << "*"+LibraryDb::constFileExt, QDir::Files); for (const QFileInfo &file: files) { if (!existing.contains(file.fileName())) { QFile::remove(file.absoluteFilePath()); } } }
bool TKvsDatabase::open() { return (driver()) ? driver()->open(databaseName(), userName(), password(), hostName(), port(), connectOptions()) : false; }
QgsOracleConn::QgsOracleConn( QgsDataSourceUri uri ) : mRef( 1 ) , mCurrentUser( QString::null ) , mHasSpatial( -1 ) { QgsDebugMsg( QString( "New Oracle connection for " ) + uri.connectionInfo() ); QString database = databaseName( uri.database(), uri.host(), uri.port() ); QgsDebugMsg( QString( "New Oracle database " ) + database ); mDatabase = QSqlDatabase::addDatabase( "QOCISPATIAL", QString( "oracle%1" ).arg( snConnections++ ) ); mDatabase.setDatabaseName( database ); QString options = uri.hasParam( "dboptions" ) ? uri.param( "dboptions" ) : "OCI_ATTR_PREFETCH_ROWS=1000"; QString workspace = uri.hasParam( "dbworkspace" ) ? uri.param( "dbworkspace" ) : QString::null; mDatabase.setConnectOptions( options ); mDatabase.setUserName( uri.username() ); mDatabase.setPassword( uri.password() ); QgsDebugMsg( QString( "Connecting with options: " ) + options ); if ( !mDatabase.open() ) { QString username = uri.username(); QString password = uri.password(); QString realm( database ); if ( !username.isEmpty() ) realm.prepend( username + "@" ); QgsCredentials::instance()->lock(); while ( !mDatabase.open() ) { bool ok = QgsCredentials::instance()->get( realm, username, password, mDatabase.lastError().text() ); if ( !ok ) break; if ( !username.isEmpty() ) { uri.setUsername( username ); realm = username + "@" + database; } if ( !password.isEmpty() ) uri.setPassword( password ); QgsDebugMsg( "Connecting to " + database ); mDatabase.setUserName( username ); mDatabase.setPassword( password ); } if ( mDatabase.isOpen() ) QgsCredentials::instance()->put( realm, username, password ); QgsCredentials::instance()->unlock(); } if ( !mDatabase.isOpen() ) { mDatabase.close(); QgsMessageLog::logMessage( tr( "Connection to database failed" ), tr( "Oracle" ) ); mRef = 0; return; } if ( !workspace.isNull() ) { QSqlQuery qry( mDatabase ); if ( !qry.exec( QString( "BEGIN\nDBMS_WM.GotoWorkspace(%1);\nEND;" ).arg( quotedValue( workspace ) ) ) ) { mDatabase.close(); QgsMessageLog::logMessage( tr( "Could not switch to workspace %1 [%2]" ).arg( workspace, qry.lastError().databaseText() ), tr( "Oracle" ) ); mRef = 0; return; } } }