Re: [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: vincent r. <vin...@gm...> - 2015-02-11 22:06:50
|
Hi, When performing bulk insert, all binding host variables must be arrays. you cannot bind an int to n1 and an array to n2. You need to bind array for both n1 and n2. That's the concept of bulk inserts ! Look at your array variable "array". you declare it of size N but you only initialize the first element !!! Other elements have non defined values ! Regards, Vincent On Wed, Feb 11, 2015 at 9:26 PM, Ivan Chernetsky <ich...@qu...> wrote: > 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 > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming. The Go Parallel Website, > sponsored by Intel and developed in partnership with Slashdot Media, is > your > hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials and more. Take a > look and join the conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > Orclib-users mailing list > Orc...@li... > https://lists.sourceforge.net/lists/listinfo/orclib-users > > -- Vincent Rogier |