Example #1
0
bool DateModel::getLocationID(int& ID)
{
    QSqlQuery query;
    query.prepare(
    tr("SELECT     TOP (1) id_location")+
    tr(" FROM         dbo.GL_Session")+
    tr(" ORDER BY ID DESC")
    );

    if (!query.exec()) return false;
    if (query.numRowsAffected()!=1) return false;//It must *always* find an id

    query.first();
    ID=query.value(0).toInt();
    return true;
}
Example #2
0
int DataBase::countReadableUsers(QString userID)
{
  int result;
  connect();
  QString queryString = "SELECT count() FROM readableUsers WHERE userID="+userID;
  QSqlQuery countReadableUsersQuery;
  countReadableUsersQuery.prepare(queryString);
  countReadableUsersQuery.exec();
  countReadableUsersQuery.first();
  if (countReadableUsersQuery.value(0).toString() =="")
      result = 0;
  else
      result = countReadableUsersQuery.value(0).toInt();
  disconnect();
  return result;
}
void MainWindow::on_pushButtonMedecinAjouter_clicked()
{
    //renvoi le medNum maximum pour pouvoir faire un +1
    QSqlQuery req;
    req.exec("select max(docNum)+1 from medecin;");
    req.first();
    this->base.exec("insert into medecin values ("+req.value(0).toString()+
                    ",'"+ui->lineEditMedecinNom->text().trimmed()+
                    "','"+ui->lineEditMedecinNumSS->text().trimmed()+
                    "','"+ui->lineEditMedecinAdr1->text().trimmed()+
                    "','"+ui->lineEditMedecinAdr2->text().trimmed()+
                    "','"+ui->lineEditMedecinCP->text().trimmed()+
                    "','"+ui->lineEditMedecinVille->text().trimmed()+
                    "','"+ui->lineEditMedecinTel->text().trimmed()+"')");
    this->chargeListeMedecin();
}
Example #4
0
void Feeds::GetFeedById(Feed * feed)
{
    QSqlQuery query;
    QString prepQuery = "SELECT * FROM FEEDS WHERE id = :id ";
    query.prepare(prepQuery);
    query.bindValue(":id", feed->id);
    if(!query.exec())
    {
        return;
    }
    query.first();

    feed->title = query.value(2).toString();
    feed->link = query.value(1).toString();
    feed->is_on = query.value(3).toBool();
}
Example #5
0
void xtClassCode::doDelete()
{
  QString sql = "SELECT deleteClassCode(%1) AS result;";
  sql = sql.arg(getId());
  if(xtlib::debug)
    qDebug() << "executing: " << sql;
  QSqlQuery query;
  query.exec(sql);
  if(query.first())
  {
    if(query.value(0).toInt() < 0)
    {
      throw std::runtime_error("Can not delete Class Code as one or more items reference it.");
    }
  }
}
Example #6
0
int DBWorker::getMaxTabId()
{
    QSqlQuery query = prepare("SELECT MAX(tab_id) FROM tab");
    if (execute(query)) {
        if (query.first()) {
#ifdef DEBUG_LOGS
            qDebug() << "read from db: " << query.value(0).toInt();
#endif
            return query.value(0).toInt();
        }
    }
#ifdef DEBUG_LOGS
    qDebug() << "query failed";
#endif
    return 0;
}
Example #7
0
void DBWorker::getTab(int tabId)
{
    QSqlQuery query = prepare("SELECT tab_id, tab_history_id FROM tab WHERE tab_id = ?;");
    query.bindValue(0, tabId);
    if (!execute(query)) {
        return;
    }

    if (query.first()) {
#ifdef DEBUG_LOGS
        Tab tab = getTabData(query.value(0).toInt(), query.value(1).toInt());
        qDebug() << query.value(0).toInt() << query.value(1).toInt() << tab.currentLink().title() << tab.currentLink().url();
#endif
        emit tabAvailable(getTabData(query.value(0).toInt(), query.value(1).toInt()));
    }
}
Example #8
0
QString SearchDlg::getDiskName(int diskId)
{
	QString sql = "SELECT name FROM Catalog_" + QString::number(catId) + " WHERE diskNo = " + QString::number(diskId) + " AND itemType = " + QString::number(DISK_ELEMENT);
	//printQS(sql);
	QSqlQuery *q = new QSqlQuery(dm->db);
	QString result;
	if (!q)
		return result;
	if (q->exec(sql))
	{
		q->first();
		result = q->value(0).toString();
	}
	delete q;
	return result;
}
Example #9
0
bool DataBase::checkReadableUser(QString userID, QString twitterID)
{
    bool result = false;
    connect();
    QString queryString = "SELECT readableUsers.twitterID FROM readableUsers, users WHERE readableUsers.twitterID=users.twitterID AND readableUsers.userID="+userID+" AND users.twitterID="+twitterID;
    QSqlQuery checkReadableUserQuery;
    checkReadableUserQuery.prepare(queryString);
    checkReadableUserQuery.exec();
    checkReadableUserQuery.first();
    if (checkReadableUserQuery.value(0).toString() =="")
        result = false;
    else
        result = true;
    disconnect();
    return result;
}
int BDDTitre::recupererId(const QString& nomFormate)
{
    QString queryStr = "Select T.Id_Titre As 'Titre' from Titre T, Relations R WHERE T.Titre_Formate='" + nomFormate + "' " ;

    QSqlQuery query = madatabase.exec( queryStr );
    int id = -1;
    if ( query.first() )
    {
        QSqlRecord rec = query.record();
        id = (rec.value( "Titre" ).toInt());

    }


    return id;
}
Example #11
0
bool Database::isUserAlreadyConnected(QString user)
{
    QSqlQuery query;
    query.exec("SELECT COUNT(user) FROM information_schema.`PROCESSLIST` WHERE USER = '" + user + "'");
    query.first();

    if (query.value(0).toInt() != 1)
    {
        QMessageBox msgBox;
        msgBox.setText("Same user already connected in game");
        msgBox.exec();
        return true;
    }
    else
        return false;
}
Example #12
0
void Feeds::GetFilterById(filters_struct * filter)
{
    QSqlQuery query;
    QString prepQuery = "SELECT * FROM FILTER WHERE id = :id ";
    query.prepare(prepQuery);
    query.bindValue(":id", filter->id);
    if(!query.exec())
    {
        return;
    }
    query.first();

    filter->title = query.value(2).toString();
    filter->comment = query.value(3).toString();
    filter->is_on = query.value(4).toBool();
}
/*!
 * \param vorname Vorname des Sch&uuml;lers.
 * \param nachname Nachname des Sch&uuml;lers. 
 * \return Sch&uuml;ler.
 */
