-
Notifications
You must be signed in to change notification settings - Fork 564
Description
Issue
The adapter is translating Rails models decimal attributes as nvarchars (in SQL Server 2019 they are defined as numerics with different precisions). If I change the attributes to float, it will detect them as ints and discard the decimal places when doing SQL inserts.
Expected behavior
decimals should be detected as decimal datatypes and numerics as numerics.
Actual behavior
decimals are detected as nvarchar and floats as integers.
How to reproduce
Create a Rails model with the following:
attribute :edebito, :decimal, default: 0.0
attribute :ettdeb, :decimal, default: 0.0
and try to do a SQL insert.
Result:
SQL (0.2ms) BEGIN TRANSACTION
D, [2020-09-08T19:52:04.451014 #355793] DEBUG -- : [98845638-2859-49ea-a033-1f59129b4e91] Order Load (0.4ms) EXEC sp_executesql N'SELECT bostamp, nmdos, obrano, dataobra, nome, etotaldeb, no FROM [boview] WHERE [boview].[obrano] = @0 ORDER BY [boview].[obrano] ASC OFFSET 0 ROWS FETCH NEXT @1 ROWS ONLY', N'@0 int, @1 int', @0 = 322005198, @1 = 1 [["obrano", nil], ["LIMIT", nil]]
D, [2020-09-08T19:52:04.452568 #355793] DEBUG -- : [98845638-2859-49ea-a033-1f59129b4e91] OrderLine Create (0.8ms) EXEC sp_executesql N'INSERT INTO [biview] ([bistamp], [obrano], [ref], [design], [bostamp], [lordem], [desconto], [qtt2], [qtt], [edebito], [ettdeb], [tabiva], [armazem], [stipo], [iva], [rescli], [ndos], [nmdos]) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17); SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident', N'@0 nvarchar(max), @1 int, @2 nvarchar(max), @3 nvarchar(max), @4 nvarchar(max), @5 int, @6 int, @7 int, @8 int, @9 int, @10 int, @11 int, @12 int, @13 int, @14 int, @15 int, @16 int, @17 nvarchar(max)', @0 = N'28757', @1 = 322005198, @2 = N'AP3610413-73', @3 = N'Bambu artificial Shiroshima', @4 = N'-Sep0819:52:042020265239 ', @5 = 0, @6 = 10.0, @7 = 0.0, @8 = 1.0, @9 = N'116.193', @10 = N'116.193', @11 = 2, @12 = 2, @13 = 4, @14 = 0.0, @15 = 1, @16 = 53, @17 = N'Encomenda Catálogo' [["bistamp", nil], ["obrano", nil], ["ref", nil], ["design", nil], ["bostamp", nil], ["lordem", nil], ["desconto", nil], ["qtt2", nil], ["qtt", nil], ["edebito", nil], ["ettdeb", nil], ["tabiva", nil], ["armazem", nil], ["stipo", nil], ["iva", nil], ["rescli", nil], ["ndos", nil], ["nmdos", nil]]
D, [2020-09-08T19:52:04.452987 #355793] DEBUG -- : [98845638-2859-49ea-a033-1f59129b4e91] SQL (0.3ms) IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION
I, [2020-09-08T19:52:04.453133 #355793] INFO -- : [98845638-2859-49ea-a033-1f59129b4e91] Completed 500 Internal Server Error in 25ms (ActiveRecord: 11.7ms | Allocations: 15830)
F, [2020-09-08T19:52:04.453591 #355793] FATAL -- : [98845638-2859-49ea-a033-1f59129b4e91]
[98845638-2859-49ea-a033-1f59129b4e91] ActiveRecord::StatementInvalid (TinyTds::Error: Error converting data type nvarchar to int.):
Details
-
Rails version:
6.0.3.2
-
SQL Server adapter version:
6.0.0
-
TinyTDS version:
2.1.2
-
FreeTDS details:
run `tsql -C` and paste here the output.
Compile-time settings (established with the "configure" script)
Version: freetds v1.1.6
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: auto
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: no
GnuTLS: yes
MARS: yes