• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ QSqlQuery函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中QSqlQuery函数的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQuery函数的具体用法?C++ QSqlQuery怎么用?C++ QSqlQuery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: QWidget

SeeStudents::SeeStudents(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SeeStudents)
{
    this->showMaximized();

    ui->setupUi(this);

    ostringstream q;
    q << "SELECT * FROM Student;";
    QSqlQuery query = QSqlQuery(QString(q.str().c_str()));
    ui->tableWidget->setColumnCount(4);
    int i = 1;

    ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Foto"));
    ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Nombre"));
    ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Localización"));
    ui->tableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem("Seleccionar para modelo"));
    ui->tableWidget->horizontalHeader()->setStretchLastSection(true);

    while(query.next()){
        int id = query.value("id").toInt();
        ui->tableWidget->setRowCount(i);
        string name = query.value("name").toString().toStdString();
        string path = query.value("directory").toString().toStdString();
        QString pathImage = QString(path.c_str()) + "/0.jpg";
        QImage* image = new QImage();
        if(!image->load(pathImage))
            cout << "ERROR LOADING" << endl;
        else{
            QTableWidgetItem *itm = new QTableWidgetItem;
            *image = image->scaledToHeight(50);
            itm->setData(Qt::DecorationRole, QPixmap::fromImage(*image));
            itm->setFlags(itm->flags() ^ Qt::ItemIsEditable);
            ui->tableWidget->setItem(i - 1, 0, itm);
            QTableWidgetItem *itm2 = new QTableWidgetItem;

            itm2->setData(Qt::DisplayRole, name.c_str());
            ui->tableWidget->setItem(i - 1, 1, itm2);
            QTableWidgetItem* itm3 = new QTableWidgetItem;
            itm3->setData(Qt::DisplayRole, path.c_str());
            ui->tableWidget->setItem(i - 1, 2, itm3);
            QCheckBox* check = new QCheckBox();
            ui->tableWidget->setCellWidget(i - 1, 3, check);
            _checks.push_back(check);
            i++;
        }
        _students.push_back(new Alumno(id, path, name));
    }
    ui->tableWidget->resizeColumnsToContents();
    ui->tableWidget->resizeRowsToContents();

}
开发者ID:AlejandroRosa,项目名称:AnalizadorAtencion,代码行数:53,代码来源:seestudents.cpp


示例2: query

QSqlQuery DBWorker::prepare(const char *statement)
{
    QSqlQuery query(m_database);
    query.setForwardOnly(true);
    if (!query.prepare(statement)) {
        qWarning() << Q_FUNC_INFO << "failed to prepare query";
        qWarning() << query.lastQuery();
        qWarning() << query.lastError();
        return QSqlQuery();
    }
    return query;
}
开发者ID:Hmaal,项目名称:sailfish-browser,代码行数:12,代码来源:dbworker.cpp


示例3: qDebug

void SoftKeyPad::connectDatabase()
{
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("china.db");
    if(db.open()) {
        qDebug() << "db open successful!";
    } else {
        qDebug() << "db open failure!";
    }

    query = QSqlQuery("china.db");
}
开发者ID:chrismayo,项目名称:ONLIGHT,代码行数:12,代码来源:softkeypad.cpp


示例4: query

QSqlQuery CommHistoryDatabase::prepare(const char *statement, const QSqlDatabase &database)
{
    QSqlQuery query(database);
    query.setForwardOnly(true);
    if (!query.prepare(statement)) {
        qWarning() << "Failed to prepare query";
        qWarning() << query.lastError();
        qWarning() << statement;
        return QSqlQuery();
    }
    return query;
}
开发者ID:sledges,项目名称:libcommhistory,代码行数:12,代码来源:commhistorydatabase.cpp


示例5: QSqlQuery

bool NGSD::isOpen() const
{
	static bool is_initialized = false;
	static bool is_open = false;
	if (!is_initialized)
	{
		is_open = QSqlQuery(*db_).exec("SELECT 1");
		is_initialized = true;
	}

	return is_open;
}
开发者ID:mdozmorov,项目名称:ngs-bits,代码行数:12,代码来源:NGSD.cpp


示例6: QSqlQuery

