当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlDatabase::close方法代码示例

本文整理汇总了C++中QSqlDatabase::close方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlDatabase::close方法的具体用法?C++ QSqlDatabase::close怎么用?C++ QSqlDatabase::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSqlDatabase的用法示例。


在下文中一共展示了QSqlDatabase::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: listDatabases

void QgsMssqlNewConnection::listDatabases()
{
  testConnection( QStringLiteral( "master" ) );
  listDatabase->clear();
  QString queryStr = QStringLiteral( "SELECT name FROM master..sysdatabases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')" );

  QSqlDatabase db = QgsMssqlProvider::GetDatabase( txtService->text().trimmed(),
                    txtHost->text().trimmed(),
                    QStringLiteral( "master" ),
                    txtUsername->text().trimmed(),
                    txtPassword->text().trimmed() );
  if ( db.open() )
  {
    QSqlQuery query = QSqlQuery( db );
    query.setForwardOnly( true );
    ( void )query.exec( queryStr );

    if ( !txtService->text().isEmpty() )
    {
      listDatabase->addItem( QStringLiteral( "(from service)" ) );
    }

    if ( query.isActive() )
    {
      while ( query.next() )
      {
        QString name = query.value( 0 ).toString();
        listDatabase->addItem( name );
      }
      listDatabase->setCurrentRow( 0 );
    }
    db.close();
  }
}
开发者ID:anitagraser,项目名称:QGIS,代码行数:34,代码来源:qgsmssqlnewconnection.cpp

示例2: allocFileSpace

FileCache::~FileCache()
{
    allocFileSpace( 0 );

    QSqlDatabase database = QSqlDatabase::database( "FileCache" );
    database.close();
}
开发者ID:Herysutrisno,项目名称:webIssue,代码行数:7,代码来源:filecache.cpp

示例3: checkConnectivity

/* checkConnectivity()
 * Called : When User Clicks Reconnect Button
 * Performs : Checks Connectivity
 */
void Settings::checkConnectivity()
{
    bool ok;
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL","test");
        db.setDatabaseName(databasenameLE->text());
        db.setPort(portLE->text().toInt());
        db.setHostName(hostnameLE->text());
        db.setUserName(usernameLE->text());
        db.setPassword(passwordLE->text());
        ok=db.open();

        if(ok)
            QMessageBox::information(this,"DocmaQ Connection","Connection Successful. <b>" + usernameLE->text() + "</b> is now Connected to <b>" + databasenameLE->text() + "</b> Database.");
        else
            QMessageBox::critical(this,"DocmaQ Connection Error", "An Error Occured while Connecting to the Database." +
                                  tr("Please Check the Database details.\n\n") + "MySQL Reports : " + db.lastError().databaseText());
        db.close();

        settings->setValue("general/mode",ok);
        databaseRB->setChecked(ok);
        manualRB->setChecked(!ok);
    }

    QSqlDatabase::removeDatabase("test");

    f[0] = true;
}
开发者ID:mskonline,项目名称:docmaqv2,代码行数:32,代码来源:settings.cpp

示例4: pegadados_cmp

void FrmCompras_cls::pegadados_cmp(QString x)
{
   {
	QSqlDatabase db ;		
	db = QSqlDatabase::addDatabase("QMYSQL","01");
	db.setHostName(my_hostname);
	db.setDatabaseName(my_database);
	db.setUserName(my_username);
	db.setPassword(my_password);
	bool ok = db.open();
	db = QSqlDatabase::database("01");
	
	QSqlQuery query = QSqlQuery::QSqlQuery(db);

	QString sql = "SELECT * FROM `Produtos` where proId="+x+"";
	query.exec(sql);
		//funcionou
		while (query.next()) {
			QString id = query.value(0).toString();		
			QString name = query.value(1).toString();
			QString codbarras = query.value(2).toString();
			ui_edt_idpro ->setText(id);			
			ui_edt_nomepro ->setText(name);
//			ui_edt_codbarras ->setText(codbarras);
		};
	db.close();   
   }
 QSqlDatabase::removeDatabase("01"); // correct
   
}
开发者ID:melkzedeke,项目名称:openomegasis,代码行数:30,代码来源:frmcompras.cpp

