1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
string corresFour(string numFour)
{
//variables base de données
static SQLHANDLE hEnv; //pointeur sur un environnement
static SQLHANDLE hDbc; //pointeur sur une connexion
int iOut;
char strOut[256];
//acces a la base de donnée
char szDSN[256] = "driver={Microsoft Access Driver (*.mdb)};dbq=[CORRES_MFGPRO.mdb];";
//ordres SQL
char szSql[256];
sprintf(szSql,"SELECT * FROM CORRES_FOUR where CODE_SITE_FOUR_ORACLE = \"%s\"",numFour.c_str());
cout << "szSql = " << szSql << endl;
system("PAUSE");
long ret1,ret2,ret3,ret4;
char corres1[128];
char corres2[128];
char corres3[128];
char corres4[128];
// 1 - Connexion a la BDD Access
SQLAllocEnv(&hEnv);
SQLAllocConnect(hEnv, &hDbc);
if((SQLDriverConnect(hDbc, NULL, (unsigned char*)szDSN, SQL_NTS, (unsigned char*)strOut, 255, (SQLSMALLINT*)&iOut, SQL_DRIVER_NOPROMPT))==SQL_SUCCESS)
cout << endl << "CONNEXION ETABLIE ..." << endl;
else
cout << endl << " !!! ERREUR DE CONNEXION !!!" << endl;
// 2 - Preparation de la requete
HSTMT hStmt;//pointeur d'instruction ODBC.
if(SQLAllocHandle(SQL_HANDLE_STMT,hDbc,&hStmt)==SQL_SUCCESS)
cout << "SQLAllocHandle OK ..." << endl;
if (SQLPrepare(hStmt, (unsigned char*)szSql, SQL_NTS)==SQL_SUCCESS)//Prépare l'ordre Sql
cout << "PREPARATION REQUETE OK ..." << endl;
// 3 - Execution de la requete
//SQLBindCol(hStmt,2,SQL_C_CHAR,corres,128,(SQLINTEGER*)&ret1);
SQLBindCol(hStmt,1,SQL_C_CHAR,corres1,128,&ret1);
SQLBindCol(hStmt,2,SQL_C_CHAR,corres2,128,&ret2);
SQLBindCol(hStmt,3,SQL_C_CHAR,corres3,128,&ret3);
SQLBindCol(hStmt,4,SQL_C_CHAR,corres4,128,&ret4);
SQLExecute(hStmt);
int retcode = SQLFetch(hStmt);
cout << "RETCODE = " << retcode << endl;
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
cout << "ok";
}
else
{
cout << "erreur";
}
// 4 - Boucle pour afficher les resultats
cout << "Le code site fournisseur Oracle " << numFour << "correspond dans MFGPRO au code " << corres2 << "." << endl;
// 5 - Liberations et fermeture de la connection a la BDD
SQLFreeStmt(hStmt, SQL_DROP);
SQLDisconnect(hDbc);
SQLFreeEnv(hEnv);
system("PAUSE");
return corres2;
} |
Partager