Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4aa1734

Browse files
committed
Added in PQconnectdb() function
Submitted by: wieck@sapserv.debis.de (Jan Wieck)
1 parent 7ee9464 commit 4aa1734

File tree

6 files changed

+549
-41
lines changed

6 files changed

+549
-41
lines changed

src/Makefile.global

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/Attic/Makefile.global,v 1.56 1996/11/08 07:47:52 scrappy Exp $
10+
# $Header: /cvsroot/pgsql/src/Attic/Makefile.global,v 1.57 1996/11/09 10:39:02 scrappy Exp $
1111
#
1212
# NOTES
1313
# This is seen by any Makefiles that include mk/postgres.mk. To
@@ -59,7 +59,7 @@
5959
# to change it in Makefile.custom.
6060
# make sure that you have no whitespaces after the PORTNAME setting
6161
# or the makefiles can get confused
62-
PORTNAME= UNDEFINED
62+
PORTNAME= BSD44_derived
6363

6464
# Ignore LINUX_ELF if you're not using Linux. But if you are, and you're
6565
# compiling to a.out (which means you're using the dld dynamic loading
@@ -860,7 +860,7 @@ includedir= $(HEADERDIR)
860860
# Flags for CC and LD. (depend on COPT and PROFILE)
861861
#
862862
# PostgreSQL should *always* compile with -Wall -Werror enabled
863-
CFLAGS+= -Wall -Werror
863+
CFLAGS+= -Wall #-Werror
864864

865865
# Globally pass debugging/optimization/profiling flags based
866866
# on the options selected above.

src/interfaces/libpgtcl/pgtcl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.3 1996/10/30 06:18:38 scrappy Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.4 1996/11/09 10:39:40 scrappy Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -75,6 +75,11 @@ Pgtcl_Init (Tcl_Interp *interp)
7575
Tcl_CreateExitHandler(Pgtcl_AtExit, (ClientData)cd);
7676

