You are viewing a plain text version of this content. The canonical link for it is here.
Posted to site-cvs@tcl.apache.org by mx...@apache.org on 2013/12/13 12:04:23 UTC

svn commit: r1550689 - in /tcl/rivet/trunk: ChangeLog rivet/packages/dio/dio_Tdbc.tcl rivet/packages/dio/pkgIndex.tcl

Author: mxmanghi
Date: Fri Dec 13 11:04:23 2013
New Revision: 1550689

URL: http://svn.apache.org/r1550689
Log:
    * rivet/packages/dio/dio_Tdbc.tcl: first version of Tdbc driver for DIO. This
    class is able to execute basic queries and needs further development


Modified:
    tcl/rivet/trunk/ChangeLog
    tcl/rivet/trunk/rivet/packages/dio/dio_Tdbc.tcl   (contents, props changed)
    tcl/rivet/trunk/rivet/packages/dio/pkgIndex.tcl

Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1550689&r1=1550688&r2=1550689&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Fri Dec 13 11:04:23 2013
@@ -1,3 +1,7 @@
+2013-12-13 Massimo Manghi <mx...@apache.org>
+    * rivet/packages/dio/dio_Tdbc.tcl: first version of Tdbc driver for DIO. This
+    class is able to execute basic queries and needs further development
+
 2013-12-08 Massimo Manghi <mx...@apache.org>
     * configure.ac: version number bumped up to 2.1.4
 

Modified: tcl/rivet/trunk/rivet/packages/dio/dio_Tdbc.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/packages/dio/dio_Tdbc.tcl?rev=1550689&r1=1550688&r2=1550689&view=diff
==============================================================================
--- tcl/rivet/trunk/rivet/packages/dio/dio_Tdbc.tcl (original)
+++ tcl/rivet/trunk/rivet/packages/dio/dio_Tdbc.tcl Fri Dec 13 11:04:23 2013
@@ -16,7 +16,7 @@
 #
 # DIO compatibility layer with Tdbc
 # 
-# $Id: $ 
+# $Id$ 
 #
 
 package provide dio_Tdbc 0.1
