tclado
をテンプレートにして作成
[
Front page
] [
Page list
|
Search
|
Recent changes
|
RSS of recent changes
]
Start:
# Sample:
#
# tclado db "Provider=Microsoft.Jet.OLEDB.4.0;Data Sourc...
# puts [db run "select * from Table1"]
#
# db configure -outputtype dict ;# dict or list(default)
# puts [db run "select * from Table1"]
#
package provide tclado 0.1
package require Itcl
namespace import ::itcl::*
package require tcom
::tcom::import "C:\Program Files\Common Files\System\ado...
class tclado {
private variable _connectionString ""
private variable con {}
public variable nullString {}
# list, dict
public variable outputtype list
constructor {connectionString} {
set con [::tcom::ref createobject "ADODB.Connect...
set _connectionString $connectionString
$con Open $connectionString
}
destructor {
$con Close
}
public method run {sql} {
set rst [$con Execute $sql]
set rows [list]
if {[$rst State] == 1} {
while {[$rst EOF] == 0} {
switch -- $outputtype {
list { set row [list] }
dict { set row [dict create] }
default {error "unknown type $output...
}
set fieldCount [[$rst Fields] Count]
for {set i 0} {$i < $fieldCount} {incr i...
set f [[$rst Fields] Item $i]
set name [$f Name]
set value [$f Value]
if {$value eq "::tcom::NULL"} {
set value $nullString
} else {
if {[$f Type] == 7} {
set datetime [expr {int(-220...
set value [clock format $dat...
}
}
switch -- $outputtype {
list { lappend row $value }
dict { dict set row $name $valu...
}
}
lappend rows $row
$rst MoveNext
}
}
return $rows
}
public method disconnect {} {
$con Close
}
}
---------------------------------------------------------...
[[CategoryTclTk]]
End:
# Sample:
#
# tclado db "Provider=Microsoft.Jet.OLEDB.4.0;Data Sourc...
# puts [db run "select * from Table1"]
#
# db configure -outputtype dict ;# dict or list(default)
# puts [db run "select * from Table1"]
#
package provide tclado 0.1
package require Itcl
namespace import ::itcl::*
package require tcom
::tcom::import "C:\Program Files\Common Files\System\ado...
class tclado {
private variable _connectionString ""
private variable con {}
public variable nullString {}
# list, dict
public variable outputtype list
constructor {connectionString} {
set con [::tcom::ref createobject "ADODB.Connect...
set _connectionString $connectionString
$con Open $connectionString
}
destructor {
$con Close
}
public method run {sql} {
set rst [$con Execute $sql]
set rows [list]
if {[$rst State] == 1} {
while {[$rst EOF] == 0} {
switch -- $outputtype {
list { set row [list] }
dict { set row [dict create] }
default {error "unknown type $output...
}
set fieldCount [[$rst Fields] Count]
for {set i 0} {$i < $fieldCount} {incr i...
set f [[$rst Fields] Item $i]
set name [$f Name]
set value [$f Value]
if {$value eq "::tcom::NULL"} {
set value $nullString
} else {
if {[$f Type] == 7} {
set datetime [expr {int(-220...
set value [clock format $dat...
}
}
switch -- $outputtype {
list { lappend row $value }
dict { dict set row $name $valu...
}
}
lappend rows $row
$rst MoveNext
}
}
return $rows
}
public method disconnect {} {
$con Close
}
}
---------------------------------------------------------...
[[CategoryTclTk]]
Page:
HTML convert time: 0.016 sec.