On Fri, 14 Dec 2001, Ian Collins wrote: > > I am having difficulties with entering binary data from a c program. > I have passed the string through mysql_real_escape_string.
Post the C data then. However read on. > > . . . > > drop table if exists junk5; > > create table junk5 > ( > id int not null, primary key(id), > s1 char(10) not null, > i1 smallint not null > ); > > insert junk5 values(1,'abc\0def\0gh', 2); > insert junk5 values(2,'abc\\0def\\0gh', 3); > insert junk5 values(3,'abc\\0def\0gh', 4); > > select * from junk5; > > By running this snippet, you will see that you need to "double escape" the > null to get it in the database. No. What you are putting in the database is (character by character): 1 => 'a', 'b', 'c', 0, 'd' ... 2 => 'a', 'b', 'c', '\', '0', 'd' ... Proof: mysql> select id, substring(s1, 1, 3) as first3, ascii(substring(s1, 4, 1)) as fourth, substring(s1, 5, 5) as remainder from junk5; +----+--------+--------+-----------+ | id | first3 | fourth | remainder | +----+--------+--------+-----------+ | 1 | abc | 0 | def | | 2 | abc | 92 | 0def\ | | 3 | abc | 92 | 0def | +----+--------+--------+-----------+ The 'problem' is in the output from the "mysql" program: it does not have a literal for null (in text); instead it seems to interpret it as end of text; this is probably because it is bound to the C zero-terminated strings model. Using the API you can get it right. -- , M A R I O data miner, LIACC, room 221 tel 351+226078830, ext 121 A M A D O Rua Campo Alegre, 823 fax 351+226003654 A L V E S P-4150-180 PORTO, Portugal mob 351+939354002 --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php