tiny_tds_vagas 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/CHANGELOG +198 -0
- data/CODE_OF_CONDUCT.md +31 -0
- data/Gemfile +6 -0
- data/ISSUE_TEMPLATE.md +5 -0
- data/MIT-LICENSE +23 -0
- data/README.md +427 -0
- data/Rakefile +110 -0
- data/VERSION +1 -0
- data/appveyor.yml +52 -0
- data/bin/defncopy +3 -0
- data/bin/tsql +3 -0
- data/ext/tiny_tds/client.c +410 -0
- data/ext/tiny_tds/client.h +49 -0
- data/ext/tiny_tds/extconf.rb +329 -0
- data/ext/tiny_tds/extconsts.rb +15 -0
- data/ext/tiny_tds/result.c +608 -0
- data/ext/tiny_tds/result.h +32 -0
- data/ext/tiny_tds/tiny_tds_ext.c +12 -0
- data/ext/tiny_tds/tiny_tds_ext.h +17 -0
- data/lib/tiny_tds.rb +37 -0
- data/lib/tiny_tds/bin.rb +86 -0
- data/lib/tiny_tds/client.rb +124 -0
- data/lib/tiny_tds/error.rb +15 -0
- data/lib/tiny_tds/result.rb +8 -0
- data/lib/tiny_tds/version.rb +3 -0
- data/ports/patches/freetds/1.00/0001-mingw_missing_inet_pton.diff +34 -0
- data/test/appveyor/dbsetup.ps1 +27 -0
- data/test/appveyor/dbsetup.sql +9 -0
- data/test/benchmark/query.rb +77 -0
- data/test/benchmark/query_odbc.rb +106 -0
- data/test/benchmark/query_tinytds.rb +126 -0
- data/test/client_test.rb +217 -0
- data/test/result_test.rb +728 -0
- data/test/schema/1px.gif +0 -0
- data/test/schema/sqlserver_2000.sql +140 -0
- data/test/schema/sqlserver_2005.sql +140 -0
- data/test/schema/sqlserver_2008.sql +140 -0
- data/test/schema/sqlserver_2014.sql +140 -0
- data/test/schema/sqlserver_azure.sql +140 -0
- data/test/schema/sybase_ase.sql +138 -0
- data/test/schema_test.rb +443 -0
- data/test/test_helper.rb +213 -0
- data/test/thread_test.rb +98 -0
- data/tiny_tds.gemspec +28 -0
- metadata +201 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
|
4
|
+
* Binary Data - Our test binary data is a 1 pixel gif. The basic (raw) data is below. Quoting this data
|
5
|
+
would involve this (encode) method and be (encoded) with the 0x prefix for raw SQL. In other clients the
|
6
|
+
(raw_db) value without the 0x prefix would need to be (packed) again yield the original (raw) value.
|
7
|
+
|
8
|
+
(raw) - "GIF89a\001\000\001\000\221\000\000\377\377\377\377\377\377\376\001\002\000\000\000!\371\004\004\024\000\377\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;"
|
9
|
+
(encode) - "0x#{raw.unpack("H*")[0]}"
|
10
|
+
(encoded) - "0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b"
|
11
|
+
(raw_db) - "47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b"
|
12
|
+
(packed) - [raw_db].pack('H*')
|
13
|
+
|
14
|
+
*/
|
15
|
+
|
16
|
+
CREATE TABLE [dbo].[datatypes] (
|
17
|
+
[id] [int] NOT NULL IDENTITY(1,1) PRIMARY KEY,
|
18
|
+
[bigint] [bigint] NULL,
|
19
|
+
[binary_50] [binary](50) NULL,
|
20
|
+
[bit] [bit] NULL,
|
21
|
+
[char_10] [char](10) NULL,
|
22
|
+
[date] [date] NULL,
|
23
|
+
[datetime] [datetime] NULL,
|
24
|
+
[datetime2_7] [datetime2](7) NULL,
|
25
|
+
[datetime2_2] [datetime2](2) NULL,
|
26
|
+
[datetimeoffset_2] [datetimeoffset](2) NULL,
|
27
|
+
[datetimeoffset_7] [datetimeoffset](7) NULL,
|
28
|
+
[decimal_9_2] [decimal](9, 2) NULL,
|
29
|
+
[decimal_16_4] [decimal](16, 4) NULL,
|
30
|
+
[float] [float] NULL,
|
31
|
+
[geography] [geography] NULL,
|
32
|
+
[geometry] [geometry] NULL,
|
33
|
+
[hierarchyid] [hierarchyid] NULL,
|
34
|
+
[image] [image] NULL,
|
35
|
+
[int] [int] NULL,
|
36
|
+
[money] [money] NULL,
|
37
|
+
[nchar_10] [nchar](10) NULL,
|
38
|
+
[ntext] [ntext] NULL,
|
39
|
+
[numeric_18_0] [numeric](18, 0) NULL,
|
40
|
+
[numeric_36_2] [numeric](36, 2) NULL,
|
41
|
+
[nvarchar_50] [nvarchar](50) NULL,
|
42
|
+
[nvarchar_max] [nvarchar](max) NULL,
|
43
|
+
[real] [real] NULL,
|
44
|
+
[smalldatetime] [smalldatetime] NULL,
|
45
|
+
[smallint] [smallint] NULL,
|
46
|
+
[smallmoney] [smallmoney] NULL,
|
47
|
+
[text] [text] NULL,
|
48
|
+
[time_2] [time](2) NULL,
|
49
|
+
[time_7] [time](7) NULL,
|
50
|
+
[timestamp] [timestamp] NULL,
|
51
|
+
[tinyint] [tinyint] NULL,
|
52
|
+
[uniqueidentifier] [uniqueidentifier] NULL,
|
53
|
+
[varbinary_50] [varbinary](50) NULL,
|
54
|
+
[varbinary_max] [varbinary](max) NULL,
|
55
|
+
[varchar_50] [varchar](50) NULL,
|
56
|
+
[varchar_max] [varchar](max) NULL,
|
57
|
+
[xml] [xml] NULL
|
58
|
+
)
|
59
|
+
|
60
|
+
SET IDENTITY_INSERT [datatypes] ON
|
61
|
+
|
62
|
+
INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 11, -9223372036854775807 )
|
63
|
+
INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 12, 9223372036854775806 )
|
64
|
+
INSERT INTO [datatypes] ([id], [binary_50]) VALUES ( 21, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
65
|
+
INSERT INTO [datatypes] ([id], [bit]) VALUES ( 31, 1 )
|
66
|
+
INSERT INTO [datatypes] ([id], [bit]) VALUES ( 32, 0 )
|
67
|
+
INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 41, '1234567890' )
|
68
|
+
INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 42, '12345678' )
|
69
|
+
INSERT INTO [datatypes] ([id], [date]) VALUES ( 51, '0001-01-01' )
|
70
|
+
INSERT INTO [datatypes] ([id], [date]) VALUES ( 52, '9999-12-31' )
|
71
|
+
INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 61, '1753-01-01T00:00:00.000' )
|
72
|
+
INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 62, '9999-12-31T23:59:59.997' )
|
73
|
+
INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 63, '2010-01-01T12:34:56.123' )
|
74
|
+
INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 71, '0001-01-01 00:00:00.0000000' )
|
75
|
+
INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 72, '1984-01-24 04:20:00.0000000' )
|
76
|
+
INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 73, '9999-12-31 23:59:59.9999999' )
|
77
|
+
INSERT INTO [datatypes] ([id], [datetime2_2]) VALUES ( 74, '9999-12-31 23:59:59.123456789' )
|
78
|
+
INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 81, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.00 -08:00
|
79
|
+
INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 82, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.00 +00:00
|
80
|
+
INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 83, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.99 +00:00
|
81
|
+
INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 84, '1984-01-24T04:20:59.1234567-08:00' ) -- 1984-01-24 04:20:59.1234567 -08:00
|
82
|
+
INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 85, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.0000000 +00:00
|
83
|
+
INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 86, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.9999999 +00:00
|
84
|
+
INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 91, 12345.01 )
|
85
|
+
INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 92, 1234567.89 )
|
86
|
+
INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 93, 0.0 )
|
87
|
+
INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 94, 123456789012.3456 )
|
88
|
+
INSERT INTO [datatypes] ([id], [float]) VALUES ( 101, 123.00000001 )
|
89
|
+
INSERT INTO [datatypes] ([id], [float]) VALUES ( 102, 0.0 )
|
90
|
+
INSERT INTO [datatypes] ([id], [float]) VALUES ( 103, 123.45 )
|
91
|
+
INSERT INTO [datatypes] ([id], [geography]) VALUES ( 111, geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) ) -- 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0
|
92
|
+
INSERT INTO [datatypes] ([id], [geometry]) VALUES ( 121, geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0) ) -- 0x0000000001040300000000000000000059400000000000005940000000000000344000000000008066400000000000806640000000000080664001000000010000000001000000FFFFFFFF0000000002
|
93
|
+
INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 131, CAST('/1/' AS hierarchyid) ) -- 0x58
|
94
|
+
INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 132, CAST('/2/' AS hierarchyid) ) -- 0x68
|
95
|
+
INSERT INTO [datatypes] ([id], [image]) VALUES ( 141, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
96
|
+
INSERT INTO [datatypes] ([id], [int]) VALUES ( 151, -2147483647 )
|
97
|
+
INSERT INTO [datatypes] ([id], [int]) VALUES ( 152, 2147483646 )
|
98
|
+
INSERT INTO [datatypes] ([id], [money]) VALUES ( 161, 4.20 )
|
99
|
+
INSERT INTO [datatypes] ([id], [money]) VALUES ( 162, -922337203685477.5807 )
|
100
|
+
INSERT INTO [datatypes] ([id], [money]) VALUES ( 163, 922337203685477.5806 )
|
101
|
+
INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 171, N'1234567890' )
|
102
|
+
INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 172, N'123456åå' )
|
103
|
+
INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 173, N'abc123' )
|
104
|
+
INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 181, N'test ntext' )
|
105
|
+
INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 182, N'test ntext åå' )
|
106
|
+
INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 191, 191 )
|
107
|
+
INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 123456789012345678 )
|
108
|
+
INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 )
|
109
|
+
INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 )
|
110
|
+
INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' )
|
111
|
+
INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' )
|
112
|
+
INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' )
|
113
|
+
INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max åå' )
|
114
|
+
INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 )
|
115
|
+
INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 )
|
116
|
+
INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 )
|
117
|
+
INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 231, '1901-01-01T15:45:00.000Z' ) -- 1901-01-01 15:45:00
|
118
|
+
INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 232, '2078-06-05T04:20:00.000Z' ) -- 2078-06-05 04:20:00
|
119
|
+
INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 241, -32767 )
|
120
|
+
INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 242, 32766 )
|
121
|
+
INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 251, 4.20 )
|
122
|
+
INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 252, -214748.3647 )
|
123
|
+
INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 253, 214748.3646 )
|
124
|
+
INSERT INTO [datatypes] ([id], [text]) VALUES ( 271, 'test text' )
|
125
|
+
INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 281, '15:45:00.709714966' ) -- 15:45:00.71
|
126
|
+
INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 282, '04:20:00.288321545' ) -- 04:20:00.29
|
127
|
+
INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 283, '15:45:00.709714966' ) -- 15:45:00.709714900
|
128
|
+
INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 284, '04:20:00.288321545' ) -- 04:20:00.288321500
|
129
|
+
INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 301, 0 )
|
130
|
+
INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 )
|
131
|
+
INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() )
|
132
|
+
INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
133
|
+
INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
134
|
+
INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' )
|
135
|
+
INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' )
|
136
|
+
INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, '<foo><bar>batz</bar></foo>' )
|
137
|
+
|
138
|
+
SET IDENTITY_INSERT [datatypes] OFF
|
139
|
+
|
140
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
|
4
|
+
* Binary Data - Our test binary data is a 1 pixel gif. The basic (raw) data is below. Quoting this data
|
5
|
+
would involve this (encode) method and be (encoded) with the 0x prefix for raw SQL. In other clients the
|
6
|
+
(raw_db) value without the 0x prefix would need to be (packed) again yield the original (raw) value.
|
7
|
+
|
8
|
+
(raw) - "GIF89a\001\000\001\000\221\000\000\377\377\377\377\377\377\376\001\002\000\000\000!\371\004\004\024\000\377\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;"
|
9
|
+
(encode) - "0x#{raw.unpack("H*")[0]}"
|
10
|
+
(encoded) - "0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b"
|
11
|
+
(raw_db) - "47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b"
|
12
|
+
(packed) - [raw_db].pack('H*')
|
13
|
+
|
14
|
+
*/
|
15
|
+
|
16
|
+
CREATE TABLE [datatypes] (
|
17
|
+
[id] [int] IDENTITY NOT NULL PRIMARY KEY,
|
18
|
+
[bigint] [bigint] NULL,
|
19
|
+
[binary_50] [binary](50) NULL,
|
20
|
+
[bit] [bit] DEFAULT 0,
|
21
|
+
[char_10] [char](10) NULL,
|
22
|
+
[date] [date] NULL,
|
23
|
+
[datetime] [datetime] NULL,
|
24
|
+
-- [datetime2_7] [datetime2](7) NULL,
|
25
|
+
-- [datetimeoffset_2] [datetimeoffset](2) NULL,
|
26
|
+
-- [datetimeoffset_7] [datetimeoffset](7) NULL,
|
27
|
+
[decimal_9_2] [decimal](9, 2) NULL,
|
28
|
+
[decimal_16_4] [decimal](16, 4) NULL,
|
29
|
+
[float] [float] NULL,
|
30
|
+
-- [geography] [geography] NULL,
|
31
|
+
-- [geometry] [geometry] NULL,
|
32
|
+
-- [hierarchyid] [hierarchyid] NULL,
|
33
|
+
[image] [image] NULL,
|
34
|
+
[int] [int] NULL,
|
35
|
+
[money] [money] NULL,
|
36
|
+
[nchar_10] [nchar](10) NULL,
|
37
|
+
-- [ntext] [ntext] NULL,
|
38
|
+
[numeric_18_0] [numeric](18, 0) NULL,
|
39
|
+
[numeric_36_2] [numeric](36, 2) NULL,
|
40
|
+
[nvarchar_50] [nvarchar](50) NULL,
|
41
|
+
-- [nvarchar_max] [nvarchar](max) NULL,
|
42
|
+
[real] [real] NULL,
|
43
|
+
[smalldatetime] [smalldatetime] NULL,
|
44
|
+
[smallint] [smallint] NULL,
|
45
|
+
[smallmoney] [smallmoney] NULL,
|
46
|
+
[text] [text] NULL,
|
47
|
+
-- [time_2] [time](2) NULL,
|
48
|
+
-- [time_7] [time](7) NULL,
|
49
|
+
[timestamp] [timestamp] NULL,
|
50
|
+
[tinyint] [tinyint] NULL,
|
51
|
+
-- [uniqueidentifier] [uniqueidentifier] NULL,
|
52
|
+
[varbinary_50] [varbinary](50) NULL,
|
53
|
+
-- [varbinary_max] [varbinary](max) NULL,
|
54
|
+
[varchar_50] [varchar](50) NULL
|
55
|
+
-- [varchar_max] [varchar](max) NULL,
|
56
|
+
-- [xml] [xml] NULL
|
57
|
+
)
|
58
|
+
|
59
|
+
SET IDENTITY_INSERT [datatypes] ON
|
60
|
+
|
61
|
+
INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 11, -9223372036854775807 )
|
62
|
+
INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 12, 9223372036854775806 )
|
63
|
+
INSERT INTO [datatypes] ([id], [binary_50]) VALUES ( 21, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
64
|
+
INSERT INTO [datatypes] ([id], [bit]) VALUES ( 31, 1 )
|
65
|
+
INSERT INTO [datatypes] ([id], [bit]) VALUES ( 32, 0 )
|
66
|
+
INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 41, '1234567890' )
|
67
|
+
INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 42, '12345678' )
|
68
|
+
INSERT INTO [datatypes] ([id], [date]) VALUES ( 51, '0001-01-01' )
|
69
|
+
INSERT INTO [datatypes] ([id], [date]) VALUES ( 52, '9999-12-31' )
|
70
|
+
INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 61, '1753-01-01T00:00:00.000' )
|
71
|
+
INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 62, '9999-12-31T23:59:59.997' )
|
72
|
+
INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 63, '2010-01-01T12:34:56.123' )
|
73
|
+
-- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 71, '0001-01-01T00:00:00.0000000Z' )
|
74
|
+
-- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 72, '1984-01-24T04:20:00.1234567-08:00' )
|
75
|
+
-- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 73, '9999-12-31T23:59:59.9999999Z' )
|
76
|
+
-- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 81, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.00 -08:00
|
77
|
+
-- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 82, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.00 +00:00
|
78
|
+
-- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 83, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.99 +00:00
|
79
|
+
-- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 84, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.1234567 -08:00
|
80
|
+
-- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 85, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.0000000 +00:00
|
81
|
+
-- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 86, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.9999999 +00:00
|
82
|
+
INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 91, 12345.01 )
|
83
|
+
INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 92, 1234567.89 )
|
84
|
+
INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 93, 0.0 )
|
85
|
+
INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 94, 123456789012.3456 )
|
86
|
+
INSERT INTO [datatypes] ([id], [float]) VALUES ( 101, 123.00000001 )
|
87
|
+
INSERT INTO [datatypes] ([id], [float]) VALUES ( 102, 0.0 )
|
88
|
+
INSERT INTO [datatypes] ([id], [float]) VALUES ( 103, 123.45 )
|
89
|
+
-- INSERT INTO [datatypes] ([id], [geography]) VALUES ( 111, geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) ) -- 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0
|
90
|
+
-- INSERT INTO [datatypes] ([id], [geometry]) VALUES ( 121, geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0) ) -- 0x0000000001040300000000000000000059400000000000005940000000000000344000000000008066400000000000806640000000000080664001000000010000000001000000FFFFFFFF0000000002
|
91
|
+
-- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 131, CAST('/1/' AS hierarchyid) ) -- 0x58
|
92
|
+
-- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 132, CAST('/2/' AS hierarchyid) ) -- 0x68
|
93
|
+
INSERT INTO [datatypes] ([id], [image]) VALUES ( 141, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
94
|
+
INSERT INTO [datatypes] ([id], [int]) VALUES ( 151, -2147483647 )
|
95
|
+
INSERT INTO [datatypes] ([id], [int]) VALUES ( 152, 2147483646 )
|
96
|
+
INSERT INTO [datatypes] ([id], [money]) VALUES ( 161, 4.20 )
|
97
|
+
INSERT INTO [datatypes] ([id], [money]) VALUES ( 162, -922337203685477.5807 )
|
98
|
+
INSERT INTO [datatypes] ([id], [money]) VALUES ( 163, 922337203685477.5806 )
|
99
|
+
INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 171, N'1234567890' )
|
100
|
+
INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 172, N'123456åå' )
|
101
|
+
INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 173, N'abc123' )
|
102
|
+
-- INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 181, N'test ntext' )
|
103
|
+
-- INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 182, N'test ntext' ) -- Removed UTF-8 chars. They make sybase choke in comments.
|
104
|
+
INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 191, 191 )
|
105
|
+
INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 123456789012345678 )
|
106
|
+
INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 )
|
107
|
+
INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 )
|
108
|
+
INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' )
|
109
|
+
INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' )
|
110
|
+
-- INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' )
|
111
|
+
-- INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max' ) -- Removed UTF-8 chars. They make sybase choke in comments.
|
112
|
+
INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 )
|
113
|
+
INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 )
|
114
|
+
INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 )
|
115
|
+
INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 231, '1901-01-01T15:45:00.000' ) -- 1901-01-01 15:45:00
|
116
|
+
INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 232, '2078-06-05T04:20:00.000' ) -- 2078-06-05 04:20:00
|
117
|
+
INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 241, -32767 )
|
118
|
+
INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 242, 32766 )
|
119
|
+
INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 251, 4.20 )
|
120
|
+
INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 252, -214748.3647 )
|
121
|
+
INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 253, 214748.3646 )
|
122
|
+
INSERT INTO [datatypes] ([id], [text]) VALUES ( 271, 'test text' )
|
123
|
+
-- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 281, '1901-01-01T15:45:00.0100001Z' ) -- 15:45:00.01
|
124
|
+
-- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 282, '1984-01-24T04:20:00.0000001-08:00' ) -- 04:20:00.00
|
125
|
+
-- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 283, '1901-01-01T15:45:00.0100001Z' ) -- 15:45:00.0100001
|
126
|
+
-- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 284, '1984-01-24T04:20:00.0000001-08:00' ) -- 04:20:00.0000001
|
127
|
+
INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 301, 0 )
|
128
|
+
INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 )
|
129
|
+
-- INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() )
|
130
|
+
INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
131
|
+
-- INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
|
132
|
+
INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' )
|
133
|
+
-- INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' )
|
134
|
+
-- INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, '<foo><bar>batz</bar></foo>' )
|
135
|
+
|
136
|
+
SET IDENTITY_INSERT [datatypes] OFF
|
137
|
+
|
138
|
+
|
data/test/schema_test.rb
ADDED
@@ -0,0 +1,443 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class SchemaTest < TinyTds::TestCase
|
5
|
+
|
6
|
+
describe 'Casting SQL Server schema' do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@@current_schema_loaded ||= load_current_schema
|
10
|
+
@client = new_connection
|
11
|
+
@gif1px = File.read('test/schema/1px.gif',:mode=>"rb:BINARY")
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'for shared types' do
|
15
|
+
|
16
|
+
it 'casts bigint' do
|
17
|
+
assert_equal -9223372036854775807, find_value(11, :bigint)
|
18
|
+
assert_equal 9223372036854775806, find_value(12, :bigint)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'casts binary' do
|
22
|
+
value = find_value(21, :binary_50)
|
23
|
+
assert_equal @gif1px + "\000", value
|
24
|
+
assert_binary_encoding(value)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'casts bit' do
|
28
|
+
assert_equal true, find_value(31, :bit)
|
29
|
+
assert_equal false, find_value(32, :bit)
|
30
|
+
assert_equal nil, find_value(21, :bit)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'casts char' do
|
34
|
+
partial_char = '12345678 '
|
35
|
+
assert_equal '1234567890', find_value(41, :char_10)
|
36
|
+
assert_equal partial_char, find_value(42, :char_10)
|
37
|
+
assert_utf8_encoding find_value(42, :char_10)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'casts datetime' do
|
41
|
+
# 1753-01-01T00:00:00.000
|
42
|
+
v = find_value 61, :datetime
|
43
|
+
assert_instance_of Time, v, 'not in range of Time class'
|
44
|
+
assert_equal 1753, v.year
|
45
|
+
assert_equal 01, v.month
|
46
|
+
assert_equal 01, v.day
|
47
|
+
assert_equal 0, v.hour
|
48
|
+
assert_equal 0, v.min
|
49
|
+
assert_equal 0, v.sec
|
50
|
+
assert_equal 0, v.usec
|
51
|
+
# 9999-12-31T23:59:59.997
|
52
|
+
v = find_value 62, :datetime
|
53
|
+
assert_instance_of Time, v, 'not in range of Time class'
|
54
|
+
assert_equal 9999, v.year
|
55
|
+
assert_equal 12, v.month
|
56
|
+
assert_equal 31, v.day
|
57
|
+
assert_equal 23, v.hour
|
58
|
+
assert_equal 59, v.min
|
59
|
+
assert_equal 59, v.sec
|
60
|
+
assert_equal 997000, v.usec
|
61
|
+
assert_equal utc_offset, find_value(62, :datetime, :timezone => :local).utc_offset
|
62
|
+
assert_equal 0, find_value(62, :datetime, :timezone => :utc).utc_offset
|
63
|
+
# 2010-01-01T12:34:56.123
|
64
|
+
v = find_value 63, :datetime
|
65
|
+
assert_instance_of Time, v, 'in range of Time class'
|
66
|
+
assert_equal 2010, v.year
|
67
|
+
assert_equal 01, v.month
|
68
|
+
assert_equal 01, v.day
|
69
|
+
assert_equal 12, v.hour
|
70
|
+
assert_equal 34, v.min
|
71
|
+
assert_equal 56, v.sec
|
72
|
+
assert_equal 123000, v.usec
|
73
|
+
assert_equal utc_offset, find_value(63, :datetime, :timezone => :local).utc_offset
|
74
|
+
assert_equal 0, find_value(63, :datetime, :timezone => :utc).utc_offset
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'casts decimal' do
|
78
|
+
assert_instance_of BigDecimal, find_value(91, :decimal_9_2)
|
79
|
+
assert_equal BigDecimal.new('12345.01'), find_value(91, :decimal_9_2)
|
80
|
+
assert_equal BigDecimal.new('1234567.89'), find_value(92, :decimal_9_2)
|
81
|
+
assert_equal BigDecimal.new('0.0'), find_value(93, :decimal_16_4)
|
82
|
+
assert_equal BigDecimal.new('123456789012.3456'), find_value(94, :decimal_16_4)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'casts float' do
|
86
|
+
assert_equal 123.00000001, find_value(101,:float)
|
87
|
+
assert_equal 0.0, find_value(102,:float)
|
88
|
+
assert_equal find_value(102,:float).object_id, find_value(102,:float).object_id, 'use global zero float'
|
89
|
+
assert_equal 123.45, find_value(103,:float)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'casts image' do
|
93
|
+
value = find_value(141,:image)
|
94
|
+
assert_equal @gif1px, value
|
95
|
+
assert_binary_encoding(value)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'casts int' do
|
99
|
+
assert_equal -2147483647, find_value(151, :int)
|
100
|
+
assert_equal 2147483646, find_value(152, :int)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'casts money' do
|
104
|
+
assert_instance_of BigDecimal, find_value(161, :money)
|
105
|
+
assert_equal BigDecimal.new('4.20'), find_value(161, :money)
|
106
|
+
assert_equal BigDecimal.new('922337203685477.5806'), find_value(163 ,:money)
|
107
|
+
assert_equal BigDecimal.new('-922337203685477.5807'), find_value(162 ,:money)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'casts nchar' do
|
111
|
+
assert_equal '1234567890', find_value(171, :nchar_10)
|
112
|
+
assert_equal '123456åå ', find_value(172, :nchar_10)
|
113
|
+
assert_equal 'abc123 ', find_value(173, :nchar_10)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'casts ntext' do
|
117
|
+
assert_equal 'test ntext', find_value(181, :ntext)
|
118
|
+
assert_equal 'test ntext åå', find_value(182, :ntext)
|
119
|
+
assert_utf8_encoding find_value(182, :ntext)
|
120
|
+
# If this test fails, try setting the "text size" in your freetds.conf. See: http://www.freetds.org/faq.html#textdata
|
121
|
+
large_value = "x" * 5000
|
122
|
+
large_value_id = @client.execute("INSERT INTO [datatypes] ([ntext]) VALUES (N'#{large_value}')").insert
|
123
|
+
assert_equal large_value, find_value(large_value_id, :ntext)
|
124
|
+
end unless sybase_ase?
|
125
|
+
|
126
|
+
it 'casts numeric' do
|
127
|
+
assert_instance_of BigDecimal, find_value(191, :numeric_18_0)
|
128
|
+
assert_equal BigDecimal('191'), find_value(191, :numeric_18_0)
|
129
|
+
assert_equal BigDecimal('123456789012345678'), find_value(192, :numeric_18_0)
|
130
|
+
assert_equal BigDecimal('12345678901234567890.01'), find_value(193, :numeric_36_2)
|
131
|
+
assert_equal BigDecimal('123.46'), find_value(194, :numeric_36_2)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'casts nvarchar' do
|
135
|
+
assert_equal 'test nvarchar_50', find_value(201, :nvarchar_50)
|
136
|
+
assert_equal 'test nvarchar_50 åå', find_value(202, :nvarchar_50)
|
137
|
+
assert_utf8_encoding find_value(202, :nvarchar_50)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'casts real' do
|
141
|
+
assert_in_delta 123.45, find_value(221, :real), 0.01
|
142
|
+
assert_equal 0.0, find_value(222, :real)
|
143
|
+
assert_equal find_value(222, :real).object_id, find_value(222, :real).object_id, 'use global zero float'
|
144
|
+
assert_in_delta 0.00001, find_value(223, :real), 0.000001
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'casts smalldatetime' do
|
148
|
+
# 1901-01-01 15:45:00
|
149
|
+
v = find_value 231, :smalldatetime
|
150
|
+
assert_instance_of Time, v
|
151
|
+
assert_equal 1901, v.year
|
152
|
+
assert_equal 01, v.month
|
153
|
+
assert_equal 01, v.day
|
154
|
+
assert_equal 15, v.hour
|
155
|
+
assert_equal 45, v.min
|
156
|
+
assert_equal 00, v.sec
|
157
|
+
assert_equal Time.local(1901).utc_offset, find_value(231, :smalldatetime, :timezone => :local).utc_offset
|
158
|
+
assert_equal 0, find_value(231, :smalldatetime, :timezone => :utc).utc_offset
|
159
|
+
# 2078-06-05 04:20:00
|
160
|
+
v = find_value 232, :smalldatetime
|
161
|
+
assert_instance_of Time, v
|
162
|
+
assert_equal 2078, v.year
|
163
|
+
assert_equal 06, v.month
|
164
|
+
assert_equal 05, v.day
|
165
|
+
assert_equal 04, v.hour
|
166
|
+
assert_equal 20, v.min
|
167
|
+
assert_equal 00, v.sec
|
168
|
+
assert_equal Time.local(2078,6).utc_offset, find_value(232, :smalldatetime, :timezone => :local).utc_offset
|
169
|
+
assert_equal 0, find_value(232, :smalldatetime, :timezone => :utc).utc_offset
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'casts smallint' do
|
173
|
+
assert_equal -32767, find_value(241, :smallint)
|
174
|
+
assert_equal 32766, find_value(242, :smallint)
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'casts smallmoney' do
|
178
|
+
assert_instance_of BigDecimal, find_value(251, :smallmoney)
|
179
|
+
assert_equal BigDecimal.new("4.20"), find_value(251, :smallmoney)
|
180
|
+
assert_equal BigDecimal.new("-214748.3647"), find_value(252, :smallmoney)
|
181
|
+
assert_equal BigDecimal.new("214748.3646"), find_value(253, :smallmoney)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'casts text' do
|
185
|
+
assert_equal 'test text', find_value(271, :text)
|
186
|
+
assert_utf8_encoding find_value(271, :text)
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'casts tinyint' do
|
190
|
+
assert_equal 0, find_value(301, :tinyint)
|
191
|
+
assert_equal 255, find_value(302, :tinyint)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'casts uniqueidentifier' do
|
195
|
+
assert_match %r|\w{8}-\w{4}-\w{4}-\w{4}-\w{12}|, find_value(311, :uniqueidentifier)
|
196
|
+
assert_utf8_encoding find_value(311, :uniqueidentifier)
|
197
|
+
end unless sybase_ase?
|
198
|
+
|
199
|
+
it 'casts varbinary' do
|
200
|
+
value = find_value(321, :varbinary_50)
|
201
|
+
assert_equal @gif1px, value
|
202
|
+
assert_binary_encoding(value)
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'casts varchar' do
|
206
|
+
assert_equal 'test varchar_50', find_value(341, :varchar_50)
|
207
|
+
assert_utf8_encoding find_value(341, :varchar_50)
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
describe 'for 2005 and up' do
|
214
|
+
|
215
|
+
it 'casts nvarchar(max)' do
|
216
|
+
assert_equal 'test nvarchar_max', find_value(211, :nvarchar_max)
|
217
|
+
assert_equal 'test nvarchar_max åå', find_value(212, :nvarchar_max)
|
218
|
+
assert_utf8_encoding find_value(212, :nvarchar_max)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'casts varbinary(max)' do
|
222
|
+
value = find_value(331, :varbinary_max)
|
223
|
+
assert_equal @gif1px, value
|
224
|
+
assert_binary_encoding(value)
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'casts varchar(max)' do
|
228
|
+
value = find_value(351, :varchar_max)
|
229
|
+
assert_equal 'test varchar_max', value
|
230
|
+
assert_utf8_encoding(value)
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'casts xml' do
|
234
|
+
value = find_value(361, :xml)
|
235
|
+
assert_equal '<foo><bar>batz</bar></foo>', value
|
236
|
+
assert_utf8_encoding(value)
|
237
|
+
end
|
238
|
+
|
239
|
+
end if sqlserver_2005? || sqlserver_2008? || sqlserver_2014? || sqlserver_azure?
|
240
|
+
|
241
|
+
|
242
|
+
describe 'for 2008 and up' do
|
243
|
+
|
244
|
+
it 'casts date' do
|
245
|
+
# 0001-01-01
|
246
|
+
v = find_value 51, :date
|
247
|
+
if @client.tds_73?
|
248
|
+
assert_instance_of Date, v
|
249
|
+
assert_equal 1, v.year, 'Year'
|
250
|
+
assert_equal 1, v.month, 'Month'
|
251
|
+
assert_equal 1, v.day, 'Day'
|
252
|
+
else
|
253
|
+
assert_equal '0001-01-01', v
|
254
|
+
end
|
255
|
+
# 9999-12-31
|
256
|
+
v = find_value 52, :date
|
257
|
+
if @client.tds_73?
|
258
|
+
assert_instance_of Date, v
|
259
|
+
assert_equal 9999, v.year, 'Year'
|
260
|
+
assert_equal 12, v.month, 'Month'
|
261
|
+
assert_equal 31, v.day, 'Day'
|
262
|
+
else
|
263
|
+
assert_equal '9999-12-31', v
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'casts time' do
|
268
|
+
# 15:45:00.709714966
|
269
|
+
v = find_value 281, :time_2
|
270
|
+
if @client.tds_73?
|
271
|
+
assert_instance_of Time, v
|
272
|
+
assert_equal 1900, v.year, 'Year'
|
273
|
+
assert_equal 1, v.month, 'Month'
|
274
|
+
assert_equal 1, v.day, 'Day'
|
275
|
+
assert_equal 15, v.hour, 'Hour'
|
276
|
+
assert_equal 45, v.min, 'Minute'
|
277
|
+
assert_equal 0, v.sec, 'Second'
|
278
|
+
assert_equal 710000, v.usec, 'Microseconds'
|
279
|
+
assert_equal 710000000, v.nsec, 'Nanoseconds'
|
280
|
+
else
|
281
|
+
assert_equal '15:45:00.71', v
|
282
|
+
end
|
283
|
+
# 04:20:00.288321545
|
284
|
+
v = find_value 282, :time_2
|
285
|
+
if @client.tds_73?
|
286
|
+
assert_instance_of Time, v
|
287
|
+
assert_equal 1900, v.year, 'Year'
|
288
|
+
assert_equal 1, v.month, 'Month'
|
289
|
+
assert_equal 1, v.day, 'Day'
|
290
|
+
assert_equal 4, v.hour, 'Hour'
|
291
|
+
assert_equal 20, v.min, 'Minute'
|
292
|
+
assert_equal 0, v.sec, 'Second'
|
293
|
+
assert_equal 290000, v.usec, 'Microseconds'
|
294
|
+
assert_equal 290000000, v.nsec, 'Nanoseconds'
|
295
|
+
else
|
296
|
+
assert_equal '04:20:00.29', v
|
297
|
+
end
|
298
|
+
# 15:45:00.709714966
|
299
|
+
v = find_value 283, :time_7
|
300
|
+
if @client.tds_73?
|
301
|
+
assert_instance_of Time, v
|
302
|
+
assert_equal 1900, v.year, 'Year'
|
303
|
+
assert_equal 1, v.month, 'Month'
|
304
|
+
assert_equal 1, v.day, 'Day'
|
305
|
+
assert_equal 15, v.hour, 'Hour'
|
306
|
+
assert_equal 45, v.min, 'Minute'
|
307
|
+
assert_equal 0, v.sec, 'Second'
|
308
|
+
assert_equal 709715, v.usec, 'Microseconds'
|
309
|
+
assert_equal 709715000, v.nsec, 'Nanoseconds'
|
310
|
+
else
|
311
|
+
assert_equal '15:45:00.7097150', v
|
312
|
+
end
|
313
|
+
# 04:20:00.288321545
|
314
|
+
v = find_value 284, :time_7
|
315
|
+
if @client.tds_73?
|
316
|
+
assert_instance_of Time, v
|
317
|
+
assert_equal 1900, v.year, 'Year'
|
318
|
+
assert_equal 1, v.month, 'Month'
|
319
|
+
assert_equal 1, v.day, 'Day'
|
320
|
+
assert_equal 4, v.hour, 'Hour'
|
321
|
+
assert_equal 20, v.min, 'Minute'
|
322
|
+
assert_equal 0, v.sec, 'Second'
|
323
|
+
assert_equal 288321, v.usec, 'Microseconds'
|
324
|
+
assert_equal 288321500, v.nsec, 'Nanoseconds'
|
325
|
+
else
|
326
|
+
assert_equal '04:20:00.2883215', v
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'casts datetime2' do
|
331
|
+
# 0001-01-01 00:00:00.0000000
|
332
|
+
v = find_value 71, :datetime2_7
|
333
|
+
if @client.tds_73?
|
334
|
+
assert_instance_of Time, v
|
335
|
+
assert_equal 1, v.year, 'Year'
|
336
|
+
assert_equal 1, v.month, 'Month'
|
337
|
+
assert_equal 1, v.day, 'Day'
|
338
|
+
assert_equal 0, v.hour, 'Hour'
|
339
|
+
assert_equal 0, v.min, 'Minute'
|
340
|
+
assert_equal 0, v.sec, 'Second'
|
341
|
+
assert_equal 0, v.usec, 'Microseconds'
|
342
|
+
assert_equal 0, v.nsec, 'Nanoseconds'
|
343
|
+
else
|
344
|
+
assert_equal '0001-01-01 00:00:00.0000000', v
|
345
|
+
end
|
346
|
+
# 1984-01-24 04:20:00.0000000
|
347
|
+
v = find_value 72, :datetime2_7
|
348
|
+
if @client.tds_73?
|
349
|
+
assert_instance_of Time, v
|
350
|
+
assert_equal 1984, v.year, 'Year'
|
351
|
+
assert_equal 1, v.month, 'Month'
|
352
|
+
assert_equal 24, v.day, 'Day'
|
353
|
+
assert_equal 4, v.hour, 'Hour'
|
354
|
+
assert_equal 20, v.min, 'Minute'
|
355
|
+
assert_equal 0, v.sec, 'Second'
|
356
|
+
assert_equal 0, v.usec, 'Microseconds'
|
357
|
+
assert_equal 0, v.nsec, 'Nanoseconds'
|
358
|
+
else
|
359
|
+
assert_equal '1984-01-24 04:20:00.0000000', v
|
360
|
+
end
|
361
|
+
# 9999-12-31 23:59:59.9999999
|
362
|
+
v = find_value 73, :datetime2_7
|
363
|
+
if @client.tds_73?
|
364
|
+
assert_instance_of Time, v
|
365
|
+
assert_equal 9999, v.year, 'Year'
|
366
|
+
assert_equal 12, v.month, 'Month'
|
367
|
+
assert_equal 31, v.day, 'Day'
|
368
|
+
assert_equal 23, v.hour, 'Hour'
|
369
|
+
assert_equal 59, v.min, 'Minute'
|
370
|
+
assert_equal 59, v.sec, 'Second'
|
371
|
+
assert_equal 999999, v.usec, 'Microseconds'
|
372
|
+
assert_equal 999999900, v.nsec, 'Nanoseconds'
|
373
|
+
else
|
374
|
+
assert_equal '9999-12-31 23:59:59.9999999', v
|
375
|
+
end
|
376
|
+
# 9999-12-31 23:59:59.123456789
|
377
|
+
v = find_value 74, :datetime2_2
|
378
|
+
if @client.tds_73?
|
379
|
+
assert_instance_of Time, v
|
380
|
+
assert_equal 9999, v.year, 'Year'
|
381
|
+
assert_equal 12, v.month, 'Month'
|
382
|
+
assert_equal 31, v.day, 'Day'
|
383
|
+
assert_equal 23, v.hour, 'Hour'
|
384
|
+
assert_equal 59, v.min, 'Minute'
|
385
|
+
assert_equal 59, v.sec, 'Second'
|
386
|
+
assert_equal 120000, v.usec, 'Microseconds'
|
387
|
+
assert_equal 120000000, v.nsec, 'Nanoseconds'
|
388
|
+
else
|
389
|
+
assert_equal '9999-12-31 23:59:59.12', v
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
it 'casts datetimeoffset' do
|
394
|
+
# 1984-01-24T04:20:00.1234567-08:00
|
395
|
+
v = find_value 84, :datetimeoffset_7
|
396
|
+
if @client.tds_73?
|
397
|
+
assertions = lambda {
|
398
|
+
assert_instance_of Time, v
|
399
|
+
assert_equal 1984, v.year, 'Year'
|
400
|
+
assert_equal 1, v.month, 'Month'
|
401
|
+
assert_equal 24, v.day, 'Day'
|
402
|
+
assert_equal 4, v.hour, 'Hour'
|
403
|
+
assert_equal 20, v.min, 'Minute'
|
404
|
+
assert_equal 59, v.sec, 'Second'
|
405
|
+
assert_equal 123456, v.usec, 'Microseconds'
|
406
|
+
assert_equal 123456700, v.nsec, 'Nanoseconds'
|
407
|
+
assert_equal -28800, v.utc_offset, 'Offset'
|
408
|
+
}
|
409
|
+
assertions.call
|
410
|
+
v = find_value 84, :datetimeoffset_7, timezone: :local
|
411
|
+
assertions.call # Ignores timezone query option.
|
412
|
+
else
|
413
|
+
assert_equal '1984-01-24 04:20:59.1234567 -08:00', v
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
# it 'casts geography' do
|
418
|
+
# value = find_value 111, :geography
|
419
|
+
# assert_equal '', value
|
420
|
+
# end
|
421
|
+
#
|
422
|
+
# it 'casts geometry' do
|
423
|
+
# value = find_value 121, :geometry
|
424
|
+
# assert_equal '', value
|
425
|
+
# end
|
426
|
+
#
|
427
|
+
# it 'casts hierarchyid' do
|
428
|
+
# value = find_value 131, :hierarchyid
|
429
|
+
# assert_equal '', value
|
430
|
+
# end
|
431
|
+
|
432
|
+
end if sqlserver_2008? || sqlserver_2014? || sqlserver_azure?
|
433
|
+
|
434
|
+
end
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
end
|
439
|
+
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
|