in sources/cqlrt_common.c [1202:1338]
static void cql_multibind_v(
cql_code *_Nonnull prc,
sqlite3 *_Nonnull db,
sqlite3_stmt *_Nullable *_Nonnull pstmt,
cql_int32 count,
const char *_Nullable vpreds,
va_list *_Nonnull args)
{
cql_int32 column = 1;
for (cql_int32 i = 0; *prc == SQLITE_OK && i < count; i++) {
cql_contract(pstmt && *pstmt);
cql_int32 type = va_arg(*args, cql_int32);
cql_int32 core_data_type = CQL_CORE_DATA_TYPE_OF(type);
if (vpreds && !vpreds[i]) {
cql_skip_arg(type, args);
continue;
}
if (type & CQL_DATA_TYPE_NOT_NULL) {
switch (core_data_type) {
case CQL_DATA_TYPE_INT32: {
cql_int32 int32_data = va_arg(*args, cql_int32);
*prc = sqlite3_bind_int(*pstmt, column, int32_data);
column++;
break;
}
case CQL_DATA_TYPE_INT64: {
cql_int64 int64_data = va_arg(*args, cql_int64);
*prc = sqlite3_bind_int64(*pstmt, column, int64_data);
column++;
break;
}
case CQL_DATA_TYPE_DOUBLE: {
cql_double double_data = va_arg(*args, cql_double);
*prc = sqlite3_bind_double(*pstmt, column, double_data);
column++;
break;
}
case CQL_DATA_TYPE_BOOL: {
cql_bool bool_data = !!(cql_bool)va_arg(*args, cql_int32);
*prc = sqlite3_bind_int(*pstmt, column, bool_data);
column++;
break;
}
case CQL_DATA_TYPE_STRING: {
cql_string_ref str_ref = va_arg(*args, cql_string_ref);
cql_alloc_cstr(temp, str_ref);
*prc = sqlite3_bind_text(*pstmt, column, temp, -1, SQLITE_TRANSIENT);
cql_free_cstr(temp, str_ref);
column++;
break;
}
case CQL_DATA_TYPE_BLOB: {
cql_blob_ref blob_ref = va_arg(*args, cql_blob_ref);
const void *bytes = cql_get_blob_bytes(blob_ref);
cql_uint32 size = cql_get_blob_size(blob_ref);
*prc = sqlite3_bind_blob(*pstmt, column, bytes, size, SQLITE_TRANSIENT);
column++;
break;
}
case CQL_DATA_TYPE_OBJECT: {
cql_object_ref obj_ref = va_arg(*args, cql_object_ref);
*prc = sqlite3_bind_int64(*pstmt, column, (int64_t)obj_ref);
column++;
break;
}
}
}
else {
switch (core_data_type) {
case CQL_DATA_TYPE_INT32: {
const cql_nullable_int32 *_Nonnull int32p = va_arg(*args, const cql_nullable_int32 *_Nonnull);
*prc = int32p->is_null ? sqlite3_bind_null(*pstmt, column) :
sqlite3_bind_int(*pstmt, column, int32p->value);
column++;
break;
}
case CQL_DATA_TYPE_INT64: {
const cql_nullable_int64 *_Nonnull int64p = va_arg(*args, const cql_nullable_int64 *_Nonnull);
*prc =int64p->is_null ? sqlite3_bind_null(*pstmt, column) :
sqlite3_bind_int64(*pstmt, column, int64p->value);
column++;
break;
}
case CQL_DATA_TYPE_DOUBLE: {
const cql_nullable_double *_Nonnull doublep = va_arg(*args, const cql_nullable_double *_Nonnull);
*prc = doublep->is_null ? sqlite3_bind_null(*pstmt, column) :
sqlite3_bind_double(*pstmt, column, doublep->value);
column++;
break;
}
case CQL_DATA_TYPE_BOOL: {
const cql_nullable_bool *_Nonnull boolp = va_arg(*args, const cql_nullable_bool *_Nonnull);
*prc =boolp->is_null ? sqlite3_bind_null(*pstmt, column) :
sqlite3_bind_int(*pstmt, column, !!boolp->value);
column++;
break;
}
case CQL_DATA_TYPE_STRING: {
cql_string_ref _Nullable nullable_str_ref = va_arg(*args, cql_string_ref);
if (!nullable_str_ref) {
*prc = sqlite3_bind_null(*pstmt, column);
}
else {
cql_alloc_cstr(temp, nullable_str_ref);
*prc = sqlite3_bind_text(*pstmt, column, temp, -1, SQLITE_TRANSIENT);
cql_free_cstr(temp, nullable_str_ref);
}
column++;
break;
}
case CQL_DATA_TYPE_BLOB: {
cql_blob_ref _Nullable nullable_blob_ref = va_arg(*args, cql_blob_ref);
if (!nullable_blob_ref) {
*prc = sqlite3_bind_null(*pstmt, column);
}
else {
const void *bytes = cql_get_blob_bytes(nullable_blob_ref);
cql_uint32 size = cql_get_blob_size(nullable_blob_ref);
*prc = sqlite3_bind_blob(*pstmt, column, bytes, size, SQLITE_TRANSIENT);
}
column++;
break;
}
case CQL_DATA_TYPE_OBJECT: {
cql_object_ref _Nullable nullable_obj_ref = va_arg(*args, cql_object_ref);
*prc = sqlite3_bind_int64(*pstmt, column, (int64_t)nullable_obj_ref);
column++;
break;
}
}
}
cql_finalize_on_error(*prc, pstmt);
}
}