I'm trying to provide a partyline interface to mysql-client, for convenience, and a bit of interest as to the method.
Basically I want to pipe the i/o to and from the external program (mysql), to display results in the dcc partyline.
Not to be confused, I already use a mysql module for code - I want to emulate the entire mysql client by executing it externally.
After a tip from someone, and looking at user's code on another forum topic, I came up with this:
Code: Select all
bind dcc n mysql mysql_1
proc mysql_1 {h i a} {
# hack to honor the "must-be-owner" setting:
*dcc:tcl $h $i [list mysql_2 $h $i $a]
}
proc mysql_2 {h i a} {
global dbi
set dbi [open "|mysql -u user --password=pwd db" r+]
fconfigure $dbi -blocking 0 -buffering line
fileevent $dbi readable [list gotline $dbi]
control $i [list mysql_3 $h]
return "Type 'exit' to return to the real world."
}
proc mysql_3 {h i a} {
global dbi
if {$a=="exit"} {
unset a
close $dbi
return 1
} {
puts $dbi $a
flush $dbi
putserv "privmsg empus :(debug) puts $dbi $a"
set a ""
}
append a \n
return 0
}
# EDIT: Added this proc for stupid irc clients that
# are incapable of displaying the tab character (\x09)
# Remove it if you don't need it.
proc putdcc {i a} {::putdcc $i [string map {\t " "} $a]}
proc gotline {dbi} {
if {![eof $dbi]} {
if {[gets $dbi] != ""} {
putserv "privmsg empus :(debug) [gets $dbi]"
#putdcc $i "mysql: [gets $dbi]"
}
}
}
putlog "\[@\] MySQL Interface Loaded."
Something is wrong here, but I'm not quite sure what... any help would be much appreciated.
Cheers,
-Mike