Insert char(0) into Mysql

Hi,

I write in c and use mysql.h. It works :)

I need to write a char * into my Mysql's table. But my char * has some char(0).

Here is my sample :

--------------------------------------
// Chaine = "Toto Titi "
char chaine[100];
chaine[0]=0x54; // Char T
chaine[1]=0x6F; // Chat o
chaine[2]=0x74; // Char t
chaine[3]=0x6F; // Char o
chaine[4]=0x00;
chaine[5]=0x54; // Char T
chaine[6]=0x69; // Char i
chaine[7]=0x74; // Char t
chaine[8]=0x69; // Char i
chaine[9]=0x00;

sprintf(requetesql,"UPDATE Table SET description='%s' WHERE id='1'",chaine);
mysql_query(idmysql,requetesql);
--------------------------------------

The Update works. But in the the Description field into my table, there are only Toto.
I think that the function Update write the string and stop to the first 0.
In another function as send or fwrite, we can specify the length of the string.

how can i do with Mysql ?


Chris
A null character (0x00) marks the end of the string. You probably want to separate the words with a space character (0x20) instead.
Yes 0x00 marks the end of the string. It's my problem, i want to write 0x00.

I want write a raw information as :

char chaine={0x00,0x01,0x77,0x00,0x04};

Try using the \0 escape sequences by replacing 0x00 with 0x5C followed by 0x30.
Last edited on
I can, but after, when i will read my sql table, how i can know if :

0x5C,0x30,0x00 is 0x00 or 0x5C,0x30,0x00 ?

Thx
I thought MySQL would automatically convert \0 into a null character.

http://dev.mysql.com/doc/refman/5.7/en/string-literals.html#character-escape-sequences
Topic archived. No new replies allowed.