mirror of https://github.com/postgres/postgres
It is my hope that the following "patches" to libpgtcl get included in the next release. See the update to the README file to get a full description of the changes. This version of libpgtcl is completely interpreter-safe, implements the database connection handle as a channel (no events yet, but will make it a lot easier to do fileevents on it in the future), and supports the SQL "copy table to stdout" and "copy table from stdin" commands, with the I/O being from and to the connection handle. The connection and result handles are formatted in a way to make access to the tables more efficient.REL6_4
parent
609026bb6b
commit
6ac2528616
@ -1,6 +1,38 @@ |
||||
libpgtcl is a library that implements Tcl commands for front-end clients |
||||
to interact with the PostgreSQL backend. See libpgtcl.doc for details. |
||||
|
||||
libpgtcl is a library that implements Tcl commands for front-end |
||||
clients to interact with the Postgresql 6.3 (and perhaps later) |
||||
backends. See libpgtcl.doc for details. |
||||
|
||||
For an example of how to build a new tclsh to use libpgtcl, see the |
||||
directory ../bin/pgtclsh |
||||
|
||||
Note this version is modified by NeoSoft to have the following additional |
||||
features: |
||||
|
||||
1. Postgres connections are a valid Tcl channel, and can therefore |
||||
be manipulated by the interp command (ie. shared or transfered). |
||||
A connection handle's results are transfered/shared with it. |
||||
(Result handles are NOT channels, though it was tempting). Note |
||||
that a "close $connection" is now functionally identical to a |
||||
"pg_disconnect $connection", although pg_connect must be used |
||||
to create a connection. |
||||
|
||||
2. Result handles are changed in format: ${connection}.<result#>. |
||||
This just means for a connection 'pgtcl0', they look like pgtcl0.0, |
||||
pgtcl0.1, etc. Enforcing this syntax makes it easy to look up |
||||
the real pointer by indexing into an array associated with the |
||||
connection. |
||||
|
||||
3. I/O routines are now defined for the connection handle. I/O to/from |
||||
the connection is only valid under certain circumstances: following |
||||
the execution of the queries "copy <table> from stdin" or |
||||
"copy <table> to stdout". In these cases, the result handle obtains |
||||
an intermediate status of "PGRES_COPY_IN" or "PGRES_COPY_OUT". The |
||||
programmer is then expected to use Tcl gets or read commands on the |
||||
database connection (not the result handle) to extract the copy data. |
||||
For copy outs, read until the standard EOF indication is encountered. |
||||
For copy ins, puts a single terminator (\.). The statement for this |
||||
would be |
||||
puts $conn "\\." or puts $conn {\.} |
||||
In either case (upon detecting the EOF or putting the `\.', the status |
||||
of the result handle will change to "PGRES_COMMAND_OK", and any further |
||||
I/O attempts will cause a Tcl error. |
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,22 +1,47 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pgtclId.h-- |
||||
* useful routines to convert between strings and pointers |
||||
* Needed because everything in tcl is a string, but often, pointers |
||||
* to data structures are needed. |
||||
* |
||||
* |
||||
* Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* $Id: pgtclId.h,v 1.5 1997/09/08 21:55:26 momjian Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
* |
||||
* pgtclId.h-- |
||||
* useful routines to convert between strings and pointers |
||||
* Needed because everything in tcl is a string, but often, pointers |
||||
* to data structures are needed. |
||||
*
|
||||
* |
||||
* Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* $Id: pgtclId.h,v 1.6 1998/03/15 08:03:00 scrappy Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
extern void PgSetConnectionId(Tcl_Interp *interp, PGconn *conn); |
||||
|
||||
extern void PgSetConnectionId(Pg_clientData * cd, char *id, PGconn *conn); |
||||
extern PGconn *PgGetConnectionId(Pg_clientData * cd, char *id); |
||||
extern void PgDelConnectionId(Pg_clientData * cd, char *id); |
||||
extern void PgSetResultId(Pg_clientData * cd, char *id, char *connid, PGresult *res); |
||||
extern PGresult *PgGetResultId(Pg_clientData * cd, char *id); |
||||
extern void PgDelResultId(Pg_clientData * cd, char *id); |
||||
extern void PgGetConnByResultId(Pg_clientData * cd, char *id, char *resid); |
||||
#if (TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION == 5) |
||||
# define DRIVER_DEL_PROTO ClientData cData, Tcl_Interp *interp, \ |
||||
Tcl_File inFile, Tcl_File outFile |
||||
# define DRIVER_OUTPUT_PROTO ClientData cData, Tcl_File outFile, char *buf, \ |
||||
int bufSize, int *errorCodePtr |
||||
# define DRIVER_INPUT_PROTO ClientData cData, Tcl_File inFile, char *buf, \ |
||||
int bufSize, int *errorCodePtr |
||||
#else |
||||
# define DRIVER_OUTPUT_PROTO ClientData cData, char *buf, int bufSize, \ |
||||
int *errorCodePtr |
||||
# define DRIVER_INPUT_PROTO ClientData cData, char *buf, int bufSize, \ |
||||
int *errorCodePtr |
||||
# define DRIVER_DEL_PROTO ClientData cData, Tcl_Interp *interp |
||||
#endif |
||||
|
||||
extern PGconn *PgGetConnectionId(Tcl_Interp *interp, char *id, \
|
||||
Pg_ConnectionId **); |
||||
extern PgDelConnectionId(DRIVER_DEL_PROTO); |
||||
extern int PgOutputProc(DRIVER_OUTPUT_PROTO); |
||||
extern PgInputProc(DRIVER_INPUT_PROTO); |
||||
extern int PgSetResultId(Tcl_Interp *interp, char *connid, PGresult *res); |
||||
extern PGresult *PgGetResultId(Tcl_Interp *interp, char *id); |
||||
extern void PgDelResultId(Tcl_Interp *interp, char *id); |
||||
extern int PgGetConnByResultId(Tcl_Interp *interp, char *resid); |
||||
|
||||
#if (TCL_MAJOR_VERSION < 8) |
||||
extern Tcl_File PgGetFileProc(ClientData cData, int direction); |
||||
#endif |
||||
|
||||
extern Tcl_ChannelType Pg_ConnType; |
||||
|
||||
Loading…
Reference in new issue