bool dialogHallType::isCanDelete(QString id) { QSqlQuery q; q.exec(QString("select IDTYPE from BLDG where IDTYPE = %1").arg(id)); q.next(); if(!q.isNull(0)) { return false; } return true; }
// Find questions int ddmGetQuestions(QList<CQuestion*> &quesList, int paperId) { QSqlQuery q; QString sql(QObject::tr("SELECT id, title, optionA, optionB, optionC, optionD, answer, type " "From questions WHERE paperId = %1").arg(paperId)); qDebug() << sql; if (!q.exec(sql)) { qDebug() << db.lastError(); return -1; } while (q.next()) { int type = q.value(7).toInt(); CQuestion *ques = CQuesManager::get_ques((QUES_TYPE)type); ques->id = q.value(0).toInt(); ques->title = q.value(1).toString(); ques->type = (QUES_TYPE)type; for (int i = 0; i < 4; ++i) { if (q.isNull(2 + i)) continue; ques->options.append(q.value(2 + i).toString()); } ques->proper_ans = q.isNull(6) ? "" : q.value(6).toString(); quesList.append(ques); } return 0; }
/* * Get the image in sensor table * @id: the primary key of sensor table */ QPixmap MainWindow::getPixmapFromTable(QString id) { QString sql="select jpg from sensor where id="; sql+=id; ui->textEdit->append(sql); QSqlQuery query; query.prepare(sql); if(!query.exec()) ui->textEdit->append(query.lastError().text()); else { while (query.next()) { if (query.isNull(0) == false) { QPixmap photo; photo.loadFromData(query.value(0).toByteArray(), "PNG"); ui->textEdit->append("Get Image: OK!"); return photo; } } } return QPixmap(); }
bool RegisterDialog::alreadyExists() { QSqlQuery query; query.prepare("select name from CUSTOMER where name = :newLogin"); query.bindValue(":newLogin", newLogin); qDebug()<<"QUERY.EXEC: "<<query.exec(); qDebug()<<"Last error: "<<query.lastError(); query.next(); qDebug()<<"value = "<< query.value(0).toString(); if (query.isNull(0)) return false; else return true; }
void Graph::populateFromResult(QSqlQuery & qry) { bool valid = FALSE; bool old_repaint = autoRepaint(); setAutoRepaint(FALSE); QVariant var; double val; int cols = qry.driver()->record(qry).count(); while(qry.next()) { if(!qry.isNull(0)) { setReferenceLabel(qry.at(), qry.value(0).toString()); } for(int c = 1; c < cols; c++) { if(!qry.isNull(c)) { val = qry.value(c).toDouble(&valid); if(valid) { setSetValue(qry.at(), c - 1, val); } } } } setAutoRepaint(old_repaint); if(autoRepaint()) repaint(); }
/** \brief Loads the object with the specified ID from the data store. \param id The ID of the object to load. \throw std::runtime_error If no table name was specified a \c std::runtime_error will be thrown. */ void xtStorable::load(long long id) { if(_data->_tableName.empty()) throw std::runtime_error("cannot load from the database without a table name"); std::string sql = "SELECT * FROM \""; sql += _data->_tableName; sql += "\" WHERE "; sql += _data->_prefix; sql += "id = '"; sql += QString::number(id).toStdString(); sql += "';"; if(xtlib::debug) qDebug() << "executing: " << QString::fromStdString(sql); QSqlQuery query; query.exec(QString::fromStdString(sql)); if(!query.first()) return; _data->_enforceReadOnly = false; std::set<std::string> propList = getPropertyNames(xtlib::FieldRole); for (std::set<std::string>::const_iterator it = propList.begin(); it != propList.end(); it++) { QVariant pFieldData = getProperty(*it, xtlib::FieldRole); xtFieldData fd = pFieldData.value<xtFieldData>(); if(fd.fieldName != "") { QVariant val; // an empty value which we'll leave for null values std::string fieldName = _data->_prefix + fd.fieldName; int fi = query.record().indexOf(QString::fromStdString(fieldName)); if(!query.isNull(fi)) { val = query.value(fi); } setProperty(*it, val); setPropertyP(*it, val, xtlib::PreviousValueRole); } else { qDebug() << "problem reading field"; } } _data->_enforceReadOnly = true; _data->_id = id; }
void login::on_pushButton_Ok_clicked() { const QString entered_login(ui->lineEdit_login->text()); const QString entered_password(ui->lineEdit_password->text()); QString correct_password; bool connection_established = mainW->openDB(); if (!connection_established) { /* QMessageBox::information(0, "Connection problem", "Cannot connect to server.\n" "Check your connection settings (settings.ini - located in program folder)");*/ return; } QSqlQuery query; query.prepare("select password_hash, customer_id from CUSTOMER where name = :login"); query.bindValue(":login", entered_login); qDebug()<<"query exec"<<query.exec(); qDebug()<<query.lastError(); qDebug()<<"query.next - "<<query.next(); if (query.isNull(0)) { ui->label_3->setVisible(true); return; } correct_password = query.value(0).toString(); qDebug()<<"password: "******"customer ID: "<< mainW->getCurrent_customer_ID(); mainW->closeDB(); if (entered_password == correct_password) { this->setVisible(false); mainW->centralWidget()->setVisible(true); mainW->dbget_Book(); mainW->setUsername(ui->lineEdit_login->text()); mainW->update_wallet(); // mainW->update_tableView_Books(); mainW->update_tableView_Bundles(); mainW->update_tableView_Cart(); mainW->update_tableView_History(); } else ui->label_3->setVisible(true); }
/* * Insert a new row into sensor table * @warningFlag: necessary, point out the sensor */ QString MainWindow::insertIntoSensor(int warningFlag) { m_strImage=ui->lineEdit_Jpg->text(); //read image from file QByteArray data; QString path = m_strImage; if(m_strImage.length()==0) return 0; QFile* file=new QFile(path); file->open(QIODevice::ReadOnly); data = file->readAll(); file->close(); //store image data to variant QVariant var(data); QString sql = QString("insert into sensor(warning_flag, jpg) values(")+(warningFlag+'0')+", ?)"; QSqlQuery query; query.prepare(sql); //bind image value, it will automatically replace the '?' in the sql statement query.addBindValue(var); if(!query.exec()) ui->textEdit->append(query.lastError().text()); else ui->textEdit->append("Insert: OK!"); //return the last id from sensor table, give it to the temperature table sql="select max(id) from sensor;"; query.clear(); query.prepare(sql); if(!query.exec()) ui->textEdit->append(query.lastError().text()); else { while(query.next()) { if(query.isNull(0)==false) return query.value(0).toString(); } } return ""; }