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


C++ QSqlQuery类代码示例

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


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

示例1: prepare

void DBWorker::deleteSetting(QString name)
{
    QSqlQuery query = prepare("DELETE FROM settings WHERE name = ?");
    query.bindValue(0, name);
    execute(query);
}
开发者ID:sailfishos,项目名称:sailfish-browser,代码行数:6,代码来源:dbworker.cpp

示例2: qDebug

void editRoom::on_addButton_clicked()
{

    QString roomno=ui->roomName->text();

    QString nameStr= ui->catList->currentText();

    QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );

    db.setDatabaseName( "./innovativedb.sqlite" );

    if( !db.open() )
    {
        qDebug() << db.lastError();
        qFatal( "MAYDAY!!!\n\nSOMETHING IS WRONG WITH YOUR DATABASE." );
    }
    qDebug( "Database Connection Validated..." );
    QSqlQuery qry;

    qry.prepare("CREATE TABLE IF NOT EXISTS roomcat (id INTEGET PRIMARY KEY, item VARCHAR(30), price INTEGER)");
    if(!qry.exec())
        qDebug() << qry.lastError();
    else
        qDebug( "Table Created!" );


    qry.prepare("SELECT id FROM roomcat WHERE item = :name");
    qry.bindValue(":name",nameStr);
    if(!qry.exec())
    {
        qDebug() << qry.lastError();
    }
    else
        qDebug( "Table Selected!" );

    int catid=0;
    while (qry.next()) {
        catid = qry.value(0).toInt();
    }
    if(catid==0)
    {
        qFatal("MAYDAY!!! DATABASE ERROR!!!");
    }

    qry.prepare("CREATE TABLE IF NOT EXISTS roomlist (id INTEGET PRIMARY KEY, roomno VARCHAR(5), cat INTEGER, occupied INTEGER)");
    if(!qry.exec())
        qDebug() << qry.lastError();
    else
        qDebug( "Room Table Validated..." );

    if(!qry.exec("SELECT id FROM roomlist"))
    {
        qDebug() << qry.lastError();
    }
    else
        qDebug( "Table Selected!" );

    int roomid=0;
    while (qry.next()) {

        int item = qry.value(0).toInt();
        if(item>roomid)
        {
            roomid=item;
        }
    }
    roomid++;

    qry.prepare("INSERT INTO roomlist (id, roomno, cat, occupied) values (:id, :roomno, :roomcat, :occ)");
    qry.bindValue(":id",roomid);
    qry.bindValue(":roomno",roomno);
    qry.bindValue(":roomcat",catid);
    qry.bindValue(":occ",0);
    if(!qry.exec())
        qDebug() << qry.lastError();
    else
    {
        qDebug( "Inserted to Room Table." );
        ui->roomList->addItem(ui->roomName->text());
        ui->roomName->clear();
    }

}
开发者ID:abdeljalilanane,项目名称:Innovative-Hotel-Manager,代码行数:83,代码来源:editroom.cpp

示例3: main

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE","file.db");
    db.setDatabaseName(QDir::homePath()+"/.rationality/file.db");

    if(!db.open())
           qWarning()<<"Errore di connessione";
    QSqlQuery myQuery = QSqlQuery(db);

  /*  if (myQuery.exec("CREATE TABLE tag (key INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT NOT NULL);")) qWarning()<<"Tabella creata";
//    else qWarning()<<"Errore o tabella esistente";
    if (myQuery.exec("CREATE TABLE parent (child INTEGER NOT NULL, parent INTEGER NOT NULL);")) qWarning()<<"Tabella creata";
//    else qWarning()<<"Errore o tabella esistente";
    if (myQuery.exec("CREATE TABLE filetag(file INTEGER NOT NULL, tag INTEGER NOT NULL);")) qWarning()<<"Tabella creata";
//    else qWarning()<<"Errore o tabella esistente";
    if (myQuery.exec("CREATE TABLE file (key INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT NOT NULL,  path TEXT NOT NULL);")) qWarning()<<"Tabella creata";
  //  else qWarning()<<"Errore o tabella esistente";
  //   myQuery.exec("INSERT INTO tag VALUES (-1,'Root');");*/
    if (myQuery.exec("CREATE TABLE tag (key INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,parent INTEGER NOT NULL, name TEXT NOT NULL, hidden INTEGER NOT NULL);")) qWarning()<<"Tabella creata";
    if (myQuery.exec("CREATE TABLE filetag(file INTEGER NOT NULL, tag INTEGER NOT NULL);")) qWarning()<<"Tabella creata";
    if (myQuery.exec("CREATE TABLE file (key INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name TEXT NOT NULL,  path TEXT NOT NULL, rating INTEGER, CONSTRAINT rating_min_5 CHECK rating < 5 );")) qWarning()<<"Tabella creata";


   if (myQuery.exec("SELECT tag.name FROM tag;")) {
        QString t;
        while (myQuery.next()){
            t=myQuery.value(0).toString();
            qWarning()<<t;
        }
    }
    if (myQuery.exec("SELECT file.name FROM file;")) {
        QString t;
        while (myQuery.next()){
            t=myQuery.value(0).toString();
            qWarning()<<t;
        }
     }





     QString cmd="";
     char c[200];
     while (1) {
         cout << "cmd: ";
         cin.getline(c,200);
         cmd = QString::fromStdString(c);
         if (QString::compare(cmd,"exit")==0) break;
         if (myQuery.exec(cmd)) cout << "\n";
         else cout << "Comando non eseguito\n";

     }
    db.close();

    return 0;
}
开发者ID:Mandarancio,项目名称:Rationality,代码行数:58,代码来源:main.cpp

