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

Function cdb2_bind_array

cdb2api/cdb2api.c:5406–5486  ·  view source on GitHub ↗

cdb2_bind_array -- bind c array to a parameter name * name is the variable name we used in the sql * type is the type of elements to bind ex. CDB2_INTEGER * varaddr is the array address * count is the number of items in the array we will bind * typelen is the size of the elements for integer-arrays sizeof(int32_t or int64_t) */

Source from the content-addressed store, hash-verified

5404 * typelen is the size of the elements for integer-arrays sizeof(int32_t or int64_t)
5405 */
5406int cdb2_bind_array(cdb2_hndl_tp *hndl, const char *name, cdb2_coltype type, const void *varaddr, size_t count, size_t typelen)
5407{
5408 if (count <= 0 || count > CDB2_MAX_BIND_ARRAY) {
5409 sprintf(hndl->errstr, "%s: bad array length:%zd (max:%d)", __func__, count, CDB2_MAX_BIND_ARRAY);
5410 return -1;
5411 }
5412
5413 CDB2SQLQUERY__Bindvalue__Array *carray = malloc(sizeof(*carray));
5414 cdb2__sqlquery__bindvalue__array__init(carray);
5415
5416 switch(type) {
5417 case CDB2_INTEGER:
5418 if (typelen == sizeof(int32_t)) {
5419 CDB2SQLQUERY__Bindvalue__I32Array *i32 = malloc(sizeof(*i32));
5420 cdb2__sqlquery__bindvalue__i32_array__init(i32);
5421 i32->elements = (int32_t *)varaddr;
5422 i32->n_elements = count;
5423 carray->type_case = CDB2__SQLQUERY__BINDVALUE__ARRAY__TYPE_I32;
5424 carray->i32 = i32;
5425 } else if (typelen == sizeof(int64_t)) {
5426 CDB2SQLQUERY__Bindvalue__I64Array *i64 = malloc(sizeof(*i64));
5427 cdb2__sqlquery__bindvalue__i64_array__init(i64);
5428 i64->elements = (int64_t *)varaddr;
5429 i64->n_elements = count;
5430 carray->type_case = CDB2__SQLQUERY__BINDVALUE__ARRAY__TYPE_I64;
5431 carray->i64 = i64;
5432 } else {
5433 goto notsupported;
5434 }
5435 break;
5436 case CDB2_REAL: {
5437 CDB2SQLQUERY__Bindvalue__DblArray *dbl = malloc(sizeof(*dbl));
5438 cdb2__sqlquery__bindvalue__dbl_array__init(dbl);
5439 dbl->elements = (double *)varaddr;
5440 dbl->n_elements = count;
5441 carray->type_case = CDB2__SQLQUERY__BINDVALUE__ARRAY__TYPE_DBL;
5442 carray->dbl = dbl;
5443 }
5444 break;
5445 case CDB2_CSTRING: {
5446 CDB2SQLQUERY__Bindvalue__TxtArray *txt = malloc(sizeof(*txt));
5447 cdb2__sqlquery__bindvalue__txt_array__init(txt);
5448 txt->elements = (char **)varaddr;
5449 txt->n_elements = count;
5450 carray->type_case = CDB2__SQLQUERY__BINDVALUE__ARRAY__TYPE_TXT;
5451 carray->txt = txt;
5452 }
5453 break;
5454 case CDB2_BLOB: {
5455 CDB2SQLQUERY__Bindvalue__BlobArray *blob = malloc(sizeof(*blob));
5456 cdb2__sqlquery__bindvalue__blob_array__init(blob);
5457 blob->elements = (ProtobufCBinaryData *) varaddr;
5458 blob->n_elements = count;
5459 carray->type_case = CDB2__SQLQUERY__BINDVALUE__ARRAY__TYPE_BLOB;
5460 carray->blob = blob;
5461 }
5462 break;
5463 default: goto notsupported;

Callers 4

test_bind_arrayFunction · 0.85
test_bind_array2Function · 0.85
test_bind_blob_arrayFunction · 0.85
test_pass_array_to_spFunction · 0.85

Calls 4

mallocFunction · 0.85
reallocFunction · 0.85
freeFunction · 0.85
cdb2_type_strFunction · 0.70

Tested by 4

test_bind_arrayFunction · 0.68
test_bind_array2Function · 0.68
test_bind_blob_arrayFunction · 0.68
test_pass_array_to_spFunction · 0.68