Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QSqlDatabase DataBase = QSqlDatabase::addDatabase("QMYSQL",keyRef);
- DataBase.setDatabaseName("outsafe_dev_db");
- DataBase.setHostName("127.0.0.1");
- if(!DataBase.open("root","XXXXX"))
- {
- qDebug() << "Connection Database error";
- return "ERROR";
- }
- QSqlQuery q(tr("SELECT * FROM `keys` WHERE iSerial = '%1' AND `key` = '%2'").arg(intKey).arg(keyRef),DataBase);
- if(q.size() != 1){
- qDebug() << "SID non trouvé ou doublon";
- return "ERROR";
- }
- int fieldIdUser = q.record().indexOf("id_user");
- int fieldConnected = q.record().indexOf("connected");
- int fieldKey = q.record().indexOf("key");
- bool *ok;
- QString connectedInt;
- while (q.next()){
- userId = q.value(fieldIdUser).toString();
- connectedInt = q.value(fieldConnected).toString();
- key = q.value(fieldKey).toString();
- qDebug() << tr("%1 state is : %2").arg(key).arg(connectedInt);
- }
- q.finish();
- bool freeKey;
- (userId.toInt() == 0) ? freeKey = true : freeKey = false;
- bool connectedKey;
- (connectedInt.toInt() == 1) ? connectedKey = true : connectedKey = false;
- bool validKey = !key.isEmpty();
- if(freeKey && !connectedKey && validKey){
- //ACTIVATION DE LA CLEF
- //SEGFAULT HERE
- QSqlQuery query(QSqlQuery(tr("UPDATE `keys` SET nom = '%1' , prenom = '%2' , adress = '%3' , cp = %4 , city = '%5' , tel = '%6' ,"
- " mail = '%7' , nation = '%8' , birth = '%9' , login = '%10' , pass = '%11' , secretQuestion = '%12' ,"
- " secretAnswer = '%13' "
- " WHERE iSerial = '%14' AND `key` = '%15' ")
- .arg(nom).arg(prenom).arg(adress).arg(cp).arg(ville).arg(tel)
- .arg(mail).arg(nation).arg(dnaiss).arg(id).arg(pw).arg(question)
- .arg(answer).arg(intKey).arg(keyRef),DataBase));
- if(query.numRowsAffected() != 1){
- qDebug() << "SQL activation failed";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement