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

Function run_statement

tools/cdb2sql/cdb2sql.cpp:1467–1696  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1465}
1466
1467static int run_statement(const char *sql, int ntypes, int *types,
1468 int *start_time, int *run_time)
1469{
1470 int rc;
1471 int ncols;
1472 int col;
1473 FILE *out = stdout;
1474 int startms = now_ms();
1475
1476 if (printmode & DISP_STDERR)
1477 out = stderr;
1478
1479 *start_time = 0;
1480 *run_time = 0;
1481
1482 if (cdb2h == NULL) {
1483 if (maxretries) {
1484 cdb2_set_max_retries(maxretries);
1485 }
1486 if (minretries) {
1487 cdb2_set_min_retries(minretries);
1488 }
1489
1490 verbose_print("calling cdb2_open\n");
1491
1492 int flags = 0;
1493 char *type = dbtype;
1494
1495 if (dbhostname) {
1496 flags |= CDB2_DIRECT_CPU;
1497 type = dbhostname;
1498 }
1499
1500 if (isadmin)
1501 flags |= CDB2_ADMIN;
1502
1503 rc = cdb2_open(&cdb2h, dbname, type, flags);
1504
1505 cdb2_push_context(cdb2h, "cdb2sql");
1506 if (rc) {
1507 fprintf(stderr, "cdb2_open rc %d %s\n", rc, cdb2_errstr(cdb2h));
1508 cdb2_close(cdb2h);
1509 cdb2h = NULL;
1510 return 1;
1511 }
1512
1513 if (connect_to_master) {
1514 rc = cdb2_run_statement(cdb2h, "SELECT host FROM comdb2_cluster WHERE is_master = 'Y'");
1515 if (rc != 0) {
1516 fprintf(stderr, "error retrieving master node rc %d %s\n", rc, cdb2_errstr(cdb2h));
1517 cdb2_close(cdb2h);
1518 cdb2h = NULL;
1519 return 1;
1520 }
1521
1522 rc = cdb2_next_record(cdb2h);
1523 if (rc != CDB2_OK) {
1524 fprintf(stderr, "error retrieving master node rc %d %s\n", rc, cdb2_errstr(cdb2h));

Callers 5

list_tablesFunction · 0.70
list_systablesFunction · 0.70
list_viewsFunction · 0.70
process_escapeFunction · 0.70
process_lineFunction · 0.70

Calls 15

now_msFunction · 0.85
cdb2_set_max_retriesFunction · 0.85
cdb2_set_min_retriesFunction · 0.85
cdb2_openFunction · 0.85
cdb2_push_contextFunction · 0.85
cdb2_errstrFunction · 0.85
cdb2_closeFunction · 0.85
cdb2_run_statementFunction · 0.85
cdb2_next_recordFunction · 0.85
cdb2_column_valueFunction · 0.85
freeFunction · 0.85
cdb2_set_debug_traceFunction · 0.85

Tested by

no test coverage detected