ODBC: how to handle Booleans?
Disclaimer: I am a n00b.
It see开发者_运维百科ms like ODBC does not support a BOOLEAN type? Is this true?
If so, what's the standard kludgearound?
Edit: I am using ADO with Delphi on Windows to write the data, but PHP 5 to read it back.
SQL itself has traditionally not supported a boolean type, so ODBC is just reflecting this. As ODBC is intended to provide portability across databases, it is generally better to implement booleans in the database as one of the standard types, such as CHAR(1), containing either 'Y' or 'N', rather than use a vendor specific type.
There's SQL_C_BIT, but you need to lookup what a given driver uses for each SQL type. For example, MySQL uses SQL_C_CHAR for bool.
I believe it depends on the actual SQL server implementation. You can check the ODBC driver/datasource settings, if you are doing it under Windows -- there might be options such as Bool As Char, or something.
精彩评论