Skip to content

Commit ac9bc43

Browse files
committed
Rename encoding keyword argument to charset
`encoding` denotes the actual `Encoding` then used to associate strings.
1 parent 5a10d48 commit ac9bc43

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

ext/tiny_tds/client.c

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ static VALUE cTinyTdsResult, cKernel, cDate;
1515
rb_encoding *binaryEncoding;
1616
VALUE opt_onek, opt_onebil, opt_float_zero, opt_four, opt_tenk;
1717

18-
static void rb_tinytds_client_mark(void *ptr)
19-
{
20-
tinytds_client_wrapper *cwrap = (tinytds_client_wrapper *)ptr;
21-
22-
if (cwrap) {
23-
rb_gc_mark(cwrap->charset);
24-
}
25-
}
26-
2718
static void rb_tinytds_client_free(void *ptr)
2819
{
2920
tinytds_client_wrapper *cwrap = (tinytds_client_wrapper *)ptr;
@@ -51,7 +42,7 @@ static size_t tinytds_client_wrapper_size(const void* data)
5142
static const rb_data_type_t tinytds_client_wrapper_type = {
5243
.wrap_struct_name = "tinytds_client_wrapper",
5344
.function = {
54-
.dmark = rb_tinytds_client_mark,
45+
.dmark = NULL,
5546
.dfree = rb_tinytds_client_free,
5647
.dsize = tinytds_client_wrapper_size,
5748
},
@@ -459,7 +450,6 @@ static VALUE allocate(VALUE klass)
459450
tinytds_client_wrapper *cwrap;
460451
obj = TypedData_Make_Struct(klass, tinytds_client_wrapper, &tinytds_client_wrapper_type, cwrap);
461452
cwrap->closed = 1;
462-
cwrap->charset = Qnil;
463453
cwrap->userdata = malloc(sizeof(tinytds_client_userdata));
464454
cwrap->userdata->closed = 1;
465455
rb_tinytds_client_reset_userdata(cwrap->userdata);
@@ -910,12 +900,6 @@ static VALUE rb_tiny_tds_do(VALUE self, VALUE sql)
910900
return rb_tinytds_affected_rows(cwrap->client);
911901
}
912902

913-
static VALUE rb_tinytds_charset(VALUE self)
914-
{
915-
GET_CLIENT_WRAPPER(self);
916-
return cwrap->charset;
917-
}
918-
919903
static VALUE rb_tinytds_encoding(VALUE self)
920904
{
921905
GET_CLIENT_WRAPPER(self);
@@ -975,7 +959,7 @@ static VALUE rb_tinytds_connect(VALUE self)
975959
contained = rb_iv_get(self, "@contained");
976960
database = rb_iv_get(self, "@database");
977961
dataserver = rb_iv_get(self, "@dataserver");
978-
charset = rb_iv_get(self, "@encoding");
962+
charset = rb_iv_get(self, "@charset");
979963
login_timeout = rb_iv_get(self, "@login_timeout");
980964
password = rb_iv_get(self, "@password");
981965
tds_version = rb_iv_get(self, "@tds_version");
@@ -1054,7 +1038,6 @@ static VALUE rb_tinytds_connect(VALUE self)
10541038
VALUE transposed_encoding, timeout_string;
10551039

10561040
cwrap->closed = 0;
1057-
cwrap->charset = charset;
10581041

10591042
if (!NIL_P(tds_version)) {
10601043
dbsetversion(NUM2INT(tds_version));
@@ -1112,7 +1095,6 @@ void init_tinytds_client()
11121095
rb_define_method(cTinyTdsClient, "execute", rb_tinytds_execute, -1);
11131096
rb_define_method(cTinyTdsClient, "insert", rb_tiny_tds_insert, 1);
11141097
rb_define_method(cTinyTdsClient, "do", rb_tiny_tds_do, 1);
1115-
rb_define_method(cTinyTdsClient, "charset", rb_tinytds_charset, 0);
11161098
rb_define_method(cTinyTdsClient, "encoding", rb_tinytds_encoding, 0);
11171099
rb_define_method(cTinyTdsClient, "escape", rb_tinytds_escape, 1);
11181100
rb_define_method(cTinyTdsClient, "return_code", rb_tinytds_return_code, 0);

lib/tiny_tds/client.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module TinyTds
22
class Client
3-
attr_reader :app_name, :contained, :database, :dataserver, :encoding, :message_handler, :login_timeout, :password, :port, :tds_version, :timeout, :username, :use_utf16
3+
attr_reader :app_name, :charset, :contained, :database, :dataserver, :message_handler, :login_timeout, :password, :port, :tds_version, :timeout, :username, :use_utf16
44

55
@default_query_options = {
66
as: :hash,
@@ -30,7 +30,7 @@ def local_offset
3030
# rubocop:disable Metrics/MethodLength
3131
# rubocop:disable Metrics/CyclomaticComplexity
3232
# rubocop:disable Metrics/PerceivedComplexity
33-
def initialize(app_name: "TinyTds", azure: false, contained: false, database: nil, dataserver: nil, encoding: "UTF-8", message_handler: nil, host: nil, login_timeout: 60, password: nil, port: 1433, tds_version: nil, timeout: 5, username: nil, use_utf16: true)
33+
def initialize(app_name: "TinyTds", azure: false, charset: "UTF-8", contained: false, database: nil, dataserver: nil, message_handler: nil, host: nil, login_timeout: 60, password: nil, port: 1433, tds_version: nil, timeout: 5, username: nil, use_utf16: true)
3434
if dataserver.to_s.empty? && host.to_s.empty?
3535
raise ArgumentError, "missing :host option if no :dataserver given"
3636
end
@@ -42,9 +42,9 @@ def initialize(app_name: "TinyTds", azure: false, contained: false, database: ni
4242
end
4343

4444
@app_name = app_name
45+
@charset = (charset.nil? || charset.casecmp("utf8").zero?) ? "UTF-8" : charset.upcase
4546
@database = database
4647
@dataserver = dataserver || "#{host}:#{port}"
47-
@encoding = (encoding.nil? || encoding.casecmp("utf8").zero?) ? "UTF-8" : encoding.upcase
4848
@login_timeout = login_timeout.to_i
4949
@password = password if password && password.to_s.strip != ""
5050
@port = port.to_i

test/client_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ class ClientTest < TinyTds::TestCase
4545
assert_equal "''hello''", @client.escape("'hello'")
4646
end
4747

48-
["CP850", "CP1252", "ISO-8859-1"].each do |encoding|
49-
it "allows valid iconv character set - #{encoding}" do
50-
client = new_connection(encoding: encoding)
51-
assert_equal encoding, client.charset
52-
assert_equal Encoding.find(encoding), client.encoding
48+
["CP850", "CP1252", "ISO-8859-1"].each do |charset|
49+
it "allows valid iconv character set - #{charset}" do
50+
client = new_connection(charset:)
51+
assert_equal charset, client.charset
52+
assert_equal Encoding.find(charset), client.encoding
5353
ensure
5454
client&.close
5555
end

0 commit comments

Comments
 (0)