trilogy 2.13.0 → 2.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/trilogy-ruby/cast.c +4 -1
- data/ext/trilogy-ruby/cext.c +3 -11
- data/ext/trilogy-ruby/src/charset.c +6 -1
- data/ext/trilogy-ruby/src/client.c +2 -1
- data/lib/trilogy/encoding.rb +6 -0
- data/lib/trilogy/version.rb +1 -1
- data/lib/trilogy.rb +25 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ea4b038d25e87b1d26c6dc0af6aa37b3cfa2b7244ea4788155bb392f7a5e93e
|
|
4
|
+
data.tar.gz: c4201dd5f2c3974244cea9ae97af6052d3d1991509e64c2dde8319882b00a53e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e58cdf8bf20b4d31e43b811ceb7972a772c2ccb44133f715a4d9c0723c1c1ed4b3139c5e7be68575b119932348f5d8d393d088b88fd73ba058eeef9d8203796
|
|
7
|
+
data.tar.gz: ef9527a11371f0b6dbab901eb6c682e5a6e7cbf48d81e483b647682355b825a08ca342491a523859f543bfcaaf598588a713c5859baf8a883fe5adcda14f59ea
|
data/ext/trilogy-ruby/cast.c
CHANGED
|
@@ -56,8 +56,11 @@ static const char *ruby_encoding_name_map[] = {
|
|
|
56
56
|
|
|
57
57
|
static rb_encoding * encoding_for_charset(TRILOGY_CHARSET_t charset)
|
|
58
58
|
{
|
|
59
|
-
|
|
59
|
+
if (RB_UNLIKELY(charset >= TRILOGY_CHARSET_MAX)) {
|
|
60
|
+
return rb_enc_find(ruby_encoding_name_map[trilogy_encoding_from_charset(charset)]);
|
|
61
|
+
}
|
|
60
62
|
|
|
63
|
+
static rb_encoding * map[TRILOGY_CHARSET_MAX];
|
|
61
64
|
if (RB_LIKELY(map[charset])) {
|
|
62
65
|
return map[charset];
|
|
63
66
|
}
|
data/ext/trilogy-ruby/cext.c
CHANGED
|
@@ -1128,7 +1128,6 @@ static VALUE rb_trilogy_query(VALUE self, VALUE query)
|
|
|
1128
1128
|
struct trilogy_ctx *ctx = get_open_ctx(self);
|
|
1129
1129
|
|
|
1130
1130
|
StringValue(query);
|
|
1131
|
-
query = rb_str_export_to_enc(query, ctx->encoding);
|
|
1132
1131
|
query = rb_str_new_frozen(query);
|
|
1133
1132
|
|
|
1134
1133
|
rb_trilogy_acquire_buffer(ctx);
|
|
@@ -1189,13 +1188,6 @@ static VALUE rb_trilogy_escape(VALUE self, VALUE str)
|
|
|
1189
1188
|
struct trilogy_ctx *ctx = get_open_ctx(self);
|
|
1190
1189
|
|
|
1191
1190
|
StringValue(str);
|
|
1192
|
-
str = rb_str_new_frozen(str);
|
|
1193
|
-
|
|
1194
|
-
rb_encoding *str_enc = rb_enc_get(str);
|
|
1195
|
-
|
|
1196
|
-
if (!rb_enc_asciicompat(str_enc)) {
|
|
1197
|
-
rb_raise(rb_eEncCompatError, "input string must be ASCII-compatible");
|
|
1198
|
-
}
|
|
1199
1191
|
|
|
1200
1192
|
const char *escaped_str;
|
|
1201
1193
|
size_t escaped_len;
|
|
@@ -1208,7 +1200,7 @@ static VALUE rb_trilogy_escape(VALUE self, VALUE str)
|
|
|
1208
1200
|
handle_trilogy_error(ctx, rc, "trilogy_escape");
|
|
1209
1201
|
}
|
|
1210
1202
|
|
|
1211
|
-
VALUE escaped_string = rb_enc_str_new(escaped_str, escaped_len,
|
|
1203
|
+
VALUE escaped_string = rb_enc_str_new(escaped_str, escaped_len, ctx->encoding);
|
|
1212
1204
|
|
|
1213
1205
|
rb_trilogy_release_buffer(ctx);
|
|
1214
1206
|
|
|
@@ -1371,9 +1363,9 @@ RUBY_FUNC_EXPORTED void Init_cext(void)
|
|
|
1371
1363
|
rb_define_private_method(Trilogy, "_connect", rb_trilogy_connect, 4);
|
|
1372
1364
|
rb_define_method(Trilogy, "change_db", rb_trilogy_change_db, 1);
|
|
1373
1365
|
rb_define_alias(Trilogy, "select_db", "change_db");
|
|
1374
|
-
|
|
1366
|
+
rb_define_private_method(Trilogy, "_query", rb_trilogy_query, 1);
|
|
1375
1367
|
rb_define_method(Trilogy, "ping", rb_trilogy_ping, 0);
|
|
1376
|
-
|
|
1368
|
+
rb_define_private_method(Trilogy, "_escape", rb_trilogy_escape, 1);
|
|
1377
1369
|
rb_define_method(Trilogy, "close", rb_trilogy_close, 0);
|
|
1378
1370
|
rb_define_method(Trilogy, "closed?", rb_trilogy_closed, 0);
|
|
1379
1371
|
rb_define_method(Trilogy, "check", rb_trilogy_check, 0);
|
|
@@ -209,4 +209,9 @@ static TRILOGY_ENCODING_t charset_to_encoding_map[] = {
|
|
|
209
209
|
[TRILOGY_CHARSET_EUCJPMS_BIN] = TRILOGY_ENCODING_EUCJPMS,
|
|
210
210
|
};
|
|
211
211
|
|
|
212
|
-
TRILOGY_ENCODING_t trilogy_encoding_from_charset(TRILOGY_CHARSET_t charset) {
|
|
212
|
+
TRILOGY_ENCODING_t trilogy_encoding_from_charset(TRILOGY_CHARSET_t charset) {
|
|
213
|
+
if ((unsigned)charset >= TRILOGY_CHARSET_MAX) {
|
|
214
|
+
return TRILOGY_ENCODING_BINARY;
|
|
215
|
+
}
|
|
216
|
+
return charset_to_encoding_map[charset];
|
|
217
|
+
}
|
|
@@ -214,6 +214,7 @@ int trilogy_flush_writes(trilogy_conn_t *conn)
|
|
|
214
214
|
|
|
215
215
|
static void set_error(trilogy_conn_t *conn, const trilogy_err_packet_t *packet)
|
|
216
216
|
{
|
|
217
|
+
conn->server_status &= ((uint16_t)~TRILOGY_SERVER_STATUS_MORE_RESULTS_EXISTS);
|
|
217
218
|
conn->error_code = packet->error_code;
|
|
218
219
|
conn->error_message = packet->error_message;
|
|
219
220
|
conn->error_message_len = packet->error_message_len;
|
|
@@ -312,7 +313,7 @@ static int read_eof_packet(trilogy_conn_t *conn)
|
|
|
312
313
|
|
|
313
314
|
static int read_auth_switch_packet(trilogy_conn_t *conn, trilogy_handshake_t *handshake)
|
|
314
315
|
{
|
|
315
|
-
trilogy_auth_switch_request_packet_t auth_switch_packet;
|
|
316
|
+
trilogy_auth_switch_request_packet_t auth_switch_packet = {0};
|
|
316
317
|
|
|
317
318
|
int rc = trilogy_parse_auth_switch_request_packet(conn->packet_buffer.buff, conn->packet_buffer.len,
|
|
318
319
|
conn->capabilities, &auth_switch_packet);
|
data/lib/trilogy/encoding.rb
CHANGED
|
@@ -84,7 +84,13 @@ class Trilogy
|
|
|
84
84
|
"binary" => CHARSET_BINARY,
|
|
85
85
|
}.freeze
|
|
86
86
|
|
|
87
|
+
UNSUPPORTED_ENCODINGS = %w[big5 sjis gbk cp932 gb18030 ucs2 utf16 utf16le utf32].freeze
|
|
88
|
+
|
|
87
89
|
def self.find(mysql_encoding)
|
|
90
|
+
if UNSUPPORTED_ENCODINGS.include?(mysql_encoding)
|
|
91
|
+
raise ArgumentError, "Unsupported encoding: #{mysql_encoding}"
|
|
92
|
+
end
|
|
93
|
+
|
|
88
94
|
unless rb_encoding = RUBY_ENCODINGS[mysql_encoding]
|
|
89
95
|
raise ArgumentError, "Unknown or unsupported encoding: #{mysql_encoding}"
|
|
90
96
|
end
|
data/lib/trilogy/version.rb
CHANGED
data/lib/trilogy.rb
CHANGED
|
@@ -16,6 +16,27 @@ class Trilogy
|
|
|
16
16
|
end
|
|
17
17
|
private_constant :IO_TIMEOUT_ERROR
|
|
18
18
|
|
|
19
|
+
def query(arg)
|
|
20
|
+
str = String.try_convert(arg) or raise TypeError, "no implicit conversion of #{arg.class} into String"
|
|
21
|
+
str = str.dup if str.equal?(arg)
|
|
22
|
+
str.freeze
|
|
23
|
+
|
|
24
|
+
str_encoding = str.encoding
|
|
25
|
+
if @encoding != str_encoding && ::Encoding::BINARY != str_encoding && !(str.ascii_only? && @encoding.ascii_compatible?)
|
|
26
|
+
raise ::Encoding::CompatibilityError, "Trilogy connection uses #{@encoding} but the query was provided in #{str_encoding}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
_query(str)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def escape(arg)
|
|
33
|
+
str = String.try_convert(arg) or raise TypeError, "no implicit conversion of #{arg.class} into String"
|
|
34
|
+
if @encoding != str.encoding && !(str.ascii_only? && @encoding.ascii_compatible?) && str.encoding != ::Encoding::ASCII_8BIT
|
|
35
|
+
str = str.encode(@encoding)
|
|
36
|
+
end
|
|
37
|
+
_escape(str)
|
|
38
|
+
end
|
|
39
|
+
|
|
19
40
|
module Synchronization
|
|
20
41
|
def initialize(...)
|
|
21
42
|
@mutex = Mutex.new
|
|
@@ -47,10 +68,12 @@ class Trilogy
|
|
|
47
68
|
|
|
48
69
|
prepend(Synchronization)
|
|
49
70
|
|
|
71
|
+
attr_reader :encoding
|
|
72
|
+
|
|
50
73
|
def initialize(options = {})
|
|
51
74
|
options[:port] = options[:port].to_i if options[:port]
|
|
52
75
|
mysql_encoding = options[:encoding] || "utf8mb4"
|
|
53
|
-
encoding = Trilogy::Encoding.find(mysql_encoding)
|
|
76
|
+
@encoding = Trilogy::Encoding.find(mysql_encoding)
|
|
54
77
|
charset = Trilogy::Encoding.charset(mysql_encoding)
|
|
55
78
|
@connection_options = options
|
|
56
79
|
@connected_host = nil
|
|
@@ -99,7 +122,7 @@ class Trilogy
|
|
|
99
122
|
end
|
|
100
123
|
end
|
|
101
124
|
|
|
102
|
-
_connect(socket, encoding, charset, options)
|
|
125
|
+
_connect(socket, @encoding, charset, options)
|
|
103
126
|
ensure
|
|
104
127
|
# Socket's fd will be dup'd in C
|
|
105
128
|
socket&.close
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: trilogy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.13.
|
|
4
|
+
version: 2.13.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GitHub Engineering
|
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
88
|
version: '0'
|
|
89
89
|
requirements: []
|
|
90
|
-
rubygems_version: 4.0.
|
|
90
|
+
rubygems_version: 4.0.20
|
|
91
91
|
specification_version: 4
|
|
92
92
|
summary: A friendly MySQL-compatible library for Ruby, binding to libtrilogy
|
|
93
93
|
test_files: []
|