This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

sql and special chars

Old posts that have not been replied to for several years.
Locked
s
slashem
Voice
Posts: 18
Joined: Tue Aug 13, 2002 6:35 pm

sql and special chars

Post by slashem »

I'm making some kind of !msg bot where members can use !msg <username> <message_text> to send msg's to offline users and when the users join the channel they'll get there message..

I'm having a problem with adding messages that contain special characters to the mysql database...

"insert into msgs ( msgcontents ) values ('$message')" doesn't work when theres's a word like " he's " or " it's " in the $message ..

anyone know how to work around this so that those words with special chars can get added and retrieved normally ?

thx in advance :-)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

This all depends on the MySQL interface you are using.

Are you using a MySQL library for Tcl, or writting to a file, and sending it to the MySQL application?

Using a Tcl package is by far the most simple, and the best way about creating a fix. To do so, you should use the function provided, for escaping caracters.

For writting to a file (or direct to stdin on the mysql app), it would all depend how you handled the incoming text.

First, follow the rules for lists, as defined in the FAQ entry on the forum. If you can't work out how, you should paste the script, that is haviong trouble, and we can give pointers.
s
slashem
Voice
Posts: 18
Joined: Tue Aug 13, 2002 6:35 pm

Post by slashem »

I'm using some tcl-mysql package (mysqltcl)

which funtion for escaping characters are you pointing to ?

the only code that generates the error is
"insert into msgs ( msgcontents ) values ('$message')" because $message contains words with a ' in it
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Read the package documentation.

There should be a command prvided, that will excape any characters for you, so that the message is designed to be sent to a MySQL server.

In this situation, only the $message variable should be passed throuhg this function.
s
slashem
Voice
Posts: 18
Joined: Tue Aug 13, 2002 6:35 pm

Post by slashem »

ok, found the function
had to use [mysqlescape $variable] .. but now a new problem has arisen :/

when I retrieve the text I put in the sql db back I get it like {he's bla bla bla bla} as a string.. with those {} :/
how can I msg that to a person without those {} ?

----
Hmm, I was trying some more stuff and apparantly found it:)
set something [mysqlnext $db]
[lindex $something 0] <- got me what I needed
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

The moral of this story, is to read the documentation.

All Tcl documentation, states what a command will return. IE, string, list, multiple dimentional list.
Locked