Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/tdbcpostgres1.1.5/tdbcpostgres.tcl @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 # tdbcpostgres.tcl -- | |
2 # | |
3 # Class definitions and Tcl-level methods for the tdbc::postgres bridge. | |
4 # | |
5 # Copyright (c) 2009 by Slawomir Cygan | |
6 # | |
7 # See the file "license.terms" for information on usage and redistribution | |
8 # of this file, and for a DISCLAIMER OF ALL WARRANTIES. | |
9 # | |
10 #------------------------------------------------------------------------------ | |
11 | |
12 package require tdbc | |
13 | |
14 ::namespace eval ::tdbc::mypostgres { | |
15 | |
16 namespace export connection datasources drivers | |
17 | |
18 } | |
19 | |
20 #------------------------------------------------------------------------------ | |
21 # | |
22 # tdbc::postgres::connection -- | |
23 # | |
24 # Class representing a connection to a Postgres database. | |
25 # | |
26 #------------------------------------------------------------------------------- | |
27 | |
28 ::oo::class create ::tdbc::postgres::connection { | |
29 | |
30 superclass ::tdbc::connection | |
31 | |
32 # The constructor is written in C. It takes alternating keywords | |
33 # and values pairs as its arguments. (See the manual page for the | |
34 # available options.) | |
35 | |
36 # The 'statementCreate' method delegates to the constructor of the | |
37 # statement class | |
38 | |
39 forward statementCreate ::tdbc::postgres::statement create | |
40 | |
41 | |
42 # The 'prepareCall' method gives a portable interface to prepare | |
43 # calls to stored procedures. It delegates to 'prepare' to do the | |
44 # actual work. | |
45 | |
46 method preparecall {call} { | |
47 regexp {^[[:space:]]*(?:([A-Za-z_][A-Za-z_0-9]*)[[:space:]]*=)?(.*)} \ | |
48 $call -> varName rest | |
49 if {$varName eq {}} { | |
50 my prepare \\{$rest\\} | |
51 } else { | |
52 my prepare \\{:$varName=$rest\\} | |
53 } | |
54 } | |
55 | |
56 # The 'init', 'begintransaction', 'commit, 'rollback', 'tables' | |
57 # and 'columns' methods are implemented in C. | |
58 | |
59 } | |
60 | |
61 #------------------------------------------------------------------------------ | |
62 # | |
63 # tdbc::postgres::statement -- | |
64 # | |
65 # The class 'tdbc::postgres::statement' models one statement against a | |
66 # database accessed through a Postgres connection | |
67 # | |
68 #------------------------------------------------------------------------------ | |
69 | |
70 ::oo::class create ::tdbc::postgres::statement { | |
71 | |
72 superclass ::tdbc::statement | |
73 | |
74 # The 'resultSetCreate' method forwards to the constructor of the | |
75 # result set. | |
76 | |
77 forward resultSetCreate ::tdbc::postgres::resultset create | |
78 | |
79 # Methods implemented in C: | |
80 # | |
81 # constructor connection SQLCode | |
82 # The constructor accepts the handle to the connection and the SQL code | |
83 # for the statement to prepare. It creates a subordinate namespace to | |
84 # hold the statement's active result sets, and then delegates to the | |
85 # 'init' method, written in C, to do the actual work of preparing the | |
86 # statement. | |
87 # params | |
88 # Returns descriptions of the parameters of a statement. | |
89 # paramtype paramname ?direction? type ?precision ?scale?? | |
90 # Declares the type of a parameter in the statement | |
91 | |
92 } | |
93 | |
94 #------------------------------------------------------------------------------ | |
95 # | |
96 # tdbc::postgres::resultset -- | |
97 # | |
98 # The class 'tdbc::postgres::resultset' models the result set that is | |
99 # produced by executing a statement against a Postgres database. | |
100 # | |
101 #------------------------------------------------------------------------------ | |
102 | |
103 ::oo::class create ::tdbc::postgres::resultset { | |
104 | |
105 superclass ::tdbc::resultset | |
106 | |
107 # The 'nextresults' method is stubbed out; tdbcpostgres does not | |
108 # allow a single call to return multiple results. | |
109 | |
110 method nextresults {} { | |
111 while {[my nextdict rubbish]} {} | |
112 return 0 | |
113 } | |
114 | |
115 # Methods implemented in C include: | |
116 | |
117 # constructor statement ?dictionary? | |
118 # -- Executes the statement against the database, optionally providing | |
119 # a dictionary of substituted parameters (default is to get params | |
120 # from variables in the caller's scope). | |
121 # columns | |
122 # -- Returns a list of the names of the columns in the result. | |
123 # nextdict | |
124 # -- Stores the next row of the result set in the given variable in | |
125 # the caller's scope as a dictionary whose keys are | |
126 # column names and whose values are column values, or else | |
127 # as a list of cells. | |
128 # nextlist | |
129 # -- Stores the next row of the result set in the given variable in | |
130 # the caller's scope as a list of cells. | |
131 # rowcount | |
132 # -- Returns a count of rows affected by the statement, or -1 | |
133 # if the count of rows has not been determined. | |
134 | |
135 } |