sqlite help with error

Clovertech Forums Read Only Archives Cloverleaf Tcl Library sqlite help with error

  • Creator
    Topic
  • #55360
    Kevin Crist
    Participant

      Trying to write info to an SQLite table. This is my first go around with this. I am getting an error and i can’t seem to figure out why. Can someone point me in the right direction.

      Here is my code:
      ######################################################################
      # Name: tps_sqlite_update
      #
      # Purpose:
      # UPoC type: tps
      # Args: tps keyedlist containing the following keys:
      #       MODE    run mode (”start”, “run” or “time”)
      #       MSGID   message handle
      #
      # Returns: tps disposition list:
      #          
      #

      proc tps_sqlite_update { args } {
      keylget args MODE mode               ;# Fetch mode
         
          global HciConnName
          set procName “tps_sqlite_update”
      set dispList {} ;# Nothing to return

      switch -exact — $mode {
      start {
      # Perform special init functions
      # N.B.: there may or may not be a MSGID key in args
      }

      run {
      # ‘run’ mode always has a MSGID; fetch and process it
      keylget args MSGID mh

      set msgtext  [msgget $mh]
      set fieldsep [crange $msgtext 3 3]
      set subfieldsep [crange $msgtext 4 4]
      set segments [split $msgtext “r”]
      set date_time [clock format [clock scan now] -format %Y%m%d%H%M%S]
      echo date_time: $date_time
      foreach seg $segments {
                   if {[cequal [crange $seg 0 2] “MSH”]} {
                # this segment (seg) is MSH
                # get the field data
                   set data [split $seg $fieldsep]
                   set field [lindex $data 8]
                   set data [split $field $subfieldsep]
                   set triggerType [lindex $data 0]
                   set triggerEvent [lindex $data 1]
      echo triggerType: $triggerType
      echo triggerEvent: $triggerEvent
           
        } elseif {[cequal [crange $seg 0 2] “PID”]} {
                # this segment (seg) is PID
                   set data [split $seg $fieldsep]
         set mrn [lindex $data 3]
      echo mrn : $mrn
                   set patientAccount [lindex $data 18]
      echo patientAccount: $patientAccount
                   set patientLName [lindex [split [lindex $data 5] $subfieldsep] 0]
      echo patientLName: $patientLName
        set patientFName [lindex [split [lindex $data 5] $subfieldsep] 1]
      echo patientFName: $patientFName
        set patientMName [lindex [split [lindex $data 5] $subfieldsep] 2]
      echo patientMName: $patientMName
        set dob [lindex $data 7]
      echo dob : $dob
        set gender [lindex $data 8]
      echo gender : $gender
        set ssn [lindex $data 19]
      echo ssn : $ssn
        } elseif {[cequal [crange $seg 0 2] “PV1″]} {
                # this segment (seg) is PV1
                   set data [split $seg $fieldsep]
         set patientType [lindex $data 2]
      echo patientType: $patientType
         set patientAdmitDate [lindex $data 44]
      echo patientAdmitDate: $patientAdmitDate
                   set patientDischargeDate [lindex $data 45]
      echo patientDischargeDate: $patientDischargeDate
         
      }
                }    
      #############################################################################################################              
      #
      # The below starts the database stuff
      #
      #############################################################################################################

       set db /home/hci/sql_test.db
      [code]######################################################################
      # Name: tps_sqlite_update
      #
      # Purpose:
      # UPoC type: tps
      # Args: tps keyedlist containing the following keys:
      #       MODE    run mode (”start”, “run” or “time”)
      #       MSGID   message handle
      #
      # Returns: tps disposition list:
      #          
      #

      proc tps_sqlite_update { args } {
      keylget args MODE mode               ;# Fetch mode
         
          global HciConnName
          set procName “tps_sqlite_update”
      set dispList {} ;# Nothing to return

      switch -exact — $mode {
      start {
      # Perform special init functions
      # N.B.: there may or may not be a MSGID key in args
      }

      run {
      # ‘run’ mode always has a MSGID; fetch and process it
      keylget args MSGID mh

      set msgtext  [msgget $mh]
      set fieldsep [crange $msgtext 3 3]
      set subfieldsep [crange $msgtext 4 4]
      set segments [split $msgtext “r”]
      set date_time [clock format [clock scan now] -format %Y%m%d%H%M%S]
      echo date_time: $date_time
      foreach seg $segments {
                   if {[cequal [crange $seg 0 2] “MSH”]} {
                # this segment (seg) is MSH
                # get the field data
                   set data [split $seg $fieldsep]
                   set field [lindex $data 8]
                   set data [split $field $subfieldsep]
                   set triggerType [lindex $data 0]
                   set triggerEvent [lindex $data 1]
      echo triggerType: $triggerType
      echo triggerEvent: $triggerEvent
           
        } elseif {[cequal [crange $seg 0 2] “PID”]} {
                # this segment (seg) is PID
                   set data [split $seg $fieldsep]
         set mrn [lindex $data 3]
      echo mrn : $mrn
                   set patientAccount [lindex $data 18]
      echo patientAccount: $patientAccount
                   set patientLName [lindex [split [lindex $data 5] $subfieldsep] 0]
      echo patientLName: $patientLName
        set patientFName [lindex [split [lindex $data 5] $subfieldsep] 1]
      echo patientFName: $patientFName
        set patientMName [lindex [split [lindex $data 5] $subfieldsep] 2]
      echo patientMName: $patientMName
        set dob [lindex $data 7]
      echo dob : $dob
        set gender [lindex $data 8]
      echo gender : $gender
        set ssn [lindex $data 19]
      echo ssn : $ssn
        } elseif {[cequal [crange $seg 0 2] “PV1″]} {
                # this segment (seg) is PV1
                   set data [split $seg $fieldsep]
         set patientType [lindex $data 2]
      echo patientType: $patientType
         set patientAdmitDate [lindex $data 44]
      echo patientAdmitDate: $patientAdmitDate
                   set patientDischargeDate [lindex $data 45]
      echo patientDischargeDate: $patientDischargeDate
         
      }
                }    
      #############################################################################################################              
      #
      # The below starts the database stuff
      #
      #############################################################################################################

       set db /home/hci/sql_test.db

    Viewing 7 reply threads
    • Author
      Replies
      • #85069
        James Cobane
        Participant

          You might want to try enclosing your db value in quotes – i.e.

          set db “/home/hci/sql_test.db”

          Not sure if the slashes are causing you an issue.  

          Just a thought.

          Jim Cobane

          Henry Ford Health System

        • #85070
          Kevin Crist
          Participant

            thanks for the idea Jim but i still get the same error.

          • #85071
            bill bearden
            Participant

              Do you have to “package require sqlite” ?

            • #85072
              Kevin Crist
              Participant

                i don’t have it on the proc i posted but i had that on an earlier version trying to troubleshoot. Didn’t make any difference. I just tried it again with no luck. Not sure if this makes a difference but i am using CL 5.8

              • #85073
                James Cobane
                Participant

                  I wonder if you have some unprintable/whitespace characters in your “sqlite DBCMD $db” line because of the fact that it is reporting invalid command name ”

                • #85074

                  You may be missing a bracket or have too many brackets.

                  -- Max Drown (Infor)

                • #85075

                  I think your braces are off here:

                  Code:

                         if {$db_id == “”} {
                             if {[catch {DBCMD eval {
                                 insert into test (
                                 date_time, mrn, lname, fname, mname, dob, gender,
                                 acct_num, ssn, admit_date, discharge_date)
                                 values (
                                     $date_time, $mrn, $lname, $fname, $mname, $dob, $gender,
                                     $acct_num, $ssn, $admit_date, $discharge_date)
                                 }} err]} {
                                     echo “Error in database processing: $err”
                                 }

                             if {$debug} {puts “DEBUG: $module: Inserted mrn: “}
                         } else {
                             if {[catch {DBCMD eval {
                                 update test
                                 set date_time=$date_time, mrn=$mrn, lname=$lname, fname=$fname, mname=$mname, dob=$dob, gender=$gender, acct_num=$acct_num, ssn=$ssn, admit_date=$admit_date, discharge_date=$discharge_date
                                 where db_id=$db_id
                                 }} err]
                             } { echo “Error in database processing: $err” }

                             if {$debug} {puts “DEBUG: $module: Updated mrn: “}
                         }

                  -- Max Drown (Infor)

                • #85076
                  Kevin Crist
                  Participant

                    i think i got that part fixed. I think since i had copied and pasted i got a bunch of spaces in front if that makes sense.  Had to go through all of the lines and fix. Never seen that before. Thanks for pointing that out. On to other issues with it now.

                    Thanks.

                Viewing 7 reply threads
                • The forum ‘Tcl Library’ is closed to new topics and replies.