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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
OCIDate dt;
text c1[128];
OCIDefine *defnp1;
ub4 prefetch = 1;
sword status;
/*init oci*/
checkerr(errhp, OCIInitialize((ub4) OCI_DEFAULT, (dvoid *)0,
(dvoid * (*)(dvoid *, size_t)) 0,
(dvoid * (*)(dvoid *, dvoid *, size_t))0,
(void (*)(dvoid *, dvoid *)) 0 ),
(char *)"Initialize");
/*alloc handles*/
status = OCIEnvCreate(&envhp, OCI_DEFAULT,0,0,0,0,0,0);
checkerr(errhp,status,(char *)"EnvCreate");
status = OCIHandleAlloc(envhp,(dvoid*)&errhp, OCI_HTYPE_ERROR, 0,0);
checkerr(errhp,status,(char *)"HandleAllocErrHp");
status = OCIHandleAlloc(envhp,(dvoid*)&svchp, OCI_HTYPE_SVCCTX, 0,0);
checkerr(errhp,status,(char *)"HandleAllocSvcHp");
status = OCIHandleAlloc(envhp,(dvoid*)&sqlhp, OCI_HTYPE_STMT, 0,0);
checkerr(errhp,status,(char *)"HandleAllocSqlHp");
OCIDateSysDate (errhp ,&dt);
/*connexion*/
status = OCILogon(envhp,errhp,&svchp,
(text *) usr, strlen(usr),
(text *) pwd, strlen(pwd),
(text *) db, strlen(db));
checkerr(errhp,status,(char *)"Logon");
/*prepare sql*/
status = OCIStmtPrepare(sqlhp, errhp, (OraText *) sql,
(ub4)strlen((char *) sql),
(ub4) OCI_NTV_SYNTAX,
(ub4) OCI_DEFAULT);
checkerr(errhp,status,(char *)"Prepare");
/*bind variable*/
checkerr(errhp, OCIBindByName(sqlhp, &bnd1, errhp, (text *) ":id_produit",
strlen(":id_produit"), (ub1 *) &id_produit, (sword) sizeof(id_produit)+1,
SQLT_STR, (dvoid *) 0, (ub2 *) 0, (ub2) 0,
(ub4) 0, (ub4 *) 0, OCI_DEFAULT),(char *)"bind1");
checkerr(errhp, OCIBindByName(sqlhp, &bnd2, errhp, (text *) ":id_version",
strlen(":id_version"), (ub1 *) &id_version, (sword) sizeof(id_version)+1,
SQLT_STR, (dvoid *) 0, (ub2 *) 0, (ub2) 0,
(ub4) 0, (ub4 *) 0, OCI_DEFAULT),(char *)"bind2");
checkerr(errhp, OCIBindByName(sqlhp, &bnd3, errhp, (text *) ":id_objet",
strlen(":id_objet"), (ub1 *) &id_objet, (sword) sizeof(id_objet),
SQLT_INT, (dvoid *) 0, (ub2 *) 0, (ub2) 0,
(ub4) 0, (ub4 *) 0, OCI_DEFAULT),(char *)"bind3");
OCIAttrSet (sqlhp,
OCI_HTYPE_STMT,
&prefetch,
0,
OCI_ATTR_PREFETCH_ROWS,
errhp);
/*execute sql*/
status = OCIStmtExecute(svchp, sqlhp, errhp, 0, 0, (OCISnapshot *)NULL,
(OCISnapshot *)NULL, OCI_DEFAULT);
checkerr(errhp,status,(char *)"Execute");
/* resultats du select */
OCIDefineByPos ( sqlhp,
&defnp1,
errhp,
1,
&c1,
128,
SQLT_STR,
(dvoid *) 0,
(dvoid *) 0,
(dvoid *) 0,
OCI_DEFAULT);
status = OCIStmtFetch ( sqlhp,errhp,1,OCI_FETCH_FIRST,OCI_DEFAULT );
printf("%s\n",c1);
if(status == OCI_NO_DATA){
fprintf(stdout,"%s\n","aucune donnee");
}
else{
fprintf(stdout,"%s\n","youhou j'ai des donnees");
} |