Re: Problem With TCL

Lists: pgsql-interfaces
From: "Paulo Ricardo Stradioti" <rev0ltz(at)hotmail(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Problem With TCL
Date: 2005-07-31 07:16:07
Message-ID: BAY7-F2302527EC9AE2E769D2BD3FCC00@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Hi all,

My name is Paulo and I'm trying to make a tcl that allows my IRC Bot
connects to my IRC Services (gnuworld) PostgreSQL database and get
information about our channels.

I thought it was working fine, until I tryed to find information about a
channel called #espaa. For our surprise the bot told "No records found for
#espaa". So I got curious and made other tests... it doesn't works for any
channels with chars like in the name.

I already tryed to google it, but (may be my bad, anyway, ) I didn't find
much.

Could anyone help me please?

My TCL code that checks information about that channels is:

bind pub $cservice(flags) ${cservice(char)}info pub.info:cservice
proc pub.info:cservice {nick uhost hand chan rest} {
global cservice
if {[lindex $rest 0] == ""} {
putserv "Notice $nick :Command should be: \002$cservice(char)purge
\<#ChannelName\>\002"
if {$cservice(dchan) != ""} {
putserv "PRIVMSG $cservice(dchan)
:\002\[\002CSC\002/\002Debug\002\]\002 Failed attemp to get \002PURGE\002
information from \002${nick}\002!${uhost} ($hand). Reason: \002Wrong Command
Syntax\002"
}
return 0
}
if {![string match "#*" [lindex $rest 0]]} {
putserv "NOTICE $nick :\002[string toupper [lindex $rest 0]]\002
doesn't seems to be a valid Channel Name!"
return 0
}
set conexao [pg_connect $cservice(database) -host $cservice(host) -port
$cservice(port)]
putserv "NOTICE $nick :Please wait while I get \002[string toupper
$cservice(command_purge)]\002 information about channel \002[string tolower
[lindex $rest 0]]\002"
set query [pg_exec $conexao "SELECT * FROM channels WHERE
lower(name)='[string tolower [lindex $rest 0]]'";]
if {[pg_result $query -numTuples] > 0} { putserv "NOTICE $nick :Results
Found" } else { putserv "NOTICE $nick :No records found" }
pg_disconnect $conexao
}

Well... another interesting notes: I can see information about that kind of
channel name using a third part PHP nterface. Current server encoding is
'SQL_ASCII'. (I'm not familiar with that... but some guys told that it may
be usefull).

Thanks for your time guys. Hugs.

Paulo

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


From: ljb <ljb220(at)mindspring(dot)com>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Problem With TCL
Date: 2005-08-01 02:21:13
Message-ID: dck0uo$dprdck0uo$dpr$1@news.hub.org@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

rev0ltz(at)hotmail(dot)com wrote:
> ...
> I thought it was working fine, until I tryed to find information about a
> channel called #espa?a. For our surprise the bot told "No records found for
> #espa?a". So I got curious and made other tests... it doesn't works for any
> channels with chars like ? in the name.
> ...
>
> Well... another interesting notes: I can see information about that kind of
> channel name using a third part PHP nterface. Current server encoding is
> 'SQL_ASCII'. (I'm not familiar with that... but some guys told that it may
> be usefull).

Two possible causes come to mind. Hope this helps.

(1) If your database encoding is SQL_ASCII, you will have problems storing
and retrieving non-ASCII characters from CHAR, VARCHAR, and TEXT fields.
Your database encoding should be something more appropriate to your locale,
perhaps "Latin1" or "UNICODE". This is especially important with Tcl
interfaces, which send and expect utf-8 (Unicode) encoded characters
to/from PostgreSQL. PostgreSQL will handle the conversion between Tcl and
your database encoding, unless the database encoding is SQL_ASCII.

(2) You have:
set query [pg_exec $conexao "SELECT * FROM channels WHERE \
lower(name)='[string tolower [lindex $rest 0]]'";]
It would be nice to think that SQL lower() gives the same results as Tcl's
[string tolower] on non-ASCII characters, but I am a skeptic, and would
want to prove it with some tests. Perhaps it does work, but only if the
database encoding is right. Or maybe it is better not to mix server-side
and client-side case mangling.