bool ibanBicStoragePlugin::setupDatabase(QSqlDatabase connection)
{
  // Get current version
  QSqlQuery query = QSqlQuery(connection);
  query.prepare("SELECT versionMajor FROM kmmPluginInfo WHERE iid = ?");
  query.bindValue(0, iid());
  if (!query.exec()) {
    qWarning("Could not execute query for ibanBicStoragePlugin: %s", qPrintable(query.lastError().text()));
    return false;
  }

  int currentVersion = 0;
  if (query.next())
    currentVersion = query.value(0).toInt();

  // Create database in it's most recent version if version is 0
  // (version 0 means the database was not installed)
  if (currentVersion == 0) {
    // If the database is recreated the table may be still there. So drop it if needed. No error handling needed
    // as this step is not necessary - only the creation is important.
    query.exec("DROP TABLE IF EXISTS kmmIbanBic;");

    if (!query.exec(
          "CREATE TABLE kmmIbanBic ("
          "  id varchar(32) NOT NULL PRIMARY KEY REFERENCES kmmPayeeIdentifier( id ) ON DELETE CASCADE ON UPDATE CASCADE,"
          "  iban varchar(32),"
          "  bic char(11) CHECK(length(bic) = 11 OR bic IS NULL),"
          "  name text"
          " );"
        )) {
      qWarning("Could not create table for ibanBicStoragePlugin: %s", qPrintable(query.lastError().text()));
      return false;
    }

    query.prepare("INSERT INTO kmmPluginInfo (iid, versionMajor, versionMinor, uninstallQuery) VALUES(?, ?, ?, ?)");
    query.bindValue(0, iid());
    query.bindValue(1, 1);
    query.bindValue(2, 0);
    query.bindValue(3, "DROP TABLE kmmIbanBic;");
    if (query.exec())
      return true;
    qWarning("Could not save plugin info for ibanBicStoragePlugin (%s): %s", qPrintable(iid()), qPrintable(query.lastError().text()));
    return false;
  }

  // Check if version is valid with this plugin
  switch (currentVersion) {
    case 1: return true;
  }

  return false;
}
开发者ID:KDE,项目名称:kmymoney,代码行数:52,代码来源:ibanbicstorageplugin.cpp


示例7: QSqlQuery

QList<key> dbAccess::getTitleID() {
    QList<key> result;
    if(dbStatus) {
        request = QSqlQuery(db);
        request.exec("select ID, Title from contacts Order by Title ASC");
        while(request.next()) {
            result.append({request.value(0).toInt(),request.value(1).toString()});
        }
        return result;
    } else {
        qDebug() << "Database doesn't open";
    }
}
开发者ID:athl64,项目名称:db_accounts,代码行数:13,代码来源:dbaccess.cpp


示例8: QSqlQuery

void SyncDatabase::saveSyncFile(SyncFile * sf, int parent_id)
{
    if (!sf->isInDatabase()) {
        QSqlQuery(*db).exec(QString("INSERT INTO content (id, parent_id, file_name, last_modified) VALUES (%1, %2, '%3', '%4')")
                            .arg(sf->index())
                            .arg(parent_id)
                            .arg(sf->getName())
                            .arg(sf->lastModifiedString()));
    } else if (sf->wasModified() && sf->wasDeleted()) {
        removeRecords(sf->index());
        return;
    } else if (sf->wasModified()) {
        QSqlQuery(*db).exec(QString("UPDATE content SET parent_id = %1, file_name = '%2', last_modified = '%3' WHERE id = %4")
                            .arg(parent_id)
                            .arg(sf->getName())
                            .arg(sf->lastModifiedString())
                            .arg(sf->index()));
    }
    for (int i = 0; i < sf->childCount(); ++i) {
        saveSyncFile(sf->childAt(i), sf->index());
    }
}
开发者ID:matus-tomlein,项目名称:synkron,代码行数:22,代码来源:syncdatabase.cpp


示例9: QSqlQuery

TaskRecorder::TaskRecorder() 
{
   this->initDatabase();
   if (!dbconn.open())
   {
        QMessageBox::critical(0, QObject::tr("Database"), QObject::tr("Sorry, I couldn't connect to SQLite database"));
        return;
   }

   query = QSqlQuery(dbconn);
   query.exec("create table if not exists tasks(id integer primary key autoincrement,event varchar, time datetime)");
   qDebug() << "open sqlite connection";
}
开发者ID:TianyuCheng,项目名称:QtSprite,代码行数:13,代码来源:TaskRecorder.cpp


