| 535 | } |
| 536 | |
| 537 | void dump_param(cson_value *param) { |
| 538 | char *name; |
| 539 | char *type; |
| 540 | |
| 541 | cson_object *obj; |
| 542 | cson_value_fetch_object(param, &obj); |
| 543 | |
| 544 | cson_value *nameval = cson_object_get(obj, "name"); |
| 545 | if (nameval == nullptr) |
| 546 | return; |
| 547 | name = (char*) cson_value_get_string(nameval); |
| 548 | |
| 549 | cson_value *typeval = cson_object_get(obj, "type"); |
| 550 | if (typeval == nullptr) |
| 551 | return; |
| 552 | type = cson_value_get_string(typeval); |
| 553 | |
| 554 | cson_value *val = cson_object_get(obj, "value"); |
| 555 | if (val == nullptr) |
| 556 | return; |
| 557 | |
| 558 | #define typecheck(type) \ |
| 559 | do { \ |
| 560 | if (!cson_value_is_##type(val)) { \ |
| 561 | fprintf(stderr, ">Unexpected type for param %s\n", name); \ |
| 562 | return; \ |
| 563 | } \ |
| 564 | } while(0) |
| 565 | |
| 566 | if (strcmp(type, "largeint") == 0) { |
| 567 | typecheck(integer); |
| 568 | printf("@bind CDB2_INTEGER %s %" PRId64"\n", name, (int64_t) cson_value_get_integer(val)); |
| 569 | } |
| 570 | else if (strcmp(type, "doublefloat") == 0) { |
| 571 | typecheck(double); |
| 572 | printf("@bind CDB2_REAL %s %f\n", name, cson_value_get_double(val)); |
| 573 | } |
| 574 | else if (strcmp(type, "char") == 0) { |
| 575 | typecheck(string); |
| 576 | printf("@bind CDB2_CSTRING %s %s\n", name, (char*) cson_value_get_string(val)); |
| 577 | } |
| 578 | else if (strcmp(type, "blob") == 0) { |
| 579 | typecheck(string); |
| 580 | printf("@bind CDB2_BLOB %s %s\n", name, (char*) cson_value_get_string(val)); |
| 581 | } |
| 582 | else if (strcmp(type, "datetime") == 0) { |
| 583 | typecheck(string); |
| 584 | printf("@bind CDB2_DATETIME %s %s\n", name, (char*) cson_value_get_string(val)); |
| 585 | } |
| 586 | else if (strcmp(type, "datetimeus") == 0) { |
| 587 | typecheck(string); |
| 588 | printf("@bind CDB2_DATETIMEUS %s %s\n", name, (char*) cson_value_get_string(val)); |
| 589 | } |
| 590 | else { |
| 591 | fprintf(stderr, ">Unknown bound_parameters type %s\n", type); |
| 592 | } |
| 593 | } |
| 594 |
no test coverage detected