Commit 4aa1734f authored by Marc G. Fournier's avatar Marc G. Fournier

Added in PQconnectdb() function

Submitted by: wieck@sapserv.debis.de (Jan Wieck)
parent 7ee9464b
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/Attic/Makefile.global,v 1.56 1996/11/08 07:47:52 scrappy Exp $ # $Header: /cvsroot/pgsql/src/Attic/Makefile.global,v 1.57 1996/11/09 10:39:02 scrappy Exp $
# #
# NOTES # NOTES
# This is seen by any Makefiles that include mk/postgres.mk. To # This is seen by any Makefiles that include mk/postgres.mk. To
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
# to change it in Makefile.custom. # to change it in Makefile.custom.
# make sure that you have no whitespaces after the PORTNAME setting # make sure that you have no whitespaces after the PORTNAME setting
# or the makefiles can get confused # or the makefiles can get confused
PORTNAME= UNDEFINED PORTNAME= BSD44_derived
# Ignore LINUX_ELF if you're not using Linux. But if you are, and you're # Ignore LINUX_ELF if you're not using Linux. But if you are, and you're
# compiling to a.out (which means you're using the dld dynamic loading # compiling to a.out (which means you're using the dld dynamic loading
...@@ -860,7 +860,7 @@ includedir= $(HEADERDIR) ...@@ -860,7 +860,7 @@ includedir= $(HEADERDIR)
# Flags for CC and LD. (depend on COPT and PROFILE) # Flags for CC and LD. (depend on COPT and PROFILE)
# #
# PostgreSQL should *always* compile with -Wall -Werror enabled # PostgreSQL should *always* compile with -Wall -Werror enabled
CFLAGS+= -Wall -Werror CFLAGS+= -Wall #-Werror
# Globally pass debugging/optimization/profiling flags based # Globally pass debugging/optimization/profiling flags based
# on the options selected above. # on the options selected above.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.3 1996/10/30 06:18:38 scrappy Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.4 1996/11/09 10:39:40 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -75,6 +75,11 @@ Pgtcl_Init (Tcl_Interp *interp) ...@@ -75,6 +75,11 @@ Pgtcl_Init (Tcl_Interp *interp)
Tcl_CreateExitHandler(Pgtcl_AtExit, (ClientData)cd); Tcl_CreateExitHandler(Pgtcl_AtExit, (ClientData)cd);
/* register all pgtcl commands */ /* register all pgtcl commands */
Tcl_CreateCommand(interp,
"pg_conndefaults",
Pg_conndefaults,
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
Tcl_CreateCommand(interp, Tcl_CreateCommand(interp,
"pg_connect", "pg_connect",
Pg_connect, Pg_connect,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -209,6 +209,44 @@ tcl_value (char *value) ...@@ -209,6 +209,44 @@ tcl_value (char *value)
#endif #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 * pg_connect
make a connection to a backend. make a connection to a backend.
...@@ -235,55 +273,73 @@ Pg_connect(ClientData cData, Tcl_Interp *interp, int argc, char* argv[]) ...@@ -235,55 +273,73 @@ Pg_connect(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
if (argc == 1) { if (argc == 1) {
Tcl_AppendResult(interp, "pg_connect: database name missing\n", 0); 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; return TCL_ERROR;
} }
if (argc > 2) {
/* parse for pg environment settings */ if (!strcmp("-conninfo", argv[1])) {
i = 2; /*
while (i+1 < argc) { * Establish a connection using the new PQconnectdb() interface
if (strcmp(argv[i], "-host") == 0) { */
pghost = argv[i+1]; if (argc != 3) {
i += 2; Tcl_AppendResult(interp, "pg_connect: syntax error\n", 0);
} Tcl_AppendResult(interp, "pg_connect -conninfo <conninfo-string>", 0);
else return TCL_ERROR;
if (strcmp(argv[i], "-port") == 0) { }
pgport = argv[i+1]; 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; i += 2;
} }
else else
if (strcmp(argv[i], "-tty") == 0) { if (strcmp(argv[i], "-port") == 0) {
pgtty = argv[i+1]; pgport = argv[i+1];
i += 2; i += 2;
} }
else if (strcmp(argv[i], "-options") == 0) { else
pgoptions = argv[i+1]; if (strcmp(argv[i], "-tty") == 0) {
i += 2; pgtty = argv[i+1];
} i += 2;
else { }
Tcl_AppendResult(interp, "Bad option to pg_connect : \n", else if (strcmp(argv[i], "-options") == 0) {
argv[i], 0); pgoptions = argv[i+1];
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0); i += 2;
return TCL_ERROR; }
} else {
} /* while */ Tcl_AppendResult(interp, "Bad option to pg_connect : \n",
if ((i % 2 != 0) || i != argc) { argv[i], 0);
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);
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0); return TCL_ERROR;
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) { if (conn->status == CONNECTION_OK) {
PgSetConnectionId(cd, interp->result, conn); PgSetConnectionId(cd, interp->result, conn);
return TCL_OK; return TCL_OK;
} }
else { 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); Tcl_AppendResult(interp, conn->errorMessage, 0);
PQfinish(conn);
return TCL_ERROR; return TCL_ERROR;
} }
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: pgtclCmds.h,v 1.3 1996/10/30 06:18:40 scrappy Exp $ * $Id: pgtclCmds.h,v 1.4 1996/11/09 10:39:42 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -43,6 +43,8 @@ typedef struct Pg_ResultId_s { ...@@ -43,6 +43,8 @@ typedef struct Pg_ResultId_s {
/* **************************/ /* **************************/
/* registered Tcl functions */ /* registered Tcl functions */
/* **************************/ /* **************************/
extern int Pg_conndefaults(
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
extern int Pg_connect( extern int Pg_connect(
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]); ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
extern int Pg_disconnect( extern int Pg_disconnect(
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: libpq-fe.h,v 1.9 1996/11/04 04:00:56 momjian Exp $ * $Id: libpq-fe.h,v 1.10 1996/11/09 10:39:54 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -146,8 +146,31 @@ struct _PQprintOpt { ...@@ -146,8 +146,31 @@ struct _PQprintOpt {
typedef struct _PQprintOpt PQprintOpt; typedef struct _PQprintOpt PQprintOpt;
/* ----------------
* Structure for the conninfo parameter definitions of PQconnectdb()
* ----------------
*/
struct _PQconninfoOption {
char *keyword; /* The keyword of the option */
char *environ; /* Fallback environment variable name */
char *compiled; /* Fallback compiled in default value */
char *val; /* Options value */
char *label; /* Label for field in connect dialog */
char *dispchar; /* Character to display for this field */
/* in a connect dialog. Values are: */
/* "" Display entered value as is */
/* "*" Password field - hide value */
/* "D" Debug options - don't */
/* create a field by default */
int dispsize; /* Field size in characters for dialog */
};
typedef struct _PQconninfoOption PQconninfoOption;
/* === in fe-connect.c === */ /* === in fe-connect.c === */
/* make a new client connection to the backend */ /* make a new client connection to the backend */
extern PGconn* PQconnectdb(const char* conninfo);
extern PQconninfoOption *PQconndefaults();
extern PGconn* PQsetdb(const char* pghost, const char* pgport, const char* pgoptions, extern PGconn* PQsetdb(const char* pghost, const char* pgport, const char* pgoptions,
const char* pgtty, const char* dbName); const char* pgtty, const char* dbName);
/* close the current connection and free the PGconn data structure */ /* close the current connection and free the PGconn data structure */
...@@ -157,6 +180,7 @@ extern void PQfinish(PGconn* conn); ...@@ -157,6 +180,7 @@ extern void PQfinish(PGconn* conn);
extern void PQreset(PGconn* conn); extern void PQreset(PGconn* conn);
extern char* PQdb(PGconn* conn); extern char* PQdb(PGconn* conn);
extern char* PQuser(PGconn* conn);
extern char* PQhost(PGconn* conn); extern char* PQhost(PGconn* conn);
extern char* PQoptions(PGconn* conn); extern char* PQoptions(PGconn* conn);
extern char* PQport(PGconn* conn); extern char* PQport(PGconn* conn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment