Re: [Cppcms-users] Cppdb: How to fetch a column of unknown type at compile time?
Brought to you by:
artyom-beilis
From: Artyom <art...@ya...> - 2011-01-04 07:29:34
|
> > How to fetch a column of unknown type at compile time with cppdb? > You can always fetch it as string, any value (with small exception of Binary Large OBjects) is convertible to string and actually under the hood it is almost always string. Why there is no functionality to get the type of the column? Because it is not always well defined. With some databases like sqlite3 the data is "typeless" and even sometimes when you fetch a column it may have some "original" type it does not promises that it would be actually the type you are trying to use or it may be even undefined as it is some combined value. Bottom line: - CppDB is dynamically typed and try to perform the conversions in the best way it can. - If you need to check whether specific value can be treated as for example integer, you can do following: try { int x = r.get<int>(v); } catch(cppdb::bad_value_cast const &e) { // ok it can't be integer } But of course of the original type is string and it holds the text "123" as string, cppdb would happily cast if for you. Artyom |