Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode column names with encoding of context #210

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions contrib/ruby/ext/trilogy-ruby/cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ struct trilogy_ctx {
trilogy_conn_t conn;
char server_version[TRILOGY_SERVER_VERSION_SIZE + 1];
unsigned int query_flags;
VALUE encoding;
rb_encoding *encoding;
};

static void mark_trilogy(void *ptr)
{
struct trilogy_ctx *ctx = ptr;
rb_gc_mark(ctx->encoding);
}

static void free_trilogy(void *ptr)
Expand Down Expand Up @@ -454,7 +453,7 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE encoding, VALUE charset, VALUE
trilogy_handshake_t handshake;
VALUE val;

RB_OBJ_WRITE(self, &ctx->encoding, encoding);
ctx->encoding = rb_to_encoding(encoding);
connopt.encoding = NUM2INT(charset);

Check_Type(opts, T_HASH);
Expand Down Expand Up @@ -811,10 +810,10 @@ static VALUE read_query_response(VALUE vargs)
}
}

#ifdef HAVE_RB_INTERNED_STR
VALUE column_name = rb_interned_str(column.name, column.name_len);
#ifdef HAVE_RB_ENC_INTERNED_STR
VALUE column_name = rb_enc_interned_str(column.name, column.name_len, ctx->encoding);
#else
VALUE column_name = rb_str_new(column.name, column.name_len);
VALUE column_name = rb_enc_str_new(column.name, column.name_len, ctx->encoding);
OBJ_FREEZE(column_name);
#endif

Expand Down Expand Up @@ -922,7 +921,7 @@ static VALUE rb_trilogy_query(VALUE self, VALUE query)
struct trilogy_ctx *ctx = get_open_ctx(self);

StringValue(query);
query = rb_str_export_to_enc(query, rb_to_encoding(ctx->encoding));
query = rb_str_export_to_enc(query, ctx->encoding);

int rc = trilogy_query_send(&ctx->conn, RSTRING_PTR(query), RSTRING_LEN(query));

Expand Down
2 changes: 1 addition & 1 deletion contrib/ruby/ext/trilogy-ruby/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

have_library("crypto", "CRYPTO_malloc")
have_library("ssl", "SSL_new")
have_func("rb_interned_str", "ruby.h")
have_func("rb_enc_interned_str", "ruby.h")

create_makefile "trilogy/cext"
Loading