I have a code that binds a string to an ODBC statement that looks like this
std::string v = "...";
SQLBindParameter(stmt, c, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
v.size(), 0, &v[0], v.size(), 0)
It works for any regular string, but not for empty string. I get an error message instead:
Error: [Microsoft][ODBC SQL Server Driver]Invalid precision value
I changed the function call to this
SQLBindParameter(stmt, c, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
std::max<SQLUINTEGER>(v.size(), 1), 0, &v[0], v.size(), 0)
And now empty string can be inserted, yet it is converted into a space instead of an empty string.
I don't want to insert a NULL value because many SQL statements become counter-intuitive when NULL is encountered. Is any way to bind an empty string at all?
(The database engine is SQL Server 2005 with ODBC3)