tags:

views:

44

answers:

2

I have a encoded character buffer array of size 512 in c, and a database field of varchar in mysql. Is it possible to store the encoded char buffer into varchar. I have try this but the problem which i face that it only store the limited area of buffer into database and ignore. Kindly guide me that what is the actual problem is, and how I solve this problem.

A: 

What size is your varchar declared for the table?

Often varchar fields are set to 255 bytes, not characters. Starting with MySQL 5.0.3 you can have longer varchar fields.

Sounds like you need a varchar(512) field, is that what you have?

See http://dev.mysql.com/doc/refman/5.0/en/char.html

Larry K
varchar size is 650 and it only stored 2 or 4 byte from the char buffer.
Arman
+3  A: 

It is not clear what you mean by encoded.

If you mean that you have an arbitrary string of byte values, then varchar is a bad fit because it will attempt to trim trailing spaces. A better choice in such cases is to use varbinary fields.

If the string you are inserting contains control characters, you might be best converting that into a hex string and inserting it like follows:

create table xx ( 
    v varbinary(512) not null );

insert into xx values ( 0x68656C6C6F20776F726C64);

This will prevent any component in the tool chain from choking on NUL characters and so forth.

Martin