Write QsqlQuery before execution [Solved]



  • Hi,

    For debuging prurpose I wouls like to print a sql query I am executing. I have no clue how to proceed.
    Here my code:

    • QSqlQuery query;
      
      query.prepare("INSERT INTO GeoAndEnergies VALUES(:smi,:chismi,:index,:rank,:comp,:met,:ba,:nha, :na, :gr, :gconv, :scfconv, :ener,:chemf,:prog,:ver,:cha,:mult,:sol,:geo, :freq, :enth, :free_e, :wei)");;
      query.bindValue(":smi",QVariant(SMILES));
      query.bindValue(":chismi",QVariant(ChiralSMILES));
      query.bindValue(":index",QVariant(IndexCS));
      query.bindValue(":rank",QVariant(Confrank));
      query.bindValue(":comp",QVariant(Comptype));
      query.bindValue(":met",QVariant(Method));
      query.bindValue(":ba",QVariant(BASE));
      query.bindValue(":nha",QVariant(NheavyAtom));
      query.bindValue(":na",QVariant(NAtoms));
      query.bindValue(":gr",QVariant(Grid));
      query.bindValue(":gconv",QVariant(GeoConvergence));
      query.bindValue(":scfconv",QVariant(SCFConvergence));
      query.bindValue(":ener",QVariant(Energy));
      query.bindValue(":chemf",QVariant(ChemicalFormula));
      query.bindValue(":prog",QVariant(SOFTWARE));
      query.bindValue(":ver",QVariant(VERSION));
      query.bindValue(":cha",QVariant(Charge));
      query.bindValue(":mult",QVariant(Multiplicity));
      query.bindValue(":sol",QVariant(SOLVANT));
      query.bindValue(":geo",QVariant(Geometry));
      query.bindValue(":freq",QVariant(freq));
      query.bindValue(":enth",QVariant(enthalpy));
      query.bindValue(":free_e",QVariant(free_enthalpy));
      query.bindValue(":wei",QVariant(weight));
      if (!query.exec()){
      std::cout << "Une erreur s'est produite. :(" << std::endl << q2c(query.lastError().text()) << std::endl;
      }
      return;

    Thanks for tips.


  • Lifetime Qt Champion

    Hi,

    Do you mean something like lastQuery ?



  • What I was looking for was query.executedQuery().

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.