#1 2015-11-04 12:02:16

zed
Member
From: Belarus
Registered: 2015-02-26
Posts: 105

ODBC with SQL_VARBINARY(MAX) gives "Invalid precision value"

When I try to update a BLOB field in MS SQL Server 2008 with data more then 8000 bytes, it raises an error about "Invalid precision value".

In mORMot model field defined as TSQLRawBlob and it translated to varbinary(max) type in MS SQL table.

I found the same problem on StackOverflow: http://stackoverflow.com/questions/1486 … sion-value where recommend set len1 to 0:

SQLLEN len1 = 0;
SQLLEN nThisLen = (SQLLEN)sData.size();
SQLBindParameter( handle, (SQLUSMALLINT)4, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, len1, 0, (SQLCHAR*)&sData.c_str(), nThisLen, &nThisLen );

so, I tried to fix this in mORMot and this is work:

procedure TODBCStatement.ExecutePrepared;
...
status := ODBC.BindParameter(fStatement, p+1, InputOutputType, CValueType,
  CType2SQL(CValueType), {ColumnSize}0, 0, ParameterValue, ColumnSize, StrLen_or_Ind[p]);
...

Also, this change tested on MySQL and PostgreSQL.

Is it correct fix?

Offline

#2 2015-11-05 06:45:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: ODBC with SQL_VARBINARY(MAX) gives "Invalid precision value"

Sounds fine to me.

The "official" documentation is really misleading and confusing...
wink

See http://synopse.info/fossil/info/86c59a0cb5

Offline

#3 2016-12-29 01:57:19

KevinChen
Member
Registered: 2016-09-10
Posts: 10

Re: ODBC with SQL_VARBINARY(MAX) gives "Invalid precision value"

I got the error "Invalid precision: cbColDef value out of range (0)" when tested on VARCHAR column in Teradata database.
Then I restored the change back and it worked.
I'm not sure if the change should be like this:

case VType of
ftBlob:
  status := ODBC.BindParameter(fStatement, p+1, InputOutputType, CValueType,
   CType2SQL(CValueType), 0, 0, ParameterValue, ColumnSize, StrLen_or_Ind[p]);
else
  status := ODBC.BindParameter(fStatement, p+1, InputOutputType, CValueType,
   CType2SQL(CValueType), ColumnSize, 0, ParameterValue, ColumnSize, StrLen_or_Ind[p]);
end;

Offline

Board footer

Powered by FluxBB