示例4: QDateTime

void DetailMeeting::updateMeeting()
{
    int duration_minute = (meeting_duration->time().hour()*60) + meeting_duration->time().minute();

    QDateTime *date_begin_real = new QDateTime(QDate(meeting_dt_begin->date().year(),meeting_dt_begin->date().month(),meeting_dt_begin->date().day()),meeting_dt_begin->time());

    QString dt_begin;
    dt_begin = QString::number(meeting_dt_begin->date().year()) + "/" + QString::number(meeting_dt_begin->date().month()) + "/" + QString::number(meeting_dt_begin->date().day()) + " " + QString::number(meeting_dt_begin->time().hour()) + ":" + QString::number(meeting_dt_begin->time().minute());

    QString dt_end;
    dt_end = QString::number(meeting_dt_end->date().year()) + "/" + QString::number(meeting_dt_end->date().month()) + "/" + QString::number(meeting_dt_end->date().day()) + " " + QString::number(meeting_dt_end->time().hour()) + ":" + QString::number(meeting_dt_end->time().minute());

    QSqlQuery query;
    query.prepare("SELECT * FROM Meeting where room = :room");
    query.bindValue(":room", id_room);
    query.exec();
    QSqlRecord rec = query.record();

    while(query.next())
    {
        QStringList date_begin = query.value(rec.indexOf("date_begin")).toString().split(" ").at(0).split("/");
        QStringList time_begin = query.value(rec.indexOf("date_begin")).toString().split(" ").at(1).split(":");

        QDate date_begin_edit(date_begin.at(0).toInt(),date_begin.at(1).toInt(),date_begin.at(2).toInt());
        QTime time_begin_edit(time_begin.at(0).toInt(),time_begin.at(1).toInt(),0);

        QStringList date_end_bis = query.value(rec.indexOf("date_end")).toString().split(" ").at(0).split("/");
        QStringList time_end = query.value(rec.indexOf("date_end")).toString().split(" ").at(1).split(":");

        QDate date_end_edit(date_end_bis.at(0).toInt(),date_end_bis.at(1).toInt(),date_end_bis.at(2).toInt());
        QTime time_end_edit(time_end.at(0).toInt(),time_end.at(1).toInt(),0);

        QDateTime datetime_begin(date_begin_edit,time_begin_edit);
        QDateTime datetime_end(date_end_edit,time_end_edit);

        if(date_begin_real->operator >(datetime_begin) && date_begin_real->operator <(datetime_end))
        {
            QMessageBox::critical(this, "Salle indisponible", "La salle selectionné est indisponible.");
            return;
        }
    }

    query.prepare("SELECT * FROM Meeting where id_meeting = :id_meeting");
    query.bindValue(":id_meeting", meeting_id);
    query.exec();
    rec = query.record();
    query.next();

    sendEmailUpdateMeeting(meeting_id,dt_begin);

    query.prepare("Update Meeting set date_begin = :date_begin , date_end =:date_end , duration = :duration WHERE id = :id_meeting");
    query.bindValue(":date_begin", dt_begin);
    query.bindValue(":date_end", dt_end);
    query.bindValue(":duration", duration_minute);
    query.bindValue(":id_meeting", meeting_id);
    query.exec();

    this->close();
    emit notifyRefreshList();
}
开发者ID:Vladk-el,项目名称:ThunderLook,代码行数:60,代码来源:detailmeeting.cpp

示例5: QDialog

