bart2puck
bart2puck

Reputation: 2522

Get ASCII Results in MySql cli Queries

I am trying to put the following value into a mysql table:

  lT~:uc9%7 4M?;~=0=^

so i:

 update table set field='lT~:uc9%7\04M?;~=0=^' where id='1';

when i select I get:

 select * from table where id='1';

result:

 lT~:uc9%7 4M?;~=0=^

I know this is because \0 is being interpretted as a space. How can i get around this. I need to get the actual value \0

Upvotes: 0

Views: 63

Answers (1)

VMai
VMai

Reputation: 10336

If you want to get the value

lT~:uc9%7\04M?;~=0=^

into your field, you've got to use

UPDATE yourtable SET field='lT~:uc9%7\\04M?;~=0=^' where id='1';

because the backslash is the escape character of MySQL, see

String Literals

Escape Sequence  | Character represented by sequence
----------------------------------------------------
\0               | An ASCII NUL (0x00) character
\\               | A backslash (“\”) character.

so \0 is not interpreted as a space. If you want to use a space in a string, simply use a space.

Upvotes: 2

Related Questions