MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / test_bind_array2

Function test_bind_array2

tests/tools/cdb2bind.c:417–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417void test_bind_array2()
418{
419 cdb2_hndl_tp *hndl = NULL;
420 test_open(&hndl, db);
421
422 test_exec(hndl, "drop table if exists t2");
423 test_exec(hndl, "create table t2 (a int, b char(1))");
424 test_exec(hndl, "insert into t2 select value, cast(value%10 as char) from generate_series(0,2999)");
425
426
427 {
428 int N = 2048;
429 int values[N];
430 for (int i = 0; i < N; i++) {
431 values[i] = i;
432 }
433 cdb2_bind_array(hndl, "myarray", CDB2_INTEGER, (const void *)values, N, sizeof(values[0]));
434 test_exec(hndl, "select a,b from t2 where a in carray(@myarray) order by a");
435 for (int i = 0; i < N; i++) {
436 test_next_record(hndl);
437 int64_t *vala = cdb2_column_value(hndl, 0);
438 if (*vala != values[i]) {
439 fprintf(stderr, "%s:%d:error got:%"PRId64" expected:%d\n", __func__, __LINE__, *vala, values[i]);
440 exit(1);
441 }
442
443 char *valb = cdb2_column_value(hndl, 1);
444 if (*valb != ('0'+values[i]%10)) {
445 fprintf(stderr, "%s:%d:error got:'%c' expected:'%d'\n", __func__, __LINE__, *valb, values[i]);
446 exit(1);
447 }
448
449 //printf("TEST 06 RESP %"PRId64" %c\n", *vala, *valb);
450 }
451
452 cdb2_clearbindings(hndl);
453 }
454
455 { // use bind to insert
456 test_exec(hndl, "drop table if exists t3");
457 test_exec(hndl, "create table t3 (a int)");
458
459 int N = 2048;
460 int values[N];
461 for (int i = 0; i < N; i++) {
462 values[i] = i + 123;
463 }
464 cdb2_bind_array(hndl, "myintarr", CDB2_INTEGER, (const void *)values, N, sizeof(values[0]));
465 test_exec(hndl, "insert into t3 select * from carray(@myintarr)");
466 cdb2_clearbindings(hndl);
467
468 // verify insert succeeded
469 test_exec(hndl, "select a from t3 order by a");
470 for (int i = 0; i < N; i++) {
471 test_next_record(hndl);
472 int64_t *vala = cdb2_column_value(hndl, 0);
473 if (*vala != values[i]) {
474 fprintf(stderr, "%s:%d:error got:%"PRId64" expected:%d\n", __func__, __LINE__, *vala, values[i]);

Callers 1

mainFunction · 0.85

Calls 8

cdb2_bind_arrayFunction · 0.85
test_next_recordFunction · 0.85
cdb2_column_valueFunction · 0.85
exitFunction · 0.85
cdb2_clearbindingsFunction · 0.85
test_closeFunction · 0.85
test_openFunction · 0.70
test_execFunction · 0.70

Tested by

no test coverage detected