示例10: setWindowTitle

void DebtReport::on_type_currentIndexChanged(int index)
{
    if (index == 0) {
        setWindowTitle(QString::fromUtf8("Отчет: задолженность по заказчикам"));

    } else if (index == 1) {
        setWindowTitle(QString::fromUtf8("Отчет: задолженность поставщикам/подрядчикам"));

    }

    ui->total->clear();
    model->setQuery(QSqlQuery());
}
开发者ID:shul20,项目名称:proprint,代码行数:13,代码来源:debtreport.cpp


示例11: QObject

BoardUtils::BoardUtils(QObject *parent) :
    QObject(parent)
{
    m_carmodel = new CarModel();
    //colors taken from gtlevel-0.4.c, line 143
    //transform them to QML color type
    m_colors.insert("DarkGreen", "darkgreen");
    m_colors.insert("purple3","mediumpurple");
    m_colors.insert("orange","orange");
    m_colors.insert("seagreen","seagreen");
    m_colors.insert("blue3","mediumblue");
    m_colors.insert("SteelBlue1","lightsteelblue");
    m_colors.insert("yellow","yellow");
    m_colors.insert("gold3","goldenrod");
    m_colors.insert("IndianRed1","indianred");
    m_colors.insert("SteelBlue4","steelblue");
    m_colors.insert("LightSkyBlue1","lightskyblue");
    m_colors.insert("SlateGray2","lightslategray");
    m_colors.insert("LavenderBlush1","lavenderblush");
    m_colors.insert("LemonChiffon1","lemonchiffon");
    m_colors.insert("MistyRose2","mistyrose");
    m_colors.insert("NavajoWhite4", "navajowhite");
    m_colors.insert("thistle2","thistle");
    m_colors.insert("red","red");

    //now let's load stuff from database
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
   // QString path = adjustPath("data/levels.db");
    QString path = "app/native/assets/levels.db";
    db.setDatabaseName(path);

    if (!db.open()) {
        //abort with error
        qDebug() << "Error opening database : " << db.lastError();
        //db.lastError();
    }
    QStringList tables = db.tables();
    if (!tables.contains("levels", Qt::CaseInsensitive)) {
        //abort with error
        QSqlError("sqlite", "data/levels.db doesn't contain tabe 'levels'");
    }
    m_query = QSqlQuery("", db);
    m_query.exec(QLatin1String("select count(id) from levels;"));
    m_query.next();
    m_numLevels = m_query.value(0).toInt();

    int lastLevel = m_sett.value("lastLevelID", 1).toInt();
    if(lastLevel<1 || lastLevel>m_numLevels) lastLevel=1;

    loadLevel(lastLevel);
}
开发者ID:MADARAHUCHIHA,项目名称:BlackBerry-10-Port-A-Thon,代码行数:51,代码来源:boardutils.cpp


示例12: QSqlQuery

QSqlQuery MysqlConnection::Query(QString sqlQuery)
{
    if(sqlQuery.isEmpty() || !m_db.isOpen())
        return QSqlQuery();

    QSqlQuery req = QSqlQuery(m_db);

    if(!req.exec(sqlQuery))
    {
        Log::Write(LOG_TYPE_NORMAL, "SQL error with %s", sqlQuery.toLatin1().data());
        Log::Write(LOG_TYPE_NORMAL, "[Error %u] %s", req.lastError().number(), req.lastError().text().toLatin1().data());

        if (req.lastError().number() == 2013 || req.lastError().number() == 2003)
        {
            if (Reconnect())
                Query(sqlQuery);
            else
                Log::Write(LOG_TYPE_NORMAL, "Reconnect failed : MySQL connection lost.");
        }
    }

    return req;
}
开发者ID:FunkyEmulation,项目名称:SumBox,代码行数:23,代码来源:MysqlConnection.cpp


示例13: QSqlDatabase

bool sqlite3::openSQL3(QString db)
{
    this->DB = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE","mysqlite3"));
    this->DB->setDatabaseName(db);

    if (!this->DB->open()){
        qDebug() << "DB error open:" << this->DB->lastError().text();
        delete this->DB;
        QSqlDatabase::removeDatabase("mysqlite3");
        return false;
    }
    this->Q = QSqlQuery(*this->DB);
    return true;
}
开发者ID:azrilrahim,项目名称:tig-fqdn-cli,代码行数:14,代码来源:sqlite3.cpp


