Permalink
Browse files

[1.9] Added a few #encoding file hints. Add 1px.gif as a schema fixtu…

…re and read it up in schema test vs worrying about internal/file encoding. All binary data works in 1.9 and comes back as binary encoded.
  • Loading branch information...
1 parent 03ab4ec commit ad5a548c10ad722aad00ba7772ee5f6af76fadac @metaskills metaskills committed Oct 7, 2010
Showing with 25 additions and 9 deletions.
  1. +1 −0 NOTES
  2. +1 −0 Rakefile
  3. +9 −2 ext/tiny_tds/result.c
  4. BIN test/schema/1px.gif
  5. +13 −7 test/schema_test.rb
  6. +1 −0 test/test_helper.rb
View
1 NOTES
@@ -26,6 +26,7 @@ TODO
- Date and time checklist.
• Make tests pass for everyone (see below maybe)
• Makes sure raise'ing "Invalid date" is right, deos this happen? If so, we need to cancel all results!
+ Maybe use just rb_warn.
• Do we need to add tests for usec support?
• Is intern local right? I thought DB time was the winner? Not local app client?
- Looking into using DBCOUNT to return affected rows.
View
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require 'rake'
require 'rake/testtask'
require 'rake/extensiontask'
View
@@ -10,6 +10,9 @@ static ID intern_new, intern_utc, intern_local, intern_encoding_from_charset_cod
intern_local_offset, intern_civil, intern_new_offset, intern_plus, intern_divide;
static ID sym_symbolize_keys, sym_as, sym_array, sym_database_timezone, sym_application_timezone, sym_local, sym_utc;
+#ifdef HAVE_RUBY_ENCODING_H
+rb_encoding *binaryEncoding;
+#endif
// Lib Backend (Memory Management)
@@ -131,9 +134,10 @@ static VALUE rb_tinytds_result_fetch_row(VALUE self, ID db_timezone, ID app_time
}
case SYBBINARY:
case SYBIMAGE:
- // TODO: When we HAVE_RUBY_ENCODING_H we will rb_enc_associate(val, binaryEncoding)
- // that will be a static init var too like mysql2 gem.
val = rb_str_new((char *)data, (long)data_len);
+ #ifdef HAVE_RUBY_ENCODING_H
+ rb_enc_associate(val, binaryEncoding);
+ #endif
break;
case 36: { // SYBUNIQUE
char converted_unique[32];
@@ -352,4 +356,7 @@ void init_tinytds_result() {
/* Hard-Coded VALUEs */
hc_tensix_power = INT2NUM(1000000);
rb_global_variable(&hc_tensix_power);
+ #ifdef HAVE_RUBY_ENCODING_H
+ binaryEncoding = rb_enc_find("binary");
+ #endif
}
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -8,7 +8,7 @@ class SchemaTest < TinyTds::TestCase
setup do
load_current_schema
@client ||= TinyTds::Client.new(connection_options)
- @gif1px = "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;"
+ @gif1px = ruby19? ? File.read('test/schema/1px.gif',:mode=>"rb:BINARY") : File.read('test/schema/1px.gif')
end
context 'for shared types' do
@@ -19,7 +19,9 @@ class SchemaTest < TinyTds::TestCase
end
should 'cast binary' do
- assert_equal @gif1px, find_value(21, :binary_50)
+ value = find_value(21, :binary_50)
+ assert_equal @gif1px, value
+ assert_equal Encoding.find('BINARY'), value.encoding if ruby19?
end
should 'cast bit' do
@@ -57,7 +59,9 @@ class SchemaTest < TinyTds::TestCase
end
should 'cast image' do
- assert_equal @gif1px, find_value(141,:image)
+ value = find_value(141,:image)
+ assert_equal @gif1px, value
+ assert_equal Encoding.find('BINARY'), value.encoding if ruby19?
end
should 'cast int' do
@@ -107,19 +111,19 @@ class SchemaTest < TinyTds::TestCase
assert_equal Time.parse('1901-01-01T15:45:00.000'), find_value(231, :smalldatetime)
assert_equal Time.parse('2078-06-05T04:20:00.000').to_s, find_value(232, :smalldatetime).to_s
end
-
+
should 'cast smallint' do
assert_equal -32767, find_value(241, :smallint)
assert_equal 32766, find_value(242, :smallint)
end
-
+
should 'cast smallmoney' do
assert_instance_of BigDecimal, find_value(251, :smallmoney)
assert_equal BigDecimal.new("4.20"), find_value(251, :smallmoney)
assert_equal BigDecimal.new("-214748.3647"), find_value(252, :smallmoney)
assert_equal BigDecimal.new("214748.3646"), find_value(253, :smallmoney)
end
-
+
should 'cast text' do
assert_equal 'test text', find_value(271, :text)
end
@@ -134,7 +138,9 @@ class SchemaTest < TinyTds::TestCase
end
should 'cast varbinary' do
- assert_equal @gif1px, find_value(321, :varbinary_50)
+ value = find_value(321, :varbinary_50)
+ assert_equal @gif1px, value
+ assert_equal Encoding.find('BINARY'), value.encoding if ruby19?
end
should 'cast varchar' do
View
@@ -1,3 +1,4 @@
+# encoding: UTF-8
require 'test/unit'
require 'rubygems'
require 'bundler'

0 comments on commit ad5a548

Please sign in to comment.