Use of TCL script with SQL -
i want write tcl script in need use mysql. have (1) read file; (2) copy data sql table, , after (3) query data table based on requirement. unable find how copy data file sql table , how query table in tcl.
load data infile 'path/filename.csv' #loading data csv file table tablename #tablename user defined fields terminated ',' #csv files use comma separated values lines terminated '\n' #till last column ignore 1 lines #ignores first row if need proc mysql_connect {} { variable mysql_dbh ; variable command set mysql_host "hostwebsite" set mysql_user "username" set mysql_password "password" set mysql_db "databasename" ## loading driver set libmysql_path "driver path" if {[catch {load $libmysql_path}]} { puts "$command error: unable load mysql file" ; exit } ## making connection mysql db if {[catch {set ::mysql_dbh [::mysql::connect -h $mysql_host -u $mysql_user -password $mysql_password -db $mysql_db]}]} { puts "$command error: unable connect mysql db"; exit } puts "db connected" } proc querydisplay {} { mysql_connect set rows [::mysql::sel $::mysql_dbh "select *from tablename" -list] foreach data $rows { puts $data } } proc mysql_disconnect {} { variable mysql_dbh ::mysql::close $::mysql_dbh }
Comments
Post a Comment