comparison quotedb.tcl @ 148:2f0c823386b0

quotedb: Simplify a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 27 May 2014 07:11:29 +0300
parents 593874678e45
children fc2654064339
comparison
equal deleted inserted replaced
147:48460e925a8c 148:2f0c823386b0
340 qdb_msg $upublic $unick $uchan "quotea #$uid ei ole." 340 qdb_msg $upublic $unick $uchan "quotea #$uid ei ole."
341 return 0 341 return 0
342 } 342 }
343 343
344 # Check if user has previously voted this item 344 # Check if user has previously voted this item
345 set uresults 0
346 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[qdb_escape $uhand]' AND urlid=$uid" 345 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[qdb_escape $uhand]' AND urlid=$uid"
347 quotedb eval $usql { 346 quotedb eval $usql {
348 incr uresults
349 # Yes, update the previous vote 347 # Yes, update the previous vote
350 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" 348 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid"
351 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { 349 if {[qdb_sql_exec $upublic $unick $uchan $usql]} {
352 qdb_log "$uhand changed vote to $uvote on #$uid / $utable" 350 qdb_log "$uhand changed vote to $uvote on #$uid / $utable"
353 qdb_msg $upublic $unick $uchan "ääni päivitetty #$uid -> $uvote" 351 qdb_msg $upublic $unick $uchan "ääni päivitetty #$uid -> $uvote"
355 } else { 353 } else {
356 return 0 354 return 0
357 } 355 }
358 } 356 }
359 357
360 if {$uresults == 0} { 358 # No previous votes, insert new
361 # No previous votes, insert new 359 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[qdb_escape $uhand]',$uid,$uvote)"
362 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[qdb_escape $uhand]',$uid,$uvote)" 360 if {[qdb_sql_exec $upublic $unick $uchan $usql]} {
363 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { 361 qdb_log "$uhand voted $uvote on #$uid / $utable"
364 qdb_log "$uhand voted $uvote on #$uid / $utable" 362 qdb_msg $upublic $unick $uchan "äänestit #$uid -> $uvote"
365 qdb_msg $upublic $unick $uchan "äänestit #$uid -> $uvote"
366 }
367 } 363 }
368 } 364 }
369 365
370 366
371 #------------------------------------------------------------------------- 367 #-------------------------------------------------------------------------