Code: Select all
if {![channel get $channel newsengine]} {
return 0
}
if you wish to exit from a loop either use 'break' or 'continue' (self both are explanatory), not 'return'.
You should move the SQL query outside the while loop and change the 'limit' to suit your needs, meaning it's stupid to do 5 queries when you can do just one to fetch 5 results from the table and then have them parsed how you wish, something like:
Code: Select all
query
while (having results) {
parse them
}
free-up memory and close the mysql connection
Edit: In mysqlnews.sql I would change from "timestamp bigint(20)" to "timestamp int(10)" if the time is stored in this way.
Here is my (foolish) attempt on doing this:
Code: Select all
bind time - "30 * * * *" autonews
bind time - "00 * * * *" autonews
proc autonews {mins hours days months years} {
global db_handle news_noflags
set limit 5
foreach channel [channels] {
if {![channel get $channel newsengine]} {
continue
}
set results [mysqlquery $db_handle "SELECT id, news, by, FROM_UNIXTIME(timestamp, "%d %b %Y %H:%M") AS when FROM news WHERE channel = $chan ORDER BY id DESC LIMIT $limit"]
if {![moreresult $results]} {
puthelp "PRIVMSG $channel :Couldn't find any news (try adding news first!)"
} else {
puthelp "PRIVMSG $channel :NEWS:"
while {[set row [mysqlfetch $results]] != ''} {
set id [lindex $row 0]
set news [lindex $row 1]
set by [lindex $row 2]
set when [lindex $row 3]
puthelp "PRIVMSG $channel :\[\002$id\002\] $when from $by on $chan: $news"
}
puthelp "PRIVMSG $channel :End of news"
}
mysqlendquery $results
}
mysqlclose $db_handle
}
haven't tested it but theoretically should work.

I'm not 100% sure about the 'FROM_UNIXTIME' thing. Anyway, I would appreciate some feedback on this.
user (a very resourceful fountain of information IMHO, too bad he's been idle lately, among others) once
posted a decr proc you should use in your scripts:
Code: Select all
proc decr var {
uplevel 1 [list incr $var -1]
}
Btw, ::mysql::map looks interesting.
Edit: Ahh, updated. Thanks username.

Once the game is over, the king and the pawn go back in the same box.