3 # Class definitions and Tcl-level methods for the tdbc::postgres bridge.
5 # Copyright (c) 2009 by Slawomir Cygan
7 # See the file "license.terms" for information on usage and redistribution
8 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10 #------------------------------------------------------------------------------
14 ::namespace eval ::tdbc::mypostgres {
16 namespace export connection datasources drivers
20 #------------------------------------------------------------------------------
22 # tdbc::postgres::connection --
24 # Class representing a connection to a Postgres database.
26 #-------------------------------------------------------------------------------
28 ::oo::class create ::tdbc::postgres::connection {
30 superclass ::tdbc::connection
32 # The constructor is written in C. It takes alternating keywords
33 # and values pairs as its arguments. (See the manual page for the
36 # The 'statementCreate' method delegates to the constructor of the
39 forward statementCreate ::tdbc::postgres::statement create
42 # The 'prepareCall' method gives a portable interface to prepare
43 # calls to stored procedures. It delegates to 'prepare' to do the
46 method preparecall {call} {
47 regexp {^[[:space:]]*(?:([A-Za-z_][A-Za-z_0-9]*)[[:space:]]*=)?(.*)} \
50 my prepare \\{$rest\\}
52 my prepare \\{:$varName=$rest\\}
56 # The 'init', 'begintransaction', 'commit, 'rollback', 'tables'
57 # and 'columns' methods are implemented in C.
61 #------------------------------------------------------------------------------
63 # tdbc::postgres::statement --
65 # The class 'tdbc::postgres::statement' models one statement against a
66 # database accessed through a Postgres connection
68 #------------------------------------------------------------------------------
70 ::oo::class create ::tdbc::postgres::statement {
72 superclass ::tdbc::statement
74 # The 'resultSetCreate' method forwards to the constructor of the
77 forward resultSetCreate ::tdbc::postgres::resultset create
79 # Methods implemented in C:
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
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
94 #------------------------------------------------------------------------------
96 # tdbc::postgres::resultset --
98 # The class 'tdbc::postgres::resultset' models the result set that is
99 # produced by executing a statement against a Postgres database.
101 #------------------------------------------------------------------------------
103 ::oo::class create ::tdbc::postgres::resultset {
105 superclass ::tdbc::resultset
107 # The 'nextresults' method is stubbed out; tdbcpostgres does not
108 # allow a single call to return multiple results.
110 method nextresults {} {
111 while {[my nextdict rubbish]} {}
115 # Methods implemented in C include:
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).
122 # -- Returns a list of the names of the columns in the result.
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.
129 # -- Stores the next row of the result set in the given variable in
130 # the caller's scope as a list of cells.
132 # -- Returns a count of rows affected by the statement, or -1
133 # if the count of rows has not been determined.