egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TCL MySQL Select querstion

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming
View previous topic :: View next topic  
Author Message
ReeVo
Voice


Joined: 30 Jul 2014
Posts: 2

PostPosted: Wed Jul 30, 2014 12:15 pm    Post subject: TCL MySQL Select querstion Reply with quote

Hello Ppl,

first sorry for my english Wink

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 Wink
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 Smile

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2831

PostPosted: Wed Jul 30, 2014 2:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Modules & Programming All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber