Skip to content

Commit 99b9029

Browse files
authored
Merge pull request #691 from larskanis/remove-static_symbol
Remove :static_symbol result field names
2 parents 6d6cc30 + f8c863c commit 99b9029

4 files changed

Lines changed: 5 additions & 34 deletions

File tree

ext/pg.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ typedef struct {
116116
/* Ruby encoding index of the client/internal encoding */
117117
int enc_idx : PG_ENC_IDX_BITS;
118118
/* flags controlling Symbol/String field names */
119-
unsigned int flags : 2;
119+
unsigned int flags : 1;
120120
/* enable automatic flushing of send data at the end of send_query calls */
121121
unsigned int flush_data : 1;
122122

@@ -151,7 +151,7 @@ typedef struct {
151151
unsigned int autoclear : 1;
152152

153153
/* flags controlling Symbol/String field names */
154-
unsigned int flags : 2;
154+
unsigned int flags : 1;
155155

156156
/* Number of fields in fnames[] .
157157
* Set to -1 if fnames[] is not yet initialized.
@@ -181,9 +181,8 @@ typedef VALUE (* t_pg_typecast_result)(t_typemap *, VALUE, int, int);
181181
typedef t_pg_coder *(* t_pg_typecast_query_param)(t_typemap *, VALUE, int);
182182
typedef VALUE (* t_pg_typecast_copy_get)( t_typemap *, VALUE, int, int, int );
183183

184-
#define PG_RESULT_FIELD_NAMES_MASK 0x03
184+
#define PG_RESULT_FIELD_NAMES_MASK 0x01
185185
#define PG_RESULT_FIELD_NAMES_SYMBOL 0x01
186-
#define PG_RESULT_FIELD_NAMES_STATIC_SYMBOL 0x02
187186

188187
#define PG_CODER_TIMESTAMP_DB_UTC 0x0
189188
#define PG_CODER_TIMESTAMP_DB_LOCAL 0x1

ext/pg_connection.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ VALUE rb_cPGconn;
1414
static ID s_id_encode;
1515
static ID s_id_autoclose_set;
1616
static VALUE sym_type, sym_format, sym_value;
17-
static VALUE sym_symbol, sym_string, sym_static_symbol;
17+
static VALUE sym_symbol, sym_string;
1818

1919
static VALUE pgconn_finish( VALUE );
2020
static VALUE pgconn_set_default_encoding( VALUE self );
@@ -4667,7 +4667,6 @@ pgconn_field_name_type_set(VALUE self, VALUE sym)
46674667
rb_check_frozen(self);
46684668
this->flags &= ~PG_RESULT_FIELD_NAMES_MASK;
46694669
if( sym == sym_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_SYMBOL;
4670-
else if ( sym == sym_static_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_STATIC_SYMBOL;
46714670
else if ( sym == sym_string );
46724671
else rb_raise(rb_eArgError, "invalid argument %+"PRIsVALUE, sym);
46734672

@@ -4689,8 +4688,6 @@ pgconn_field_name_type_get(VALUE self)
46894688

46904689
if( this->flags & PG_RESULT_FIELD_NAMES_SYMBOL ){
46914690
return sym_symbol;
4692-
} else if( this->flags & PG_RESULT_FIELD_NAMES_STATIC_SYMBOL ){
4693-
return sym_static_symbol;
46944691
} else {
46954692
return sym_string;
46964693
}
@@ -4710,7 +4707,6 @@ init_pg_connection(void)
47104707
sym_value = ID2SYM(rb_intern("value"));
47114708
sym_string = ID2SYM(rb_intern("string"));
47124709
sym_symbol = ID2SYM(rb_intern("symbol"));
4713-
sym_static_symbol = ID2SYM(rb_intern("static_symbol"));
47144710

47154711
rb_cPGconn = rb_define_class_under( rb_mPG, "Connection", rb_cObject );
47164712
/* Help rdoc to known the Constants module */

ext/pg_result.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "pg.h"
88

99
VALUE rb_cPGresult;
10-
static VALUE sym_symbol, sym_string, sym_static_symbol;
10+
static VALUE sym_symbol, sym_string;
1111

1212
static VALUE pgresult_type_map_set( VALUE, VALUE );
1313
static t_pg_result *pgresult_get_this( VALUE );
@@ -465,9 +465,6 @@ pgresult_get(VALUE self)
465465
static VALUE pg_cstr_to_sym(char *cstr, unsigned int flags, int enc_idx)
466466
{
467467
VALUE fname;
468-
#ifdef TRUFFLERUBY
469-
if( flags & (PG_RESULT_FIELD_NAMES_SYMBOL | PG_RESULT_FIELD_NAMES_STATIC_SYMBOL) ){
470-
#else
471468
if( flags & PG_RESULT_FIELD_NAMES_SYMBOL ){
472469
rb_encoding *enc = rb_enc_from_index(enc_idx);
473470
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)
476473
PG_ENCODING_SET_NOCHECK(fname, enc_idx);
477474
fname = rb_str_intern(fname);
478475
}
479-
} else if( flags & PG_RESULT_FIELD_NAMES_STATIC_SYMBOL ){
480-
#endif
481-
rb_encoding *enc = rb_enc_from_index(enc_idx);
482-
fname = ID2SYM(rb_intern3(cstr, strlen(cstr), enc));
483476
} else {
484477
fname = rb_str_new2(cstr);
485478
PG_ENCODING_SET_NOCHECK(fname, enc_idx);
@@ -1720,7 +1713,6 @@ pgresult_stream_each_tuple(VALUE self)
17201713
* It can be set to one of:
17211714
* * +:string+ to use String based field names
17221715
* * +:symbol+ to use Symbol based field names
1723-
* * +:static_symbol+ to use pinned Symbol (can not be garbage collected) - Don't use this, it will probably be removed in future.
17241716
*
17251717
* The default is retrieved from PG::Connection#field_name_type , which defaults to +:string+ .
17261718
*
@@ -1743,7 +1735,6 @@ pgresult_field_name_type_set(VALUE self, VALUE sym)
17431735

17441736
this->flags &= ~PG_RESULT_FIELD_NAMES_MASK;
17451737
if( sym == sym_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_SYMBOL;
1746-
else if ( sym == sym_static_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_STATIC_SYMBOL;
17471738
else if ( sym == sym_string );
17481739
else rb_raise(rb_eArgError, "invalid argument %+"PRIsVALUE, sym);
17491740

@@ -1764,8 +1755,6 @@ pgresult_field_name_type_get(VALUE self)
17641755
t_pg_result *this = pgresult_get_this(self);
17651756
if( this->flags & PG_RESULT_FIELD_NAMES_SYMBOL ){
17661757
return sym_symbol;
1767-
} else if( this->flags & PG_RESULT_FIELD_NAMES_STATIC_SYMBOL ){
1768-
return sym_static_symbol;
17691758
} else {
17701759
return sym_string;
17711760
}
@@ -1776,7 +1765,6 @@ init_pg_result(void)
17761765
{
17771766
sym_string = ID2SYM(rb_intern("string"));
17781767
sym_symbol = ID2SYM(rb_intern("symbol"));
1779-
sym_static_symbol = ID2SYM(rb_intern("static_symbol"));
17801768

17811769
rb_cPGresult = rb_define_class_under( rb_mPG, "Result", rb_cObject );
17821770
rb_undef_alloc_func(rb_cPGresult);

spec/pg/result_spec.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@
7878
expect(res.field_name_type).to eq(:symbol)
7979
end
8080

81-
it "can set static_symbol field names" do
82-
res.field_name_type = :static_symbol
83-
expect(res.field_name_type).to eq(:static_symbol)
84-
end
85-
8681
it "can't set symbol field names after #fields" do
8782
res.fields
8883
expect{ res.field_name_type = :symbol }.to raise_error(ArgumentError, /already materialized/)
@@ -108,13 +103,6 @@
108103
expect( res[0][:b] ).to eq( '2' )
109104
end
110105

111-
it "acts as an array of hashes with static_symbols" do
112-
res = @conn.exec("SELECT 1 AS a, 2 AS b")
113-
res.field_name_type = :static_symbol
114-
expect( res[0][:a] ).to eq( '1' )
115-
expect( res[0][:b] ).to eq( '2' )
116-
end
117-
118106
it "yields a row as an array" do
119107
res = @conn.exec("SELECT 1 AS a, 2 AS b")
120108
list = []

0 commit comments

Comments
 (0)