7777
/* register all pgtcl commands */
78+
Tcl_CreateCommand(interp,
79+
"pg_conndefaults",
80+
Pg_conndefaults,
81+
(ClientData)cd, (Tcl_CmdDeleteProc*)NULL);
82+
7883
Tcl_CreateCommand(interp,
7984
"pg_connect",
8085
Pg_connect,

src/interfaces/libpgtcl/pgtclCmds.c

Lines changed: 89 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.5 1996/10/30 06:18:39 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.6 1996/11/09 10:39:41 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -209,6 +209,44 @@ tcl_value (char *value)
209209

210210
#endif
211211

212+
/**********************************
213+
* pg_conndefaults
214+
215+
syntax:
216+
pg_conndefaults
217+
218+
the return result is a list describing the possible options and their
219+
current default values for a call to pg_connect with the new -conninfo
220+
syntax. Each entry in the list is a sublist of the format:
221+
222+
{optname label dispchar dispsize value}
223+
224+
**********************************/
225+
226+
int
227+
Pg_conndefaults(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
228+
{
229+
PQconninfoOption *option;
230+
char buf[8192];
231+
232+
Tcl_ResetResult(interp);
233+
for(option = PQconndefaults(); option->keyword != NULL; option++) {
234+
if(option->val == NULL) {
235+
option->val = "";
236+
}
237+
sprintf(buf, "{%s} {%s} {%s} %d {%s}",
238+
option->keyword,
239+
option->label,
240+
option->dispchar,
241+
option->dispsize,
242+
option->val);
243+
Tcl_AppendElement(interp, buf);
244+
}
245+
246+
return TCL_OK;
247+
}
248+
249+
212250
/**********************************
213251
* pg_connect
214252
make a connection to a backend.
@@ -235,55 +273,73 @@ Pg_connect(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
235273

236274
if (argc == 1) {
237275
Tcl_AppendResult(interp, "pg_connect: database name missing\n", 0);
238-
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]", 0);
276+
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]\n", 0);
277+
Tcl_AppendResult(interp, "pg_connect -conninfo <conninfo-string>", 0);
239278
return TCL_ERROR;
240279

241280
}
242-
if (argc > 2) {
243-
/* parse for pg environment settings */
244-
i = 2;
245-
while (i+1 < argc) {
246-
if (strcmp(argv[i], "-host") == 0) {
247-
pghost = argv[i+1];
248-
i += 2;
249-
}
250-
else
251-
if (strcmp(argv[i], "-port") == 0) {
252-
pgport = argv[i+1];
281+
282+
if (!strcmp("-conninfo", argv[1])) {
283+
/*
284+
* Establish a connection using the new PQconnectdb() interface
285+
*/
286+
if (argc != 3) {
287+
Tcl_AppendResult(interp, "pg_connect: syntax error\n", 0);
288+
Tcl_AppendResult(interp, "pg_connect -conninfo <conninfo-string>", 0);
289+
return TCL_ERROR;
290+
}
291+
conn = PQconnectdb(argv[2]);
292+
} else {
293+
/*
294+
* Establish a connection using the old PQsetdb() interface
295+
*/
296+
if (argc > 2) {
297+
/* parse for pg environment settings */
298+
i = 2;
299+
while (i+1 < argc) {
300+
if (strcmp(argv[i], "-host") == 0) {
301+
pghost = argv[i+1];
253302
i += 2;
254303
}
255304
else
256-
if (strcmp(argv[i], "-tty") == 0) {
257-
pgtty = argv[i+1];
305+
if (strcmp(argv[i], "-port") == 0) {
306+
pgport = argv[i+1];
258307
i += 2;
259308
}
260-
else if (strcmp(argv[i], "-options") == 0) {
261-
pgoptions = argv[i+1];
262-
i += 2;
263-
}
264-
else {
265-
Tcl_AppendResult(interp, "Bad option to pg_connect : \n",
266-
argv[i], 0);
267-
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
268-
return TCL_ERROR;
269-
}
270-
} /* while */
271-
if ((i % 2 != 0) || i != argc) {
272-
Tcl_AppendResult(interp, "wrong # of arguments to pg_connect\n", argv[i],0);
273-
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
274-
return TCL_ERROR;
309+
else
310+
if (strcmp(argv[i], "-tty") == 0) {
311+
pgtty = argv[i+1];
312+
i += 2;
313+
}
314+
else if (strcmp(argv[i], "-options") == 0) {
315+
pgoptions = argv[i+1];
316+
i += 2;
317+
}
318+
else {
319+
Tcl_AppendResult(interp, "Bad option to pg_connect : \n",
320+
argv[i], 0);
321+
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
322+
return TCL_ERROR;
323+
}
324+
} /* while */
325+
if ((i % 2 != 0) || i != argc) {
326+
Tcl_AppendResult(interp, "wrong # of arguments to pg_connect\n", argv[i],0);
327+
Tcl_AppendResult(interp, "pg_connect databaseName [-host hostName] [-port portNumber] [-tty pgtty]]",0);
328+
return TCL_ERROR;
329+
}
275330
}
331+
dbName = argv[1];
332+
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
276333
}
277-
dbName = argv[1];
278334

279-
conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName);
280335
if (conn->status == CONNECTION_OK) {
281336
PgSetConnectionId(cd, interp->result, conn);
282337
return TCL_OK;
283338
}
284339
else {
285-
Tcl_AppendResult(interp, "Connection to ", dbName, " failed\n", 0);
340+
Tcl_AppendResult(interp, "Connection to database failed\n", 0);
286341
Tcl_AppendResult(interp, conn->errorMessage, 0);
342+
PQfinish(conn);
287343
return TCL_ERROR;
288344
}
289345
}

src/interfaces/libpgtcl/pgtclCmds.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: pgtclCmds.h,v 1.3 1996/10/30 06:18:40 scrappy Exp $
8+
* $Id: pgtclCmds.h,v 1.4 1996/11/09 10:39:42 scrappy Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -43,6 +43,8 @@ typedef struct Pg_ResultId_s {
4343
/* **************************/
4444
/* registered Tcl functions */
4545
/* **************************/
46+
extern int Pg_conndefaults(
47+
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
4648
extern int Pg_connect(
4749
ClientData cData, Tcl_Interp *interp, int argc, char* argv[]);
4850
extern int Pg_disconnect(

0 commit comments

Comments
 (0)