Cesar D. Rodas wrote:
Hello,

Merry Christmas for every one!

I am wondering if someone did a function (the language doesn't care very
much) to get the table information and want to share him/her code.
Here's some Tcl code that may help. It does more than look at the SQL, but that part may be of interest, too. It was written when my Tcl skills were even weaker than they are now, so it won't win any style points, but it has been working for years.

Merry Xmas,

Gerry


proc fillattachwin attachedname  {
# Global data filled up here:
# arrays (with first index $attachedname, second index starting at 1, matching line numbers) of:
#    ::GEB::tablename  (names of the tables)
# ::GEB::tableindex ("inverse" of ::GEB::tablename e.g. $::GEB::tableindex(main.table1) = 1)
#    ::GEB::entrycount (# entries in each table),
#    ::GEB::fieldlist (lists of field names, indices starting at 0)
#    ::GEB::colnamelist (lists of column names, indices starting at 0)
# ::GEB::coldeflist (lists of column def'ns--name+type, indices starting at 0)
#    ::GEB::fieldcount (numbers of fields)
#    ::GEB::tablesql (sql that created the table)

#      ::GEB::tablelist: table names (just names, not datatypes)
#    ::GEB::tablesarray($attachedname): array of tablelists
# ::GEB::attachtablelist: $attachedname.$tablename -- (created in fillattachwins)

#    ::GEB::attachednames: list of attachednames, starting with main
# ::GEB::tcltablelist($attachedname): list of tables in that file with fields named tcl wm title .$attachedname "SQLite $::GEB::attachfilename($attachedname) as $attachedname"

 set tables [sq eval "select sql from $attachedname.sqlite_master"]
 set numtables 0
 set   ::GEB::tablelist ""
 set ::GEB::fieldcount($attachedname,max) 0
 foreach dbtable $tables {
   regsub -all { +} $dbtable { } dbtable
   if {[regexp -nocase "create table" $dbtable]} {
     incr numtables
     regsub -nocase {create table } $dbtable {} dbtable
scan $dbtable {%[^(]%[^!]} currentname ::GEB::tablesql($attachedname,$numtables)
     set currentname [string trim $currentname]
set ::GEB::tablename($attachedname,$numtables) $attachedname.$currentname
     set ::GEB::tableindex($attachedname.$currentname) $numtables
     lappend   ::GEB::tablelist $::GEB::tablename($attachedname,$numtables)
set tablefields($numtables) [string range $::GEB::tablesql($attachedname,$numtables) 1 end-1]
     regsub -all {, } $tablefields($numtables) {,} tablefields($numtables)
set ::GEB::entrycount($attachedname,$numtables) "[sq eval "select count(*) from $::GEB::tablename($attachedname,$numtables)"]"
     set ::GEB::coldeflist($attachedname,$numtables) {}
     foreach fldnm  [split $tablefields($numtables) ,] {
lappend ::GEB::coldeflist($attachedname,$numtables) [string trim $fldnm]
     }
set ::GEB::fieldcount($attachedname,$numtables) [expr [regsub -all , $tablefields($numtables) { } tablefields($numtables)] + 1] if {$::GEB::fieldcount($attachedname,$numtables) > $::GEB::fieldcount($attachedname,max)} { set ::GEB::fieldcount($attachedname,max) $::GEB::fieldcount($attachedname,$numtables)
     }
   }
 }
 array set ::GEB::fieldlist [array get ::GEB::coldeflist]
####################################3
 set ::GEB::colnamelist [firstwords ::GEB::coldeflist]
 set ::GEB::tablesarray($attachedname) $::GEB::tablelist
 set ::GEB::tcltablelist($attachedname) {}
 foreach maybetcltablename $::GEB::tablelist {
if {[lsearch $::GEB::fieldlist($attachedname,$::GEB::tableindex($maybetcltablename)) tcl ] > -1} {
     lappend ::GEB::tcltablelist($attachedname) $maybetcltablename
   }
 }
# List the table names and other info in the main window
# While doing so, force a redraw
 $::GEB::tablestktable($attachedname) clear cache
$::GEB::tablestktable($attachedname) configure -state normal -cols [expr $::GEB::fieldcount($attachedname,max) + 2] \ -rows [expr $numtables + 1] -command [list GEB::readtktable4file %i %r %c %s $attachedname] -cache 1 \ -drawmode single -bd 1 -ipadx 2 -titlerows 1 -titlecols 1 -anchor w -browsecmd [list showtableattachwin %S $attachedname] \
    -padx [$::GEB::tablestktable($attachedname) cget -padx]
 $::GEB::tablestktable($attachedname) tag row headers 0
 $::GEB::tablestktable($attachedname) tag configure headers -anchor center
 $::GEB::tablestktable($attachedname) tag col entries 1
 $::GEB::tablestktable($attachedname) tag configure entries -anchor e
}

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to