Purpose: '''Accumulate simple examples demonstrating the use of the [[ [Oratcl] ]] database library''' ---- * [ora2txt] performs a select and outputs the results as tab delimited text from a command-line * [Oratcl Logon Dialog] is a program extract showing a logon routine ---- The following examples are using a simple option table called PROPERTY. The table contains only two columns KEY and VALUE, each of them are VARCHAR2 types. The variables 'lda' and 'sth' contain the connection to the database and the statement handle for executing queries, inserts etc. A simple logon routine package require Oratcl set lda [oralogon user/pass@dbname -async] set sth [oraopen $lda] if {[oramsg $sth rc] == 0} { puts "Successfully connected" } else { puts "Unable to connect to the database." } oralogoff $lda Inserting into a database Not that big problem. Let's assume we have a button called .b and want to save all of its options in our database table. We use foreach and configure to get 'em and put them in the PROPERTY table using simple insert statements. foreach opt [.b configure] { orasql $sth "INSERT INTO PROPERTY KEY, VALUE VALUES ('[lindex $opt 0]', '[lindex $opt 4]')" } oracommit $lda Deleting from a database # code goes here Retrieving data from a database # code goes here Binding # code goes here PL/SQL # code goes here Anything else you want to see regarding Oratcl... [RLH] - Besides the above, I would like to see some stuff about pulling data out and displaying it via [CGI]. ---- ''[Todd Helfter] wrote on comp.lang.tcl:'' Here are two examples. package require Oratcl # should see '4.3' # open logon handle set lda [oralogon tmh/password@db] # should see 'oratcl0' # open statement handle % set cur [oraopen $lda] # should see 'oratcl0.0' # parse sql statement oraparse $cur {select table_name from user_tables} # should see '0' :: 0 == OCI_SUCCESS # execute the statement handle oraexec $cur # should see '0' # fetch the results (loop until return code != OCI_SUCCESS) while {[orafetch $cur -datavariable row] == 0} { puts $row } # I got back table name 'STACKS' # describe a table oradesc $lda stacks # I got back {SID 22 NUMBER 0 -127 1} {EBE 3 CHAR 0 0 1} {PART 20 CHAR 0 0 1} # example with a bind. Only return rows with sid = 6 oraparse $cur {select * from stacks where sid = :sid} orabind $cur :sid 6 oraexec $cur oracols $cur # I got back SID EBE PART oracols $cur all # I got back {SID 22 NUMBER 0 -127 1} {EBE 3 CHAR {} {} 1} {PART 20 CHAR {} {} 1} while {[orafetch $cur -datavariable row] == 0} { puts $row } # 1st row: 6 TMH {} # 2nd row: 6 TMH {} oraclose $cur oralogoff $lda ---- [RLH] - Thank you very much! ---- [[[Category Example]|[Category Database]]]