Ignore:
Timestamp:
Apr 3, 2013, 5:01:25 PM (11 years ago)
Author:
mmc
Message:

Fixed a problem with single quotes in text strings. The quotes need to
be escaped by doubling them before inserting into SQLite. Also fixed a
problem with empty string values for integers/reals. They need to be
represented as in SQLite.

Fixed the error message that you get when calling rptimes with no files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/apps/rptimes

    r3507 r3624  
    3939
    4040if {[llength $argv] < 1} {
    41     puts stderr "bad option \"$arg\""
    4241    puts stderr "USAGE: rptimes run.xml ?run.xml...?"
    4342    exit 1
     
    147146    }
    148147    return $rlist
     148}
     149
     150# ----------------------------------------------------------------------
     151# USAGE: escapeQuotes <string>
     152#
     153# Escapes single quotes in the given <string> by escaping the quote.
     154# In SQLite, this is done by doubling the quote.  This makes it
     155# possible to embed the string in another quoted string like
     156# 'hello ''world'''.  Returns a string with escaped quotes.
     157# ----------------------------------------------------------------------
     158proc escapeQuotes {str} {
     159    regsub -all {([^\'])\'} $str {\1''} str
     160    return $str
    149161}
    150162
     
    215227                    set id [format "x%03d" [incr num]]
    216228
    217                     db eval "INSERT INTO parameters values('$id','$rp','$def','$type')"
     229                    db eval "INSERT INTO parameters values('$id','$rp','[escapeQuotes $def]','$type')"
    218230                    db eval "ALTER TABLE jobs ADD COLUMN $id $type;"
    219231                }
     
    232244                lappend cols $id
    233245                if {$type eq "TEXT"} {
    234                     lappend vals '$val'
     246                    lappend vals '[escapeQuotes $val]'
     247                } elseif {$val ne ""} {
     248                    lappend vals $val
    235249                } else {
    236                     lappend vals $val
     250                    lappend vals ''
    237251                }
    238252            }
Note: See TracChangeset for help on using the changeset viewer.