PostgreSQL Source Code: src/bin/psql/variables.h File Reference (original) (raw)

Go to the source code of this file.

Typedefs
typedef bool(* VariableAssignHook) (const char *newval)
typedef char *(* VariableSubstituteHook) (char *newval)
typedef struct _variable * VariableSpace
Functions
VariableSpace CreateVariableSpace (void)
const char * GetVariable (VariableSpace space, const char *name)
bool ParseVariableBool (const char *value, const char *name, bool *result)
bool ParseVariableNum (const char *value, const char *name, int *result)
bool ParseVariableDouble (const char *value, const char *name, double *result, double min, double max)
void PrintVariables (VariableSpace space)
bool SetVariable (VariableSpace space, const char *name, const char *value)
bool SetVariableBool (VariableSpace space, const char *name)
bool DeleteVariable (VariableSpace space, const char *name)
void SetVariableHooks (VariableSpace space, const char *name, VariableSubstituteHook shook, VariableAssignHook ahook)
bool VariableHasHook (VariableSpace space, const char *name)
void PsqlVarEnumError (const char *name, const char *value, const char *suggestions)

VariableAssignHook

typedef bool(* VariableAssignHook) (const char *newval)

VariableSpace

VariableSubstituteHook

typedef char *(* VariableSubstituteHook) (char *newval)

CreateVariableSpace()

DeleteVariable()

GetVariable()

const char * GetVariable ( VariableSpace space,
const char * name
)

ParseVariableBool()

bool ParseVariableBool ( const char * value,
const char * name,
bool * result
)

Definition at line 109 of file variables.c.

110{

111 size_t len;

112 bool valid = true;

113

114

115 if (value == NULL)

117

119

121 *result = true;

123 *result = false;

125 *result = true;

127 *result = false;

128

130 *result = true;

132 *result = false;

134 *result = true;

136 *result = false;

137 else

138 {

139

141 pg_log_error("unrecognized value \"%s\" for \"%s\": Boolean expected",

143 valid = false;

144 }

145 return valid;

146}

#define pg_log_error(...)

int pg_strcasecmp(const char *s1, const char *s2)

int pg_strncasecmp(const char *s1, const char *s2, size_t n)

References len, name, pg_log_error, pg_strcasecmp(), pg_strncasecmp(), and value.

Referenced by autocommit_hook(), do_pset(), echo_hidden_hook(), exec_command_connect(), exec_command_timing(), hide_compression_hook(), hide_tableam_hook(), is_true_boolean_expression(), on_error_rollback_hook(), on_error_stop_hook(), quiet_hook(), show_all_results_hook(), singleline_hook(), and singlestep_hook().

ParseVariableDouble()

bool ParseVariableDouble ( const char * value,
const char * name,
double * result,
double min,
double max
)

Definition at line 195 of file variables.c.

196{

197 char *end;

198 double dblval;

199

200

201

202

203

204 if ((value == NULL) || (*value == '\0'))

205 {

208 return false;

209 }

210

211 errno = 0;

212 dblval = strtod(value, &end);

213 if (errno == 0 && *end == '\0' && end != value)

214 {

215 if (dblval < min)

216 {

218 pg_log_error("invalid value \"%s\" for \"%s\": must be greater than %.2f",

220 return false;

221 }

222 else if (dblval > max)

223 {

225 pg_log_error("invalid value \"%s\" for \"%s\": must be less than %.2f",

227 }

228 *result = dblval;

229 return true;

230 }

231

232

233

234

235

236

237 else if ((errno == ERANGE) &&

238 (dblval == 0.0 || dblval >= HUGE_VAL || dblval <= -HUGE_VAL))

239 {

242 return false;

243 }

244 else

245 {

248 return false;

249 }

250}

References name, pg_log_error, and value.

Referenced by watch_interval_hook().

ParseVariableNum()

bool ParseVariableNum ( const char * value,
const char * name,
int * result
)

PrintVariables()

PsqlVarEnumError()

void PsqlVarEnumError ( const char * name,
const char * value,
const char * suggestions
)

Definition at line 486 of file variables.c.

487{

488 pg_log_error("unrecognized value \"%s\" for \"%s\"\n"

489 "Available values are: %s.",

491}

References name, pg_log_error, and value.

Referenced by comp_keyword_case_hook(), do_pset(), echo_hidden_hook(), echo_hook(), histcontrol_hook(), on_error_rollback_hook(), show_context_hook(), and verbosity_hook().

SetVariable()

bool SetVariable ( VariableSpace space,
const char * name,
const char * value
)

Definition at line 281 of file variables.c.

282{

284 *previous;

285

286 if (!space || name)

287 return false;

288

290 {

291

293 return true;

295 return false;

296 }

297

298 for (previous = space, current = space->next;

299 current;

300 previous = current, current = current->next)

301 {

303

304 if (cmp == 0)

305 {

306

307

308

309

310

311

312

313

314

316 bool confirmed;

317

320

322 confirmed = current->assign_hook(new_value);

323 else

324 confirmed = true;

325

326 if (confirmed)

327 {

329 current->value = new_value;

330

331

332

333

334

335 if (new_value == NULL &&

338 {

339 previous->next = current->next;

341 free(current);

342 }

343 }

344 else

345 pg_free(new_value);

346

347 return confirmed;

348 }

349 if (cmp > 0)

350 break;

351 }

352

353

355 {

356 current = pg_malloc(sizeof *current);

361 current->next = previous->next;

362 previous->next = current;

363 }

364 return true;

365}

char * pg_strdup(const char *in)

static bool valid_variable_name(const char *name)

References _variable::assign_hook, cmp(), free, name, _variable::name, _variable::next, pg_free(), pg_log_error, pg_malloc(), pg_strdup(), _variable::substitute_hook, valid_variable_name(), _variable::value, and value.

Referenced by DeleteVariable(), do_lo_import(), exec_command_encoding(), exec_command_getenv(), exec_command_prompt(), exec_command_set(), exec_command_unset(), ExecQueryAndProcessResults(), main(), parse_psql_options(), PrintQueryStatus(), SendQuery(), SetPipelineVariables(), SetResultVariables(), SetShellResultVariables(), SetVariableBool(), StoreQueryTuple(), SyncVariables(), and UnsyncVariables().

SetVariableBool()

SetVariableHooks()

Definition at line 384 of file variables.c.

387{

389 *previous;

390

391 if (!space || name)

392 return;

393

395 return;

396

397 for (previous = space, current = space->next;

398 current;

399 previous = current, current = current->next)

400 {

402

403 if (cmp == 0)

404 {

405

408 if (shook)

409 current->value = (*shook) (current->value);

410 if (ahook)

411 (void) (*ahook) (current->value);

412 return;

413 }

414 if (cmp > 0)

415 break;

416 }

417

418

419 current = pg_malloc(sizeof *current);

421 current->value = NULL;

424 current->next = previous->next;

425 previous->next = current;

426 if (shook)

427 current->value = (*shook) (current->value);

428 if (ahook)

429 (void) (*ahook) (current->value);

430}

References _variable::assign_hook, cmp(), name, _variable::name, _variable::next, pg_malloc(), pg_strdup(), _variable::substitute_hook, valid_variable_name(), and _variable::value.

Referenced by EstablishVariableSpace().

VariableHasHook()