int main(void) { OCI_Connection *cn; OCI_Statement *st; OCI_Resultset *rs; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); OCI_Prepare(st, "update products set code = code+10 returning code into :i"); OCI_RegisterInt(st, ":i"); OCI_Execute(st); rs = OCI_GetResultset(st); while (OCI_FetchNext(rs)) printf("%i\n", OCI_GetInt(rs, 1)); printf("count : %i\n", OCI_GetRowCount(rs)); OCI_Commit(cn); OCI_Cleanup(); return EXIT_SUCCESS; }
int ociw_res_num_rows(db_wrap_result * self, size_t *num) { RES_DECL(DB_WRAP_E_BAD_ARG); if (! num) return DB_WRAP_E_BAD_ARG; int rc = OCI_GetRowCount(wres->result); if (rc < 0) { return DB_WRAP_E_UNKNOWN_ERROR; } *num = (size_t)rc; return 0; }
int main(void) { OCI_Connection *cn; OCI_Statement *st; OCI_Resultset *rs; product_t prd; product_ind_t ind; char buf[100]; int i = 0; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); OCI_ExecuteStmt(st, "select * from products"); rs = OCI_GetResultset(st); OCI_SetStructNumericType(rs, 1, OCI_NUM_INT); OCI_SetStructNumericType(rs, 3, OCI_NUM_DOUBLE); while (OCI_FetchNext(rs)) { i++; OCI_GetStruct(rs, &prd, &ind); OCI_DateToText(prd.creation, "DD-MM-YYYY", 100, buf); printf("row #%d \n" "...prd.code : %d \n" "...prd.name : %s \n" "...prd.price : %g \n" "...prd.creation : %s \n" " \n", i, prd.code, prd.name, prd.price, buf ); } printf("\n\n%d row(s) fetched\n", OCI_GetRowCount(rs)); OCI_Cleanup(); return EXIT_SUCCESS; }
int main(void) { OCI_Connection *cn; OCI_Statement *st; OCI_Resultset *rs; OCI_Lob *lob1, *lob2; char temp[SIZE_BUF+1]; int code, n; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); OCI_ExecuteStmt(st, "select code, content from test_lob for update"); rs = OCI_GetResultset(st); while (OCI_FetchNext(rs)) { code = OCI_GetInt(rs, 1); lob1 = OCI_GetLob(rs, 2); lob2 = OCI_LobCreate(cn, OCI_CLOB); n = OCI_LobWrite(lob1, "Today, ", 7); OCI_LobSeek(lob1, n, OCI_SEEK_SET); n = OCI_LobWrite(lob2, "I'm going to the cinema !", 25); OCI_LobAppendLob(lob1, lob2); OCI_LobSeek(lob1, 0, OCI_SEEK_SET); n = OCI_LobRead(lob1, temp, SIZE_BUF); temp[n] = 0; printf("code: %i, action : %s\n", code, temp); OCI_LobFree(lob2); } printf("\n%d row(s) fetched\n", OCI_GetRowCount(rs)); OCI_Cleanup(); return EXIT_SUCCESS; }