PDA

View Full Version : I have a validation in 3 days and my projects does not work !!!! please help



chams
19th November 2017, 16:53
okay so i need to simply add information to an oracle (sql) database and it loads this message and i don't understand what is the source f the problem and you see if i can't add then i can't modify or delete or anything !!!!!!!!!!!! please help !!!!!!!!!!!!!!!!


this is the message :QODBCResult::exec: Unable to execute statement: "[Microsoft][Gestionnaire de pilotes ODBC] Erreur de séquence de la fonction"
although it says that i'm connected to database !!!!!!!!! for any futher information about the code tell me and i will send it to you

ChrisW67
20th November 2017, 08:05
The actual code including the offending SQL would be a good start.

chams
20th November 2017, 08:31
Thank you so much for your reply so here is the function add in convention.cpp:


#include "convention.h"
#include "ui_convontion.h"
#include"connexion.h"
#include <QtSql>
#include<QSqlQuery>
#include"QString"
#include<QtSql/QSqlDatabase>
#include<QMessageBox>
convention::convention(int id_c,QString nom_entreprise,int pourcentage_c,QString date_expiration)

{
this->id_c=id_c;
this->nom_entreprise=nom_entreprise;
this->pourcentage_c=pourcentage_c;
this->date_expiration=date_expiration;
}

/*convention::~convention()
{
delete ui;
}*/

bool convention::ajouter_convention(convention *c)
{ //bool verif=false;
QSqlQuery query;

query.prepare("INSERT INTO CONVENTIONS (id_c,nom_entreprise,pourcentage_c, date_expiration) "
"VALUES (:id_c, :nom_entreprise, :pourcentage_c, :date_expiration");

//verif= query.exec();

query.bindValue(0, c->get_Id_c());
query.bindValue(1,c->get_Nom_entreprise());
query.bindValue(2, c->get_Pourcentage_c());
query.bindValue(3, c->get_date_expiration());


return query.exec();

//verif ;


}

and this is the pushbutton code :


#include "form_ajout_convontion.h"
#include "ui_form_ajout_convontion.h"
#include"convention.h"
#include"QMessageBox"
#include"ui_convontion.h"
#include"connexion.h"

Form_ajout_convontion::Form_ajout_convontion(QWidg et *parent) :
QWidget(parent),
ui(new Ui::Form_ajout_convontion)
{
ui->setupUi(this);
}

Form_ajout_convontion::~Form_ajout_convontion()
{
delete ui;
}

void Form_ajout_convontion::on_pushButton_clicked()
{

int id_c;
QString nom_entreprise;
int pourcentage_c;
QString date_expiration ;

id_c=ui->lineEdit->text().toInt();
nom_entreprise =ui->lineEdit_2->text();
pourcentage_c=ui->lineEdit_3->text().toInt();
date_expiration=ui->lineEdit_4->text();

convention *c =new convention(id_c, nom_entreprise,pourcentage_c, date_expiration) ;
c->ajouter_convention(c);



}


and this is the connexion.cpp code:


#include "mainwindow.h"
#include"connexion.h"
//#include "ui_mainwindow.h"
//#include <QMainWindow>
#include<QDebug>
//#include <QWidget>
#include <QApplication>
#include<QtSql/QSqlDatabase>
#include<QMessageBox>


bool Connexion::create_connection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("mybase");
db.setUserName("hr");
db.setPassword("26113051malek");

//return (db.open());
if (!db.open()) {
qDebug()<<"not connected to database";
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs Oracle support. Please read "
"the Qt OCI driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);

return false;
}
else
{
qDebug()<<"connected to database";
return true;
}



}

so , no error is loaded while compiling this code but when i hit the add button this message is written and no adding to the databse happends :
connected to database
QODBCResult::exec: Unable to execute statement: "[Microsoft][Gestionnaire de pilotes ODBC] Erreur de séquence de la fonction"




in the end thank you so much for any help you can give !!!

high_flyer
20th November 2017, 10:36
Your error is an ODBC/SQL error - the sequence of operations you are doing on the query is not right.
You probably will get more help from SQL/ODBC related forums.

However on a C++ level one thing seems odd in your code:


convention *c =new convention(id_c, nom_entreprise,pourcentage_c, date_expiration) ;
c->ajouter_convention(c);

Why are you creating an instance of 'convention' only to give it to it self?
Do you know what 'this' is?