Updated 2012-09-10 14:14:05 by LkpPo

TimpleSQL v1.3 was released on February 25, 2003!

Downloads & Additional Info/Examples: http://www.simplifiedlogic.com/TimpleSQL/Default.htm

ECS @ 2005-11-03: Link is broken. (The domain is still there, but the TimpleSQL and below appear to be gone.)

2006-01-04 : Now hosted on http://www.sourceforge.net/projects/timplesql

What is TimpleSQL?

TimpleSQL is a set of standalone procedures that helps the developer either quickly prepare values, or execute submission, for INSERT or UPDATE queries into a database using tclodbc.

TimpleSQL only requires a standard one-dimensional Tcl Array of your input values and the target table name/array where you want to insert or update your information. TimpleSQL gathers the target table's column name/formatting requirements and, depending on your desired action, will generate the proper SQL input string based on the matching indexes in your Tcl Array. You can also Validate your submission data relative to the target table before submission (recommended).

TimpleSQL can either prepare and execute the submission of the generated SQL, or you can use some lower level commands to help you generate SQL structures (e.g., SELECT, INSERT, UPDATE) for hard coding SQL in your own applications.

Using TimpleSQL, you can quickly database-enable standard Tcl/TK and CGI Applications for things like submission forms, polls, and shopping carts.

QUICK EXAMPLE: INSERT Record into Database (uses tclodbc):
 # 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!