annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/tdbcpostgres1.1.5/tdbcpostgres.tcl @ 69:33d812a61356

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