This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

help with code

Help for those learning Tcl or writing their own scripts.
Post Reply
W
Wayno
Voice
Posts: 3
Joined: Mon Apr 10, 2006 3:22 pm

help with code

Post by Wayno »

hi i have writen some code and it returns with { and } at the ends and i would like to remvoe them how todo it?

Code: Select all

proc invite_me { nick host handle text } {
  
  global db_handle staffchan

      set sql "SELECT username, irc FROM users WHERE username='$nick'"


      set result [mysqlsel $db_handle $sql -list]

        if {$result > 0} {

            set username [lindex [split $result] 0]
            set password [lindex [split $result] 1] 
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

If you do not provide an explicit return value using the "return" command, your proc will exit with the return value of the last successful command within the proc (not counting conditional constructs themselves).

Your code is however somewhat confusing; is $result a list of matching records, or is it the number of records returned?

Code: Select all

if {$result > 0} {
This suggests $result is the number of records returned from your query (being an integer).

Code: Select all

set username [lindex [split $result] 0]
This however suggests that $result is a resultset from your query, with each field being whitespace separated (ie. not a proper tcllist). I am not familiar with the -list parameter for mysqlsel, but from what I can tell from resources on the net, it makes mysqlsel return a list of lists. Hence, split should NOT be used here.

From the bits and pieces I've managed to gather from your script and mysqltcl, I guess you should have something like this:

Code: Select all

proc invite_me { nick host handle text } {
 global db_handle staffchan
 set sql "SELECT username, irc FROM users WHERE username='$nick'"
 set result [mysqlsel $db_handle $sql -list]
 if {[llength $result] > 0} {
  set username [lindex [lindex $result 0] 0]
  set password [lindex [lindex $result 0] 1] 
 }
 ....
}
NML_375
Post Reply