Looking for one liner example how to bind and insert a null value into a database using ODBC API

别来无恙 提交于 2019-12-10 16:01:13

问题


The function is

SQLRETURN SQLBindParameter(
      SQLHSTMT        StatementHandle,
      SQLUSMALLINT    ParameterNumber,
      SQLSMALLINT     InputOutputType,
      SQLSMALLINT     ValueType,
      SQLSMALLINT     ParameterType,
      SQLULEN         ColumnSize,
      SQLSMALLINT     DecimalDigits,
      SQLPOINTER      ParameterValuePtr,
      SQLLEN          BufferLength,
      SQLLEN *        StrLen_or_IndPtr);

The documentations I have seen is confusing. Do the srguments depend on the data type or not I found an example here http://support.microsoft.com/kb/248799 which does not seem to work on DB2. I thought odbc was consistent across databases. A specific code example would he helpful.


回答1:


Its not one line as such but

SQLLEN ival;

ret = SQLBindParameter( stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 100, 0, NULL, 0, &ival );

/*
 * before execution is called
 */

ival = SQL_NULL_DATA;

That inserts a NULL value as a CHAR(100) datatype. Pick the actual datatype to match what your column type is, but the important thing is to set the indicator value to SQL_NULL_DATA before the SQLExecute or SQLExecDirect is called. And make sure its still set to that value at the execute point.



来源:https://stackoverflow.com/questions/6486746/looking-for-one-liner-example-how-to-bind-and-insert-a-null-value-into-a-databas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!