示例5: deleteSite

void SitesDatabaseInterface::deleteSite(int id)
{
    qDebug() << "db: " << this->dbPath;
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(this->dbPath);

    if(false == db.open())
    {
        qDebug() << "can not open database";
    }

    QSqlQuery query;
    query.prepare("DELETE FROM sites WHERE ID = :id;");
    query.bindValue(":id", id);
    if(false == query.exec())
    {
       qDebug() << "SQL ERROR : " << query.lastError();
    }
    db.commit();

    //We have also to delete the associated weather data to this site
    query.prepare("DELETE FROM meteo WHERE id_site = :id;");
    query.bindValue(":id", id);
    if(false == query.exec())
    {
       qDebug() << "SQL ERROR : " << query.lastError();
    }

    db.commit();
    db.close();
}
开发者ID:rgex,项目名称:previRecolte,代码行数:31,代码来源:sitesdatabaseinterface.cpp

示例6: qDebug

QList<Site*> SitesDatabaseInterface::getAllSites()
{
    qDebug() << "db: " << this->dbPath;
    QList<Site*> siteList;

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(this->dbPath);

    if(false == db.open())
    {
        qDebug() << "can not open database";
    }

    QSqlQuery query= db.exec("SELECT * FROM sites");
    while (query.next())
    {
        int id = query.value(0).toInt();
        QString nom = query.value(1).toString();
        QString years = query.value(2).toString();
        QStringList yearsList = years.split(";");
        Site* site = new Site();

        site->setId(id);
        site->setNom(nom);
        site->setYears(yearsList);
        siteList.append(site);
    }
    db.close();

    return siteList;
}
开发者ID:rgex,项目名称:previRecolte,代码行数:31,代码来源:sitesdatabaseinterface.cpp

示例7: initaldatabase

void initaldatabase()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL","first");
    db.setHostName("localhost");
    db.setDatabaseName("whztest");
    db.setUserName("root");
    db.setPassword("infonet313");
    if (!db.open())
    {
        cout<<"firstlink OPEN error~!"<<endl;
        exit(1);
    }
    else
    {
        qDebug()<<"Initial OK!";
        QSqlQuery query(db);
        query.exec("drop table if exists InsertTest;");
         if(!query.exec("create table if not exists InsertTest("                   
                   "id BIGINT AUTO_INCREMENT PRIMARY KEY ,"
                   "taskseq int NOT NULL,"
                   "protocoltype CHAR(10) DEFAULT 'Ethernet',"
                   "threadnumintask int NOT NULL,"
                   "idinthread int NOT NULL,"
                   "framesize int NOT NULL,"
                   "DestMac VARCHAR(60) DEFAULT NULL,"
                   "SourMac VARCHAR(60) DEFAULT NULL,"
                   "TypeorLength VARCHAR(20) DEFAULT NULL,"
                   "Data VARCHAR(6000) DEFAULT NULL,"
                   "Upperlayer VARCHAR(30) DEFAULT NULL)"))
        qDebug()<<"exec error:"<< query.lastError().databaseText();
    }
    db.close();
}
开发者ID:HezhouW,项目名称:SQL-whz,代码行数:33,代码来源:main.cpp

示例8: runSqlScript

	void Database::runSqlScript(QString script_path) {
		QSqlDatabase db = QSqlDatabase::database();

		if (not db.open())
			throw new ErrorOpeningDatabase(path());

		QFile script(script_path);
		if (not script.open(QIODevice::ReadOnly | QIODevice::Text))
			throw new ErrorReadingSQLScript(script_path);

		// NOTE query object must be created after database is open
		QSqlQuery query;

		QString line;
		while (!script.atEnd()) {
			line = QString(script.readLine());
			if (lineCanBeIgnored(line))
				continue;

			if (not query.exec(line))
				throw new SqlQueryError(query);
		}
		db.close();
		script.close();
	}
开发者ID:Jellofishi,项目名称:JBLib2,代码行数:25,代码来源:database.cpp

示例9: load

