summaryrefslogtreecommitdiff
path: root/src/interfaces/libpgtcl/pgtclCmds.c
diff options
context:
space:
mode:
authorMarc G. Fournier <scrappy@hub.org>1996-11-09 10:39:54 +0000
committerMarc G. Fournier <scrappy@hub.org>1996-11-09 10:39:54 +0000
commit4aa1734f3642a5a7c5e1156892f72dcc4c55645a (patch)
treeddd364767d558473b8bd7b8a3b73bbdade5d98ef /src/interfaces/libpgtcl/pgtclCmds.c
parent7ee9464bc1c545031fe968d3dc0e23636deb8034 (diff)
downloadpostgresql-4aa1734f3642a5a7c5e1156892f72dcc4c55645a.tar.gz
Added in PQconnectdb() function
Submitted by: wieck@sapserv.debis.de (Jan Wieck)
Diffstat (limited to 'src/interfaces/libpgtcl/pgtclCmds.c')
-rw-r--r--src/interfaces/libpgtcl/pgtclCmds.c122
1 files changed, 89 insertions, 33 deletions
diff --git a/src/interfaces/libpgtcl/pgtclCmds.c b/src/interfaces/libpgtcl/pgtclCmds.c
index 91be2bd37f..397bcd15f7 100644
--- a/src/interfaces/libpgtcl/pgtclCmds.c
+++ b/src/interfaces/libpgtcl/pgtclCmds.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.5 1996/10/30 06:18:39 scrappy Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.6 1996/11/09 10:39:41 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -210,6 +210,44 @@ tcl_value (char *value)
#endif
/**********************************
+ * pg_conndefaults
+
+ syntax:
+ pg_conndefaults
+
+ the return result is a list describing the possible options and their
+ current default values for a call to pg_connect with the new -conninfo
+ syntax. Each entry in the list is a sublist of the format:
+
+ {optname label dispchar dispsize value}
+
+ **********************************/
+
+int
+Pg_conndefaults(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
+{
+ PQconninfoOption *option;
+ char buf[8192];
+
+ Tcl_ResetResult(interp);
+ for(option = PQconndefaults(); option->keyword != NULL; option++) {
+ if(option->val == NULL) {
+ option->val = "";
+ }
+ sprintf(buf, "{%s} {%s} {%s} %d {%s}",
+ option->keyword,
+ option->label,
+ option->dispchar,
+ option->dispsize,
+ option->val);
+ Tcl_AppendElement(interp, buf);
+ }
+
+ return TCL_OK;
+}
+
+
+/**********************************
* pg_connect
make a connection to a backend.
@@ -235,55 +273,73 @@ Pg_connect(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
if (argc == 1) {
Tcl_AppendResult(interp, "pg_connect: database name missing\n", 0);
- Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]", 0);
+ Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]\n", 0);
+ Tcl_AppendResult(interp, "pg_connect -conninfo <conninfo-string>", 0);
return TCL_ERROR;
}
- if (argc > 2) {
- /* parse for pg environment settings */
- i = 2;
- while (i+1 < argc) {
- if (strcmp(argv[i], "-host") == 0) {
- pghost = argv[i+1];
- i += 2;
- }
- else
- if (strcmp(argv[i], "-port") == 0) {
- pgport = argv[i+1];
+
+ if (!strcmp("-conninfo", argv[1])) {
+ /*
+ * Establish a connection using the new PQconnectdb() interface
+ */
+ if (argc != 3) {
+ Tcl_AppendResult(interp, "pg_connect: syntax error\n", 0);
+ Tcl_AppendResult(interp, "pg_connect -conninfo <conninfo-string>", 0);
+ return TCL_ERROR;
+ }
+ conn = PQconnectdb(argv[2]);
+ } else {
+ /*
+ * Establish a connection using the old PQsetdb() interface
+ */
+ if (argc > 2) {
+ /* parse for pg environment settings */
+ i = 2;
+ while (i+1 < argc) {
+ if (strcmp(argv[i], "-host") == 0) {
+ pghost = argv[i+1];
i += 2;
}
else
- if (strcmp(argv[i], "-tty") == 0) {
- pgtty = argv[i+1];
+ if (strcmp(argv[i], "-port") == 0) {
+ pgport = argv[i+1];
i += 2;
}
- else if (strcmp(argv[i], "-options") == 0) {
- pgoptions = argv[i+1];
- i += 2;
- }
- else {
- Tcl_AppendResult(interp, "Bad option to pg_connect : \n",
- argv[i], 0);
- Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
- return TCL_ERROR;
- }
- } /* while */
- if ((i % 2 != 0) || i != argc) {
- Tcl_AppendResult(interp, "wrong # of arguments to pg_connect\n", argv[i],0);
- Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
- return TCL_ERROR;
+ else
+ if (strcmp(argv[i], "-tty") == 0) {
+ pgtty = argv[i+1];
+ i += 2;
+ }
+ else if (strcmp(argv[i], "-options") == 0) {
+ pgoptions = argv[i+1];
+ i += 2;
+ }
+ else {
+ Tcl_AppendResult(interp, "Bad option to pg_connect : \n",
+ argv[i], 0);
+ Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
+ return TCL_ERROR;
+ }
+ } /* while */
+ if ((i % 2 != 0) || i != argc) {
+ Tcl_AppendResult(interp, "wrong # of arguments to pg_connect\n", argv[i],0);
+ Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
+ return TCL_ERROR;
+ }
}
+ dbName = argv[1];
+ conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
}
- dbName = argv[1];
- conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
if (conn->status == CONNECTION_OK) {
PgSetConnectionId(cd, interp->result, conn);
return TCL_OK;
}
else {
- Tcl_AppendResult(interp, "Connection to ", dbName, " failed\n", 0);
+ Tcl_AppendResult(interp, "Connection to database failed\n", 0);
Tcl_AppendResult(interp, conn->errorMessage, 0);
+ PQfinish(conn);
return TCL_ERROR;
}
}