From 68e190cfa4d3f121de310fbbad89b4f26fb9198f Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 7 Sep 2001 21:55:00 +0000 Subject: [PATCH] >has anyone ever successfully done copy to/from stdout with the >tcl-extension for postgreSQL. >I'm currently using 7.0 and always getting a seg fault when I try to >read from the database connection after issueing a "COPY table TO >stdout;" (I'm using the connection handle, *not* the result handle). >Maybe this is fixed in a later release. >The README file in src/interfaces/libpgtcl tells me, that this should >work, but unforunately it doesn't. Yes, it seems broken. It is a bug in libpgtcl. Are you running Tcl >= 8.3.2? That's when the Tcl team changed the data structure for channel callbacks. The change itself was designed to be backward compatible, but I suspect a related change made the code more sensitive to errors in the structure (NULL pointers where functions are required). Either that, or nobody has tried to use libpgtcl with COPY in a long time. First, I have to say I can't think of a good reason to use PostgreSQL's COPY command from a Tcl application. I think it should only be used with psql for importing data from another source into PostgreSQL, or for exporting PostgreSQL data into another database (but why would anyone do that?) If it was me, I would stick with SELECT and INSERT and be "SQL Compliant". OK, editorial is over. Try applying the patch below to fix src/interfaces/libpgtcl/pgtclId.c and let us know if it works. I did little testing on it, but my test did segfault before and ran fine (copy in and copy out) after the patch. This is for PostgreSQL-7.1.2 - since you are running older 7.0, I don't know if this will work, but I suspect it will. PS It's the absence of PgWatchProc which kills it. I didn't upgrade it to the "V2" channel type structure, so it should be compatible with older Tcl's. But aside from gets and puts, I doubt any other file operations would work on the handle during a copy. ljb --- src/interfaces/libpgtcl/pgtclId.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c index af58f66247..ef34c595a4 100644 --- a/src/interfaces/libpgtcl/pgtclId.c +++ b/src/interfaces/libpgtcl/pgtclId.c @@ -13,7 +13,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.26 2001/09/06 02:54:56 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.27 2001/09/07 21:55:00 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -138,17 +138,32 @@ PgGetFileProc(ClientData cData, int direction) #endif +/* + * The WatchProc and GetHandleProc are no-ops but must be present. + */ +static void +PgWatchProc(ClientData instanceData, int mask) +{ +} +static int +PgGetHandleProc(ClientData instanceData, int direction, + ClientData *handlePtr) +{ + return TCL_ERROR; +} + Tcl_ChannelType Pg_ConnType = { "pgsql", /* channel type */ NULL, /* blockmodeproc */ PgDelConnectionId, /* closeproc */ PgInputProc, /* inputproc */ PgOutputProc, /* outputproc */ - - /* - * Note the additional stuff can be left NULL, or is initialized - * during a PgSetConnectionId - */ + NULL, /* SeekProc, Not used */ + NULL, /* SetOptionProc, Not used */ + NULL, /* GetOptionProc, Not used */ + PgWatchProc, /* WatchProc, must be defined */ + PgGetHandleProc, /* GetHandleProc, must be defined */ + NULL /* Close2Proc, Not used */ }; /*