Let's put the above code in theory and see what really happens inside.
Code: Select all
% set data [list "1" "3" "5" "2" "9" "7"]
1 3 5 2 9 7
% proc foo {a} {
foreach i $a {
if {$i eq 2} {
return $i
}
}
puts "done?"
}
Considering the above code, what happens when I execute "foo $data" ? Will i get to see the "done" message? Answer is NO!
Why don't we see it? Umm.. Because of the return statement maybe?
Let's see. If we change the above code a bit to add something so we know we had a match and break the loop when we got this match (if this was what we where looking for in the first place).
Code: Select all
proc foo {a} {
set match 0
foreach i $a {
if {$i eq 2} {
incr match
break
}
}
puts "done?"
return $match
}
then the result is:
OMG! It works!
Bottom line is: never, ever use a
return inside a loop. Break it if your proc matched something or use continue if it didn't.
Long story told short, you get this issue because of the return that stops the process before reaching the part where it closes the session to the mysql database.
PS: You should drop the
-list at the end if you just want to see the number of rows returned as the result of the query.
If sql-statement is a SELECT statement and no -list or -flatlist option is specified, the command returns the number of rows returned as the result of the query. The rows can be obtained by the ::mysql::fetch and/or the ::mysql::map commands.
Taken from
::mysql:sel's documentation
As it stands right now your select statement looks rather dumb. What exactly do you want to achive there? Want to see if there's something in the database with a
fk_i_category_id that is matching the given
number? Do you
sanitize that number btw?
I would consider doing at least a:
Code: Select all
if {![string is integer $number]} return
or something.
Once the game is over, the king and the pawn go back in the same box.