Skip to content
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
7 changes: 3 additions & 4 deletions ext/pg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions ext/pg_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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);

Expand All @@ -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;
}
Expand All @@ -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 */
Expand Down
14 changes: 1 addition & 13 deletions ext/pg_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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+ .
*
Expand All @@ -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);

Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions spec/pg/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand All @@ -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 = []
Expand Down
Loading