| View previous topic :: View next topic |
| Author |
Message |
ReeVo Voice
Joined: 30 Jul 2014 Posts: 2
|
Posted: Wed Jul 30, 2014 12:15 pm Post subject: TCL MySQL Select querstion |
|
|
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: | 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
} |
|
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Wed Jul 30, 2014 2:08 pm Post subject: |
|
|
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, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|