示例14: qDebug

void CrmClusterLineEdit::silentSetId(const int pId)
{
  if (DEBUG)
    qDebug("VCLE %s::silentSetId(%d)", qPrintable(objectName()), pId);

  if (pId == -1)
  {
    XLineEdit::clear();
    _model = new QSqlQueryModel(this);
  }
  else
  {
    XSqlQuery idQ;
    idQ.prepare(_query + _idClause + QString(";"));
    idQ.bindValue(":id", pId);
    idQ.exec();
    if (idQ.first())
    {
      if (_completer)
        static_cast<QSqlQueryModel* >(_completer->model())->setQuery(QSqlQuery());

      _id = pId;
      _valid = true;

      _model->setQuery(idQ);

      setText(idQ.value("number").toString());
      if (_hasName)
        _name = (idQ.value("name").toString());
      if (_hasDescription)
        _description = idQ.value("description").toString();
      if (_hasActive)
        setStrikeOut(!idQ.value("active").toBool());
      if (_hasOwner)
        _owner = idQ.value("owner").toString();
      if (_hasAssignto)
        _assignto = idQ.value("assignto").toString();
    }
    else if (idQ.lastError().type() != QSqlError::NoError)
      QMessageBox::critical(this, tr("A System Error Occurred at %1::%2.")
                            .arg(__FILE__)
                            .arg(__LINE__),
                            idQ.lastError().databaseText());
  }

  _parsed = true;
  sHandleNullStr();
  emit parsed();
}
开发者ID:AlFoX,项目名称:qt-client,代码行数:49,代码来源:crmCluster.cpp


示例15: queryExtents

QString QgsDb2GeometryColumns::open( const QString &schemaName, const QString &tableName )
{
  QString queryExtents( "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, TYPE_NAME, "
                        "SRS_ID, SRS_NAME, MIN_X, MIN_Y, MAX_X, MAX_Y "
                        "FROM DB2GSE.ST_GEOMETRY_COLUMNS" );
  QString queryNoExtents( "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, TYPE_NAME, "
                          "SRS_ID, SRS_NAME "
                          "FROM DB2GSE.ST_GEOMETRY_COLUMNS" );
  mQuery = QSqlQuery( mDatabase );
  QString nativeError;
  mEnvironment = ENV_LUW;

  if ( !schemaName.isEmpty() && !tableName.isEmpty() )
  {
    QString whereClause = QStringLiteral( " WHERE TABLE_SCHEMA = '%1' AND TABLE_NAME = '%2'" )
                          .arg( schemaName, tableName );
    queryExtents += whereClause;
    queryNoExtents += whereClause;
  }
  QgsDebugMsg( queryExtents );
  // issue the sql query
  if ( !mQuery.exec( queryExtents ) )
  {
    QgsDebugMsg( "ST_Geometry_Columns query failed: " + mDatabase.lastError().text() );
    nativeError = mQuery.lastError().nativeErrorCode();
    QgsDebugMsg( QStringLiteral( "SQLCODE: %1" ).arg( nativeError ) );
    /* The MIN_X, MIN_Y, MAX_X, and MAX_Y columns are not available on z/OS (and LUW 9.5)
       so SQLCODE -206 is returned when specifying non-existent columns. */
    if ( mQuery.lastError().nativeErrorCode() == QStringLiteral( "-206" ) )
    {
      QgsDebugMsg( QStringLiteral( "Try query with no extents" ) );
      mQuery.clear();

      if ( !mQuery.exec( queryNoExtents ) )
      {
        QgsDebugMsg( QStringLiteral( "SQLCODE: %1" ).arg( mQuery.lastError().nativeErrorCode() ) );
      }
      else
      {
        QgsDebugMsg( QStringLiteral( "success; must be z/OS" ) );
        mEnvironment = ENV_ZOS;
        nativeError.clear();
      }
    }
  }
//  QgsDebugMsg( QStringLiteral( "sqlcode: %1" ).arg( sqlcode ) );

  return nativeError;
}
开发者ID:AlisterH,项目名称:Quantum-GIS,代码行数:49,代码来源:qgsdb2geometrycolumns.cpp


示例16: disconnect

