SimplePanda SimplePanda - 4 months ago 9
MySQL Question

Is data returned from a MySQL Connector/C query not in native C data format?

If I execute a query against the MySQL Connector/C library the data I'm getting back all appears to be in straight

char *
format, including numerical data types.

For example, if I execute a query that returns 4 columns, all of which are
INTEGER
in MySQL, rather than getting back 4 bytes worth of data (each byte representing a single column row value), I'm actually getting back 4 ASCII encoded character bytes, where
1
is actually a byte with the numeric value
49
in it (ASCII for
1
).

Is this accurate or am I just missing something complete?

Do I really need to then
atoi
that returned byte into an
int
in my code or is there a mechanism to get the native C data types out of the MySQL client directly?

I guess my real question is: is the
mysql_store_result
structure converting that data to ASCII encoded representations in a way that can be bypassed by my application code?

Answer

I believe the data is sent on the wire as text in the MySQL protocol (I just confirmed this with Wireshark). So that means mysql_store_result() is not converting the data, it's just simply passing the data on as it was received. MySQL actually sends integers as text. I agree this always seemed like an odd design to me as well.