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

Function printCol

tools/cdb2_sqlreplay/cdb2_sqlreplay.cpp:398–498  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396}
397
398void printCol(FILE *f, cdb2_hndl_tp *hndl, void *val, int col, int printmode)
399{
400 int string_blobs = 1;
401 switch (cdb2_column_type(hndl, col)) {
402 case CDB2_INTEGER:
403 if (printmode == DEFAULT)
404 fprintf(f, "%s=%lld", cdb2_column_name(hndl, col),
405 *(long long *)val);
406 else
407 fprintf(f, "%lld", *(long long *)val);
408 break;
409 case CDB2_REAL:
410 if (printmode == DEFAULT)
411 fprintf(f, "%s=", cdb2_column_name(hndl, col));
412 fprintf(f, "%f", *(double *)val);
413 break;
414 case CDB2_CSTRING:
415 if (printmode == DEFAULT) {
416 fprintf(f, "%s=", cdb2_column_name(hndl, col));
417 dumpstring(f, (char *)val, 1, 0);
418 } else if (printmode & TABS)
419 dumpstring(f, (char *)val, 0, 0);
420 else
421 dumpstring(f, (char *)val, 1, 1);
422 break;
423 case CDB2_BLOB:
424 if (printmode == DEFAULT)
425 fprintf(f, "%s=", cdb2_column_name(hndl, col));
426 if (string_blobs) {
427 char *c = (char*) val;
428 int len = cdb2_column_size(hndl, col);
429 fputc('\'', stdout);
430 while (len > 0) {
431 if (isprint(*c) || *c == '\n' || *c == '\t') {
432 fputc(*c, stdout);
433 } else {
434 fprintf(f, "\\x%02x", (int)*c);
435 }
436 len--;
437 c++;
438 }
439 fputc('\'', stdout);
440 } else {
441 if (printmode == BINARY) {
442 int rc = write(1, val, cdb2_column_size(hndl, col));
443 exit(0);
444 } else {
445 fprintf(f, "x'");
446 hexdump(f, val, cdb2_column_size(hndl, col));
447 fprintf(f, "'");
448 }
449 }
450 break;
451 case CDB2_DATETIME: {
452 cdb2_client_datetime_t *cdt = (cdb2_client_datetime_t *)val;
453 if (printmode == DEFAULT)
454 fprintf(f, "%s=", cdb2_column_name(hndl, col));
455 fprintf(f, "\"%4.4u-%2.2u-%2.2uT%2.2u%2.2u%2.2u.%3.3u %s\"",

Callers 1

replayFunction · 0.70

Calls 6

cdb2_column_typeFunction · 0.85
cdb2_column_nameFunction · 0.85
cdb2_column_sizeFunction · 0.85
exitFunction · 0.85
dumpstringFunction · 0.70
hexdumpFunction · 0.70

Tested by

no test coverage detected