* \c or \connect -- connect to database using the specified parameters. * * \c [-reuse-previous=BOOL] dbname user host port * * Specifying a parameter as '-' is equivalent to omitting it. Examples: * * \c - - hst Connect to current database on current port of * host "hst" as current user. * \c - usr - prt Connect to current database on port "prt" of current host * as user "usr".
| 485 | * as current user. |
| 486 | */ |
| 487 | static backslashResult |
| 488 | exec_command_connect(PsqlScanState scan_state, bool active_branch) |
| 489 | { |
| 490 | bool success = true; |
| 491 | |
| 492 | if (active_branch) |
| 493 | { |
| 494 | static const char prefix[] = "-reuse-previous="; |
| 495 | char *opt1, |
| 496 | *opt2, |
| 497 | *opt3, |
| 498 | *opt4; |
| 499 | enum trivalue reuse_previous = TRI_DEFAULT; |
| 500 | |
| 501 | opt1 = read_connect_arg(scan_state); |
| 502 | if (opt1 != NULL && strncmp(opt1, prefix, sizeof(prefix) - 1) == 0) |
| 503 | { |
| 504 | bool on_off; |
| 505 | |
| 506 | success = ParseVariableBool(opt1 + sizeof(prefix) - 1, |
| 507 | "-reuse-previous", |
| 508 | &on_off); |
| 509 | if (success) |
| 510 | { |
| 511 | reuse_previous = on_off ? TRI_YES : TRI_NO; |
| 512 | free(opt1); |
| 513 | opt1 = read_connect_arg(scan_state); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | if (success) /* give up if reuse_previous was invalid */ |
| 518 | { |
| 519 | opt2 = read_connect_arg(scan_state); |
| 520 | opt3 = read_connect_arg(scan_state); |
| 521 | opt4 = read_connect_arg(scan_state); |
| 522 | |
| 523 | success = do_connect(reuse_previous, opt1, opt2, opt3, opt4); |
| 524 | |
| 525 | free(opt2); |
| 526 | free(opt3); |
| 527 | free(opt4); |
| 528 | } |
| 529 | free(opt1); |
| 530 | } |
| 531 | else |
| 532 | ignore_slash_options(scan_state); |
| 533 | |
| 534 | return success ? PSQL_CMD_SKIP_LINE : PSQL_CMD_ERROR; |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * \cd -- change directory |
no test coverage detected