<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/17750" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2010-04-29T15:56:03-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/17750</id>

		<entry>
		<author><name><![CDATA[nightshade2109]]></name></author>
		<updated>2010-04-29T15:56:03-04:00</updated>

		<published>2010-04-29T15:56:03-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92971#p92971</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92971#p92971"/>
		<title type="html"><![CDATA[mysqltcl help proc and bind with 2 variables]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92971#p92971"><![CDATA[
Thanks for the reply, it's working <img class="smilies" src="https://forum.eggheads.org/images/smilies/icon_smile.gif" width="15" height="15" alt=":)" title="Smile"><br><br>This is my first attempt at writing a TCL script thanks for the pointers.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11192">nightshade2109</a> — Thu Apr 29, 2010 3:56 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nml375]]></name></author>
		<updated>2010-04-29T14:46:33-04:00</updated>

		<published>2010-04-29T14:46:33-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92969#p92969</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92969#p92969"/>
		<title type="html"><![CDATA[mysqltcl help proc and bind with 2 variables]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92969#p92969"><![CDATA[
<span style="color:red">Step 1: Patience... aka bumping within 12h will certainly end up in the Junk Yard... Period.</span><br><br>Step 2: read the docs (doc/tcl-command.doc) and look up the pub binding:<blockquote class="uncited"><div>    (4)  PUB<br>         bind pub &lt;flags&gt; &lt;command&gt; &lt;proc&gt;<br>         procname &lt;nick&gt; &lt;user@host&gt; &lt;handle&gt; &lt;channel&gt; &lt;text&gt;<br><br>         Description: used for commands given on a channel. The first word<br>           becomes the command and everything else is the text argument.<br>         Module: irc</div></blockquote>This tells us that when the binding is triggered, your command is called with 5 arguments, being the nickname of the caller, the user@host identifier of the caller, the handle (or * if not recognized) of the caller, channel the text was posted in, and the text that followed the keyword.<br>Thus, your proc should start something like this:<div class="codebox"><p>Code: </p><pre><code>proc fetch {nick host handle channel text} {...</code></pre></div>Next, we need to extract the first two words of "text". There are plenty of different approaches, though using lists is what most people prefer:<div class="codebox"><p>Code: </p><pre><code>proc fetch {nick host handle channel text} {  set tmp [split $text] #convert text into a list, and store in tmp  set text1 [lindex $tmp 0] #extract the first item from the list, and store in text1  set text2 [lindex $tmp 1] #extract the second item...</code></pre></div>Further, since this is coming from irc, we really should make sure both text1 and text2 are safe - to prevent SQL injection exploits:<div class="codebox"><p>Code: </p><pre><code>proc fetch {nick host handle channel text} {  set tmp [split $text] #convert text into a list, and store in tmp  set text1 [::mysql::escape [lindex $tmp 0]]  set text2 [::mysql::escape [lindex $tmp 1]]</code></pre></div>Next, implement the database code.. Though your SQL-query really makes no sense at all... If you want two rows, either use OR (not AND), or consider using the FIELD() function<div class="codebox"><p>Code: </p><pre><code>proc fetch {nick host handle channel text} {  global db_handle  set tmp [split $text] #convert text into a list, and store in tmp  set text1 [::mysql::escape [lindex $tmp 0]]  set text2 [::mysql::escape [lindex $tmp 1]]  set sql "SELECT * FROM table WHERE `name`='$text1' OR `name`='$text2'"  set data [::mysql::sel $db_handle $sql -list]  set text1out [lindex $data 0 0]  set text2out [lindex $data 1 0]  puthelp "PRIVMSG $chan :$text1out $text2out"}</code></pre></div>Using the mysql namespace is the preferred way since mysqltcl v3, but if you are using an older version of mysqltcl that does not support the mysql namespace, simply remove the :: from the commands (ie ::mysql::sel becomes mysqlsel)<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=8052">nml375</a> — Thu Apr 29, 2010 2:46 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[nightshade2109]]></name></author>
		<updated>2010-04-28T21:14:29-04:00</updated>

		<published>2010-04-28T21:14:29-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=92963#p92963</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=92963#p92963"/>
		<title type="html"><![CDATA[mysqltcl help proc and bind with 2 variables]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=92963#p92963"><![CDATA[
Hi guys perhaps some could help I cant seem to figure this out.<br><br>Basically what I'm trying to do is look up 2 id's in a database on different rows with a public command: .get username1 username2 with the column "name" then have the 2 id's displayed in the channel.<br><br>MySQL tables looks like this<br><br>tablename<br>id name<br>1  username1<br>2  username2<br><br><br>This is what i have so far although its not working at all.<br><br>if someone could help it would be appreciated.<div class="codebox"><p>Code: </p><pre><code>package require mysqltclproc command_connect { } {global db_handleset db_handle [mysqlconnect -host localhost -user root -password mypass -db mydb]if {$db_handle != ""} {return 1} else {return 0}}bind pub "-|-" .get fetchproc ping { } {global db_handleif [::mysql::ping $db_handle] {return 1} else {return [command_connect]}}proc fetch { nick host handle text1 text2} {  global db_handle chan  set chan "#channel"  set sql "SELECT * FROM table WHERE name='$text1' AND (name='$text2')"  set result [mysqlquery $db_handle $sql]    if {[set row [mysqlnext $result]] != ""} {        set text1out [lindex $row 0]set text2out [lindex $row 0]        putquick "PRIVMSG $chan :$text1out $text2out"      }       mysqlendquery $result}command_connect</code></pre></div><p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=11192">nightshade2109</a> — Wed Apr 28, 2010 9:14 pm</p><hr />
]]></content>
	</entry>
	</feed>
