I have a MySQL query that returns a result with a single column of integers. Is there any way to get the MySQL C API to transfer this as actually integers rather than as ASCII text? For that matter is there a way to get MySQL to do /any/ of the API stuff as other than ASCII text. I'm thinking this would save a bit of time in sprintf/sscanf or whatever else is used as well as in bandwidth.
to transfer this as actually integers rather than as ASCII text?
What do you mean? Do the mysql libraries give you C strings when you select data out of a table with integer columns, or are you talking about the communication between the mysql server and it's own client libraries?
You're probably out of luck, to be honest. Looking at the MySQL C API (http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html, http://dev.mysql.com/doc/refman/5.0/en/c-api-datatypes.html, look at MYSQL_ROW) there doesn't seem to be a mechanism for returning data in its actual type... the joys of using structs I guess.
You could always implement a wrapper which checks against the MYSQL_ROW's type attribute (http://dev.mysql.com/doc/refman/5.0/en/c-api-datatypes.html) and returns a C union, but that's probably poor advice; don't do that.
What do you mean? Do the mysql libraries give you C strings ... or are you talking about the communication between the mysql server and it's own client libraries?
Both
You could always implement a wrapper which checks against the MYSQL_ROW's type attribute ... and returns a C union, but that's probably poor advice; don't do that.
I have been known to do worse things:
// union a struct pointer and some data;
union Bob { Foo* ptr, struct {short a, short b}}
// the struct
struct Foo
{
void Something()
{
// pull data out of my this pointer
Bob bob;
bob.ptr = this;
writef("%d, %d\n", bob.a, bob.b);
}
}
void main()
{
Bob bob;
bob.a=1; bob.b=2;
void delegate() dg = &bob.ptr.Something;
// other stuff
dg(); // prints out "1, 2"
}