// Load the DB from a DomElement
bool MemDbLoader::load(const QDomElement & elemSource, QSqlDatabase db)
{
    _lastError = "";
    
    // Login to the SQLITE memory DB

	if(db.isOpen()) {
		db.close();
		db.open();
	}

	if(db.databaseName() != memDbName) {
		_lastError = createMemoryDB();
		if(!_lastError.isEmpty()) {
			return false;
		}
		db = QSqlDatabase::database();
		if(!db.open()) {
			_lastError = "Error opening QSQLITE memory database";
			return false;
		}  
	}
	_db = db;

    QDomNodeList nlist = elemSource.childNodes();
    for(int i = 0; i < nlist.count(); i++ ) {
        QDomElement it = nlist.item(i).toElement();
        if(it.tagName()=="table") {
            parseTable(it.toElement());
        }
    }
    return _lastError.isEmpty();
}
开发者ID:0TheFox0,项目名称:MayaOpenRPT,代码行数:34,代码来源:memdbloader.cpp

示例10: create

//Creates the database for session storage
bool SessionManager::create(){
    
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("sess.db");
    
    if(db.open()){
        //Is the session table there ?
        if(db.tables().indexOf("sessions") == -1){
            QSqlQuery query(db);
            query.prepare("CREATE TABLE sessions "
                          "(id INTEGER PRIMARY KEY AUTOINCREMENT,"
                          "name TEXT,"
                          "hostname TEXT,"
                          "username TEXT,"
                          "password TEXT,"
                          "port INTEGER,"
                          "type TEXT,"
                          "initpath TEXT)");
            if(!query.exec()){
                qDebug() << query.lastInsertId();
                return false;
            }
        }
    }else{
        return false;
    }
    
    db.close();
    return true;
}
开发者ID:juliendz,项目名称:ssProject,代码行数:31,代码来源:SessionManager.cpp

示例11: on_btn_excluir_clicked

void FrmVendas_cls::on_btn_excluir_clicked()
{
QString idpro = ui_grd_vendas->item(ui_grd_vendas->currentRow (),0) ->text();
	{
		QSqlDatabase db ;		
		db = QSqlDatabase::addDatabase("QMYSQL","01");
		db.setHostName("localhost");
		db.setDatabaseName("Omega");
		db.setUserName("root");
                db.setPassword("");
		bool ok = db.open();
		db = QSqlDatabase::database("01");
		
		QSqlQuery query = QSqlQuery::QSqlQuery(db);
		
		QString sql = "delete from tmp_vendas where idpro="+idpro;
//		qDebug() << sql;
		query.exec(sql);				
		db.close();	

	    }
 
	 QSqlDatabase::removeDatabase("01"); // correct
//	qDebug() << idpro;
ui_grd_vendas->removeRow(ui_grd_vendas->currentRow ());
}
开发者ID:melkzedeke,项目名称:openomegasis,代码行数:26,代码来源:frmvendas.cpp

示例12: pegadados_vnd

void FrmVendas_cls::pegadados_vnd(QString x)
{
   {
	QSqlDatabase db ;		
	db = QSqlDatabase::addDatabase("QMYSQL","01");
	db.setHostName("localhost");
	db.setDatabaseName("Omega");
	db.setUserName("root");
        db.setPassword("");
	bool ok = db.open();
	db = QSqlDatabase::database("01");
	
	QSqlQuery query = QSqlQuery::QSqlQuery(db);
//	QString name = ui_edt_nome -> text();
//	QString codx =x;

	QString sql = "SELECT * FROM `Produtos` where proId="+x+"";
	query.exec(sql);
		//funcionou
		while (query.next()) {
			QString id = query.value(0).toString();		
			QString name = query.value(1).toString();
			QString codbarras = query.value(2).toString();
			ui_edt_idpro ->setText(id);			
			ui_edt_nomepro ->setText(name);
//			ui_edt_codbarras ->setText(codbarras);
		};
	db.close();   
   }
 QSqlDatabase::removeDatabase("01"); // correct
      preenche_grd_vnd();
}
开发者ID:melkzedeke,项目名称:openomegasis,代码行数:32,代码来源:frmvendas.cpp

示例13: buscar_informacoes_his_saida

