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.

error when var not exist (part is mysqltcl)

Old posts that have not been replied to for several years.
Locked
s
shanks
Voice
Posts: 19
Joined: Mon Aug 18, 2003 7:03 am

error when var not exist (part is mysqltcl)

Post by shanks »

Code: Select all

proc getpost {} {
  global db_handle posttimer
  putlog "\[ #ns.pcw \] - Processing queue slot 1"

  set que1 "SELECT * FROM posts ORDER BY thetime ASC LIMIT 1"
  
  set newpost [mysqlsel $db_handle $que1 -flatlist]

  foreach {id ircnick qauth thetime post} $newpost {
    puthelp "PRIVMSG $::relay(adchan) :$id $ircnick $qauth $thetime $post"
  }

  set que2 "DELETE FROM posts WHERE id='$id'"
  
  set result [mysqlexec $db_handle $que2]
  
  puthelp "PRIVMSG $::relay(adchan) :Post \[ $id \] successfully copied and deleted."
  
  set posttimer [utimer 30 getpost]
  putlog "\[ #ns.pcw \] - getpost proc timer reset"
}

The proc will take a single line from the database, and then put it into an irc channel ($::relay(adchan)) then deletes it from the database - It works fine as long as there are rows in the table - however, if there isn't any thing in the table, then it has no definition for $id, so it gives an error and stops the proc...

so, need a re-write so it won't kill the loop if the table is empty....

any ideas? :/
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

you just need to add a couple of lines to your foreach-loop

Code: Select all

  foreach {id ircnick qauth thetime post} $newpost {
    if {![info exists id]} { 
      set posttimer [utimer 30 getpost] 
      putlog "\[ #ns.pcw \] - getpost proc timer reset"
      return
    }
    puthelp "PRIVMSG $::relay(adchan) :$id $ircnick $qauth $thetime $post" 
  }
Elen sila lúmenn' omentielvo
s
shanks
Voice
Posts: 19
Joined: Mon Aug 18, 2003 7:03 am

Post by shanks »

Well i added that line... tested it today


didn't really go too well :o

<NSP-Hub> [17:51] Tcl error in script for 'timer28'
<NSP-Hub> [17:51] can't read "id": no such variable

Code: Select all

proc getpost {} {
  global db_handle posttimer
  putlog "\[ #ns.pcw \] - Processing queue slot 1"

  set que1 "SELECT * FROM posts ORDER BY thetime ASC LIMIT 1"
  
  set newpost [mysqlsel $db_handle $que1 -flatlist]

  # INSERT CODE FOR DECOMPOSE + PUT ALL BOTS

  foreach {id ircnick qauth thetime post} $newpost { 
    if {![info exists id]} { 
      set posttimer [utimer 30 getpost] 
      putlog "\[ #ns.pcw \] - Table empty - timer reset" 
      return 0
    } 
    puthelp "PRIVMSG $::relay(adchan) :$id $ircnick $qauth $thetime $post" 
  }

  set que2 "DELETE FROM posts WHERE id='$id'"
  
  set result [mysqlexec $db_handle $que2]
  
  puthelp "PRIVMSG $::relay(adchan) :Post \[ $id \] successfully copied and deleted."
  
  set posttimer [utimer 30 getpost]
  putlog "\[ #ns.pcw \] - Post deleted - timer reset"
}
any ideas? thanks for your help
Locked