The SQLite database holds the database schema in the table sqlite_master.
The table definition is as follows:
CREATE TABLE [table2] ([t2c1] VARCHAR, [t2c2] VARCHAR, CONSTRAINT "p_key" PRIMARY KEY ([t2c1], [t2c2]) ON CONFLICT ABORT)
The following procedure returns a list of defined tables.
Its functionality is similar to the tclODBC command db tables.
proc GetTables {{NameStart ""}} { return [db eval "select tbl_name from sqlite_master\ where (type = \"table\") and (tbl_name like \"${NameStart}%\")"] }
find defined columns of a table (from KBK)
The functionality is similar to the tclODBC command db columns.
TABLE_INFO calls the attached function once for each column with the following array elements set:
proc cols {db table} { set result {} $db eval "PRAGMA TABLE_INFO($table)" row { lappend result $row(name) } return $result }
find information about keys
Get primary key columns:
proc pk {db table} { set result {} $db eval "PRAGMA TABLE_INFO($table)" row { if {$row(pk)} { lappend result $row(name) } } return $result }
Get a matrix of keys by enumerating the unique keys:
The primary key is missing in the list, if it is on a column of type integer.
INDEX_LIST returns:
INDEX_INFO returns:
proc keys {db table} { set result {} $db eval "PRAGMA INDEX_LIST($table)" row { if {$row(unique)} { set keycols {} $db eval "PRAGMA INDEX_INFO($row(name))" detail { lappend keycols $detail(name) } lappend result $keycols } } return $result }