void tela_produto::buscar_informacoes_his_saida(int id){
    conexao_bd conexao;
    QSqlDatabase bd;

    int id_venda;
    int quantidade;
    double valor_venda_uni;
    QString data;

    std::vector< his_saidas * > aux_his;

    //realiza conexão ao banco de dados
    if (conexao.conetar_bd()){

        //Retorna o banco de dados
        bd = conexao.retorna_bd();

        //Declara a variável que irá fazer a consulta
        QSqlQuery consultar(bd);

        //realiza a consulta
        consultar.exec("SELECT l.`id_venda`, l.`quantidade`, l.`valor_venda_uni`, c.`data_venda` FROM lista_venda l,venda c WHERE l.id_venda=c.id_venda AND l.id_produto = "+QString::number(id)+";");
        while(consultar.next()){
            id_venda = consultar.value(0).toString().toInt();
            quantidade = consultar.value(1).toString().toInt();
            valor_venda_uni = consultar.value(2).toString().toDouble();
            data = consultar.value(3).toString();
            aux_his.push_back(new his_saidas(id_venda,quantidade,valor_venda_uni,data));
        }
        consultar.clear();
        bd.close();
        conexao.fechar_conexao();
    }
    mostrar_informacoes_his_saida(aux_his);
}
开发者ID:jmessias1725,项目名称:sexloja,代码行数:35,代码来源:tela_produto.cpp

示例14: main

int main(int argc, char ** argv)
{
	QApplication app( argc, argv );
	QCoreApplication::setApplicationName("qrdc");
	QCoreApplication::setApplicationVersion("0.0.1");
	QCoreApplication::setOrganizationName("TI_Eugene");
	QCoreApplication::setOrganizationDomain("eap.su");
	// <tr>
	QTranslator appTranslator;
	QString trpath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);	// /usr/share/qt4/translations
	QString trfile = QCoreApplication::applicationName() + "_" + QLocale::system().name().left(2);
	if (not QFile::exists(trpath + QDir::separator() + trfile + ".qm"))
		trpath = app.applicationDirPath() + QDir::separator() + "i18n";
	appTranslator.load(trpath + QDir::separator() + trfile);
	app.installTranslator(&appTranslator);
	// </tr>
	// <db>
	QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
	if (!createConnection(db))
		return 1;
	// </db>
	MainWindowImpl *win = new MainWindowImpl();
	win->setModels(&db);
	win->go(); 
	app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
	int retvalue = app.exec();
	delete win;
	db.close();
	return retvalue;
}
开发者ID:rgfernandes,项目名称:qtdesktop,代码行数:30,代码来源:main.cpp

示例15: if

DataConnect::DataConnect()
{
        QSqlDatabase mydb = QSqlDatabase::addDatabase("QSQLITE");
        mydb.setDatabaseName("data.db");
        if  (mydb.open()) {
            std::cout<<"Database is open\n";
        } else {
            std::cout<<"Database is not open\n";
        }
        QSqlQuery comman;
        QString exc = "create table if not exists collection ( id INTEGER NOT NULL , type VARCHAR(100), dataType VARCHAR(100),title VARCHAR(100),version VARCHAR(100),publisher VARCHAR(100), yearRecored int, duration int, category VARCHAR(100) );";
        if (comman.exec(exc)) {
            std::cout << "collection data run\n";
        } else {
            std::cout << "collection data not run\n";
        }
        exc = "create table if not exists items ( id INTEGER NOT NULL, idenCode int,barcode int,borrowStatus VARCHAR(100),borrTime int,dateBorr VARCHAR(100), dayBorr int );";

        if (comman.exec(exc)) {
            std::cout << "items data run\n";
        } else {
            std::cout << "item data not run\n";
        }

        exc = "create table if not exists borrowers ( id INTEGER NOT NULL,name VARCHAR(100),type VARCHAR(100),department VARCHAR(100),mobileNumber VARCHAR(100), itemBorr int, itemLate int , itemString VARCHAR(100));";

        if (comman.exec(exc)) {
            std::cout << "borrowers data run\n";
        } else {
            std::cout << "borrowers data not run\n";
        }
        mydb.close();
}
开发者ID:nguyenhoangtuan,项目名称:LibrarySystem,代码行数:33,代码来源:dataconnect.cpp


注:本文中的QSqlDatabase::close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。