Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1.     QSqlDatabase DataBase = QSqlDatabase::addDatabase("QMYSQL",keyRef);
  2.     DataBase.setDatabaseName("outsafe_dev_db");
  3.     DataBase.setHostName("127.0.0.1");
  4.     if(!DataBase.open("root","XXXXX"))
  5.     {
  6.         qDebug() << "Connection Database error";
  7.         return "ERROR";
  8.     }
  9.  
  10.     QSqlQuery q(tr("SELECT * FROM `keys` WHERE iSerial = '%1' AND `key` = '%2'").arg(intKey).arg(keyRef),DataBase);
  11.     if(q.size() != 1){
  12.         qDebug() << "SID non trouvé ou doublon";
  13.         return "ERROR";
  14.     }
  15.  
  16.     int fieldIdUser = q.record().indexOf("id_user");
  17.     int fieldConnected = q.record().indexOf("connected");
  18.     int fieldKey = q.record().indexOf("key");
  19.     bool *ok;
  20.     QString connectedInt;
  21.     while (q.next()){
  22.         userId = q.value(fieldIdUser).toString();
  23.         connectedInt = q.value(fieldConnected).toString();
  24.         key = q.value(fieldKey).toString();
  25.         qDebug() << tr("%1 state is : %2").arg(key).arg(connectedInt);
  26.     }
  27.     q.finish();
  28.  
  29.     bool freeKey;
  30.     (userId.toInt() == 0) ? freeKey = true : freeKey = false;
  31.     bool connectedKey;
  32.     (connectedInt.toInt() == 1) ? connectedKey = true : connectedKey = false;
  33.     bool validKey = !key.isEmpty();
  34.  
  35.     if(freeKey && !connectedKey && validKey){
  36.         //ACTIVATION DE LA CLEF
  37. //SEGFAULT HERE
  38.         QSqlQuery query(QSqlQuery(tr("UPDATE `keys` SET nom = '%1' , prenom = '%2' , adress = '%3' , cp = %4 , city = '%5' , tel = '%6' ,"
  39.                                      " mail = '%7' , nation = '%8' , birth = '%9' , login = '%10' , pass = '%11' , secretQuestion = '%12' ,"
  40.                                      " secretAnswer = '%13' "
  41.                                      " WHERE iSerial = '%14' AND `key` = '%15' ")
  42.                                              .arg(nom).arg(prenom).arg(adress).arg(cp).arg(ville).arg(tel)
  43.                                              .arg(mail).arg(nation).arg(dnaiss).arg(id).arg(pw).arg(question)
  44.                                                  .arg(answer).arg(intKey).arg(keyRef),DataBase));
  45.  
  46.         if(query.numRowsAffected() != 1){
  47.             qDebug() << "SQL activation failed";
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement