Guest User

Untitled

a guest
Jun 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.69 KB | None | 0 0
  1. diff --git a/ext/tiny_tds/result.c b/ext/tiny_tds/result.c
  2. index 205677e..115db74 100644
  3. --- a/ext/tiny_tds/result.c
  4. +++ b/ext/tiny_tds/result.c
  5. @@ -74,7 +74,7 @@ static VALUE rb_tinytds_result_fetch_row(VALUE self, ID timezone, int symbolize_
  6. rwrap->fields = rb_ary_new2(rwrap->number_of_fields);
  7. for (i = 0; i < rwrap->number_of_fields; i++) {
  8. char *colname = dbcolname(rwrap->client, i+1);
  9. - VALUE field = symbolize_keys ? ID2SYM(rb_intern(colname)) : rb_obj_freeze(rb_str_new2(colname));
  10. + VALUE field = symbolize_keys ? ID2SYM(rb_intern(colname)) : rb_obj_freeze(ENCODED_STR_NEW2(colname));
  11. rb_ary_store(rwrap->fields, i, field);
  12. }
  13. }
  14. @@ -157,11 +157,15 @@ static VALUE rb_tinytds_result_fetch_row(VALUE self, ID timezone, int symbolize_
  15. val = ENCODED_STR_NEW2(converted_unique);
  16. break;
  17. }
  18. - case SYBDATETIME4:
  19. - dbconvert(rwrap->client, coltype, data, data_len, SYBDATETIME, data, data_len);
  20. + case SYBDATETIME4: {
  21. + DBDATETIME new_data;
  22. + dbconvert(rwrap->client, coltype, data, data_len, SYBDATETIME, &new_data, sizeof(new_data));
  23. + data = &new_data;
  24. + data_len = sizeof(new_data);
  25. + }
  26. case SYBDATETIME: {
  27. DBDATEREC date_rec;
  28. - dbdatecrack(rwrap->client, &date_rec, (DBDATETIME *)data);
  29. + dbdatecrack(rwrap->client, &date_rec, (DBDATETIME *)data);
  30. int year = date_rec.year,
  31. month = date_rec.month,
  32. day = date_rec.day,
  33. diff --git a/test/result_test.rb b/test/result_test.rb
  34. index a085caf..95ae0e8 100644
  35. --- a/test/result_test.rb
  36. +++ b/test/result_test.rb
  37. @@ -101,19 +101,21 @@ class ResultTest < TinyTds::TestCase
  38. end
  39.  
  40. should 'delete, insert and find data' do
  41. - text = 'test insert and delete'
  42. + text = 'test insert and delete with umlaute öäüß'
  43. @client.execute("DELETE FROM [datatypes] WHERE [varchar_50] IS NOT NULL").do
  44. @client.execute("INSERT INTO [datatypes] ([varchar_50]) VALUES ('#{text}')").do
  45. - row = @client.execute("SELECT [varchar_50] FROM [datatypes] WHERE [varchar_50] IS NOT NULL").each.first
  46. + # row = @client.execute("SELECT [varchar_50] FROM [datatypes] WHERE [varchar_50] IS NOT NULL").each.first
  47. + row = @client.execute("SELECT [varchar_50] FROM [datatypes] WHERE [varchar_50] = '#{text}'").each.first
  48. assert row
  49. assert_equal text, row['varchar_50']
  50. end
  51.  
  52. should 'insert and find unicode data' do
  53. - text = '✓'
  54. + text = "Unicode Smile: \u263A Theta: \u0398 Pts: \u20A7"
  55. @client.execute("DELETE FROM [datatypes] WHERE [nvarchar_50] IS NOT NULL").do
  56. @client.execute("INSERT INTO [datatypes] ([nvarchar_50]) VALUES (N'#{text}')").do
  57. - row = @client.execute("SELECT [nvarchar_50] FROM [datatypes] WHERE [nvarchar_50] IS NOT NULL").each.first
  58. + # row = @client.execute("SELECT [nvarchar_50] FROM [datatypes] WHERE [nvarchar_50] IS NOT NULL").each.first
  59. + row = @client.execute("SELECT [nvarchar_50] FROM [datatypes] WHERE [nvarchar_50] = N'#{text}'").each.first
  60. assert_equal text, row['nvarchar_50']
  61. end
  62.  
  63. diff --git a/test/schema/sqlserver_2005.sql b/test/schema/sqlserver_2005.sql
  64. index 86626ad..57bd21c 100644
  65. --- a/test/schema/sqlserver_2005.sql
  66. +++ b/test/schema/sqlserver_2005.sql
  67. @@ -53,7 +53,8 @@ CREATE TABLE [datatypes] (
  68. [varbinary_max] [varbinary](max) NULL,
  69. [varchar_50] [varchar](50) NULL,
  70. [varchar_max] [varchar](max) NULL,
  71. - [xml] [xml] NULL
  72. + [xml] [xml] NULL,
  73. + [Special_öäüß_column] [varchar](50) NULL
  74. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  75.  
  76. SET IDENTITY_INSERT [datatypes] ON
  77. @@ -106,9 +107,9 @@ INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 12345678901234
  78. INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 )
  79. INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 )
  80. INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' )
  81. -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' )
  82. +INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 öäüß' )
  83. INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' )
  84. -INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max åå' )
  85. +INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max öäüß' )
  86. INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 )
  87. INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 )
  88. INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 )
  89. @@ -129,10 +130,10 @@ INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 )
  90. INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() )
  91. INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
  92. INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b )
  93. -INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' )
  94. -INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' )
  95. +INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50 öäüß' )
  96. +INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max öäüß' )
  97. INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, '<foo><bar>batz</bar></foo>' )
  98. -
  99. +INSERT INTO [datatypes] ([id], [Special_öäüß_column]) VALUES ( 370, "I'm still here!" )
  100. SET IDENTITY_INSERT [datatypes] OFF
  101.  
  102.  
  103. diff --git a/test/schema_test.rb b/test/schema_test.rb
  104. index a904c2e..a519e45 100644
  105. --- a/test/schema_test.rb
  106. +++ b/test/schema_test.rb
  107. @@ -128,7 +128,7 @@ class SchemaTest < TinyTds::TestCase
  108.  
  109. should 'cast nvarchar' do
  110. assert_equal 'test nvarchar_50', find_value(201, :nvarchar_50)
  111. - assert_equal 'test nvarchar_50 åå', find_value(202, :nvarchar_50)
  112. + assert_equal 'test nvarchar_50 öäüß', find_value(202, :nvarchar_50)
  113. assert_utf8_encoding find_value(202, :nvarchar_50)
  114. end
  115.  
  116. @@ -198,7 +198,7 @@ class SchemaTest < TinyTds::TestCase
  117. end
  118.  
  119. should 'cast varchar' do
  120. - assert_equal 'test varchar_50', find_value(341, :varchar_50)
  121. + assert_equal 'test varchar_50 öäüß', find_value(341, :varchar_50)
  122. assert_utf8_encoding find_value(341, :varchar_50)
  123. end
  124.  
  125. @@ -209,7 +209,7 @@ class SchemaTest < TinyTds::TestCase
  126.  
  127. should 'cast nvarchar(max)' do
  128. assert_equal 'test nvarchar_max', find_value(211, :nvarchar_max)
  129. - assert_equal 'test nvarchar_max åå', find_value(212, :nvarchar_max)
  130. + assert_equal 'test nvarchar_max öäüß', find_value(212, :nvarchar_max)
  131. assert_utf8_encoding find_value(212, :nvarchar_max)
  132. end
  133.  
  134. @@ -221,7 +221,7 @@ class SchemaTest < TinyTds::TestCase
  135.  
  136. should 'cast varchar(max)' do
  137. value = find_value(351, :varchar_max)
  138. - assert_equal 'test varchar_max', value
  139. + assert_equal 'test varchar_max öäüß', value
  140. assert_utf8_encoding(value)
  141. end
  142.  
  143. @@ -230,7 +230,13 @@ class SchemaTest < TinyTds::TestCase
  144. assert_equal '<foo><bar>batz</bar></foo>', value
  145. assert_utf8_encoding(value)
  146. end
  147. -
  148. +
  149. + should 'cast special column' do
  150. + value = find_value(370, :Special_öäüß_column)
  151. + assert_equal "I'm still here!", value
  152. + assert_utf8_encoding(value)
  153. + end
  154. +
  155. end if sqlserver_2005? || sqlserver_2008?
Add Comment
Please, Sign In to add comment