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.

TCL MySQL Select querstion

Discussion of Eggdrop's code and module programming in C.
Post Reply
R
ReeVo
Voice
Posts: 2
Joined: Wed Jul 30, 2014 11:53 am

TCL MySQL Select querstion

Post by ReeVo »

Hello Ppl,

first sorry for my english ;)

i dont know if i`m on the right place here, but i have some question/problem with a tcl that i try to script ;)
I want that my Bot(Eggdrop) post every 30 Minutes news message that is stored in my Database and put it in my channel #news, it dont work :)

Here my code

Code: Select all

load /usr/lib/libmysql/libmysqltcl3.05.so

set db_handle [mysql::connect -host localhost -user XXX -password XXXX -db XXX]

putlog "My first script successfully loaded"

if {![info exists myproc_running]} {   
    timer 30 myproc                      
    set myproc_running 1                 
  }                                      

  proc myproc {channel} {                       
      set sql "SELECT * FROM news ORDER BY id desc limit 1"         
      set result [mysqlquery $db_handle $sql]  
      puthelp "PRIVMSG $channel: $news"
      timer 30 myproc                    
      return 1                           
  }         
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

There are a few issues with the script.

First off, your proc "myproc" expects a channel-name as an argument, yet you never provide one when calling it.

Secondly, the mysqlquery command returns a "query handle", which can be then used to retrieve the actual data from the database. This query also needs to be closed, by using mysqlendquery, to avoid resource-leaks.
A better option in this case would be the mysqlsel command with the -list option, which would return the data directly, and will close the query on its own.

Thirdly, it is not uncommon for mysql-servers to close connections that remain idle for some time, and your code does not check for that. You should consider opening and closing the connection as needed, or at least use mysqlping to verify and/or reconnect to the server when needed.
Also, leaving the connection open and idle wastes server resources, and can be an issue on server with high load.
NML_375
Post Reply