Debian Codegraph @

doc/PGTCL-NOTES

raw
1
2
3 Commands:
4
5 pg_conndefaults
6
7 pg_connect dbName [-host hostName] [-port portNumber] [-tty pqtty] ?-connhandle connHandleName?
8
9 The result is either an error message or a handle for a database
10 connection. Handles start with the prefix "pgp".
11
12 (DEPRECATED, use pg_connect -conninfo instead.)
13
14 pg_connect -conninfo conninfoString ?-connhandle connHandleName?
15
16 The modern way to connect, all necessary information required for
17 the connection (host, port, database, user, password, etc.) is
18 specified in the connect info string.
19
20 pg_connect -connlist name_value_list ?-connhandle connHandleName?
21 This was added to better suit Tcl style of data structures. You can set
22 an array with the connection info, such as:
23
24 array set myinfo {host myhost port 5000}
25
26 And then do:
27
28 pg_connect -connlist [array get myinfo]
29
30
31 pg_dbinfo connections
32 This returns the currect connection handles
33
34 pg_dbinfo results $conn
35 This returns the currect result handles for connection $conn
36
37 pg_disconnect $conn
38
39 Close a backend connection.
40
41 pg_exec $conn query
42
43 Send a query string to the backend connection.
44
45 The return result is either an error message or a handle for a query result.
46 Handles start with the prefix "pgp".
47
48
49 pg_select
50
51 send a select query string to the backend connection
52
53 syntax:
54 pg_select connection query var proc
55
56 The query must be a select statement
57 The var is used in the proc as an array
58 The proc is run once for each row found
59
60 example:
61
62 set conn [pg_connect www]
63
64 pg_select $conn "select * from users" user {
65 parray user
66 }
67
68 pg_disconnect $conn
69
70
71 You can "continue" and "return" in the body and it'll do the
72 expected thing.
73
74 pg_result
75
76 Get information about the results of a query.
77
78 pg_result result ?option?
79
80 the options are:
81
82 -status the status of the result
83
84 -error the error message, if the status indicates error;
85 otherwise an empty string
86
87 -conn the connection that produced the result
88
89 -oid if command was an INSERT, the OID of the inserted tuple
90
91 -numTuples the number of tuples in the query
92
93 -numAttrs returns the number of attributes returned by the query
94
95 -assign arrayName
96 assign the results to an array, using
97 subscripts of the form (tupno,attributeName)
98
99 -assignbyidx arrayName ?appendstr?
100 assign the results to an array using the first
101 field's value as a key.
102
103 All but the first field of each tuple are stored,
104 using subscripts of the form
105 (field0value,attributeNameappendstr)
106
107 -getTuple tupleNumber
108 returns the values of the tuple in a list
109
110 -tupleArray tupleNumber arrayName
111 stores the values of the tuple in array arrayName,
112 indexed by the attributes returned
113
114 -attributes returns a list of the name/type pairs of the tuple
115 attributes
116
117 -lAttributes returns a list of the {name type len} entries of the
118 tuple attributes
119
120 -list returns a list with the results
121
122 -llist returns a list of lists with the results
123
124 -dict returns a dict object with the results
125
126 -clear clear the result buffer. Do not reuse after this
127
128 -null_value_string ?value?
129 if value is specified or has been set via the connection's
130 pg_null_value_string, this string value is returned for
131 the various query styles when the corresponding row element
132 is NULL.
133
134
135 pg_results
136 returns a list of result handles for a particular connection
137
138 syntax:
139 pg_results connhandle
140
141 pg_execute
142
143 Send a query string to the backend connection and process the result.
144
145 syntax:
146 pg_execute ?-array name? ?-oid varname? connection query ?loop_body?
147
148 The return result is the number of tuples processed. If the query
149 returns tuples (i.e. a SELECT statement), the result is placed into
150 variables.
151
152
153 pg_lo_open
154
155 Open a large object
156
157 syntax:
158
159 pg_lo_open conn objOid mode
160
161 ...where mode can be either 'r', 'w', or 'rw'
162
163 pg_lo_close
164
165 close a large object
166
167 syntax:
168
169 pg_lo_close conn fd
170
171 pg_lo_read
172
173 reads at most len bytes from a large object into a variable named bufVar
174
175 syntax:
176
177 pg_lo_read conn fd bufVar len
178
179 bufVar is the name of a variable in which to start the contents of the read
180
181 pg_lo_write
182 write at most len bytes to a large object
183
184 pg_lo_write conn fd buf len
185
186 pg_lo_seek
187 seek to a certain position in a large object
188
189 syntax
190 pg_lo_seek conn fd offset whence
191
192 whence can be either
193 "SEEK_CUR", "SEEK_END", or "SEEK_SET"
194
195 pg_lo_creat
196
197 create a new large object with mode
198
199 syntax:
200 pg_lo_creat conn mode
201
202 mode can be any OR'ing together of INV_READ, INV_WRITE.
203 For now, we don't support any additional storage managers.
204
205 pg_lo_tell
206 returns the current seek location of the large object
207
208 syntax:
209 pg_lo_tell conn fd
210
211
212 pg_lo_creat
213
214 pg_lo_unlink
215 unlink a file based on lobject id
216
217 syntax:
218 pg_lo_unlink conn lobjId
219
220 pg_lo_import
221 import a UNIX file into an (inversion) large object
222 returns the oid of that object upon success
223 returns InvalidOid upon failure
224
225 syntax:
226 pg_lo_import conn filename
227
228 pg_lo_export
229 export an inversion large object to a UNIX file
230
231 syntax:
232 pg_lo_export conn lobjId filename
233
234
235 pg_listen
236 create or remove a callback request for notifies on a given name
237
238 syntax:
239 pg_listen conn notifyname ?callbackcommand?
240
241 With a fourth arg, creates or changes the callback command for
242 notifies on the given name; without, cancels the callback request.
243
244 Callbacks can occur whenever Tcl is executing its event loop.
245 This is the normal idle loop in Tk; in plain tclsh applications,
246 vwait or update can be used to enter the Tcl event loop.
247
248 pg_quote
249 quotes a string suitable for SQL statements to the backend
250
251 syntax:
252 pg_quote string
253
254 pg_escape_string
255 escapes a string suitable for SQL statements to the backend
256
257 syntax:
258 pg_escape_string string
259
260 pg_escape_bytea
261 escapes a binary string suitable for SQL statements to the backend
262
263 syntax:
264 pg_escape_bytea binaryString
265
266 pg_unescape_bytea
267 unescapes a binary string that was stored in the backend
268
269 syntax:
270 pg_unescape_bytea binaryString