Schueler* Datenbank::getSchueler(QString vorname, QString nachname)
{
	QSqlQuery query;
	query.prepare("SELECT * FROM h_schueler WHERE vorname = :vorname AND nachname = :nachname");
	query.bindValue(":vorname", vorname);
	query.bindValue(":nachname", nachname);
	query.exec();
	Schueler *schueler = new Schueler();
	query.first();
	QSqlRecord record = query.record();
	schueler->setSchuelerID(query.value(record.indexOf("schuelerid")).toInt());
	schueler->setVorname(query.value(record.indexOf("vorname")).toString()); 
	schueler->setNachname(query.value(record.indexOf("nachname")).toString()); 
	schueler->setPasswort(query.value(record.indexOf("passwort")).toString());
	return schueler;
}
Example #14
0
  AgentInfo ServerManager::getAgent(const QString &id) {
    AgentInfo info;

    QSqlQuery query;
    query.prepare("SELECT Created, PSW FROM Agents WHERE ID = ?");
    query.addBindValue(id);
    query.exec();

    if (query.first()) {
      info.created = Database::stringToDate(query.value(0).toString());
      info.id = id;
      info.pswDigest = query.value(1).toByteArray();      
    }
    
    return info;
  }
Example #15
0
void MessageWindow::readSettings()
{
    QString configName = "messagesWindow";
    QHash<QString, int> settingValues;
    QSettings settings;
    if (settings.status() == QSettings::NoError)
    {
        settings.beginGroup(configName);
        if (settings.contains("x") &&
            settings.contains("y") &&
            settings.contains("width") &&
            settings.contains("height") &&
            settings.value("width", 0).toInt() > 0 &&
            settings.value("height", 0).toInt() > 0)
        {
            settingValues.insert("x", settings.value("x").toInt());
            settingValues.insert("y", settings.value("y").toInt());
            settingValues.insert("width", settings.value("width").toInt());
            settingValues.insert("height", settings.value("height").toInt());
        }
        else
        {
            // Если локальные значения координат и размеров окна прочитать не удалось, попытаемся загрузить их с сервера
            app->showMessageOnStatusBar(tr("Загрузка с сервера геометрии окна справочника ") + configName + "...");
            QSqlQuery config = app->getDBFactory()->getConfig();
            config.first();
            while (config.isValid())
            {
                if (config.record().value("group").toString() == configName)
                {
                    settingValues.remove(config.record().value("name").toString());
                    settingValues.insert(config.record().value("name").toString(), config.record().value("value").toInt());
                }
                config.next();
            }
            app->showMessageOnStatusBar("");
        }
        settings.endGroup();

        int x = settingValues.value("x", 0);
        int y = settingValues.value("y", 0);
        int w = settingValues.value("width", 400);
        int h = settingValues.value("height", 200);

        subWindow->setGeometry(x, y, w, h);
    }
}
Example #16
0
//取得id的值
bool DB::GetValue(const QString& id, int& value)
{
	SQLmutex.lock();
	QSqlQuery query = sqldb.exec(QString("SELECT value FROM save where id='") + id + QString("'"));
    SQLmutex.unlock();

	if (query.first())
	{ 
		bool ok;
		value = query.value(0).toInt(&ok);
		return true;
	}
	else
	{
		return false;
	}
}
Example #17
0
bool Prefix::isExistsByName(const QString prefix_name) const{
    QSqlQuery query;
    query.prepare("SELECT id FROM prefix WHERE name=:prefix_name");
    query.bindValue(":prefix_name", prefix_name);

    if (!query.exec()){
        qDebug()<<"SqlError: "<<query.lastError()<<query.executedQuery();
        return false;
    }

    query.first();
    if (query.isValid()){
        return true;
    }

    return false;
}
Handle<BDDTitre> BDDTitre::recupererBDD( const int id )
{

    QString queryStr = "SELECT Titre, Titre_Formate, R.Id_Artiste, R.Id_Album FROM Titre T,Relations R WHERE T.Id_Titre='" + QString::number(id) + "' AND R.Id_Titre=T.Id_Titre";
    QSqlQuery query = madatabase.exec(queryStr);

    QString nom, nomFormate;
    if (query.first() )
    {
        QSqlRecord rec = query.record();
        nom = rec.value("Titre").toString().replace("$", "'");
        nomFormate = rec.value("Titre_Formate").toString();

    }

    return Handle<BDDTitre>(new BDDTitre( id, nom, nomFormate ));
}
Example #19
0
void DBWorker::goBack(int tabId) {
    QSqlQuery query = prepare("SELECT id FROM tab_history WHERE tab_id = ? AND id < (SELECT tab_history_id FROM tab WHERE tab_id = ?) ORDER BY id DESC LIMIT 1;");
    query.bindValue(0, tabId);
    query.bindValue(1, tabId);
    if (!execute(query)) {
        return;
    }

    int historyId = 0;
    if (query.first()) {
        historyId = query.value(0).toInt();
    }

    if (historyId > 0) {
        updateTab(tabId, historyId);
    }
}
Example #20
0
void SongsQueryWideget::getValue(QSqlQuery &_query, Media &_media)
{
    _query.first();
    _media.mid = _query.value("mid").toString();
    _media.serial_id = _query.value("serial_id").toString();
    _media.name = _query.value("name").toString();
    _media.language = _query.value("language").isNull()?"": _query.value("language").toString();
    _media.type = _query.value("type").isNull()?"":_query.value("type").toString();

    _media.singer = _query.value("singer").toString();
    _media.artist_sid_1 = _query.value("artist_sid_1").toString();
    _media.artist_sid_2 = _query.value("artist_sid_2").toString();
    _media.pinyin = _query.value("pinyin").toString();
    _media.header = _query.value("header").toString();

    _media.head = _query.value("head").toString();
    _media.words = _query.value("words").toString();
    _media.path = _query.value("path").toString();
    _media.lyric = _query.value("lyric").toString();
    _media.original_track = _query.value("original_track").toString();

    _media.sound_track = _query.value("sound_track").toString();
    _media.start_volume_1 = _query.value("start_volume_1").toString();
    _media.start_volume_2 = _query.value("start_volume_2").toString();
    _media.prelude = _query.value("prelude").isNull()?"":_query.value("prelude").toString();
    _media.effect = _query.value("effect").isNull()?"":_query.value("effect").toString();

    _media.version = _query.value("version").isNull()?"":_query.value("version").toString();
    _media.create_time = _query.value("create_time").toString();
    _media.stars = _query.value("stars").isNull()?"":_query.value("stars").toString();
    _media.hot = _query.value("hot").toString();
    _media.count = _query.value("count").toString();

    _media.enabled = _query.value("enabled").isNull()?"":_query.value("enabled").toString();
    _media.black = _query.value("black").isNull()?"":_query.value("black").toString();
    _media.match = _query.value("match").isNull()?"":_query.value("match").toString();
    _media.update_time = _query.value("update_time").toString();
    _media.resolution = _query.value("resolution").isNull()?"":_query.value("resolution").toString();

    _media.quality = _query.value("quality").isNull()?"":_query.value("quality").toString();
    _media.source = _query.value("source").isNull()?"":_query.value("source").toString();
    _media.rhythm = _query.value("rhythm").isNull()?"":_query.value("rhythm").toString();
    _media.pitch = _query.value("pitch").isNull()?"":_query.value("pitch").toString();
    _media.info = _query.value("info").toString();

}
Example #21
0
int DbManager::getLicenseValidity(const int id_license) const
{
    if(id_license > 0) {
        QSqlQuery query;
        QString query_string = "SELECT license.validity FROM license WHERE license.id = :id_license";
        query.prepare(query_string);
        query.bindValue(":id_license", id_license);
        if(query.exec()) {
            if(query.isActive()) {
                if(query.first()) {
                    return query.value(0).toInt();
                }
            }
        }
    }
    return -1;
}
Example #22
0
QHash<QString,QString> Prefix::getByName(const QString prefix_name) const{
    QHash<QString,QString> values;

    QSqlQuery query;
    QSettings settings(APP_SHORT_NAME, "default");
    settings.beginGroup("wine");

    query.prepare("SELECT path, wine_dllpath, wine_loader, wine_server, wine_exec, cdrom_mount, id, name, arch, mountpoint_windrive, run_string, version_id FROM prefix WHERE name=:prefix_name");
    query.bindValue(":prefix_name", prefix_name);

    if (query.exec()){
        query.first();
        if (query.isValid()){
            if (prefix_name == "Default"){
                values.insert("path", QString("%1/.wine").arg(QDir::homePath()));
            } else {
                if (query.value(0).toString().isEmpty()){
                    values.insert("path", QString("%1/.wine").arg(QDir::homePath()));
                } else {
                    values.insert("path", query.value(0).toString());
                }
            }
            values.insert("libs", query.value(1).toString());
            values.insert("loader", query.value(2).toString());
            values.insert("server", query.value(3).toString());
            values.insert("bin", query.value(4).toString());
            values.insert("mount", query.value(5).toString());
            values.insert("id", query.value(6).toString());
            values.insert("name", query.value(7).toString());
            values.insert("arch", query.value(8).toString());
            values.insert("mountpoint_windrive", query.value(9).toString());
            if (!query.value(10).toString().isEmpty()){
                values.insert("run_string", query.value(10).toString());
            } else {
                values.insert("run_string", RUN_STRING_TEMPLATE_DEFAULT);
            }
            values.insert("version_id", query.value(11).toString());
        }
    } else {
        qDebug()<<"SqlError: "<<query.lastError();
    }
    settings.endGroup();
    query.clear();

    return values;
}
Example #23
0
QString Prefix::getName(const QString prefix_path) const{
    QString value;
    QSqlQuery query;
    query.prepare("SELECT name FROM prefix WHERE path=:prefix_path");
    query.bindValue(":prefix_path", prefix_path);

    if (query.exec()){
        query.first();
        if (query.isValid()){
            value.append(query.value(0).toString());
        }
    } else {
        qDebug()<<"SqlError: "<<query.lastError();
    }
    query.clear();
    return value;
}
void DatabasePersister::persistImageFileData(DatabasePersistRequest* request)
{
    if (databaseConnection->getDatabase().open())
    {
        QSqlQuery query;
        query.prepare("INSERT INTO images (filename, timedate, location) VALUES (:filename, :timestamp, :location)");
		query.bindValue(":filename", request->originalImageFilename);
		query.bindValue(":timestamp", request->timeStamp);
        query.bindValue(":location", QString("cam"));
        if(!query.exec())
        {
			QString error("inserting image data.");
			throw ErrorException(error, 0);
        }

        query.clear();
		query.prepare("SELECT id FROM images WHERE filename = :filename");
        query.bindValue(":filename", request->originalImageFilename);
        if(!query.exec())
        {
            QString error("inserting image data.");
			throw ErrorException(error, 1);
        }

        query.first();
        qint64 imageId = query.value(0).toLongLong();

        for (unsigned int i = 0; i < request->facesFilenames.size(); i++)
        {
            query.clear();
			query.prepare("INSERT INTO faces (filename, image_id) VALUES (:filename, :imageId)");
            query.bindValue(":filename", request->facesFilenames[i]);
            query.bindValue(":imageId", imageId);
            if(!query.exec())
            {
                QString error("inserting face data.");
				throw ErrorException(error, 2);
            }
        }
    }
	else
	{
		QString error("database closed.");
		throw ErrorException(error, 3);
	}
}
Example #25
0
void dlgReports::queryToSheetHeader(Worksheet *sh, QString query)
{
  Format fmtHeader; {
    fmtHeader.setFontSize(10);
    fmtHeader.setHorizontalAlignment(Format::AlignHCenter);
    fmtHeader.setVerticalAlignment(Format::AlignVCenter);
    fmtHeader.setFontBold(true); }

  QSqlQuery q = App::theApp()->db().exec(query);
  if (q.lastError().isValid()) { qDebug() << "Ошибка выполнения запроса: " << q.lastQuery(); return; }

  if (!q.first()) return;
  for (int c(0); c < q.record().count(); c++) {
    sh->setColumnWidth(c + 1, c + 1, q.value(c).toDouble());
    sh->write(1, c + 1, q.record().fieldName(c), fmtHeader);
  }
}
void massExpireComponent::sExpire()
{
  if ( (_original->isValid()) && (_expireAsOf->isValid()) )
  {
    QSqlQuery expire;
    if (_metrics->boolean("RevControl"))
    {
      expire.prepare("SELECT 1"
                     "  FROM bomitem"
                     "  JOIN rev ON (bomitem_rev_id=rev_id)"
                     " WHERE ((rev_status='P')"
                     "   AND  (bomitem_item_id=:item_id))"
                     " LIMIT 1;");
      expire.bindValue(":item_id", _original->id());
      expire.exec();
      if (expire.first())
        QMessageBox::information(this, tr("Mass Expire"),
                                 tr("<p>This process will only affect active "
                                   "revisions. Items on pending revisions must "
                                   "be expired manually."));
      else if (ErrorReporter::error(QtCriticalMsg, this, tr("Checking Revisions"),
                                    expire, __FILE__, __LINE__))
        return;
    }

    if (_expireAsOf->isNull())
      expire.prepare("SELECT massExpireBomitem(:item_id, CURRENT_DATE, :ecn);");
    else
      expire.prepare("SELECT massExpireBomitem(:item_id, :expire_date, :ecn);");

    expire.bindValue(":item_id", _original->id());
    expire.bindValue(":expire_date", _expireAsOf->date());
    expire.bindValue(":ecn", _ecn->text());

    expire.exec();

    if (_captive)
      close();

    _close->setText(tr("&Close"));
    _original->setId(-1);
    _ecn->clear();
    _original->setFocus();
  }
}
Example #27
0
Person * DbManager::buildPerson(const int id_person) const
{
    Person *person = nullptr;
    if(id_person > 0) {
        QSqlQuery query;
        QString query_string = "SELECT  "
                                                    "people.last_name, "
                                                    "people.first_name, "
                                                    "address.street_name, "
                                                    "address.zip, "
                                                    "address.municipality, "
                                                    "address.province, "
                                                    "address.state, "
                                                    "people.personal_code, "
                                                    "people.job, "
                                                    "people.email, "
                                                    "people.phone "
                                "FROM                people "
                                "INNER JOIN          address ON people.id = address.person";

        query_string += " AND people.id = :id_person";

        query.prepare(query_string);
        query.bindValue(":id_person", QVariant(id_person));

        if(query.exec()) {
            if(query.isActive()) {
                if(query.first()) {
                    person = new Person(        query.value(1).toString(),
                                                query.value(0).toString(),
                                                new Address (       query.value(2).toString(),
                                                                    query.value(3).toString(),
                                                                    query.value(4).toString(),
                                                                    query.value(5).toString(),
                                                                    query.value(6).toString()       ),
                                                query.value(7).toString(),
                                                query.value(8).toString(),
                                                query.value(9).toString(),
                                                query.value(10).toString()      );                
                }
            }
        }
    }
    return person;
}
Example #28
0
bool otros::agregar()
{
    Sesion* s=Sesion::getSesion();
    int cVitri=0, cAlma=0;
    QSqlQuery query;
    query.prepare("INSERT INTO Producto(codigo,descripcion,precioCompra,precioVenta,precioDescuento,accesorios,stock,observaciones,Estado_idEstado,Marca_idMarca,idColaborador,cantidadVitrina,cantidadAlmacen) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)");
    query.bindValue(0,codigo);
    query.bindValue(1,descripcion);
    query.bindValue(2,precioCompra);
    query.bindValue(3,precioVenta);
    query.bindValue(4,precioDescuento);
    query.bindValue(5,accesorios);
    query.bindValue(6,stock);
    query.bindValue(7,observaciones);
    query.bindValue(8,pEstado.getIdEstado());
    query.bindValue(9,pMarca.getIdMarca());
    query.bindValue(10,s->getIdColaborador());
    query.bindValue(11,cVitri);
    query.bindValue(12,cAlma);
    if(query.exec())
    {
        query.clear();
        query.prepare("SELECT @@identity AS id;");
        query.exec();
        if(query.size()!=0)
        {
            query.first();
            idProducto=query.value(0).toString();
        }
        query.clear();
        query.prepare("INSERT INTO Otros(Producto_idProducto,Color_idColor,Talla_idTalla,Calidad_idCalidad,TipoOtros_idTipoOtros,Genero_idGenero) VALUES(?,?,?,?,?,?)");
        query.bindValue(0,idProducto);
        query.bindValue(1,pColor.getIdColor());
        query.bindValue(2,pTalla.getIdTalla());
        query.bindValue(3,pCalidad.getIdCalidad());
        query.bindValue(4,pTipoOtros.getIdTipoOtros());
        query.bindValue(5,pGenero.getIdgenero());
        if(query.exec())
            return true;
        else
            return false;
    }
    else
        return false;
}
Example #29
0
QSqlQuery DBManager::managerLogin(QString id ,QString password)
{
    QSqlQuery query;
    QString s = "select userid, name, type from serveruser where userid= %1 and password= \'%2\' ";
    if( query.exec(s.arg(id).arg(password)))
    {
        query.first();
        User::GetInstance().setType(query.value(2).toInt());
        qDebug() << "managerLogin] " << query.lastError();
        return query;
    }
    else
    {
        qDebug()  << "managerLogin] " << query.lastError();
        return query;
    }

}
Example #30
0
bool object_Tarjeta::completar()
{
    QSqlQuery query;
    query.prepare("SELECT idTarjeta FROM Tarjeta WHERE nombre=?");
    query.bindValue(0,md_o_nombre);
    if(query.exec())
    {
        if(query.size()!=0)
        {
            query.first();
            md_o_idTarjeta=query.value(0).toString();            
            return true;
        }
        return false;
    }
    else
        return false;
}