comparison quotedb.tcl @ 27:6e381916b016

Some fixes in the query mechanisms of QuoteDB and URLLog.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Sep 2011 19:51:46 +0300
parents 3f999371de82
children c3c597cac4b6
comparison
equal deleted inserted replaced
26:3f999371de82 27:6e381916b016
182 } 182 }
183 183
184 set maxdiff [expr $qdb_max_deltime * 60] 184 set maxdiff [expr $qdb_max_deltime * 60]
185 185
186 if {[regexp "(\[0-9\]+)" $utext umatch unum]} { 186 if {[regexp "(\[0-9\]+)" $utext umatch unum]} {
187 set quoteID $unum
187 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable WHERE id=$unum AND user='[qdb_escape $uhand]'" 188 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable WHERE id=$unum AND user='[qdb_escape $uhand]'"
188 } else { 189 } else {
189 qdb_msg $upublic $unick $uchan "ID # annettava." 190 qdb_msg $upublic $unick $uchan "ID # annettava."
191 return 0
190 } 192 }
191 193
192 quotedb eval $usql { 194 quotedb eval $usql {
193 set udiff [expr [unixtime] - $utime] 195 set udiff [expr [unixtime] - $utime]
194 if {$udiff < $maxdiff} { 196 if {$udiff < $maxdiff} {
243 245
244 ### Parse the given command 246 ### Parse the given command
245 qdb_log "$unick/$uhand/$uchan searched $utable: $utext" 247 qdb_log "$unick/$uhand/$uchan searched $utable: $utext"
246 248
247 set ftokens [split $utext " "] 249 set ftokens [split $utext " "]
250 set fpatlist ""
248 foreach ftoken $ftokens { 251 foreach ftoken $ftokens {
249 set fprefix [string range $ftoken 0 0] 252 set fprefix [string range $ftoken 0 0]
250 set fpattern [string range $ftoken 1 end] 253 set fpattern [string range $ftoken 1 end]
251 254
252 if {$fprefix == "-"} { 255 if {$fprefix == "-"} {
257 # foo 260 # foo
258 } else { 261 } else {
259 lappend fpatlist "utext LIKE '%[qdb_escape $ftoken]%'" 262 lappend fpatlist "utext LIKE '%[qdb_escape $ftoken]%'"
260 } 263 }
261 } 264 }
265 if {[llength $fpatlist] > 0} {
266 set fquery "WHERE [join $fpatlist " AND "]"
267 } else {
268 set fquery ""
269 }
262 270
263 set uresults 0 271 set uresults 0
264 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable WHERE [join $fpatlist " AND "] ORDER BY utime DESC LIMIT $ulimit" 272 set usql "SELECT id AS quoteID, utime AS utime, utext AS utext, user AS uuser, host AS uhost FROM $utable $fquery ORDER BY utime DESC LIMIT $ulimit"
265 quotedb eval $usql { 273 quotedb eval $usql {
266 incr uresults 274 incr uresults
267 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[qdb_ctime $utime])" 275 qdb_msg $upublic $unick $uchan "#${quoteID}: $utext ($uuser@[qdb_ctime $utime])"
268 } 276 }
269 277