DetailMeeting::DetailMeeting(int _meeting_id, QWidget *parent) : QDialog(parent)
{
    global_settings = new QSettings("../Thunderlook/data/settings/settings.ini", QSettings::IniFormat);

    db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName(global_settings->value("SQL/addr_ip").toString());
    db.setPort(QString(global_settings->value("SQL/port").toString()).toInt());
    db.setDatabaseName("thunderlook");
    db.setUserName("esgi");
    db.setPassword("esgi");

    if (!db.open())
    {
        qDebug() << "Impossible de se connecter à la base de données." << endl;
        return;
    }

    meeting_id = _meeting_id;

    setWindowTitle("Détails de la réunion");

    QSqlQuery *req = new QSqlQuery();
    req->prepare("SELECT * FROM Meeting m WHERE id = :meeting_id");
    req->bindValue(":meeting_id", meeting_id);
    req->exec();
    QSqlRecord rec = req->record();
    req->next();

    lb_label = new QLabel(req->value(rec.indexOf("title")).toString());

    // DATE BEGIN
    QStringList date_begin = req->value(rec.indexOf("date_begin")).toString().split(" ").at(0).split("/");
    QStringList time_begin = req->value(rec.indexOf("date_begin")).toString().split(" ").at(1).split(":");

    QDate date_begin_edit(date_begin.at(0).toInt(),date_begin.at(1).toInt(),date_begin.at(2).toInt());
    QTime time_begin_edit(time_begin.at(0).toInt(),time_begin.at(1).toInt(),0);

    QDateTime date_time_begin(date_begin_edit,time_begin_edit);

    meeting_dt_begin = new QDateTimeEdit(date_time_begin);
    meeting_dt_begin->setDisplayFormat("dd/MM/yyyy hh:mm");
    meeting_dt_begin->setMinimumTime(QTime(8,0,0,0));
    meeting_dt_begin->setMaximumTime(QTime(19,45,0,0));

    // DATE END
    QStringList date_end = req->value(rec.indexOf("date_end")).toString().split(" ").at(0).split("/");
    QStringList time_end = req->value(rec.indexOf("date_end")).toString().split(" ").at(1).split(":");

    QDate date_end_edit(date_end.at(0).toInt(),date_end.at(1).toInt(),date_end.at(2).toInt());
    QTime time_end_edit(time_end.at(0).toInt(),time_end.at(1).toInt(),0);

    QDateTime date_time_end(date_end_edit,time_end_edit);

    meeting_dt_end = new QDateTimeEdit(date_time_end);
    meeting_dt_end->setDisplayFormat("dd/MM/yyyy hh:mm");
    meeting_dt_end->setMinimumTime(QTime(8,0,0,0));
    meeting_dt_end->setMaximumTime(QTime(19,45,0,0));

    meeting_duration = new QTimeEdit();
    meeting_duration->setDisplayFormat("hh:mm");

    QTime time(0,0,0);
    meeting_duration->setTime(time.addSecs(req->value(rec.indexOf("duration")).toInt()*60));

    btn_action = new QPushButton("Mettre à jour");
    btn_cancel = new QPushButton("Annuler");
    btn_del = new QPushButton("Supprimer cette réunion");

    global_settings = new QSettings("../Thunderlook/data/settings/settings.ini", QSettings::IniFormat);

    QSqlQuery *reqOrganizer = new QSqlQuery();
    reqOrganizer->prepare("SELECT Users.address FROM Meeting,Users WHERE Meeting.id = :meeting_id AND Users.id = Meeting.organizer");
    reqOrganizer->bindValue(":meeting_id", meeting_id);
    reqOrganizer->exec();
    QSqlRecord recOrganizer = reqOrganizer->record();
    reqOrganizer->next();

    // Enable Item if user is not organizer
    if(reqOrganizer->value(recOrganizer.indexOf("address")).toString() != global_settings->value("Send/smtp_user").toString())
    {
        btn_del->setEnabled(false);
        btn_action->setEnabled(false);
        meeting_dt_end->setEnabled(false);
        meeting_dt_begin->setEnabled(false);
        meeting_duration->setEnabled(false);
    }

    cb_organizer = new QComboBox();
    cb_organizer->setEnabled(false);

    QSqlQuery *reqUser = new QSqlQuery();

    reqUser->prepare("SELECT * FROM Users WHERE id = :id_user");
    reqUser->bindValue(":id_user", req->value(rec.indexOf("organizer")).toString());
    QString organiz(req->value(rec.indexOf("organizer")).toString());
    reqUser->exec();
    QSqlRecord recUser = reqUser->record();
    while(reqUser->next())
    {
        cb_organizer->addItem(reqUser->value(recUser.indexOf("address")).toString());
//.........这里部分代码省略.........
开发者ID:Vladk-el,项目名称:ThunderLook,代码行数:101,代码来源:detailmeeting.cpp

示例6: packErrorInfo

bool TestAssistance::updateQuestionInfo(const QUESTIONINFO &info, bool updateImage)
{
    //open database
    if (!m_objDatabase.open()) {
        packErrorInfo(m_objDatabase.lastError().text(),
                      TA_ERROR_NOTCONNECTED);
        return false;
    }

    //check if updateImage
    QString imgValue("");
    if(updateImage)
        imgValue = ",qimage=:qimage ";

    QSqlQuery query;
    query.prepare(QString("UPDATE questions SET qtxt=:qtxt,qgrade=:qgrade,") +
                  "qmajor=:qmajor,qcourse=:qcourse," +
                  "qcnt=:qcnt,qhard=:qhard," +
                  "qdate=:qdate,qright=:qright," +
                  "qtype=:qtype,qknowpoint=:qknowpoint " +
                  imgValue +
                  "WHERE qno=:qno");
    query.bindValue(":qno", info.qno);
    query.bindValue(":qtxt", info.qtxt);
    query.bindValue(":qgrade", info.qgrade);
    query.bindValue(":qmajor", info.qmajor);
    query.bindValue(":qcourse", info.qcourse);
    query.bindValue(":qcnt", info.qcnt);
    query.bindValue(":qhard", info.qhard);
    query.bindValue(":qdate", info.qdate);
    query.bindValue(":qright", info.qright);
    query.bindValue(":qtype", info.qtype);
    query.bindValue(":qknowpoint", info.qknowpoint);
    if(updateImage)
        query.bindValue(":qimage", info.qimage);

    if(!query.exec()){
        packErrorInfo(query.lastError().text(),
                      TA_ERROR_SQLERROR);
        m_objDatabase.close();
        return false;
    }
    m_objDatabase.close();
    return true;
}
开发者ID:KanagiMiss,项目名称:testassist,代码行数:45,代码来源:testassistance.cpp

示例7: fixup

bool DataBase::fixup() {
    QSqlQuery query;
    if (!query.exec("SELECT arch FROM prefix")) {
        if (!query.exec("ALTER TABLE prefix ADD COLUMN arch TEXT")) {
            qDebug()<<"[EE] Cannot alter prefix table";
            return false;
        }
    }
    if (!query.exec("SELECT mountpoint_windrive FROM prefix")) {
        if (!query.exec("ALTER TABLE prefix ADD COLUMN mountpoint_windrive TEXT")) {
            qDebug()<<"[EE] Cannot alter prefix table";
            return false;
        }
    }
    if (!query.exec("SELECT lang FROM icon")) {
        if (!query.exec("ALTER TABLE icon ADD COLUMN lang TEXT")) {
            qDebug()<<"[EE] Cannot alter icon table";
            return false;
        }
    }
    if (!query.exec("SELECT lang FROM last_run_icon")) {
        if (!query.exec("ALTER TABLE last_run_icon ADD COLUMN lang TEXT")) {
            qDebug()<<"[EE] Cannot alter last_run_icon table";
            return false;
        }
    }
    if (!query.exec("SELECT prerun FROM icon")) {
        if (!query.exec("ALTER TABLE icon ADD COLUMN prerun TEXT")) {
            qDebug()<<"[EE] Cannot alter icon table";
            return false;
        }
    }
    if (!query.exec("SELECT postrun FROM icon")) {
        if (!query.exec("ALTER TABLE icon ADD COLUMN postrun TEXT")) {
            qDebug()<<"[EE] Cannot alter icon table";
            return false;
        }
    }
    if (!query.exec("SELECT run_string FROM prefix")) {
        if (!query.exec("ALTER TABLE prefix ADD COLUMN run_string TEXT")) {
            qDebug()<<"[EE] Cannot alter prefix table";
            return false;
        }
    }
    if (!query.exec("SELECT version_id FROM prefix")) {
        if (!query.exec("ALTER TABLE prefix ADD COLUMN version_id INTEGER")) {
            qDebug()<<"[EE] Cannot alter prefix table";
            return false;
        }
        if (!query.exec("UPDATE prefix SET version_id=1")) {
            qDebug()<<"[EE] Cannot update prefix table";
            return false;
        }
    }
    return true;
}
开发者ID:torto9,项目名称:q4wine,代码行数:56,代码来源:db.cpp

示例8: while

/**
  Load a manPage from /usr/share/man. Also load usage, examples and options
*/
  void Man::loadPage() {
    tblOptions->clear();
    tblOptions->setRowCount(0);
    QSqlQuery query;
    query.exec("SELECT PATH FROM TMAN_PAGE WHERE TITLE = '"+ cbbManPagelist->itemText(cbbManPagelist->currentIndex())+"'");
    
    while (query.next())  {
      system("mkdir /tmp/man");
      std::string cmdCopy = "cp " + query.value(0).toString().toStdString() + " /tmp/man/";
      std::string name;
      std::string command;
      system(cmdCopy.c_str());

      if (query.value(0).toString().toStdString().find(".bz2") != -1) {
          name = query.value(0).toString().toStdString().substr( query.value(0).toString().toStdString().find_last_of("/") +1, (query.value(0).toString().toStdString().size() - query.value(0).toString().toStdString().find_last_of("/") -1));
          command =  "bunzip2 -d /tmp/man/" + name;
          name = name.substr(0, name.find(".bz2"));
      }
      else {
	name = query.value(0).toString().toStdString().substr( query.value(0).toString().toStdString().find_last_of("/") +1, (query.value(0).toString().toStdString().size() - query.value(0).toString().toStdString().find_last_of("/") -1));
	//unGz(name);
	command =  "gunzip /tmp/man/" + name;
	name = name.substr(0, name.find(".gz"));
      }
      system(command.c_str());
      rtfManPage->setHtml(ManParser::parseManPage(name).c_str());
    }

    QSqlQuery query2;
    query2.exec("SELECT OPT_NAME,OPT_DES FROM TOPTION WHERE COMMAND = '"+ cbbManPagelist->itemText(cbbManPagelist->currentIndex())+"'");
    int row = 1;
    tblOptions->setColumnCount(2);
    while (query2.next()) {
      tblOptions->setRowCount(row);
      QWidget* aWidget = new QWidget(tblOptions); //Dirty hack to fix a QT bug
      QLabel* aTableWidget = new QLabel(aWidget);
      aTableWidget->setText(query2.value(0).toString());
      tblOptions->setCellWidget((row-1), 0, aWidget);
      aWidget->setToolTip(query2.value(0).toString());
      
      QWidget* aWidget2 = new QWidget(tblOptions); //Dirty hack to fix a QT bug
      QLabel* aTableWidget2 = new QLabel(aWidget2);
      aTableWidget2->setText(query2.value(1).toString());
      tblOptions->setCellWidget((row-1), 1, aWidget2);
      aWidget2->setToolTip(query2.value(1).toString());
      tblOptions->setRowHeight(row-1, 25);
      row++;
    }

    QSqlQuery query3;
    query3.exec("SELECT USAGE,USAGE_DES FROM TUSAGE WHERE COMMAND = '"+ cbbManPagelist->itemText(cbbManPagelist->currentIndex())+"'");
    int row2 = 1;
    tblUsage->setColumnCount(2);
    while (query3.next()) {
      tblUsage->setRowCount(row2);

      QWidget* aWidget = new QWidget(tblUsage);
      QLabel* aTableWidget = new QLabel(aWidget);
      aTableWidget->setObjectName(QString::fromUtf8("aTableLabel"));
      aTableWidget->setText(query3.value(0).toString().toStdString().c_str());
      tblUsage->setCellWidget((row2-1), 0, aWidget);
      aWidget->setToolTip(query3.value(0).toString());
      
      QWidget* aWidget2 = new QWidget(tblUsage);
      QLabel* aTableWidget2 = new QLabel(aWidget2);
      aTableWidget2->setText(query3.value(1).toString());
      tblUsage->setCellWidget((row2-1), 1, aWidget2);
      aWidget2->setToolTip(query3.value(1).toString());
      tblUsage->setRowHeight(row2-2, 25);
      row2++;
    }
  }
开发者ID:Elv13,项目名称:KliNG,代码行数:75,代码来源:man.cpp

示例9: QDockWidget


//.........这里部分代码省略.........
    verticalLayout = new QVBoxLayout(dockManualContents);
    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
    verticalLayout->setContentsMargins(0, 0, 0, 0);
    hlFindManPage = new QHBoxLayout();
    hlFindManPage->setObjectName(QString::fromUtf8("hlFindManPage"));
    cbbManPagelist = new KComboBox(dockManualContents);
    cbbManPagelist->setObjectName(QString::fromUtf8("cbbManPagelist"));
    cbbManPagelist->setEditable(true);
    cbbManPagelist->setMaxVisibleItems(50);
    cbbManPagelist->setInsertPolicy(QComboBox::NoInsert);
    cbbManPagelist->setAutoCompletion(false);
    cbbManPagelist->setTrapReturnKey(false);
    hlFindManPage->addWidget(cbbManPagelist);

    btnFindManPage = new KPushButton(dockManualContents);
    btnFindManPage->setObjectName(QString::fromUtf8("btnFindManPage"));
    btnFindManPage->setMaximumSize(QSize(60, 16777215));
    btnFindManPage->setSizeIncrement(QSize(0, 0));
    hlFindManPage->addWidget(btnFindManPage);
    verticalLayout->addLayout(hlFindManPage);

    tbManInfo = new QToolBox(dockManualContents);
    tbManInfo->setObjectName(QString::fromUtf8("tbManInfo"));
    QSizePolicy sizePolicy6(QSizePolicy::Expanding, QSizePolicy::Expanding);
    sizePolicy6.setHorizontalStretch(0);
    sizePolicy6.setVerticalStretch(0);
    sizePolicy6.setHeightForWidth(tbManInfo->sizePolicy().hasHeightForWidth());
    tbManInfo->setSizePolicy(sizePolicy6);
    tbManInfo->setBaseSize(QSize(240, 91));
    tbManInfo->setStyleSheet(QString::fromUtf8(""));
    tbManInfo->setLineWidth(1);
    pageManual = new QWidget();
    pageManual->setObjectName(QString::fromUtf8("pageManual"));
    pageManual->setGeometry(QRect(0, 0, 179, 469));
    verticalLayout_2 = new QVBoxLayout(pageManual);
    verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
    rtfManPage = new QTextBrowser(pageManual);
    rtfManPage->setObjectName(QString::fromUtf8("rtfManPage"));
    verticalLayout_2->addWidget(rtfManPage);

    tbManInfo->addItem(pageManual, "Manuel");
    PageUsage = new QWidget();
    PageUsage->setObjectName(QString::fromUtf8("PageUsage"));
    PageUsage->setGeometry(QRect(0, 0, 179, 469));
    verticalLayout_4 = new QVBoxLayout(PageUsage);
    verticalLayout_4->setObjectName(QString::fromUtf8("verticalLayout_4"));
    tblUsage = new QTableWidget(PageUsage);
    if (tblUsage->columnCount() < 2)
        tblUsage->setColumnCount(2);
    QTableWidgetItem *__colItem = new QTableWidgetItem();
    tblUsage->setHorizontalHeaderItem(0, __colItem);
    QTableWidgetItem *__colItem1 = new QTableWidgetItem();
    tblUsage->setHorizontalHeaderItem(1, __colItem1);
    tblUsage->setObjectName(QString::fromUtf8("tblUsage"));
    tblUsage->setMidLineWidth(0);
    tblUsage->setEditTriggers(QAbstractItemView::NoEditTriggers);
    tblUsage->setSelectionMode(QAbstractItemView::NoSelection);
    tblUsage->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
    tblUsage->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
    verticalLayout_4->addWidget(tblUsage);

    tbManInfo->addItem(PageUsage, "Usage");
    pageOptions = new QWidget();
    pageOptions->setObjectName(QString::fromUtf8("pageOptions"));
    pageOptions->setGeometry(QRect(0, 0, 179, 469));
    verticalLayout_3 = new QVBoxLayout(pageOptions);
    verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
    tblOptions = new QTableWidget(pageOptions);
    if (tblOptions->columnCount() < 2)
        tblOptions->setColumnCount(2);
    QTableWidgetItem *__colItem2 = new QTableWidgetItem();
    tblOptions->setHorizontalHeaderItem(0, __colItem2);
    QTableWidgetItem *__colItem3 = new QTableWidgetItem();
    tblOptions->setHorizontalHeaderItem(1, __colItem3);
    tblOptions->setObjectName(QString::fromUtf8("tblOptions"));
    tblOptions->setEnabled(true);
    tblOptions->setDragEnabled(true);
    tblOptions->setDragDropMode(QAbstractItemView::DragOnly);
    tblOptions->setSelectionMode(QAbstractItemView::NoSelection);
    verticalLayout_3->addWidget(tblOptions);
    tbManInfo->addItem(pageOptions, "Options");

    verticalLayout->addWidget(tbManInfo);
    tblUsage->verticalHeader()->hide();
    tblOptions->verticalHeader()->hide();
    
    setWidget(dockManualContents);
    tbManInfo->setCurrentIndex(0);
    translateUi();

    QSqlQuery query;
    query.exec("SELECT TITLE FROM TMAN_PAGE");
    
     while (query.next()) 
       cbbManPagelist->addItem(query.value(0).toString());
         
    cbbManPagelist->model()->sort(0);
    cbbManPagelist->setCurrentIndex(0);
    QObject::connect(cbbManPagelist, SIGNAL(currentIndexChanged(int)), this, SLOT(loadPage()));
  }
开发者ID:Elv13,项目名称:KliNG,代码行数:101,代码来源:man.cpp

示例10: QgsDebugMsg

bool QgsDb2Provider::changeAttributeValues( const QgsChangedAttributesMap &attr_map )
{
  QgsDebugMsg( "Entering" );
  if ( attr_map.isEmpty() )
    return true;

  if ( mFidColName.isEmpty() )
    return false;

  for ( QgsChangedAttributesMap::const_iterator it = attr_map.begin(); it != attr_map.end(); ++it )
  {
    QgsFeatureId fid = it.key();

    // skip added features
    if ( FID_IS_NEW( fid ) )
      continue;

    const QgsAttributeMap& attrs = it.value();
    if ( attrs.isEmpty() )
      continue;

    QString statement = QString( "UPDATE %1.%2 SET " ).arg( mSchemaName, mTableName );

    bool first = true;
    if ( !mDatabase.isOpen() )
    {
      QString errMsg;
      mDatabase = getDatabase( mConnInfo, errMsg );
      if ( !errMsg.isEmpty() )
      {
        return false;
      }
    }
    QSqlQuery query = QSqlQuery( mDatabase );
    query.setForwardOnly( true );

    for ( QgsAttributeMap::const_iterator it2 = attrs.begin(); it2 != attrs.end(); ++it2 )
    {
      QgsField fld = mAttributeFields.at( it2.key() );

      if ( fld.typeName().endsWith( " identity", Qt::CaseInsensitive ) )
        continue; // skip identity field

      if ( fld.name().isEmpty() )
        continue; // invalid

      if ( !first )
        statement += ',';
      else
        first = false;

      statement += QString( "%1=?" ).arg( fld.name() );
    }

    if ( first )
      return true; // no fields have been changed

    // set attribute filter
    statement += QString( " WHERE %1=%2" ).arg( mFidColName, FID_TO_STRING( fid ) );

    // use prepared statement to prevent from sql injection
    if ( !query.prepare( statement ) )
    {
      QgsDebugMsg( query.lastError().text() );
      return false;
    }
    QgsDebugMsg( statement );
    for ( QgsAttributeMap::const_iterator it2 = attrs.begin(); it2 != attrs.end(); ++it2 )
    {
      QgsField fld = mAttributeFields.at( it2.key() );

      if ( fld.name().isEmpty() )
        continue; // invalid

      QVariant::Type type = fld.type();
      if ( it2->isNull() || !it2->isValid() )
      {
        // binding null values
        if ( type == QVariant::Date || type == QVariant::DateTime )
          query.addBindValue( QVariant( QVariant::String ) );
        else
          query.addBindValue( QVariant( type ) );
      }
      else if ( type == QVariant::Int )
      {
        // binding an INTEGER value
        query.addBindValue( it2->toInt() );
      }
      else if ( type == QVariant::Double )
      {
        // binding a DOUBLE value
        query.addBindValue( it2->toDouble() );
      }
      else if ( type == QVariant::String )
      {
        // binding a TEXT value
        query.addBindValue( it2->toString() );
      }
      else if ( type == QVariant::DateTime )
      {
//.........这里部分代码省略.........
开发者ID:mterente,项目名称:QGIS,代码行数:101,代码来源:qgsdb2provider.cpp

示例11: QSqlQuery

// update the extent for this layer
void QgsDb2Provider::updateStatistics() const
{
  // get features to calculate the statistics
  QString statement;

  QSqlQuery query = QSqlQuery( mDatabase );
  query.setForwardOnly( true );

  statement = QString( "SELECT MIN(DB2GSE.ST_MINX(%1)), MIN(DB2GSE.ST_MINY(%1)), MAX(DB2GSE.ST_MAXX(%1)), MAX(DB2GSE.ST_MAXY(%1))" ).arg( mGeometryColName );

  statement += QString( " FROM %1.%2" ).arg( mSchemaName, mTableName );

  if ( !mSqlWhereClause.isEmpty() )
  {
    statement += " WHERE (" + mSqlWhereClause + ")";
  }
  QgsDebugMsg( statement );

  if ( !query.exec( statement ) )
  {
    QgsDebugMsg( query.lastError().text() );
  }

  if ( !query.isActive() )
  {
    return;
  }

  if ( query.next() )
  {
    mExtent.setXMinimum( query.value( 0 ).toDouble() );
    mExtent.setYMinimum( query.value( 1 ).toDouble() );
    mExtent.setXMaximum( query.value( 2 ).toDouble() );
    mExtent.setYMaximum( query.value( 3 ).toDouble() );
    QgsDebugMsg( QString( "after setting; mExtent: %1" ).arg( mExtent.toString() ) );
  }

  QgsDebugMsg( QString( "mSRId: %1" ).arg( mSRId ) );
  QgsDb2GeometryColumns gc( mDatabase );
  int rc = gc.open( mSchemaName, mTableName );  // returns SQLCODE if failure
  if ( rc == 0 )
  {
    mEnvironment = gc.db2Environment();
    if ( -1 == mSRId )
    {
      QgsDb2LayerProperty layer;
      gc.populateLayerProperty( layer );
      if ( !layer.srid.isEmpty() )
      {
        mSRId = layer.srid.toInt();
        mSrsName = layer.srsName;
      }
      mGeometryColType = layer.type;
      QgsDebugMsg( QString( "srs_id: %1; srs_name: %2; mGeometryColType: %3" )
                   .arg( mSRId ).arg( mSrsName, mGeometryColType ) );
      return;
    }
  }
  else
  {
    QgsDebugMsg( "Couldn't get srid from geometry columns" );
  }

  // Try to get the srid from the data if srid isn't already set
  QgsDebugMsg( QString( "mSRId: %1" ).arg( mSRId ) );
  if ( -1 == mSRId )
  {
    query.clear();
    statement = QString( "SELECT DB2GSE.ST_SRID(%1) FROM %2.%3 FETCH FIRST ROW ONLY" )
                .arg( mGeometryColName, mSchemaName, mTableName );

    QgsDebugMsg( statement );

    if ( !query.exec( statement ) || !query.isActive() )
    {
      QgsDebugMsg( query.lastError().text() );
    }

    if ( query.next() )
    {
      mSRId = query.value( 0 ).toInt();
      QgsDebugMsg( QString( "srid from data: %1" ).arg( mSRId ) );
      return;
    }
    else
    {
      QgsDebugMsg( "Couldn't get srid from data" );
    }
  }
}
开发者ID:mterente,项目名称:QGIS,代码行数:91,代码来源:qgsdb2provider.cpp

示例12: Q_UNUSED

QgsVectorLayerImport::ImportError QgsDb2Provider::createEmptyLayer( const QString& uri,
    const QgsFields &fields,
    QgsWkbTypes::Type wkbType,
    const QgsCoordinateReferenceSystem& srs,
    bool overwrite,
    QMap<int, int> *oldToNewAttrIdxMap,
    QString *errorMessage,
    const QMap<QString, QVariant> *options )
{
  Q_UNUSED( options );

  // populate members from the uri structure
  QgsDataSourceUri dsUri( uri );

  QString connInfo = dsUri.connectionInfo();
  QString errMsg;
  QString srsName;
  QgsDebugMsg( "uri: " + uri );

  // connect to database
  QSqlDatabase db = QgsDb2Provider::getDatabase( connInfo, errMsg );

  if ( !errMsg.isEmpty() )
  {
    if ( errorMessage )
      *errorMessage = errMsg;
    return QgsVectorLayerImport::ErrConnectionFailed;
  }

  // Get the SRS name using srid, needed to register the spatial column
  // srs->posgisSrid() seems to return the authority id which is
  // most often the EPSG id.  Hopefully DB2 has defined an SRS using this
  // value as the srid / srs_id.  If not, we are out of luck.
  QgsDebugMsg( "srs: " + srs.toWkt() );
  long srid = srs.postgisSrid();
  QgsDebugMsg( QString( "srid: %1" ).arg( srid ) );
  if ( srid >= 0 )
  {
    QSqlQuery query( db );
    QString statement = QString( "SELECT srs_name FROM db2gse.st_spatial_reference_systems where srs_id=%1" )
                        .arg( srid );
    QgsDebugMsg( statement );

    if ( !query.exec( statement ) || !query.isActive() )
    {
      QgsDebugMsg( query.lastError().text() );
    }

    if ( query.next() )
    {
      srsName = query.value( 0 ).toString();
      QgsDebugMsg( QString( "srs_name: %1" ).arg( srsName ) );
    }
    else
    {
      QgsDebugMsg( "Couldn't get srs_name from db2gse.st_spatial_reference_systems" );
    }
  }

  QString schemaName = dsUri.schema().toUpper();
  QString tableName = dsUri.table().toUpper();
  QString fullName;

  if ( schemaName.isEmpty() )
  {
    schemaName = dsUri.username().toUpper();  // set schema to user name
  }
  fullName = schemaName + "." + tableName;

  QString geometryColumn = dsUri.geometryColumn().toUpper();
  QString primaryKey = dsUri.keyColumn().toUpper();
  QString primaryKeyType;

  // TODO - this is a bad hack to cope with shapefiles.
  // The wkbType from the shapefile header is usually a multi-type
  // even if all the data is a single-type. If we create the column as
  // a multi-type, the insert will fail if the actual data is a single-type
  // due to type mismatch.
  // We could potentially defer adding the spatial column until addFeatures is
  // called the first time, but QgsVectorLayerImport doesn't pass the CRS/srid
  // information to the DB2 provider and we need this information to register
  // the spatial column.
  // This hack is problematic because the drag/drop will fail if the
  // actual data is a multi-type which is possible with a shapefile or
  // other data source.
  QgsWkbTypes::Type wkbTypeSingle;
  wkbTypeSingle = QgsWkbTypes::singleType( wkbType );
  if ( wkbType != QgsWkbTypes::NoGeometry && geometryColumn.isEmpty() )
    geometryColumn = "GEOM";

  if ( primaryKey.isEmpty() )
    primaryKey = "QGS_FID";

  // get the pk's name and type
  // if no pk name was passed, define the new pk field name
  int fieldCount = fields.size();
  if ( primaryKey.isEmpty() )
  {
    int index = 0;
    QString pk = primaryKey = "QGS_FID";
//.........这里部分代码省略.........
开发者ID:mterente,项目名称:QGIS,代码行数:101,代码来源:qgsdb2provider.cpp

示例13: getSingleCattle

Cattle CattleController::getSingleCattle(const int id)
{
   Cattle cow;

   string tagNumber;
   string NLSTag;
   string name;
   string description;
   string imagePath;
   int cowID;
   bool show;

   const QString getSingleCattleTemplate = "select cowID, cowTag, cowNlsTag, entName, entDescription, entImagePath, entShow from Cattle, Entity where entID = %1";

   QSqlQuery query;
   QSqlRecord record;

   const string getSingleCattleQuery = getSingleCattleTemplate.arg(id).toStdString();

   try
   {
      query = databaseController.selectQuery(getSingleCattleQuery);
      record = query.record();
   }
   catch (SQLException & e)
   {
      cerr << "Exception caught at " << __FILE__ << ": " << __LINE__  << endl
            << e.what() << endl;

      throw e;
   }

   query.first();

   name = query.value(record.indexOf("entName")).toString().toStdString();
   tagNumber = query.value(record.indexOf("cowTag")).toString().toStdString();
   NLSTag = query.value(record.indexOf("cowNlsTag")).toString().toStdString();
   description = query.value(record.indexOf("entDescription")).toString().toStdString();
   imagePath = query.value(record.indexOf("entImagePath")).toString().toStdString();
   show = query.value(record.indexOf("entShow")).toBool();

   bool ok;
   cowID = query.value(record.indexOf("cowID")).toInt(&ok);

   cow.setMother(getMother(cow));
   cow.setFather(getFather(cow));

   cow.setTagNumber(tagNumber);
   cow.setNLSTag(NLSTag);
   cow.setName(name);
   cow.setDescription(description);
   cow.setImagePath(imagePath);
   cow.setEntityID(cowID);

   cow.setShow(show);

#warning The controllers have to be implemented here still
	/**

   cow.setHorn(hornController.getHorn(cow));
   cow.setColour(colourController.getColour(cow));
   cow.setGender(genderController.getGender(cow));
   cow.setVariety(varietyController.getVariety(cow));
   cow.setLocation(locationController.getLocation(cow));
   cow.setSource(sourceController.getSource(cow));
   cow.setModule(moduleController.getModule(cow));
   cow.setEvents(eventController.getEvents(cow));
	*/

   query.clear();

   return cow;
}
开发者ID:myFarmDB,项目名称:myFarmDB,代码行数:73,代码来源:cattlecontroller.cpp

示例14: getInfoFromMediaId

void MovieMedia::getInfoFromMediaId(unsigned int id) {
    QSqlQuery q;
    QString whereName = "mediaId";
    QString idString = QString("%1").arg(id);
    DatabaseManager::getInstance()->queryImdbInfoWhere(q, whereName, idString);

    int fieldImdbId         = q.record().indexOf("ImdbId");
    int fieldGenre          = q.record().indexOf("genre");
    int fieldYear           = q.record().indexOf("year");
    int fieldRuntime        = q.record().indexOf("runtime");
    int fieldRating         = q.record().indexOf("rating");
    int fieldTitle          = q.record().indexOf("title");
    int fieldDirector       = q.record().indexOf("director");
    int fieldCountry        = q.record().indexOf("country");
    int fieldImage          = q.record().indexOf("image");
    int fieldCast           = q.record().indexOf("cast");
    int fieldPlot           = q.record().indexOf("plot");

    while (q.next()) {
        this->setImdbId(q.value(fieldImdbId).toInt());
        this->setGenre(q.value(fieldGenre).toString());
        this->setYear(q.value(fieldYear).toInt());
        this->setRuntime(q.value(fieldRuntime).toInt());
        this->setRating(q.value(fieldRating).toDouble());
        this->setTitle(q.value(fieldTitle).toString());
        this->setDirector(q.value(fieldDirector).toString());
        this->setCountry(q.value(fieldCountry).toString());
        this->setImage(q.value(fieldImage).toString());
        this->setCast(q.value(fieldCast).toString());
        this->setPlot(q.value(fieldPlot).toString());
    }
}
开发者ID:slopjong,项目名称:MediaSpy,代码行数:32,代码来源:moviemedia.cpp

示例15: AddStadium

/**
 * @brief Database::AddStadium
 * Adds new Stadium to the data base with the following attributes.
 * @param stadiumName
 * @param teamName
 * @param address
 * @param phoneNumber
 * @param dateOpened
 * @param capacity
 * @param turfType
 * @param revenue
 * @param leauge
 * @param typology
 * @return true if it worked else false
 */
bool Database::AddStadium(QString stadiumName,QString teamName,QString address,
                          QString phoneNumber,QString dateOpened,QString capacity,QString turfType,
                          long revenue,QString leauge,QString typology)
{
    QSqlQuery query;
    query.prepare("INSERT INTO stadiums(name,team,address,phone,date,capacity,turf,revenue,league,typology)"
                  "VALUES (:name,:team,:address,:phone,:date,:capacity,:turf,:revenue,:league,:typology)");

        query.bindValue(":name", stadiumName);
        query.bindValue(":team", teamName);
        query.bindValue(":address", address);
        query.bindValue(":phone", phoneNumber);
        query.bindValue(":date", dateOpened);
        query.bindValue(":capacity", capacity);
        query.bindValue(":turf", turfType);
        query.bindValue(":revenue", QString::number(revenue));
        query.bindValue(":league", leauge);
        query.bindValue(":typology", typology);
        if(query.exec()){
            return true;
        }

            qDebug() << query.lastError().text();
            return false;
}
开发者ID:home-run,项目名称:subtle-cosmic-moose,代码行数:40,代码来源:database.cpp


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