Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ODBC error 'String data, right truncation' when updating uniqueidentifier column with null value

I'm trying to update column of type uniqueidentifier with null. My query looks like:

UPDATE table_name SET column_name = ?

The column is bound with:

SQLLEN _nullLen(SQL_NULL_DATA);

_rc = SQLBindParameter(_hstmt,          
    static_cast<SQLUSMALLINT>(1),   
    SQL_PARAM_INPUT,                    
    SQL_C_CHAR,                         
    SQL_VARCHAR,                        
    37,                         
    NULL,                               
    NULL,                               
    0,                                  
    &_nullLen);                         

Executing the query results in a ODBC error 'String data, right truncation'. Using the exact same SQLBindParameter I'm able to successfuly insert a new row with null data. Why does this not work for updating the row?

like image 812
Sander Delfos Avatar asked Oct 15 '22 22:10

Sander Delfos


1 Answers

Please read
https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlbindparameter-function?view=sql-server-ver15 thoroughly.

According to it, the 6th parameter to SQLBindParameter is ColumnSize, which you set to 37. Why this value?

The 8th parameter is ParameterValuePtr, but you set it to NULL. Is NULL the value you are trying to set?

The 10th parameter is StrLen_or_IndPtr which you set to &_nullLen where SQLLEN _nullLen(SQL_NULL_DATA), but that's not the kind of thing it should point to.

Please make sure you understand each parameter passed to SQLBindParameter().

like image 73
Brecht Sanders Avatar answered Oct 19 '22 02:10

Brecht Sanders