MCPcopy Create free account
hub / github.com/apache/cloudberry / getVariable

Function getVariable

src/bin/pgbench/pgbench.c:1461–1491  ·  view source on GitHub ↗

Get the value of a variable, in string form; returns NULL if unknown */

Source from the content-addressed store, hash-verified

1459
1460/* Get the value of a variable, in string form; returns NULL if unknown */
1461static char *
1462getVariable(CState *st, char *name)
1463{
1464 Variable *var;
1465 char stringform[64];
1466
1467 var = lookupVariable(st, name);
1468 if (var == NULL)
1469 return NULL; /* not found */
1470
1471 if (var->svalue)
1472 return var->svalue; /* we have it in string form */
1473
1474 /* We need to produce a string equivalent of the value */
1475 Assert(var->value.type != PGBT_NO_VALUE);
1476 if (var->value.type == PGBT_NULL)
1477 snprintf(stringform, sizeof(stringform), "NULL");
1478 else if (var->value.type == PGBT_BOOLEAN)
1479 snprintf(stringform, sizeof(stringform),
1480 "%s", var->value.u.bval ? "true" : "false");
1481 else if (var->value.type == PGBT_INT)
1482 snprintf(stringform, sizeof(stringform),
1483 INT64_FORMAT, var->value.u.ival);
1484 else if (var->value.type == PGBT_DOUBLE)
1485 snprintf(stringform, sizeof(stringform),
1486 "%.*g", DBL_DIG, var->value.u.dval);
1487 else /* internal error, unexpected type */
1488 Assert(0);
1489 var->svalue = pg_strdup(stringform);
1490 return var->svalue;
1491}
1492
1493/* Try to convert variable to a value; return false on failure */
1494static bool

Callers 4

assignVariablesFunction · 0.85
getQueryParamsFunction · 0.85
runShellCommandFunction · 0.85
evaluateSleepFunction · 0.85

Calls 2

lookupVariableFunction · 0.85
pg_strdupFunction · 0.85

Tested by

no test coverage detected