need help with tcl catch statement

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf need help with tcl catch statement

  • Creator
    Topic
  • #53838
    Diana de Bruin
    Participant

      I need some help stucturing the tcl catch statement in a proc that we use to connect to a database in Cloverleaf 5.8

      How can I make sure the $rc is always created and filled with a usefull value.

      My current statement:

       if { [catch {set rc [odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt]} err]

          ||

          ![cequal $rc “SQL_SUCCESS”] }

       {

       gc_dbHandleODBCError “SQLAllocHandle ($rc)” $henv $hdbc $hstmt

       }

      The above statement results in the following error if the database connection can’t be established:

       result = ‘can’t read “rc”: no such variable’

       errorInfo: ‘

       can’t read “rc”: no such variable

           while executing

       “gc_dbHandleODBCError “SQLAllocHandle ($rc)” $henv $hdbc $hstmt”

      Diana

      LUMC -Leiden University Medical Centre
      The Netherlands

    Viewing 2 reply threads
    • Author
      Replies
      • #79142
        James Cobane
        Participant

          Diana,

          A simple fix would be to initialize the “rc” variable prior to the if statement.  Simply:

          set rc “”

          That way it is initially valued (to null), and will get re-valued in your statement {set rc [odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt]}

          If your  [odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt] statement doesn’t return anything, rc will still be null, and you can do some additional conditional logic based on the null value.

          Hope that helps.

          Jim Cobane

          Henry Ford Health

        • #79143
          Diana de Bruin
          Participant

            Thanks,

            But I knew that adding the set rc “” would prevent my error message.

            However if I do that I still won’t have info on why the odbc statement failed to put into my gc_dbHandleODBCError call….

            Diana

            LUMC -Leiden University Medical Centre
            The Netherlands

          • #79144

            Try something like this instead. I haven’t tested this code, so you may need to debug it a little.

            Code:

            set rc “”
            catch {odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt} rc
            if { $rc != “SQL_SUCCESS”] } {gc_dbHandleODBCError “SQLAllocHandle ($rc)” $henv $hdbc $hstmt}

            -- Max Drown (Infor)

        Viewing 2 reply threads
        • The forum ‘Cloverleaf’ is closed to new topics and replies.