@@ -28,14 +28,32 @@ namespace eval DIO {
         inherit Database
 
         private variable dbhandle
+        public  variable interface "Tdbc"
         private common   conncnt    0
 
-        public varabile backend "" {
+        public variable backend "" {
 
-            if {![string equal $backend "mysql"] && \
-                ![string equal $backend "postgres"] && \
-                ![string equal $backend "sqlite3"] && \
-                ![string equal $backend "odbc"]} {
+            if {$backend == "mysql"} {
+
+                package require tdbc::mysql
+
+            } elseif {$backend == "postgres"} {
+
+                package require tdbc::postgres
+
+            } elseif {$backend == "sqlite3"} {
+
+                package require tdbc::sqlite3
+
+            } elseif {$backend == "odbc"} {
+
+                package require tdbc::odbc
+
+            } elseif {$backend == ""} {
+
+                return -code error "DIO Tdbc needs a backend be specified"
+
+            } else {
 
                 return -code error "backend '$backend' not supported"
 
@@ -43,12 +61,23 @@ namespace eval DIO {
 
         }
 
+# -- 
+
         constructor {args} { eval configure $args } {
             if {[catch {package require tdbc}]} {
 
                 return -code error "No Tdbc package available"
 
             }
+
+            eval configure $args
+
+            if {[lempty $db]} {
+                if {[lempty $user]} {
+                    set user $::env(USER)
+                }
+                set db $user
+            }
         }
 
         destructor { close }
@@ -72,17 +101,22 @@ namespace eval DIO {
 #
 
         public method open {} {
-            set command [list ::tdbc::mysql::connection create [incr conncnt]]
+            if {$backend == ""} {
+                return -code error "no backend set"
+            }
+            set command [::list ::tdbc::${backend}::connection create tdbc[incr conncnt]]
 
             if {![lempty $user]} { lappend command -user $user }
             if {![lempty $pass]} { lappend command -password $pass }
             if {![lempty $port]} { lappend command -port $port }
             if {![lempty $host]} { lappend command -host $host }
+            if {![lempty $db]}   { lappend command -database $db }
 
             if {[catch {
                 set dbhandle [eval $command]
             } e]} { return -code error $e }
 
+
             return -code ok
         }
 
@@ -93,19 +127,24 @@ namespace eval DIO {
 #
 
         public method exec {sql} {
+
             if {![info exists dbhandle]} { $this open }
 
             set sqlstat [$dbhandle prepare $sql]
 
-            if {[catch {set res [$sqlstat execute]} err} {
+            if {[catch {set res [$sqlstat execute]} err]} {
                 set obj [result Tdbc -error 1 -errorinfo $err]
             } else {
                 set obj [result Tdbc -resultid $res           \
+                                     -sqlstatement $sqlstat   \
                                      -numrows [$res rowcount] \
-                                     -fields  [$res columns]]
+                                     -fields  [::list [$res columns]]]
             }
 
-            $sqlstat destroy
+            #$res nextlist cols
+            #puts "rows: [$res rowcount]"
+            #puts "cols: $cols"
+
             return $obj
         }
 
@@ -114,6 +153,7 @@ namespace eval DIO {
 #  extended version of the standard DIO method exec that
 # makes room for an extra argument storing the dictionary
 # of variables to be substituted in the SQL statement
+#
 
         public method execute {sql {substitute_d ""}} {
 
@@ -135,9 +175,8 @@ namespace eval DIO {
                                         -fields  [$res columns]]
             }
 
-            $sqlstat destroy
+            $sqlstat close
             return $obj
-
         }
 
 
@@ -152,23 +191,36 @@ namespace eval DIO {
 
     }
 
-# -- TdbcResult
+# 
+# -- Class TdbcResult
 #
-# Basically a wrapper around a Tdbc resultset object
+# Class wrapping a Tdbc resultset object and adapting it
+# to the DIO Results interface
 #
 
     ::itcl::class TdbcResult {
         inherit Result
 
+        public variable sqlstatement
+
         constructor {args} {
             eval configure $args
         }
 
-        public method nextrow {} {
+        destructor {
+            catch {$sqlstatement close}
+        }
 
+# -- nextrow
+#
+# Returns the list of values selected by a SQL command.
+# Values appear in the list with the same order of 
+# the columns names returned by the 'columns' object command
+#
+
+        public method nextrow {} {
             $resultid nextlist v
             return $v
-
         }
 
     }

Propchange: tcl/rivet/trunk/rivet/packages/dio/dio_Tdbc.tcl
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: tcl/rivet/trunk/rivet/packages/dio/pkgIndex.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/packages/dio/pkgIndex.tcl?rev=1550689&r1=1550688&r2=1550689&view=diff
==============================================================================
--- tcl/rivet/trunk/rivet/packages/dio/pkgIndex.tcl (original)
+++ tcl/rivet/trunk/rivet/packages/dio/pkgIndex.tcl Fri Dec 13 11:04:23 2013
@@ -1,6 +1,17 @@
+# Tcl package index file, version 1.1
+# This file is generated by the "pkg_mkIndex" command
+# and sourced either when an application starts up or
+# by a "package unknown" script.  It invokes the
+# "package ifneeded" command to set up package-related
+# information so that packages will be loaded automatically
+# in response to "package require" commands.  When this
+# script is sourced, the variable $dir must contain the
+# full path name of this file's directory.
+
 package ifneeded DIO 1.0 [list source [file join $dir dio.tcl]]
 package ifneeded DIODisplay 1.0 [list source [file join $dir diodisplay.tcl]]
 package ifneeded dio_Mysql 0.2 [list source [file join $dir dio_Mysql.tcl]]
+package ifneeded dio_Oracle 0.1 [list source [file join $dir dio_Oracle.tcl]]
 package ifneeded dio_Postgresql 0.1 [list source [file join $dir dio_Postgresql.tcl]]
 package ifneeded dio_Sqlite 0.1 [list source [file join $dir dio_Sqlite.tcl]]
-package ifneeded dio_Oracle 0.2 [list source [file join $dir dio_Oracle.tcl]]
+package ifneeded dio_Tdbc 0.1 [list source [file join $dir dio_Tdbc.tcl]]



---------------------------------------------------------------------
To unsubscribe, e-mail: site-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: site-cvs-help@tcl.apache.org