Bug 162219 - Unable to insert decimal values in Base into a decimal column in SQL Server
Summary: Unable to insert decimal values in Base into a decimal column in SQL Server
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
24.2.5.2 release
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:25.2.0 target:24.8.1
Keywords:
Depends on: 162227
Blocks:
  Show dependency treegraph
 
Reported: 2024-07-27 03:23 UTC by Joe Enos
Modified: 2024-08-05 10:26 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joe Enos 2024-07-27 03:23:24 UTC
Description:
When inserting or updating a decimal value into a table in SQL Server, I get the following error:

SQL Status: HY104

[Microsoft][ODBC Driver 18 for SQL Server]Invalid precision or scale value at C:/cygwin64/home/buildslave/source/libo-core/connectivity/source/drivers/odbc/OTools.cxx:352

Error updating the current record at C:/cygwin64/home/buildslave/source/libo-core/connectivity/source/commontools/dbtools.cxx:744

Steps to Reproduce:
1.
-- SQL Server 2022
CREATE DATABASE [base_sandbox];
GO
USE [base_sandbox];
CREATE TABLE [dbo].[Foo] (
     [ID] INT NOT NULL IDENTITY PRIMARY KEY
    ,[SomeValue] [decimal](19, 4)
);
GO

2.
Open ODBC Data Source Administrator (64-bit)

3.
Create new User DSN

4.
ODBC Driver 18 for SQL Server

5.
Name: base_sandbox

6.
Server: (local)

7.
Default database: base_sandbox

8.
Open Base

9.
Connect to an existing database: ODBC

10.
Name: base_sandbox

11.
Save the odb file and open for editing

12.
Navigate to tables: dbo.Foo

13.
Open the table for editing data

14.
Attempt to insert or update the value to any number:
1.0000
0.0000
1.2000
1.2345
1.2340

Values 1.0000, 0.0000, 1.2000 fail with the listed error. Values 1.2345 and 1.2340 succeed.


Actual Results:
SQL Status: HY104

[Microsoft][ODBC Driver 18 for SQL Server]Invalid precision or scale value at C:/cygwin64/home/buildslave/source/libo-core/connectivity/source/drivers/odbc/OTools.cxx:352

Error updating the current record at C:/cygwin64/home/buildslave/source/libo-core/connectivity/source/commontools/dbtools.cxx:744

Expected Results:
Should have inserted/updated the values.


Reproducible: Sometimes


User Profile Reset: Yes

Additional Info:
This happens with both v17 and v18 of the ODBC driver. I'm on Windows 11 Home. 

Running Base 24.2.5.2.

Tried different decimal sizes and precisions, same problem.

In .NET, I'm able to successfully insert:

using System.Data.Odbc;
using OdbcConnection conn = new("DSN=base_sandbox");
conn.Open();
using OdbcCommand comm = conn.CreateCommand();
comm.CommandText = "INSERT INTO [dbo].[Foo] ([SomeValue]) VALUES (?);";
comm.Parameters.Add(new OdbcParameter("?`", OdbcType.Decimal) {
	Size = 19, Precision = 4, Value = 123.5m 
});
comm.ExecuteNonQuery();
Comment 1 Mike Kaganski 2024-07-27 15:14:19 UTC
Error in the DecimalDigits argument passed to SQLBindParameter [1]. This value is set to the scale of the target DECIMAL field (4), for any string passed there ("1" for 1.0000, "1.2" for 1.2000, etc.). But the value in this case must describe not the target data, but source data. Passing 0 as DecimalDigits for passed "1" (or 1 for "1.2") makes it work fine.

Likely an error in dbtools::setObjectWithInfo.

[1] https://learn.microsoft.com/en-us/sql/odbc/reference/syntax/sqlbindparameter-function
Comment 2 Commit Notification 2024-07-27 23:14:50 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/233af54afb6e493c3538efe7c93d0f53f1b4c3ab

tdf#162219: pass correct DecimalDigits value to SQLBindParameter

It will be available in 25.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2024-08-05 10:26:22 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/a03c481dcbbd595168ffbad017579f8fdf7a66e3

tdf#162219: pass correct DecimalDigits value to SQLBindParameter

It will be available in 24.8.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.