diff --git a/ext/pg.h b/ext/pg.h index 290333db5..58fa630d2 100644 --- a/ext/pg.h +++ b/ext/pg.h @@ -116,7 +116,7 @@ typedef struct { /* Ruby encoding index of the client/internal encoding */ int enc_idx : PG_ENC_IDX_BITS; /* flags controlling Symbol/String field names */ - unsigned int flags : 2; + unsigned int flags : 1; /* enable automatic flushing of send data at the end of send_query calls */ unsigned int flush_data : 1; @@ -151,7 +151,7 @@ typedef struct { unsigned int autoclear : 1; /* flags controlling Symbol/String field names */ - unsigned int flags : 2; + unsigned int flags : 1; /* Number of fields in fnames[] . * Set to -1 if fnames[] is not yet initialized. @@ -181,9 +181,8 @@ typedef VALUE (* t_pg_typecast_result)(t_typemap *, VALUE, int, int); typedef t_pg_coder *(* t_pg_typecast_query_param)(t_typemap *, VALUE, int); typedef VALUE (* t_pg_typecast_copy_get)( t_typemap *, VALUE, int, int, int ); -#define PG_RESULT_FIELD_NAMES_MASK 0x03 +#define PG_RESULT_FIELD_NAMES_MASK 0x01 #define PG_RESULT_FIELD_NAMES_SYMBOL 0x01 -#define PG_RESULT_FIELD_NAMES_STATIC_SYMBOL 0x02 #define PG_CODER_TIMESTAMP_DB_UTC 0x0 #define PG_CODER_TIMESTAMP_DB_LOCAL 0x1 diff --git a/ext/pg_connection.c b/ext/pg_connection.c index 696f26f6f..7751023bc 100644 --- a/ext/pg_connection.c +++ b/ext/pg_connection.c @@ -14,7 +14,7 @@ VALUE rb_cPGconn; static ID s_id_encode; static ID s_id_autoclose_set; static VALUE sym_type, sym_format, sym_value; -static VALUE sym_symbol, sym_string, sym_static_symbol; +static VALUE sym_symbol, sym_string; static VALUE pgconn_finish( VALUE ); static VALUE pgconn_set_default_encoding( VALUE self ); @@ -4642,7 +4642,6 @@ pgconn_field_name_type_set(VALUE self, VALUE sym) rb_check_frozen(self); this->flags &= ~PG_RESULT_FIELD_NAMES_MASK; if( sym == sym_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_SYMBOL; - else if ( sym == sym_static_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_STATIC_SYMBOL; else if ( sym == sym_string ); else rb_raise(rb_eArgError, "invalid argument %+"PRIsVALUE, sym); @@ -4664,8 +4663,6 @@ pgconn_field_name_type_get(VALUE self) if( this->flags & PG_RESULT_FIELD_NAMES_SYMBOL ){ return sym_symbol; - } else if( this->flags & PG_RESULT_FIELD_NAMES_STATIC_SYMBOL ){ - return sym_static_symbol; } else { return sym_string; } @@ -4685,7 +4682,6 @@ init_pg_connection(void) sym_value = ID2SYM(rb_intern("value")); sym_string = ID2SYM(rb_intern("string")); sym_symbol = ID2SYM(rb_intern("symbol")); - sym_static_symbol = ID2SYM(rb_intern("static_symbol")); rb_cPGconn = rb_define_class_under( rb_mPG, "Connection", rb_cObject ); /* Help rdoc to known the Constants module */ diff --git a/ext/pg_result.c b/ext/pg_result.c index 553fce25f..472d03c8c 100644 --- a/ext/pg_result.c +++ b/ext/pg_result.c @@ -7,7 +7,7 @@ #include "pg.h" VALUE rb_cPGresult; -static VALUE sym_symbol, sym_string, sym_static_symbol; +static VALUE sym_symbol, sym_string; static VALUE pgresult_type_map_set( VALUE, VALUE ); static t_pg_result *pgresult_get_this( VALUE ); @@ -465,9 +465,6 @@ pgresult_get(VALUE self) static VALUE pg_cstr_to_sym(char *cstr, unsigned int flags, int enc_idx) { VALUE fname; -#ifdef TRUFFLERUBY - if( flags & (PG_RESULT_FIELD_NAMES_SYMBOL | PG_RESULT_FIELD_NAMES_STATIC_SYMBOL) ){ -#else if( flags & PG_RESULT_FIELD_NAMES_SYMBOL ){ rb_encoding *enc = rb_enc_from_index(enc_idx); fname = rb_check_symbol_cstr(cstr, strlen(cstr), enc); @@ -476,10 +473,6 @@ static VALUE pg_cstr_to_sym(char *cstr, unsigned int flags, int enc_idx) PG_ENCODING_SET_NOCHECK(fname, enc_idx); fname = rb_str_intern(fname); } - } else if( flags & PG_RESULT_FIELD_NAMES_STATIC_SYMBOL ){ -#endif - rb_encoding *enc = rb_enc_from_index(enc_idx); - fname = ID2SYM(rb_intern3(cstr, strlen(cstr), enc)); } else { fname = rb_str_new2(cstr); PG_ENCODING_SET_NOCHECK(fname, enc_idx); @@ -1692,7 +1685,6 @@ pgresult_stream_each_tuple(VALUE self) * It can be set to one of: * * +:string+ to use String based field names * * +:symbol+ to use Symbol based field names - * * +:static_symbol+ to use pinned Symbol (can not be garbage collected) - Don't use this, it will probably be removed in future. * * The default is retrieved from PG::Connection#field_name_type , which defaults to +:string+ . * @@ -1715,7 +1707,6 @@ pgresult_field_name_type_set(VALUE self, VALUE sym) this->flags &= ~PG_RESULT_FIELD_NAMES_MASK; if( sym == sym_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_SYMBOL; - else if ( sym == sym_static_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_STATIC_SYMBOL; else if ( sym == sym_string ); else rb_raise(rb_eArgError, "invalid argument %+"PRIsVALUE, sym); @@ -1736,8 +1727,6 @@ pgresult_field_name_type_get(VALUE self) t_pg_result *this = pgresult_get_this(self); if( this->flags & PG_RESULT_FIELD_NAMES_SYMBOL ){ return sym_symbol; - } else if( this->flags & PG_RESULT_FIELD_NAMES_STATIC_SYMBOL ){ - return sym_static_symbol; } else { return sym_string; } @@ -1748,7 +1737,6 @@ init_pg_result(void) { sym_string = ID2SYM(rb_intern("string")); sym_symbol = ID2SYM(rb_intern("symbol")); - sym_static_symbol = ID2SYM(rb_intern("static_symbol")); rb_cPGresult = rb_define_class_under( rb_mPG, "Result", rb_cObject ); rb_undef_alloc_func(rb_cPGresult); diff --git a/spec/pg/result_spec.rb b/spec/pg/result_spec.rb index 164828051..2044fdb6f 100644 --- a/spec/pg/result_spec.rb +++ b/spec/pg/result_spec.rb @@ -78,11 +78,6 @@ expect(res.field_name_type).to eq(:symbol) end - it "can set static_symbol field names" do - res.field_name_type = :static_symbol - expect(res.field_name_type).to eq(:static_symbol) - end - it "can't set symbol field names after #fields" do res.fields expect{ res.field_name_type = :symbol }.to raise_error(ArgumentError, /already materialized/) @@ -108,13 +103,6 @@ expect( res[0][:b] ).to eq( '2' ) end - it "acts as an array of hashes with static_symbols" do - res = @conn.exec("SELECT 1 AS a, 2 AS b") - res.field_name_type = :static_symbol - expect( res[0][:a] ).to eq( '1' ) - expect( res[0][:b] ).to eq( '2' ) - end - it "yields a row as an array" do res = @conn.exec("SELECT 1 AS a, 2 AS b") list = []