comparison quotedb.tcl @ 670:fdd20366406e

quotedb: Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 23 Feb 2021 14:40:37 +0200
parents a026f5eb9439
children 3904fcfeeb9a
comparison
equal deleted inserted replaced
669:3f5f9d0745a6 670:fdd20366406e
119 # set numQuotes 0 119 # set numQuotes 0
120 # set usql "SELECT count(*) AS numQuotes FROM $utable" 120 # set usql "SELECT count(*) AS numQuotes FROM $utable"
121 # if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { return 0 } 121 # if {![qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { return 0 }
122 122
123 ### Log some data 123 ### Log some data
124 qdb_log "Added $utable #$quoteID ($unick/$uhand@$uchan): $utext" 124 qdb_log "Added ${utable} #${quoteID} (${unick}/${uhand}@${uchan}): ${utext}"
125 125
126 ### Report success to user 126 ### Report success to user
127 qdb_msg $ucmd $utable $upublic $unick $uchan "add_success" [list $quoteID] 127 qdb_msg $ucmd $utable $upublic $unick $uchan "add_success" [list $quoteID]
128 return 1 128 return 1
129 } 129 }
281 qdb_handle eval $usql { 281 qdb_handle eval $usql {
282 # Yes, update the previous vote 282 # Yes, update the previous vote
283 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" 283 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid"
284 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { 284 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} {
285 set urating [qdb_get_rating_for_id $utable $uid] 285 set urating [qdb_get_rating_for_id $utable $uid]
286 qdb_log "$uhand changed vote to $uvote on #$uid / $utable, total $urating" 286 qdb_log "${uhand} changed vote to ${uvote} on #${uid} / ${utable}, total ${urating}"
287 qdb_msg $ucmd $utable $upublic $unick $uchan "vote_updated" [list $uid $uvote $urating] 287 qdb_msg $ucmd $utable $upublic $unick $uchan "vote_updated" [list $uid $uvote $urating]
288 return 1 288 return 1
289 } else { 289 } else {
290 return 0 290 return 0
291 } 291 }
293 293
294 # No previous votes, insert new 294 # No previous votes, insert new
295 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)" 295 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)"
296 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} { 296 if {[qdb_sql_exec $ucmd $utable $upublic $unick $uchan $usql]} {
297 set urating [qdb_get_rating_for_id $utable $uid] 297 set urating [qdb_get_rating_for_id $utable $uid]
298 qdb_log "$uhand voted $uvote on #$uid / $utable, total $urating" 298 qdb_log "${uhand} voted ${uvote} on #${uid} / ${utable}, total ${urating}"
299 qdb_msg $ucmd $utable $upublic $unick $uchan "you_voted" [list $uid $uvote $urating] 299 qdb_msg $ucmd $utable $upublic $unick $uchan "you_voted" [list $uid $uvote $urating]
300 } 300 }
301 } 301 }
302 302
303 303
307 307
308 set usql "SELECT total(${utable}_votes.vote) AS uvote, ${utable}.id AS quoteID, ${utable}.utext AS uquote, ${utable}.utime AS utime, ${utable}.user AS uuser FROM ${utable} LEFT JOIN ${utable}_votes ON ${utable}_votes.urlid = ${utable}.id" 308 set usql "SELECT total(${utable}_votes.vote) AS uvote, ${utable}.id AS quoteID, ${utable}.utext AS uquote, ${utable}.utime AS utime, ${utable}.user AS uuser FROM ${utable} LEFT JOIN ${utable}_votes ON ${utable}_votes.urlid = ${utable}.id"
309 309
310 if {$uindex >= 0} { 310 if {$uindex >= 0} {
311 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id" 311 append usql " WHERE ${utable}.id=$uindex GROUP BY ${utable}.id"
312 qdb_log "$unick searched $utable #$uindex" 312 qdb_log "${unick} searched ${utable} #${uindex}"
313 } elseif {$uindex == -1} { 313 } elseif {$uindex == -1} {
314 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1" 314 append usql " GROUP BY ${utable}.id ORDER BY RANDOM() LIMIT 1"
315 qdb_log "$unick get random $utable" 315 qdb_log "${unick} get random ${utable}"
316 } elseif {$uindex == -2} { 316 } elseif {$uindex == -2} {
317 append usql " GROUP BY ${utable}.id ORDER BY ${utable}.id DESC LIMIT 1" 317 append usql " GROUP BY ${utable}.id ORDER BY ${utable}.id DESC LIMIT 1"
318 qdb_log "$unick get latest $utable" 318 qdb_log "${unick} get latest ${utable}"
319 } else { 319 } else {
320 qdb_log "$unick invalid qdb_get $utable index value." 320 qdb_log "${unick} invalid qdb_show ${utable} index value."
321 return 0 321 return 0
322 } 322 }
323 323
324 set urlprefix [qdb_qm $utable "urlprefix"] 324 set urlprefix [qdb_qm $utable "urlprefix"]
325 325