I’m using MySQL C API with C++ to connect to a database. I wold like so select some numbers from the database.
Is there a way to fetch number types like INTEGER or DOUBLE into native C types like int or double directly without having to parse them from a string?
EDIT:
How about ENUMs? I would hate do do a strcmp every time instead of using switch.
Thank you, but actually I think I just found a way while looking for something different…
Prepared statements can do the job. When selecting data the results are stored in a MYSQL_BIND, just like the prepared statement arguments. And in MYSQL_BIND the values are stored as native C types. I think these links are helpful:
http://lgallardo.com/en/2011/06/23/sentencias-preparadas-de-mysql-en-c-ejemplo-completo/
http://dev.mysql.com/doc/refman/5.5/en/mysql-stmt-fetch.html#id1363684