Mercurial > hg > egg-tcls
changeset 295:141bb4a2b76f
utillib: utl_escape (which will be deprecated soon).
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 26 Jan 2015 14:07:16 +0200 |
parents | 2bb9bcfb104a |
children | a7455b0dc144 |
files | quotedb.tcl urllog.tcl utillib.tcl |
diffstat | 3 files changed, 21 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/quotedb.tcl Mon Jan 26 14:04:17 2015 +0200 +++ b/quotedb.tcl Mon Jan 26 14:07:16 2015 +0200 @@ -76,10 +76,6 @@ } -proc qdb_escape {str} { - return [string map {' ''} $str] -} - proc qdb_sql_exec { upublic unick uchan usql } { global qdb_handle qdb_msg_sql_error if {[catch {qdb_handle eval $usql} uerrmsg]} { @@ -112,7 +108,7 @@ return 0 } - set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[qdb_escape $utext]', '[qdb_escape $uhand]', '[qdb_escape $uhost]', '[qdb_escape $uchan]')" + set usql "INSERT INTO $utable (utime,utext,user,host,chan) VALUES ([unixtime], '[utl_escape $utext]', '[utl_escape $uhand]', '[utl_escape $uhost]', '[utl_escape $uchan]')" if {![qdb_sql_exec $upublic $unick $uchan $usql]} { return 0 } @@ -149,7 +145,7 @@ set qoverride [matchattr $uhand n] set usql "SELECT utime AS utime FROM $utable WHERE id=$unum" if {$qoverride == 0} { - append usql " AND user='[qdb_escape $uhand]'" + append usql " AND user='[utl_escape $uhand]'" set qextra "" } else { set qextra " (owner/time override)" @@ -199,7 +195,7 @@ set qoverride [matchattr $uhand n] set usql "SELECT utime AS utime FROM $utable WHERE id=$unum" if {$qoverride == 0} { - append usql " AND user='[qdb_escape $uhand]'" + append usql " AND user='[utl_escape $uhand]'" set qextra "" } else { set qextra $qdb_msg_update_override @@ -208,7 +204,7 @@ qdb_handle eval $usql { set udiff [expr [unixtime] - $utime] if {$udiff < $maxdiff || $qoverride} { - set usql "UPDATE $utable SET utext='[qdb_escape $uquote]', utime=[unixtime] WHERE id=$unum" + set usql "UPDATE $utable SET utext='[utl_escape $uquote]', utime=[unixtime] WHERE id=$unum" if {![qdb_sql_exec $upublic $unick $uchan $usql]} { return 0 } else { @@ -275,7 +271,7 @@ } # Check if user has previously voted this item - set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[qdb_escape $uhand]' AND urlid=$uid" + set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[utl_escape $uhand]' AND urlid=$uid" qdb_handle eval $usql { # Yes, update the previous vote set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" @@ -289,7 +285,7 @@ } # No previous votes, insert new - set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[qdb_escape $uhand]',$uid,$uvote)" + set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)" if {[qdb_sql_exec $upublic $unick $uchan $usql]} { qdb_log "$uhand voted $uvote on #$uid / $utable" qdb_msg $upublic $unick $uchan $qdb_msg_you_voted [list $uid $uvote] @@ -343,15 +339,15 @@ set fpattern [string range $ftoken 1 end] if {$fprefix == "-"} { - lappend fpatlist "utext NOT LIKE '%[qdb_escape $fpattern]%'" + lappend fpatlist "utext NOT LIKE '%[utl_escape $fpattern]%'" } elseif {$fprefix == "%"} { - lappend fpatlist "user LIKE '[qdb_escape $fpattern]'" + lappend fpatlist "user LIKE '[utl_escape $fpattern]'" } elseif {$fprefix == "@"} { # foo } elseif {$fprefix == "+"} { - lappend fpatlist "utext LIKE '%[qdb_escape $fpattern]%'" + lappend fpatlist "utext LIKE '%[utl_escape $fpattern]%'" } else { - lappend fpatlist "utext LIKE '%[qdb_escape $ftoken]%'" + lappend fpatlist "utext LIKE '%[utl_escape $ftoken]%'" } } if {[llength $fpatlist] > 0} {
--- a/urllog.tcl Mon Jan 26 14:04:17 2015 +0200 +++ b/urllog.tcl Mon Jan 26 14:07:16 2015 +0200 @@ -187,8 +187,8 @@ proc urllog_exists {urlStr urlNick urlHost urlChan} { global urldb urlmsg_alreadyknown urllog_shorturl - set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, chan AS uchan, title AS utitle FROM urls WHERE url='[urllog_escape $urlStr]'" - urldb eval $usql { + set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, chan AS uchan, title AS utitle FROM urls WHERE url='[utl_escape $urlStr]'" + $usql foreach urow { urllog_log "URL said by $urlNick ($urlStr) already known" if {$urllog_shorturl != 0} { set qstr "[urllog_get_short $uid] " @@ -215,9 +215,9 @@ if {$urlTitle == ""} { set uins "NULL" } else { - set uins "'[urllog_escape $urlTitle]'" + set uins "'[utl_escape $urlTitle]'" } - set usql "INSERT INTO urls (utime,url,user,host,chan,title) VALUES ([unixtime], '[urllog_escape $urlStr]', '[urllog_escape $urlNick]', '[urllog_escape $urlHost]', '[urllog_escape $urlChan]', $uins)" + set usql "INSERT INTO urls (utime,url,user,host,chan,title) VALUES ([unixtime], '[utl_escape $urlStr]', '[utl_escape $urlNick]', '[utl_escape $urlHost]', '[utl_escape $urlChan]', $uins)" if {[catch {urldb eval $usql} uerrmsg]} { urllog_log "$uerrmsg on SQL:\n$usql" return 0 @@ -561,7 +561,7 @@ foreach ftoken $ftokens { set fprefix [string range $ftoken 0 0] set fpattern [string range $ftoken 1 end] - set qpattern "'%[urllog_escape $fpattern]%'" + set qpattern "'%[utl_escape $fpattern]%'" if {$fprefix == "-"} { lappend fpatlist "(url NOT LIKE $qpattern OR title NOT LIKE $qpattern)" @@ -572,7 +572,7 @@ } elseif {$fprefix == "+"} { lappend fpatlist "(url LIKE $qpattern OR title LIKE $qpattern)" } else { - set qpattern "'%[urllog_escape $ftoken]%'" + set qpattern "'%[utl_escape $ftoken]%'" lappend fpatlist "(url LIKE $qpattern OR title LIKE $qpattern)" } }