pgtcl is a Tcl package for client programs to interface with Red Hat Database servers. It makes most of the functionality of libpq available to Tcl scripts.
Table 4-1. pgtcl Commands
Command | Description |
---|---|
pg_connect | Opens a connection to the backend server |
pg_disconnect | Closes a connection |
pg_conndefaults | Gets connection options and their defaults |
pg_exec | Sends a query to the backend |
pg_result | Manipulates the results of a query |
pg_select | Loops over the result of a SELECT statement |
pg_listen | Establishes a callback for NOTIFY messages |
pg_lo_creat | Creates a large object |
pg_lo_open | Opens a large object |
pg_lo_close | Closes a large object |
pg_lo_read | Reads a large object |
pg_lo_write | Writes a large object |
pg_lo_lseek | Seeks to a position in a large object |
pg_lo_tell | Returns the current seek position of a large object |
pg_lo_unlink | Deletes a large object |
pg_lo_import | Imports a Linux file into a large object |
pg_lo_export | Exports a large object into a Linux file |
The pg_lo* routines are interfaces to the Large Object features of Red Hat Database. The functions are designed to mimic the analogous file-system functions in the standard Unix file system interface. The pg_lo* routines should be used within a BEGIN/COMMIT transaction block because the file descriptor returned by pg_lo_open is valid only for the current transaction. pg_lo_import and pg_lo_export must be used in a BEGIN/COMMIT transaction block.
Here is a small example of how to use the routines:
# getDBs : # get the names of all the databases at a given host and port # number with the defaults being the localhost and port 5432 # return them in alphabetical order proc getDBs { {host "localhost"} {port "5432"} } { # datnames is the list to be result set conn [pg_connect template1 -host $host -port $port] set res [pg_exec $conn "SELECT datname FROM pg_database ORDER BY datname"] set ntups [pg_result $res -numTuples] for {set i 0} {$i < $ntups} {incr i} { lappend datnames [pg_result $res -getTuple $i] } pg_result $res -clear pg_disconnect $conn return $datnames } |