|
3 | 3 | *
|
4 | 4 | * Copyright (c) 2000-2010, PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.223 2010/07/20 14:14:30 rhaas Exp $ |
| 6 | + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.224 2010/07/23 14:56:54 rhaas Exp $ |
7 | 7 | */
|
8 | 8 | #include "postgres_fe.h"
|
9 | 9 | #include "command.h"
|
@@ -300,14 +300,23 @@ exec_command(const char *cmd,
|
300 | 300 | char *db = PQdb(pset.db);
|
301 | 301 | char *host = PQhost(pset.db);
|
302 | 302 |
|
303 |
| - if (!db) |
| 303 | + if (db == NULL) |
304 | 304 | printf("You are not connected.\n");
|
305 |
| - else if (host) |
306 |
| - printf("You are connected to database \"%s\" on host \"%s\" at port \"%s\" as user \"%s\".\n", |
307 |
| - db, host, PQport(pset.db), PQuser(pset.db)); |
308 | 305 | else
|
309 |
| - printf("You are connected to database \"%s\" via local socket at port \"%s\" as user \"%s\".\n", |
310 |
| - db, PQport(pset.db), PQuser(pset.db)); |
| 306 | + { |
| 307 | + if (host == NULL) |
| 308 | + host = DEFAULT_PGSOCKET_DIR; |
| 309 | + /* |
| 310 | + * If the host is an absolute path, the connection is via local |
| 311 | + * socket. |
| 312 | + */ |
| 313 | + if (is_absolute_path(host)) |
| 314 | + printf("You are connected to database \"%s\" via local socket in \"%s\" at port \"%s\" as user \"%s\".\n", |
| 315 | + db, host, PQport(pset.db), PQuser(pset.db)); |
| 316 | + else |
| 317 | + printf("You are connected to database \"%s\" on host \"%s\" at port \"%s\" as user \"%s\".\n", |
| 318 | + db, host, PQport(pset.db), PQuser(pset.db)); |
| 319 | + } |
311 | 320 | }
|
312 | 321 |
|
313 | 322 | /* \copy */
|
@@ -1366,7 +1375,15 @@ do_connect(char *dbname, char *user, char *host, char *port)
|
1366 | 1375 | printf(_("You are now connected to database \"%s\""), PQdb(pset.db));
|
1367 | 1376 |
|
1368 | 1377 | if (param_is_newly_set(PQhost(o_conn), PQhost(pset.db)))
|
1369 |
| - printf(_(" on host \"%s\""), PQhost(pset.db)); |
| 1378 | + { |
| 1379 | + char *host = PQhost(pset.db); |
| 1380 | + |
| 1381 | + /* If the host is an absolute path, the connection is via local socket */ |
| 1382 | + if (is_absolute_path(host)) |
| 1383 | + printf(_(" via local socket in \"%s\""), host); |
| 1384 | + else |
| 1385 | + printf(_(" on host \"%s\""), host); |
| 1386 | + } |
1370 | 1387 |
|
1371 | 1388 | if (param_is_newly_set(PQport(o_conn), PQport(pset.db)))
|
1372 | 1389 | printf(_(" at port \"%s\""), PQport(pset.db));
|
|
0 commit comments