void DBConnectMainWindow::disconnect(void)
{
    // clear query associated with DB.
    m_QueryModel.setQuery(QSqlQuery());

    // clear model and close database.
    m_QueryModel.clear();
    m_FullFetchModel.clear();
    m_DbConnection.close();

    // remove the connection.
    QString connection_name(m_DbConnection.connectionName());
    m_DbConnection = QSqlDatabase();
    m_DbConnection.removeDatabase(connection_name);
}
开发者ID:whztt07,项目名称:DBConnect,代码行数:15,代码来源:DBConnectMainWindow.cpp


示例17: execSqlCode

/*! \brief Execute SQL statements in \p code use databse connection \p db
 *  \note Does nothing if \p sqlCode is empty
 *  \throws SqlQueryError if no connection to database or if SQL exec fails (SQL query has error)
 */
QSqlQuery execSqlCode(const QString& sqlCode, const QSqlDatabase& db)
{
  if (sqlCode.trimmed().isEmpty())
    return QSqlQuery(QString(), db);

  if (!db.isValid() || !db.isOpen()) {
    throw SqlQueryError(QSqlError(QLatin1String("db is not valid or not open"),
                                  QLatin1String(""),
                                  QSqlError::ConnectionError));
  }

  QSqlQuery qry = db.exec(sqlCode);
  qttools::throwIfError(qry);
  return qry;
}
开发者ID:Alexandr-Galko,项目名称:fougtools,代码行数:19,代码来源:qsql_query_tools.cpp


示例18: value

