[Orclib-users] Crash when using BindArray* and Bind* functions together
Open source C and C++ library for accessing Oracle Databases
Brought to you by:
vince_del_paris
From: Ivan C. <ich...@qu...> - 2015-02-11 21:30:11
|
Hello everybody, With N sufficiently large (on my machine 100000 is large enough), the below program segfaults. With N sufficiently small (on my machine 1000 is small enough) trash values get written into ns table. It is not allowed to use BindInt with BindArrayOfInts with the same statement, by design, is it? If so, BindInt should return some error code, instead of silently allowing it. Again, if so, what is the proper way of binding single variables and arrays? #include <ocilib.h> #define N 100000 int main(void) { OCI_Connection *cn = NULL; OCI_Statement *st = NULL; int single = 0, array[N] = {1}; const char *host = "db", *user = "user", *password = "pass"; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate(host, user, password, OCI_SESSION_DEFAULT); if (cn == NULL) return EXIT_FAILURE; st = OCI_StatementCreate(cn); if (st == NULL) return EXIT_FAILURE; OCI_Prepare(st, "DROP TABLE ns"); OCI_Execute(st); OCI_Commit(cn); if (!OCI_Prepare(st, "CREATE TABLE ns (n1 NUMBER, n2 NUMBER)")) return EXIT_FAILURE; if (!OCI_Execute(st)) return EXIT_FAILURE; if (!OCI_Commit(cn)) return EXIT_FAILURE; if (!OCI_Prepare(st, "INSERT INTO ns (n1, n2) VALUES (:single, :array)")) return EXIT_FAILURE; if (!OCI_BindArraySetSize(st, N)) return EXIT_FAILURE; if (!OCI_BindInt(st, ":single", &single)) return EXIT_FAILURE; if (!OCI_BindArrayOfInts(st, ":array", array, N)) return EXIT_FAILURE; if (!OCI_Execute(st)) return EXIT_FAILURE; printf("rows affected: %u\n", OCI_GetAffectedRows(st)); if (!OCI_Commit(cn)) return EXIT_FAILURE; OCI_Cleanup(); return EXIT_SUCCESS; } -- Ivan Chernetsky Qualys, Inc. | Continuous Security | www.qualys.com Work: (650) 801-7737 | Cell: (650) 422-9092 |