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 

Returning Results

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
danwa
Voice


Joined: 17 Oct 2011
Posts: 2

PostPosted: Mon Oct 17, 2011 11:56 pm    Post subject: Returning Results Reply with quote

Using this in conjunction with the mysql eggdrop module

http://www.barkerjr.net/eggdropmodules.html
http://wiki.barkerjr.net/wiki/MySQL_Module#Tcl_Commands

Code:
proc mysql {n u h c a} {
mysql_connect dbname dbhost dbuser dbpass
mysql_query "select * from Residential WHERE Phone1 = 'a'"
puthelp "PRIVMSG $c: $a"
mysql_errno
}
bind pub -|- !mysqlquery mysql


In the Table Residential there is a field named Phone1 that is populated in every row.

I can't get it to return anything, saying that, i'm not very confident with TCL.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Oct 18, 2011 2:25 am    Post subject: Reply with quote

The script isn't working cos you forgot to fetch the results after you've queried the database. Don't know your database structure so I will fetch first 3 rows of the database and you should change this.
Code:

set db(host) "localhost"
set db(user) "user"
set db(pass) "secret"
set db(dbase) "search"

bind pub -|- !mysqlquery mysql

proc mysql {nick uhost hand chan txt} {
   global db
   set db_handle [mysqlconnect -host $db(host) -user $db(user) -password $db(pass) -db $db(dbase)]
   set results [mysqlquery $db_handle "SELECT * from Residential WHERE Phone1 = 'a'"]
   if {![moreresult $results]} {
      puthelp "PRIVMSG $chan :Couldn't find any matches."
   } else {
      puthelp "PRIVMSG $chan :Matches:"
      while {[set row [mysqlfetch $results]] != ''} {
         set row1 [lindex $row 0]
         set row2 [lindex $row 1]
         set row3 [lindex $row 2]
         puthelp "PRIVMSG $chan :row1: $row1, row2: $row2, row3: $row3"
      }
      mysqlendquery $results
   }
   mysqlclose $db_handle
}

Haven't tested this but in theory should work, if you change the database info and the rows. Let me know if it doesn't. Wink
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Oct 18, 2011 3:23 am    Post subject: Reply with quote

The code posted by caesar is written for the mysqltcl tcl module, not BarkerJr's eggdrop module. Personally, I'd recommend the mysqltcl module as well, as it's a bit more flexible, and remains the same across other tcl-based applications.

That said, the problem with your script, is that you don't use the return-value of the mysql_query command:
Code:
...
mysql_query "select * from Residential where Phone1 = 'a'"
..

To store the result in a variable, use this:
Code:
set result [mysql_query "select * from Residential where Phone1 = 'a'"]

Now you can send the result to the channel, one record at a time:
Code:
foreach item $result {
  puthelp "PRIVMSG $c :Record: $item"
## Or perhaps a little neater:
# puthelp "PRIVMSG $c :Record: [join $item ", "]"
}

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
danwa
Voice


Joined: 17 Oct 2011
Posts: 2

PostPosted: Tue Oct 18, 2011 7:46 am    Post subject: Reply with quote

Thanks for letting me know guys Smile
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Oct 19, 2011 1:08 am    Post subject: Reply with quote

Thanks nml375. Smile I forgot to mention that.
_________________
Once the game is over, the king and the pawn go back in the same box.
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 -> Scripting Help 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