void UserData::update_db()
{
    const int version = value("version").toInt();
    if( version < 3 )
    {
        QStringList query_list;
        query_list << "BEGIN;";
        query_list << "CREATE  TABLE IF NOT EXISTS UpdateMessages (id BIGINT NOT NULL ,message TEXT NOT NULL, date BIGINT NOT NULL, PRIMARY KEY (id) );";
        query_list << "COMMIT;";

        foreach( const QString & query_str, query_list )
            QSqlQuery( query_str, p->db ).exec();

        setValue("version","3");
    }
开发者ID:Barlend,项目名称:Cutegram,代码行数:15,代码来源:userdata.cpp


示例19: QSqlQuery

bool TipoLancamentoDAO::deletaTipoLancamento(TipoLancamento tipo) {
    if(db.open()) {
        query = QSqlQuery(db);
        query.prepare("DELETE FROM TipLan WHERE CodTip = ?");
        query.addBindValue(tipo.getCodTip());
        if(!query.exec()){
            std::cout << query.lastError().text().toStdString() << std::endl;
        }
        db.close();
        return true;
    } else {
        std::cout << db.lastError().text().toStdString() << std::endl;
        return false;
    }
}
开发者ID:LuanTavares,项目名称:Controle-De-Despesas,代码行数:15,代码来源:TipoLancamentoDAO.cpp


示例20: WHERE

QList<geodbObject> GeodbSql::getStreetList(QString text)
{
    QList<geodbObject> geodbObjectList;
    QString CommandText = "SELECT DISTINCT plz_code.loc_id AS id_PLZ, plz_code.text_val AS PLZ, stadt.loc_id AS id_Stadt, stadt.text_val AS Stadt, bezirk.loc_id AS id_Bezirk, bezirk.text_val AS Bezirk, ortsteil.loc_id AS id_Ortsteil, ortsteil.text_val AS Ortsteil, street.loc_id AS id_Strasse, street.text_val AS Strasse, street.valid_since AS Strasse_Von, street.valid_until AS Strasse_Bis, street.text_type AS Strasse_Typ, coord.loc_id AS id_LatLong, coord.valid_since AS LatLong_Von, coord.valid_until AS LatLong_Bis, coord.lat AS Latitude, coord.lon AS Longitude FROM geodb_textdata_berlin street, geodb_textdata_berlin plz_code_such, geodb_textdata_berlin plz_code, geodb_textdata_berlin ortsteil_such, geodb_textdata_berlin ortsteil, geodb_textdata_berlin bezirk_such, geodb_textdata_berlin bezirk, geodb_textdata_berlin stadt_such, geodb_textdata stadt, geodb_coordinates_berlin coord WHERE  ((street.text_val RLIKE :searchText) AND (street.text_type >= 101100000) AND (street.text_type <= 101400000)) AND ((plz_code_such.loc_id = street.loc_id) AND  (plz_code_such.text_type = 400100000)) AND ((plz_code.loc_id = plz_code_such.text_val) AND  (plz_code.text_type = 500300000)) AND ((ortsteil_such.loc_id = street.loc_id) AND  (ortsteil_such.text_type = 400100000)) AND ((ortsteil.loc_id = ortsteil_such.text_val) AND  (ortsteil.text_type = 101000000)) AND ((bezirk_such.loc_id = ortsteil.loc_id) AND  (bezirk_such.text_type = 400100000)) AND ((bezirk.loc_id = bezirk_such.text_val) AND  (bezirk.text_type = 100900000)) AND ((stadt_such.loc_id = bezirk.loc_id) AND  (stadt_such.text_type = 400100000)) AND ((stadt.loc_id = stadt_such.text_val) AND  (stadt.text_type = 500100000)) AND ((coord.loc_id = street.loc_id))  AND  (((street.valid_since >= '0001-01-01') AND (street.valid_until <= '3000-01-01'))  AND  ((plz_code_such.valid_since < street.valid_until) AND (plz_code_such.valid_until >= street.valid_until))  AND  ((plz_code.valid_since < street.valid_until) AND (plz_code.valid_until >= street.valid_until))  AND  ((ortsteil_such.valid_since < street.valid_until) AND (ortsteil_such.valid_until >= street.valid_until))  AND  ((ortsteil.valid_since < street.valid_until) AND (ortsteil.valid_until >= street.valid_until))  AND  ((bezirk_such.valid_since < street.valid_until) AND (bezirk_such.valid_until >= street.valid_until))  AND  ((bezirk.valid_since < street.valid_until) AND (bezirk.valid_until >= street.valid_until))  AND  ((stadt_such.valid_since < street.valid_until) AND (stadt_such.valid_until >= street.valid_until))  AND  ((stadt.valid_since < street.valid_until) AND (stadt.valid_until >= street.valid_until))  AND  ((coord.valid_since < street.valid_until) AND (coord.valid_until >= street.valid_until)))  UNION SELECT DISTINCT 0 AS id_PLZ, 'na' AS PLZ, stadt.loc_id AS id_Stadt, stadt.text_val AS Stadt, bezirk.loc_id AS id_Bezirk, bezirk.text_val AS Bezirk, ortsteil.loc_id AS id_Ortsteil, ortsteil.text_val AS Ortsteil, transport.loc_id AS id_Strasse, transport.text_val AS Strasse, transport.valid_since AS Strasse_Von, transport.valid_until AS Strasse_Bis, transport.text_type AS Strasse_Typ, coord.loc_id AS id_LatLong, coord.valid_since AS LatLong_Von, coord.valid_until AS LatLong_Bis, coord.lat AS Latitude, coord.lon AS Longitude FROM geodb_textdata_berlin_transport transport, geodb_textdata_berlin_transport ortsteil_such, geodb_textdata_berlin ortsteil, geodb_textdata_berlin bezirk_such, geodb_textdata_berlin bezirk, geodb_textdata_berlin stadt_such, geodb_textdata stadt, geodb_coordinates_berlin coord WHERE  ((transport.text_val RLIKE :searchText) AND (transport.text_type > 101100000) AND (transport.text_type <= 101400000)) AND ((ortsteil_such.loc_id = transport.loc_id) AND  (ortsteil_such.text_type = 400100000)) AND ((ortsteil.loc_id = ortsteil_such.text_val) AND  (ortsteil.text_type = 101000000)) AND ((bezirk_such.loc_id = ortsteil.loc_id) AND  (bezirk_such.text_type = 400100000)) AND ((bezirk.loc_id = bezirk_such.text_val) AND  (bezirk.text_type = 100900000)) AND ((stadt_such.loc_id = bezirk.loc_id) AND  (stadt_such.text_type = 400100000)) AND ((stadt.loc_id = stadt_such.text_val) AND  (stadt.text_type = 500100000)) AND ((coord.loc_id = transport.loc_id))  AND  (((transport.valid_since >= '0001-01-01') AND (transport.valid_until <= '3000-01-01'))  AND  ((ortsteil_such.valid_since < transport.valid_until) AND (ortsteil_such.valid_until >= transport.valid_until))  AND  ((ortsteil.valid_since < transport.valid_until) AND (ortsteil.valid_until >= transport.valid_until))  AND  ((bezirk_such.valid_since < transport.valid_until) AND (bezirk_such.valid_until >= transport.valid_until))  AND  ((bezirk.valid_since < transport.valid_until) AND (bezirk.valid_until >= transport.valid_until))  AND  ((stadt_such.valid_since < transport.valid_until) AND (stadt_such.valid_until >= transport.valid_until))  AND  ((stadt.valid_since < transport.valid_until) AND (stadt.valid_until >= transport.valid_until))  AND  ((coord.valid_since < transport.valid_until) AND (coord.valid_until >= transport.valid_until)))  UNION SELECT DISTINCT 0 AS id_PLZ, 'na' AS PLZ, land.loc_id AS id_Stadt, land.text_val AS Stadt, kreis.loc_id AS id_Bezirk, kreis.text_val AS Bezirk, name.loc_id AS id_Ortsteil, name.text_val AS Ortsteil, transport2.loc_id AS id_Strasse, transport2.text_val AS Strasse, transport2.valid_since AS Strasse_Von, transport2.valid_until AS Strasse_Bis, transport2.text_type AS Strasse_Typ, coord.loc_id AS id_LatLong, coord.valid_since AS LatLong_Von, coord.valid_until AS LatLong_Bis, coord.lat AS Latitude, coord.lon AS Longitude FROM geodb_textdata_berlin_transport transport2, geodb_textdata_berlin_transport name_such, geodb_textdata name, geodb_textdata kreis, geodb_textdata kreis_such, geodb_textdata land_such, geodb_textdata land, geodb_coordinates_berlin coord WHERE  ((transport2.text_val RLIKE :searchText) AND (transport2.text_type > 101100000) AND (transport2.text_type <= 101400000)) AND ((name_such.loc_id = transport2.loc_id) AND  (name_such.text_type = 400100000)) AND ((name.loc_id = name_such.text_val) AND  (name.text_type = 500100000)) AND ((kreis_such.loc_id = name.loc_id) AND  (kreis_such.text_type = 400100000)) AND ((kreis.loc_id = kreis_such.text_val) AND  (kreis.text_type = 500100000)) AND ((land_such.loc_id = kreis.loc_id) AND  (land_such.text_type = 400100000)) AND ((land.loc_id = land_such.text_val) AND  (land.text_type = 500100000)) AND ((coord.loc_id = transport2.loc_id))  ORDER BY Stadt, Strasse, PLZ, Bezirk, Ortsteil";
    QSqlQuery query = QSqlQuery(db);
    if(!query.prepare(CommandText))
    {
        QSqlError err = query.lastError();
        qDebug() << err.text() + "\n";
        qDebug() << CommandText + " line:" + QString("%1").arg(__LINE__) +"\n";
    }
    //query.bindValue(":searchText", "'"+text+"'");
    CommandText.replace(":searchText", "'"+text+"'");
    //qDebug()<<CommandText;
    bool bQuery = query.exec(CommandText);
    if(!bQuery)
    {
        QSqlError err = query.lastError();
        qDebug() << err.text() + "\n";
        qDebug() << CommandText + " line:" + QString("%1").arg(__LINE__) +"\n";
        db.close();
        exit(EXIT_FAILURE);
    }
    while(query.next())
    {
        geodbObject go;
        go.id_PLZ = query.value(0).toInt();
        go.PLZ = query.value(1).toString();
        go.idStadt = query.value(2).toInt();
        go.Stadt = query.value(3).toString();
        go.idBezirk = query.value(4).toInt();
        go.Bezirk = query.value(5).toString();
        go.idOrsteil=query.value(6).toInt();
        go.Ortstiel = query.value(7).toString();
        go.idStrasse = query.value(8).toInt();
        go.Strasse = query.value(9).toString();
        go.Strasse_von = query.value(10).toString();
        go.Strasse_bis = query.value(11).toString();
        go.Strasse_type = query.value(12).toInt();
        go.idLatLong = query.value(13).toInt();
        go.LatLong_von = query.value(14).toString();
        go.LatLon_bis = query.value(15).toString();
        go.latitude = query.value(16).toDouble();
        go.longitude = query.value(17).toDouble();
        geodbObjectList.append(go);
    }
    return geodbObjectList;
}
开发者ID:allenck,项目名称:mapper,代码行数:48,代码来源:geodbsql.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ QSqlRecord函数代码示例发布时间:2022-05-30
下一篇:
C++ QSqlError函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap