* Try to connect to the appropriate maintenance database. * * This differs from connectDatabase only in that it has a rule for * inserting a default "dbname" if none was given (which is why cparams * is not const). Note that cparams->dbname should typically come from * a --maintenance-db command line parameter. */
| 136 | * a --maintenance-db command line parameter. |
| 137 | */ |
| 138 | PGconn * |
| 139 | connectMaintenanceDatabase(ConnParams *cparams, |
| 140 | const char *progname, bool echo) |
| 141 | { |
| 142 | PGconn *conn; |
| 143 | |
| 144 | /* If a maintenance database name was specified, just connect to it. */ |
| 145 | if (cparams->dbname) |
| 146 | return connectDatabase(cparams, progname, echo, false, false); |
| 147 | |
| 148 | /* Otherwise, try postgres first and then template1. */ |
| 149 | cparams->dbname = "postgres"; |
| 150 | conn = connectDatabase(cparams, progname, echo, true, false); |
| 151 | if (!conn) |
| 152 | { |
| 153 | cparams->dbname = "template1"; |
| 154 | conn = connectDatabase(cparams, progname, echo, false, false); |
| 155 | } |
| 156 | return conn; |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * Disconnect the given connection, canceling any statement if one is active. |
no test coverage detected