0

I am running MS SQL server 2019 on Windows and try to fill - besides others - a 'numberic(5,2)' field using MS ODBC driver version 18 for Linux, but always get an error if I set scale.

The table structure:

CREATE TABLE [dbo].[dboutput_test](
    [MD_ID] [int] NOT NULL,
...
    [FLD_ASK] [numeric](5, 2) NULL,
...
) ON [PRIMARY]
GO

I am binding the parameter using SQL_NUMERIC_STRUCT:

                  retcode = SQLBindParameter(inStmt,
                                             inIdx,
                                             SQL_PARAM_INPUT,
                                             SQL_C_NUMERIC,
                                             SQL_NUMERIC,
                                             inParam._num.precision,
                                             inParam._num.scale,
                                             &inParam._num,
                                             0,
                                             &cbNumStr);

But as soon as inParam._num.scale is > 0, I get [[Microsoft][ODBC Driver 18 for SQL Server]Numeric value out of range].

If inParam._num.scale == 0, the value is set but sure with the wrong decimal point.

I even tried the example from MS Retrieve numeric data with SQL_NUMERIC_STRUCT documentation, but with the same result. I also played with the settings of the numeric field, but withot any effect.

PS.: I found in the meantime, that when I ecplicitely set field descriptions in that way it seems to work:

                  SQLHDESC   hdesc = NULL;
                  uint64_t   prec  = inParam._num.precision;
                  uint64_t   scale = inParam._num.scale;

                  SQLGetStmtAttr(inStmt, SQL_ATTR_APP_PARAM_DESC, &hdesc, 0, NULL);
                  SQLSetDescField(hdesc, inIdx, SQL_DESC_TYPE, (SQLPOINTER) SQL_C_NUMERIC, 0);
                  SQLSetDescField(hdesc, inIdx, SQL_DESC_PRECISION, (SQLPOINTER) prec, 0);
                  SQLSetDescField(hdesc, inIdx, SQL_DESC_SCALE, (SQLPOINTER) scale, 0);
                  SQLSetDescField(hdesc, inIdx, SQL_DESC_DATA_PTR, (SQLPOINTER) &inParam._num, 0);

Is it really the way it has to be done?

0 Answers0