Formatting with Double Quotes in tcl

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Formatting with Double Quotes in tcl

  • Creator
    Topic
  • #51355
    David Harrison
    Participant

    I want to format a comma separated variable with double quotes for input to a sqlite table. I can do it ok with single quotes but double quotes is giving me a problem.

    Code:


    proc XltSetRMCOdata {} {
     upvar xlateInVals   xlateInVals
     xlateOutVals  xlateOutVals
     set msg “‘”
     append msg [join $xlateInVals “‘,'”]
     append msg “‘”
     set dtTm [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}]
     set sqlcmd “INSERT INTO rm VALUES ($msg,’$dtTm’)”
     echo “XltSetRMCOdata >$sqlcmd<"  package require sqlite  sqlite db /export/quovadx/qdx5.6/integrator/prd/tclprocs/agfa.db  if { [catch {db eval $sqlcmd} result] } {     echo "$result"  }  db close }


    Input

  • O’CONNOR,SIOBHAN,,19720215,F,21 WAYFARERS DRIVE,NEWTON LE WILLOWS,MERSEYSIDE,,WA12 8DF,1,NHS,4444458569,99921023

  • Output

  • XltSetRMCOdata >INSERT INTO rm VALUES (‘5878879992102200008000000001′,’000011101′,’587887′,’O’CONNOR,SIOBHAN,,19720215,F,21′,’WAYFARERS’,’DRIVE,NEWTON’,’LE’,’WILLOWS,MERSEYSIDE,,WA12′,”,’8DF,1,NHS,4444458569,99921023′,”,”,”,’99921022′,’3015′,’2009-11-20 11:38:44′)<

  • I need to use double quotes because of the apostrophes.

    Any help appreciated

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

      David,

      You should be able to use double-quotes by “escaping” them with the backslash

      Try this:

      set msg “”

      foreach item $xlateInVals {

         lappend msg “$item”

      }

      set msg [join $msg ,]

      Hope this helps.

      Jim Cobane

      Henry Ford Health

    • #69862
      Jim Kosloskey
      Participant

      Another way:

      append msg [join $xlateInVals {“,”}]

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #69863
      David Barr
      Participant

      David Harrison wrote:

      I want to format a comma separated variable with double quotes for input to a sqlite table. I can do it ok with single quotes but double quotes is giving me a problem.

      You should have sqlite expand the variables for you, like this:

      Code:

      lassign $xlateInVals v1 v2 v3 v4 v5
      set dtTm [clock format [clock seconds] -format {%Y-%m-%d %H:%M:%S}]
      set sqlcmd {INSERT INTO rm VALUES ($v1,$v2,$v3,$v4,$v5,$dtTm)}

      Notice the use of squirrelly brackets instead of quotes to prevent the variable values from being substituted immediately. You don’t have to worry about scanning your data for SQL special characters.

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

Forums

Forum Statistics

Registered Users
5,125
Forums
28
Topics
9,294
Replies
34,439
Topic Tags
287
Empty Topic Tags
10