# Load the Packages package require TimpleSQL package require tclodbc # Connect to the database database db MyDatabaseName # Submission data that you create in your appliation/CGI. # - The Array Index Values are the Target Table Column Names set arr(FName) John set arr(LName) "Doe's last name" set arr(State) Anywhere set arr(ZIP) 12345 set arr(AddToMailingList) 1 set arr(submitDate) [clock format [clock seconds] -format %m/%d/%y] # Generate the Table Column Type Cross Ref Info GenTableColTypes typTbl tbl_RegistrationInfo # Validate the Submission Value Formats to the Target Table Formats if [catch {ValidateSubmissionData arr typTbl} err] { # Data is NOT Valid - Report Errors foreach item [join $err] { puts "ERROR: $item" } } else { # Data is Valid/Compatiable with Target Database - Insert Record TimpleSQLInsert arr typTbl } # Disconnect from the Database & Exit db disconnect exit
OTHER FEATURES:UPDATE Database Records: TimpleSQL can also do record updates using the same basic approach and supports straight SQL Instructions! For Example:
if [catch {ValidateSubmissionData arr typTbl} err] { # Data is NOT Valid - Report Errors foreach item [join $err] { puts "ERROR: $item" } } else { # Data is Valid/Compatiable with the Target Database - Update the Record TimpleSQLUpdate arr typTbl "FName = 'Dave'" # Note: A standard WHERE SQL Condition is at the end of the command. This is passed \ to the command so that the SQL UPDATE can modify the proper record/records in the database. }Record Existance Checking: The EntriesExist Command in TimpleSQL produces a Tcl boolean response based on your submission array and table. This is quite handy for CGI, Login Screens, etc.. For Example:
# Validation Contents set arr2(LoginName) buba set arr2(LoginPasswd) buba1 # Generate the Table Column Type Cross Ref Info GenTableColTypes typTbl tbl_LoginVerification if [EntriesExist arr2 typTbl] { # Login OK } else { # Login Failed }
Dynamic SQL Generation: You can also use TimpleSQL for dynamic SQL Generation, if you choose not to use the TimpleSQLInsert or Update Commands.Hope you enjoy this package as much as I have.David Bigelow
If you want to add comments or notation to this page, please do so in a separate section, DO NOT change original sample code as it may confuse people trying to use library.Thanks!