@@ -13,6 +13,7 @@ import (
1313 "testing"
1414 "time"
1515
16+ "github.com/shopspring/decimal"
1617 "github.com/stretchr/testify/assert"
1718)
1819
@@ -29,6 +30,8 @@ func TestBulkcopyWithInvalidNullableType(t *testing.T) {
2930 "test_nullint16" ,
3031 "test_nulltime" ,
3132 "test_nulluniqueidentifier" ,
33+ "test_nulldecimal" ,
34+ "test_nullmoney" ,
3235 }
3336 values := []interface {}{
3437 sql.NullFloat64 {Valid : false },
@@ -40,6 +43,8 @@ func TestBulkcopyWithInvalidNullableType(t *testing.T) {
4043 sql.NullInt16 {Valid : false },
4144 sql.NullTime {Valid : false },
4245 NullUniqueIdentifier {Valid : false },
46+ decimal.NullDecimal {Valid : false },
47+ Money [decimal.NullDecimal ]{decimal.NullDecimal {Valid : false }},
4348 }
4449
4550 pool , logger := open (t )
@@ -176,9 +181,11 @@ func testBulkcopy(t *testing.T, guidConversion bool) {
176181 {"test_nullint32" , sql.NullInt32 {2147483647 , true }, 2147483647 },
177182 {"test_nullint16" , sql.NullInt16 {32767 , true }, 32767 },
178183 {"test_nulltime" , sql.NullTime {time .Date (2010 , 11 , 12 , 13 , 14 , 15 , 120000000 , time .UTC ), true }, time .Date (2010 , 11 , 12 , 13 , 14 , 15 , 120000000 , time .UTC )},
184+ {"test_nulldecimal" , decimal .NewNullDecimal (decimal .New (1232355 , - 4 )), decimal .New (1232355 , - 4 )},
185+ {"test_nullmoney" , Money [decimal.NullDecimal ]{decimal .NewNullDecimal (decimal .New (- 21232311232355 , - 4 ))}, decimal .New (- 21232311232355 , - 4 )},
179186 {"test_datetimen_midnight" , time .Date (2025 , 1 , 1 , 23 , 59 , 59 , 998_350_000 , time .UTC ), time .Date (2025 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )},
180- // {"test_smallmoney", 1234.56, nil },
181- // {"test_money", 1234.56, nil },
187+ {"test_smallmoney" , Money [decimal. Decimal ]{ decimal . New ( - 32856 , - 4 )}, decimal . New ( - 32856 , - 4 ) },
188+ {"test_money" , Money [decimal. Decimal ]{ decimal . New ( - 21232311232355 , - 4 )}, decimal . New ( - 21232311232355 , - 4 ) },
182189 {"test_decimal_18_0" , 1234.0001 , "1234" },
183190 {"test_decimal_9_2" , - 1234.560001 , "-1234.56" },
184191 {"test_decimal_20_0" , 1234 , "1234" },
@@ -334,6 +341,20 @@ func compareValue(a interface{}, expected interface{}) bool {
334341 return expected .Equal (got ) && ez == az
335342 }
336343 return false
344+ case decimal.Decimal :
345+ actual , err := decimal .NewFromString (a .(string ))
346+ if err != nil {
347+ return false
348+ }
349+
350+ return expected .Equal (actual )
351+ case Money [decimal.Decimal ]:
352+ actual , err := decimal .NewFromString (a .(string ))
353+ if err != nil {
354+ return false
355+ }
356+
357+ return expected .Decimal .Equal (actual )
337358 default :
338359 return reflect .DeepEqual (expected , a )
339360 }
@@ -351,6 +372,8 @@ func setupNullableTypeTable(ctx context.Context, t *testing.T, conn *sql.Conn, t
351372 [test_nullint16] [smallint] NULL,
352373 [test_nulltime] [datetime] NULL,
353374 [test_nulluniqueidentifier] [uniqueidentifier] NULL,
375+ [test_nulldecimal] [decimal](18, 4) NULL,
376+ [test_nullmoney] [money] NULL,
354377 CONSTRAINT [PK_` + tableName + `_id] PRIMARY KEY CLUSTERED
355378(
356379 [id] ASC
@@ -438,6 +461,8 @@ func setupTable(ctx context.Context, t *testing.T, conn *sql.Conn, tableName str
438461 [test_nullint32] [int] NULL,
439462 [test_nullint16] [smallint] NULL,
440463 [test_nulltime] [datetime] NULL,
464+ [test_nulldecimal] [decimal](18, 4) NULL,
465+ [test_nullmoney] [money] NULL,
441466 [test_datetimen_midnight] [datetime] NULL,
442467 CONSTRAINT [PK_` + tableName + `_id] PRIMARY KEY CLUSTERED
443468(
0 commit comments