Neatware Header
Home   Products   Solutions   Partners   Store   Company   

ODBC Examples

Below example creates a new Access database in current directory, sets its datasource as testdb, and builds some tables.

package require tclodbc

set driver "Microsoft Access Driver (*.mdb)"
set dbfile testdb.mdb
set dsn TESTDB

create datasource with driver, dbfile, and dsn.

proc create_datasource {driver dbfile dsn} {
  if {![file exists $dbfile]} {
    database configure config_dsn \\
      $driver [list "CREATE_DB=\"$dbfile\" General"]
  }

  database configure add_dsn \\
      $driver [list "DSN=$dsn" "DBQ=$dbfile"]
}

remove datasource

proc remove_datasource {driver dsn} {
  database configure remove_dsn $driver "DSN=$dsn"
}

create tables

proc create_tables {db} {
  $db "CREATE TABLE Table (
       IntData INTEGER, CharData CHAR (20), DateData DATE)"
  $db "CREATE UNIQUE INDEX TableIdx0 ON Table (IntData)"
  $db "CREATE INDEX TableIdx1 ON Table (CharData, DateData)"
}

connect to datasource, and create a database as well as tables.

database db $dsn
create_datasource $driver $dbfile $dsn
database db $dsn
create_tables db

close database

db disconnect


Google
  Web Neatware.com