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

Function do_bindings

tools/cdb2_sqlreplay/cdb2_sqlreplay.cpp:228–337  ·  view source on GitHub ↗

TODO: add all types supported */

Source from the content-addressed store, hash-verified

226
227/* TODO: add all types supported */
228bool do_bindings(cdb2_hndl_tp *db, cson_value *event_val,
229 std::vector<uint8_t *> &blobs_vect)
230{
231 cson_array *bound_parameters = get_arrprop(event_val, "bound_parameters");
232 if(bound_parameters == nullptr)
233 return true;
234
235 unsigned int arr_len = cson_array_length_get(bound_parameters);
236 for (int i = 0; i < arr_len; i++) {
237 cson_value *bp = cson_array_get(bound_parameters, i);
238 const char *name = get_strprop(bp, "name");
239 const char *type = get_strprop(bp, "type");
240 int cdb2_type = 0;
241 int length = 0;
242 void *varaddr = NULL;
243 int ret;
244 if(get_ispropnull(bp, "value")) { /* bind null value as type INT for simplicity */
245 cdb2_type = CDB2_INTEGER;
246 varaddr = NULL;
247 length = 0;
248 if (verbose)
249 std::cout << "binding "<< type << " column " << name << " to NULL " << std::endl;
250 }
251 else if (strcmp(type, "largeint") == 0 || strcmp(type, "int") == 0 || strcmp(type, "smallint") == 0) {
252 int64_t *iv = (int64_t*) malloc(sizeof(int64_t));
253 bool succ = get_intprop(bp, "value", iv);
254 if (!succ) {
255 std::cerr << "Error getting " << type << " value of bound parameter " << name << std::endl;
256 return false;
257 }
258 cdb2_type = CDB2_INTEGER;
259 varaddr = iv;
260 length = sizeof(*iv);
261 if (verbose)
262 std::cout << "binding "<< type << " column " << name << " to value " << *iv << std::endl;
263 }
264 else if (strcmp(type, "float") == 0 || strcmp(type, "doublefloat") == 0) {
265 double *dv = (double*) malloc(sizeof(double));
266 bool succ = get_doubleprop(bp, "value", dv);
267 if (!succ) {
268 std::cerr << "Error getting " << type << " value of bound parameter " << name << std::endl;
269 return false;
270 }
271 cdb2_type = CDB2_REAL;
272 varaddr = dv;
273 length = sizeof(*dv);
274 if (verbose)
275 std::cout << "binding "<< type << " column " << name << " to value " << *dv << std::endl;
276 }
277 else if (strcmp(type, "char") == 0 || strcmp(type, "datetime") == 0 ||
278 strcmp(type, "datetimeus") == 0 || strcmp(type, "interval month") == 0 ||
279 strcmp(type, "interval sec") == 0 || strcmp(type, "interval usec") == 0
280 ) {
281 const char *strp = get_strprop(bp, "value");
282 if (strp == nullptr) {
283 std::cerr << "Error getting " << type << " value of bound parameter " << name << std::endl;
284 return false;
285 }

Callers 1

replayFunction · 0.85

Calls 12

get_arrpropFunction · 0.85
cson_array_length_getFunction · 0.85
cson_array_getFunction · 0.85
get_strpropFunction · 0.85
get_ispropnullFunction · 0.85
mallocFunction · 0.85
get_intpropFunction · 0.85
get_doublepropFunction · 0.85
cdb2_bind_indexFunction · 0.85
cdb2_bind_paramFunction · 0.85
fromhexFunction · 0.70
strdupFunction · 0.50

Tested by

no test coverage detected