pg 1.4.5-x86-mingw32 → 1.5.0-x86-mingw32
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
- checksums.yaml.gz.sig +0 -0
- data/.appveyor.yml +15 -9
- data/.github/workflows/binary-gems.yml +41 -10
- data/.github/workflows/source-gem.yml +18 -12
- data/.gitignore +11 -2
- data/.travis.yml +2 -2
- data/{History.rdoc → History.md} +223 -153
- data/README.ja.md +276 -0
- data/README.md +286 -0
- data/Rakefile +12 -3
- data/Rakefile.cross +7 -11
- data/certs/larskanis-2023.pem +24 -0
- data/ext/pg.c +10 -28
- data/ext/pg.h +10 -5
- data/ext/pg_binary_decoder.c +79 -0
- data/ext/pg_binary_encoder.c +224 -0
- data/ext/pg_coder.c +16 -7
- data/ext/pg_connection.c +156 -60
- data/ext/pg_copy_coder.c +306 -17
- data/ext/pg_record_coder.c +5 -4
- data/ext/pg_result.c +88 -17
- data/ext/pg_text_decoder.c +28 -10
- data/ext/pg_text_encoder.c +22 -9
- data/ext/pg_tuple.c +34 -31
- data/ext/pg_type_map.c +3 -2
- data/ext/pg_type_map_all_strings.c +2 -2
- data/ext/pg_type_map_by_class.c +5 -3
- data/ext/pg_type_map_by_column.c +9 -3
- data/ext/pg_type_map_by_oid.c +7 -4
- data/ext/pg_type_map_in_ruby.c +5 -2
- data/lib/2.5/pg_ext.so +0 -0
- data/lib/2.6/pg_ext.so +0 -0
- data/lib/2.7/pg_ext.so +0 -0
- data/lib/3.0/pg_ext.so +0 -0
- data/lib/3.1/pg_ext.so +0 -0
- data/lib/3.2/pg_ext.so +0 -0
- data/lib/pg/basic_type_map_based_on_result.rb +21 -1
- data/lib/pg/basic_type_map_for_queries.rb +13 -8
- data/lib/pg/basic_type_map_for_results.rb +26 -3
- data/lib/pg/basic_type_registry.rb +30 -32
- data/lib/pg/binary_decoder/date.rb +9 -0
- data/lib/pg/binary_decoder/timestamp.rb +26 -0
- data/lib/pg/binary_encoder/timestamp.rb +20 -0
- data/lib/pg/coder.rb +15 -13
- data/lib/pg/connection.rb +82 -30
- data/lib/pg/exceptions.rb +7 -0
- data/lib/pg/text_decoder/date.rb +18 -0
- data/lib/pg/text_decoder/inet.rb +9 -0
- data/lib/pg/text_decoder/json.rb +14 -0
- data/lib/pg/text_decoder/numeric.rb +9 -0
- data/lib/pg/text_decoder/timestamp.rb +30 -0
- data/lib/pg/text_encoder/date.rb +12 -0
- data/lib/pg/text_encoder/inet.rb +28 -0
- data/lib/pg/text_encoder/json.rb +14 -0
- data/lib/pg/text_encoder/numeric.rb +9 -0
- data/lib/pg/text_encoder/timestamp.rb +24 -0
- data/lib/pg/version.rb +1 -1
- data/lib/pg.rb +44 -15
- data/lib/x86-mingw32/libpq.dll +0 -0
- data/pg.gemspec +4 -2
- data/rakelib/task_extension.rb +1 -1
- data/translation/.po4a-version +7 -0
- data/translation/po/all.pot +910 -0
- data/translation/po/ja.po +1047 -0
- data/translation/po4a.cfg +12 -0
- data.tar.gz.sig +0 -0
- metadata +111 -35
- metadata.gz.sig +0 -0
- data/README.ja.rdoc +0 -13
- data/README.rdoc +0 -233
- data/lib/pg/binary_decoder.rb +0 -23
- data/lib/pg/constants.rb +0 -12
- data/lib/pg/text_decoder.rb +0 -46
- data/lib/pg/text_encoder.rb +0 -59
data/ext/pg_connection.c
CHANGED
@@ -16,9 +16,6 @@ static ID s_id_autoclose_set;
|
|
16
16
|
static VALUE sym_type, sym_format, sym_value;
|
17
17
|
static VALUE sym_symbol, sym_string, sym_static_symbol;
|
18
18
|
|
19
|
-
static PQnoticeReceiver default_notice_receiver = NULL;
|
20
|
-
static PQnoticeProcessor default_notice_processor = NULL;
|
21
|
-
|
22
19
|
static VALUE pgconn_finish( VALUE );
|
23
20
|
static VALUE pgconn_set_default_encoding( VALUE self );
|
24
21
|
static VALUE pgconn_wait_for_flush( VALUE self );
|
@@ -117,7 +114,7 @@ pgconn_close_socket_io( VALUE self )
|
|
117
114
|
rb_funcall( socket_io, rb_intern("close"), 0 );
|
118
115
|
}
|
119
116
|
|
120
|
-
this->socket_io
|
117
|
+
RB_OBJ_WRITE(self, &this->socket_io, Qnil);
|
121
118
|
}
|
122
119
|
|
123
120
|
|
@@ -237,7 +234,7 @@ static const rb_data_type_t pg_connection_type = {
|
|
237
234
|
},
|
238
235
|
0,
|
239
236
|
0,
|
240
|
-
|
237
|
+
RUBY_TYPED_WB_PROTECTED,
|
241
238
|
};
|
242
239
|
|
243
240
|
|
@@ -258,14 +255,14 @@ pgconn_s_allocate( VALUE klass )
|
|
258
255
|
VALUE self = TypedData_Make_Struct( klass, t_pg_connection, &pg_connection_type, this );
|
259
256
|
|
260
257
|
this->pgconn = NULL;
|
261
|
-
this->socket_io
|
262
|
-
this->notice_receiver
|
263
|
-
this->notice_processor
|
264
|
-
this->type_map_for_queries
|
265
|
-
this->type_map_for_results
|
266
|
-
this->encoder_for_put_copy_data
|
267
|
-
this->decoder_for_get_copy_data
|
268
|
-
this->trace_stream
|
258
|
+
RB_OBJ_WRITE(self, &this->socket_io, Qnil);
|
259
|
+
RB_OBJ_WRITE(self, &this->notice_receiver, Qnil);
|
260
|
+
RB_OBJ_WRITE(self, &this->notice_processor, Qnil);
|
261
|
+
RB_OBJ_WRITE(self, &this->type_map_for_queries, pg_typemap_all_strings);
|
262
|
+
RB_OBJ_WRITE(self, &this->type_map_for_results, pg_typemap_all_strings);
|
263
|
+
RB_OBJ_WRITE(self, &this->encoder_for_put_copy_data, Qnil);
|
264
|
+
RB_OBJ_WRITE(self, &this->decoder_for_get_copy_data, Qnil);
|
265
|
+
RB_OBJ_WRITE(self, &this->trace_stream, Qnil);
|
269
266
|
rb_ivar_set(self, rb_intern("@calls_to_put_copy_data"), INT2FIX(0));
|
270
267
|
|
271
268
|
return self;
|
@@ -766,6 +763,10 @@ pgconn_conninfo( VALUE self )
|
|
766
763
|
*
|
767
764
|
* ... and other constants of kind PG::Constants::CONNECTION_*
|
768
765
|
*
|
766
|
+
* This method returns the status of the last command from memory.
|
767
|
+
* It doesn't do any socket access hence is not suitable to test the connectivity.
|
768
|
+
* See check_socket for a way to verify the socket state.
|
769
|
+
*
|
769
770
|
* Example:
|
770
771
|
* PG.constants.grep(/CONNECTION_/).find{|c| PG.const_get(c) == conn.status} # => :CONNECTION_OK
|
771
772
|
*/
|
@@ -941,7 +942,7 @@ pgconn_socket_io(VALUE self)
|
|
941
942
|
/* Disable autoclose feature */
|
942
943
|
rb_funcall( socket_io, s_id_autoclose_set, 1, Qfalse );
|
943
944
|
|
944
|
-
this->socket_io
|
945
|
+
RB_OBJ_WRITE(self, &this->socket_io, socket_io);
|
945
946
|
}
|
946
947
|
|
947
948
|
return socket_io;
|
@@ -1158,7 +1159,7 @@ static const rb_data_type_t pg_typecast_buffer_type = {
|
|
1158
1159
|
},
|
1159
1160
|
0,
|
1160
1161
|
0,
|
1161
|
-
RUBY_TYPED_FREE_IMMEDIATELY,
|
1162
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
1162
1163
|
};
|
1163
1164
|
|
1164
1165
|
static char *
|
@@ -1191,7 +1192,7 @@ static const rb_data_type_t pg_query_heap_pool_type = {
|
|
1191
1192
|
},
|
1192
1193
|
0,
|
1193
1194
|
0,
|
1194
|
-
RUBY_TYPED_FREE_IMMEDIATELY,
|
1195
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
1195
1196
|
};
|
1196
1197
|
|
1197
1198
|
static int
|
@@ -1814,6 +1815,7 @@ pgconn_set_single_row_mode(VALUE self)
|
|
1814
1815
|
{
|
1815
1816
|
PGconn *conn = pg_get_pgconn(self);
|
1816
1817
|
|
1818
|
+
rb_check_frozen(self);
|
1817
1819
|
if( PQsetSingleRowMode(conn) == 0 )
|
1818
1820
|
pg_raise_conn_error( rb_ePGerror, self, "%s", PQerrorMessage(conn));
|
1819
1821
|
|
@@ -2148,6 +2150,7 @@ pgconn_sync_setnonblocking(VALUE self, VALUE state)
|
|
2148
2150
|
{
|
2149
2151
|
int arg;
|
2150
2152
|
PGconn *conn = pg_get_pgconn(self);
|
2153
|
+
rb_check_frozen(self);
|
2151
2154
|
if(state == Qtrue)
|
2152
2155
|
arg = 1;
|
2153
2156
|
else if (state == Qfalse)
|
@@ -2446,8 +2449,9 @@ pgconn_async_flush(VALUE self)
|
|
2446
2449
|
VALUE socket_io = pgconn_socket_io(self);
|
2447
2450
|
events = RB_NUM2INT(pg_rb_io_wait(socket_io, RB_INT2NUM(PG_RUBY_IO_READABLE | PG_RUBY_IO_WRITABLE), Qnil));
|
2448
2451
|
|
2449
|
-
if (events & PG_RUBY_IO_READABLE)
|
2452
|
+
if (events & PG_RUBY_IO_READABLE){
|
2450
2453
|
pgconn_consume_input(self);
|
2454
|
+
}
|
2451
2455
|
}
|
2452
2456
|
return Qtrue;
|
2453
2457
|
}
|
@@ -2463,6 +2467,7 @@ pgconn_wait_for_flush( VALUE self ){
|
|
2463
2467
|
static VALUE
|
2464
2468
|
pgconn_flush_data_set( VALUE self, VALUE enabled ){
|
2465
2469
|
t_pg_connection *conn = pg_get_connection(self);
|
2470
|
+
rb_check_frozen(self);
|
2466
2471
|
conn->flush_data = RTEST(enabled);
|
2467
2472
|
return enabled;
|
2468
2473
|
}
|
@@ -2717,6 +2722,7 @@ pgconn_trace(VALUE self, VALUE stream)
|
|
2717
2722
|
VALUE new_file;
|
2718
2723
|
t_pg_connection *this = pg_get_connection_safe( self );
|
2719
2724
|
|
2725
|
+
rb_check_frozen(self);
|
2720
2726
|
if(!rb_respond_to(stream,rb_intern("fileno")))
|
2721
2727
|
rb_raise(rb_eArgError, "stream does not respond to method: fileno");
|
2722
2728
|
|
@@ -2738,7 +2744,7 @@ pgconn_trace(VALUE self, VALUE stream)
|
|
2738
2744
|
rb_raise(rb_eArgError, "stream is not writable");
|
2739
2745
|
|
2740
2746
|
new_file = rb_funcall(rb_cIO, rb_intern("new"), 1, INT2NUM(new_fd));
|
2741
|
-
this->trace_stream
|
2747
|
+
RB_OBJ_WRITE(self, &this->trace_stream, new_file);
|
2742
2748
|
|
2743
2749
|
PQtrace(this->pgconn, new_fp);
|
2744
2750
|
return Qnil;
|
@@ -2757,7 +2763,7 @@ pgconn_untrace(VALUE self)
|
|
2757
2763
|
|
2758
2764
|
PQuntrace(this->pgconn);
|
2759
2765
|
rb_funcall(this->trace_stream, rb_intern("close"), 0);
|
2760
|
-
this->trace_stream
|
2766
|
+
RB_OBJ_WRITE(self, &this->trace_stream, Qnil);
|
2761
2767
|
return Qnil;
|
2762
2768
|
}
|
2763
2769
|
|
@@ -2816,13 +2822,14 @@ pgconn_set_notice_receiver(VALUE self)
|
|
2816
2822
|
VALUE proc, old_proc;
|
2817
2823
|
t_pg_connection *this = pg_get_connection_safe( self );
|
2818
2824
|
|
2825
|
+
rb_check_frozen(self);
|
2819
2826
|
/* If default_notice_receiver is unset, assume that the current
|
2820
2827
|
* notice receiver is the default, and save it to a global variable.
|
2821
2828
|
* This should not be a problem because the default receiver is
|
2822
2829
|
* always the same, so won't vary among connections.
|
2823
2830
|
*/
|
2824
|
-
if(default_notice_receiver == NULL)
|
2825
|
-
default_notice_receiver = PQsetNoticeReceiver(this->pgconn, NULL, NULL);
|
2831
|
+
if(this->default_notice_receiver == NULL)
|
2832
|
+
this->default_notice_receiver = PQsetNoticeReceiver(this->pgconn, NULL, NULL);
|
2826
2833
|
|
2827
2834
|
old_proc = this->notice_receiver;
|
2828
2835
|
if( rb_block_given_p() ) {
|
@@ -2831,10 +2838,10 @@ pgconn_set_notice_receiver(VALUE self)
|
|
2831
2838
|
} else {
|
2832
2839
|
/* if no block is given, set back to default */
|
2833
2840
|
proc = Qnil;
|
2834
|
-
PQsetNoticeReceiver(this->pgconn, default_notice_receiver, NULL);
|
2841
|
+
PQsetNoticeReceiver(this->pgconn, this->default_notice_receiver, NULL);
|
2835
2842
|
}
|
2836
2843
|
|
2837
|
-
this->notice_receiver
|
2844
|
+
RB_OBJ_WRITE(self, &this->notice_receiver, proc);
|
2838
2845
|
return old_proc;
|
2839
2846
|
}
|
2840
2847
|
|
@@ -2849,10 +2856,10 @@ notice_processor_proxy(void *arg, const char *message)
|
|
2849
2856
|
VALUE self = (VALUE)arg;
|
2850
2857
|
t_pg_connection *this = pg_get_connection( self );
|
2851
2858
|
|
2852
|
-
if (this->
|
2859
|
+
if (this->notice_processor != Qnil) {
|
2853
2860
|
VALUE message_str = rb_str_new2(message);
|
2854
2861
|
PG_ENCODING_SET_NOCHECK( message_str, this->enc_idx );
|
2855
|
-
rb_funcall(this->
|
2862
|
+
rb_funcall(this->notice_processor, rb_intern("call"), 1, message_str);
|
2856
2863
|
}
|
2857
2864
|
return;
|
2858
2865
|
}
|
@@ -2876,25 +2883,26 @@ pgconn_set_notice_processor(VALUE self)
|
|
2876
2883
|
VALUE proc, old_proc;
|
2877
2884
|
t_pg_connection *this = pg_get_connection_safe( self );
|
2878
2885
|
|
2886
|
+
rb_check_frozen(self);
|
2879
2887
|
/* If default_notice_processor is unset, assume that the current
|
2880
2888
|
* notice processor is the default, and save it to a global variable.
|
2881
2889
|
* This should not be a problem because the default processor is
|
2882
2890
|
* always the same, so won't vary among connections.
|
2883
2891
|
*/
|
2884
|
-
if(default_notice_processor == NULL)
|
2885
|
-
default_notice_processor = PQsetNoticeProcessor(this->pgconn, NULL, NULL);
|
2892
|
+
if(this->default_notice_processor == NULL)
|
2893
|
+
this->default_notice_processor = PQsetNoticeProcessor(this->pgconn, NULL, NULL);
|
2886
2894
|
|
2887
|
-
old_proc = this->
|
2895
|
+
old_proc = this->notice_processor;
|
2888
2896
|
if( rb_block_given_p() ) {
|
2889
2897
|
proc = rb_block_proc();
|
2890
2898
|
PQsetNoticeProcessor(this->pgconn, gvl_notice_processor_proxy, (void *)self);
|
2891
2899
|
} else {
|
2892
2900
|
/* if no block is given, set back to default */
|
2893
2901
|
proc = Qnil;
|
2894
|
-
PQsetNoticeProcessor(this->pgconn, default_notice_processor, NULL);
|
2902
|
+
PQsetNoticeProcessor(this->pgconn, this->default_notice_processor, NULL);
|
2895
2903
|
}
|
2896
2904
|
|
2897
|
-
this->
|
2905
|
+
RB_OBJ_WRITE(self, &this->notice_processor, proc);
|
2898
2906
|
return old_proc;
|
2899
2907
|
}
|
2900
2908
|
|
@@ -2926,6 +2934,7 @@ pgconn_sync_set_client_encoding(VALUE self, VALUE str)
|
|
2926
2934
|
{
|
2927
2935
|
PGconn *conn = pg_get_pgconn( self );
|
2928
2936
|
|
2937
|
+
rb_check_frozen(self);
|
2929
2938
|
Check_Type(str, T_STRING);
|
2930
2939
|
|
2931
2940
|
if ( (gvl_PQsetClientEncoding(conn, StringValueCStr(str))) == -1 )
|
@@ -3094,7 +3103,7 @@ pgconn_async_get_last_result(VALUE self)
|
|
3094
3103
|
VALUE rb_pgresult = Qnil;
|
3095
3104
|
PGresult *cur, *prev;
|
3096
3105
|
|
3097
|
-
|
3106
|
+
cur = prev = NULL;
|
3098
3107
|
for(;;) {
|
3099
3108
|
int status;
|
3100
3109
|
|
@@ -3126,8 +3135,14 @@ pgconn_async_get_last_result(VALUE self)
|
|
3126
3135
|
* conn.discard_results()
|
3127
3136
|
*
|
3128
3137
|
* Silently discard any prior query result that application didn't eat.
|
3129
|
-
* This is
|
3130
|
-
*
|
3138
|
+
* This is internally used prior to Connection#exec and sibling methods.
|
3139
|
+
* It doesn't raise an exception on connection errors, but returns +false+ instead.
|
3140
|
+
*
|
3141
|
+
* Returns:
|
3142
|
+
* * +nil+ when the connection is already idle
|
3143
|
+
* * +true+ when some results have been discarded
|
3144
|
+
* * +false+ when a failure occured and the connection was closed
|
3145
|
+
*
|
3131
3146
|
*/
|
3132
3147
|
static VALUE
|
3133
3148
|
pgconn_discard_results(VALUE self)
|
@@ -3135,8 +3150,12 @@ pgconn_discard_results(VALUE self)
|
|
3135
3150
|
PGconn *conn = pg_get_pgconn(self);
|
3136
3151
|
VALUE socket_io;
|
3137
3152
|
|
3138
|
-
|
3139
|
-
|
3153
|
+
switch( PQtransactionStatus(conn) ) {
|
3154
|
+
case PQTRANS_IDLE:
|
3155
|
+
case PQTRANS_INTRANS:
|
3156
|
+
case PQTRANS_INERROR:
|
3157
|
+
return Qnil;
|
3158
|
+
default:;
|
3140
3159
|
}
|
3141
3160
|
|
3142
3161
|
socket_io = pgconn_socket_io(self);
|
@@ -3149,10 +3168,21 @@ pgconn_discard_results(VALUE self)
|
|
3149
3168
|
* To avoid this call pg_rb_io_wait() and PQconsumeInput() without rb_raise().
|
3150
3169
|
*/
|
3151
3170
|
while( gvl_PQisBusy(conn) ){
|
3152
|
-
|
3153
|
-
|
3154
|
-
|
3155
|
-
|
3171
|
+
int events;
|
3172
|
+
|
3173
|
+
switch( PQflush(conn) ) {
|
3174
|
+
case 1:
|
3175
|
+
events = RB_NUM2INT(pg_rb_io_wait(socket_io, RB_INT2NUM(PG_RUBY_IO_READABLE | PG_RUBY_IO_WRITABLE), Qnil));
|
3176
|
+
if (events & PG_RUBY_IO_READABLE){
|
3177
|
+
if ( PQconsumeInput(conn) == 0 ) goto error;
|
3178
|
+
}
|
3179
|
+
break;
|
3180
|
+
case 0:
|
3181
|
+
pg_rb_io_wait(socket_io, RB_INT2NUM(PG_RUBY_IO_READABLE), Qnil);
|
3182
|
+
if ( PQconsumeInput(conn) == 0 ) goto error;
|
3183
|
+
break;
|
3184
|
+
default:
|
3185
|
+
goto error;
|
3156
3186
|
}
|
3157
3187
|
}
|
3158
3188
|
|
@@ -3162,7 +3192,9 @@ pgconn_discard_results(VALUE self)
|
|
3162
3192
|
status = PQresultStatus(cur);
|
3163
3193
|
PQclear(cur);
|
3164
3194
|
if (status == PGRES_COPY_IN){
|
3165
|
-
gvl_PQputCopyEnd(conn, "COPY terminated by new
|
3195
|
+
while( gvl_PQputCopyEnd(conn, "COPY terminated by new query or discard_results") == 0 ){
|
3196
|
+
pgconn_async_flush(self);
|
3197
|
+
}
|
3166
3198
|
}
|
3167
3199
|
if (status == PGRES_COPY_OUT){
|
3168
3200
|
for(;;) {
|
@@ -3171,10 +3203,7 @@ pgconn_discard_results(VALUE self)
|
|
3171
3203
|
if( st == 0 ) {
|
3172
3204
|
/* would block -> wait for readable data */
|
3173
3205
|
pg_rb_io_wait(socket_io, RB_INT2NUM(PG_RUBY_IO_READABLE), Qnil);
|
3174
|
-
if ( PQconsumeInput(conn) == 0 )
|
3175
|
-
pgconn_close_socket_io(self);
|
3176
|
-
return Qfalse;
|
3177
|
-
}
|
3206
|
+
if ( PQconsumeInput(conn) == 0 ) goto error;
|
3178
3207
|
} else if( st > 0 ) {
|
3179
3208
|
/* some data retrieved -> discard it */
|
3180
3209
|
PQfreemem(buffer);
|
@@ -3187,6 +3216,10 @@ pgconn_discard_results(VALUE self)
|
|
3187
3216
|
}
|
3188
3217
|
|
3189
3218
|
return Qtrue;
|
3219
|
+
|
3220
|
+
error:
|
3221
|
+
pgconn_close_socket_io(self);
|
3222
|
+
return Qfalse;
|
3190
3223
|
}
|
3191
3224
|
|
3192
3225
|
/*
|
@@ -3643,6 +3676,14 @@ pgconn_send_flush_request(VALUE self)
|
|
3643
3676
|
* LARGE OBJECT SUPPORT
|
3644
3677
|
**************************************************************************/
|
3645
3678
|
|
3679
|
+
#define BLOCKING_BEGIN(conn) do { \
|
3680
|
+
int old_nonblocking = PQisnonblocking(conn); \
|
3681
|
+
PQsetnonblocking(conn, 0);
|
3682
|
+
|
3683
|
+
#define BLOCKING_END(th) \
|
3684
|
+
PQsetnonblocking(conn, old_nonblocking); \
|
3685
|
+
} while(0);
|
3686
|
+
|
3646
3687
|
/*
|
3647
3688
|
* call-seq:
|
3648
3689
|
* conn.lo_creat( [mode] ) -> Integer
|
@@ -3663,7 +3704,10 @@ pgconn_locreat(int argc, VALUE *argv, VALUE self)
|
|
3663
3704
|
else
|
3664
3705
|
mode = NUM2INT(nmode);
|
3665
3706
|
|
3666
|
-
|
3707
|
+
BLOCKING_BEGIN(conn)
|
3708
|
+
lo_oid = lo_creat(conn, mode);
|
3709
|
+
BLOCKING_END(conn)
|
3710
|
+
|
3667
3711
|
if (lo_oid == 0)
|
3668
3712
|
pg_raise_conn_error( rb_ePGerror, self, "lo_creat failed");
|
3669
3713
|
|
@@ -3708,7 +3752,10 @@ pgconn_loimport(VALUE self, VALUE filename)
|
|
3708
3752
|
|
3709
3753
|
Check_Type(filename, T_STRING);
|
3710
3754
|
|
3711
|
-
|
3755
|
+
BLOCKING_BEGIN(conn)
|
3756
|
+
lo_oid = lo_import(conn, StringValueCStr(filename));
|
3757
|
+
BLOCKING_END(conn)
|
3758
|
+
|
3712
3759
|
if (lo_oid == 0) {
|
3713
3760
|
pg_raise_conn_error( rb_ePGerror, self, "%s", PQerrorMessage(conn));
|
3714
3761
|
}
|
@@ -3726,11 +3773,16 @@ pgconn_loexport(VALUE self, VALUE lo_oid, VALUE filename)
|
|
3726
3773
|
{
|
3727
3774
|
PGconn *conn = pg_get_pgconn(self);
|
3728
3775
|
Oid oid;
|
3776
|
+
int ret;
|
3729
3777
|
Check_Type(filename, T_STRING);
|
3730
3778
|
|
3731
3779
|
oid = NUM2UINT(lo_oid);
|
3732
3780
|
|
3733
|
-
|
3781
|
+
BLOCKING_BEGIN(conn)
|
3782
|
+
ret = lo_export(conn, oid, StringValueCStr(filename));
|
3783
|
+
BLOCKING_END(conn)
|
3784
|
+
|
3785
|
+
if (ret < 0) {
|
3734
3786
|
pg_raise_conn_error( rb_ePGerror, self, "%s", PQerrorMessage(conn));
|
3735
3787
|
}
|
3736
3788
|
return Qnil;
|
@@ -3761,7 +3813,11 @@ pgconn_loopen(int argc, VALUE *argv, VALUE self)
|
|
3761
3813
|
else
|
3762
3814
|
mode = NUM2INT(nmode);
|
3763
3815
|
|
3764
|
-
|
3816
|
+
BLOCKING_BEGIN(conn)
|
3817
|
+
fd = lo_open(conn, lo_oid, mode);
|
3818
|
+
BLOCKING_END(conn)
|
3819
|
+
|
3820
|
+
if(fd < 0) {
|
3765
3821
|
pg_raise_conn_error( rb_ePGerror, self, "can't open large object: %s", PQerrorMessage(conn));
|
3766
3822
|
}
|
3767
3823
|
return INT2FIX(fd);
|
@@ -3786,8 +3842,12 @@ pgconn_lowrite(VALUE self, VALUE in_lo_desc, VALUE buffer)
|
|
3786
3842
|
if( RSTRING_LEN(buffer) < 0) {
|
3787
3843
|
pg_raise_conn_error( rb_ePGerror, self, "write buffer zero string");
|
3788
3844
|
}
|
3789
|
-
|
3790
|
-
|
3845
|
+
BLOCKING_BEGIN(conn)
|
3846
|
+
n = lo_write(conn, fd, StringValuePtr(buffer),
|
3847
|
+
RSTRING_LEN(buffer));
|
3848
|
+
BLOCKING_END(conn)
|
3849
|
+
|
3850
|
+
if(n < 0) {
|
3791
3851
|
pg_raise_conn_error( rb_ePGerror, self, "lo_write failed: %s", PQerrorMessage(conn));
|
3792
3852
|
}
|
3793
3853
|
|
@@ -3815,7 +3875,12 @@ pgconn_loread(VALUE self, VALUE in_lo_desc, VALUE in_len)
|
|
3815
3875
|
pg_raise_conn_error( rb_ePGerror, self, "negative length %d given", len);
|
3816
3876
|
|
3817
3877
|
buffer = ALLOC_N(char, len);
|
3818
|
-
|
3878
|
+
|
3879
|
+
BLOCKING_BEGIN(conn)
|
3880
|
+
ret = lo_read(conn, lo_desc, buffer, len);
|
3881
|
+
BLOCKING_END(conn)
|
3882
|
+
|
3883
|
+
if(ret < 0)
|
3819
3884
|
pg_raise_conn_error( rb_ePGerror, self, "lo_read failed");
|
3820
3885
|
|
3821
3886
|
if(ret == 0) {
|
@@ -3845,7 +3910,11 @@ pgconn_lolseek(VALUE self, VALUE in_lo_desc, VALUE offset, VALUE whence)
|
|
3845
3910
|
int lo_desc = NUM2INT(in_lo_desc);
|
3846
3911
|
int ret;
|
3847
3912
|
|
3848
|
-
|
3913
|
+
BLOCKING_BEGIN(conn)
|
3914
|
+
ret = lo_lseek(conn, lo_desc, NUM2INT(offset), NUM2INT(whence));
|
3915
|
+
BLOCKING_END(conn)
|
3916
|
+
|
3917
|
+
if(ret < 0) {
|
3849
3918
|
pg_raise_conn_error( rb_ePGerror, self, "lo_lseek failed");
|
3850
3919
|
}
|
3851
3920
|
|
@@ -3865,7 +3934,11 @@ pgconn_lotell(VALUE self, VALUE in_lo_desc)
|
|
3865
3934
|
PGconn *conn = pg_get_pgconn(self);
|
3866
3935
|
int lo_desc = NUM2INT(in_lo_desc);
|
3867
3936
|
|
3868
|
-
|
3937
|
+
BLOCKING_BEGIN(conn)
|
3938
|
+
position = lo_tell(conn, lo_desc);
|
3939
|
+
BLOCKING_END(conn)
|
3940
|
+
|
3941
|
+
if(position < 0)
|
3869
3942
|
pg_raise_conn_error( rb_ePGerror, self, "lo_tell failed");
|
3870
3943
|
|
3871
3944
|
return INT2FIX(position);
|
@@ -3883,8 +3956,13 @@ pgconn_lotruncate(VALUE self, VALUE in_lo_desc, VALUE in_len)
|
|
3883
3956
|
PGconn *conn = pg_get_pgconn(self);
|
3884
3957
|
int lo_desc = NUM2INT(in_lo_desc);
|
3885
3958
|
size_t len = NUM2INT(in_len);
|
3959
|
+
int ret;
|
3960
|
+
|
3961
|
+
BLOCKING_BEGIN(conn)
|
3962
|
+
ret = lo_truncate(conn,lo_desc,len);
|
3963
|
+
BLOCKING_END(conn)
|
3886
3964
|
|
3887
|
-
if(
|
3965
|
+
if(ret < 0)
|
3888
3966
|
pg_raise_conn_error( rb_ePGerror, self, "lo_truncate failed");
|
3889
3967
|
|
3890
3968
|
return Qnil;
|
@@ -3901,8 +3979,13 @@ pgconn_loclose(VALUE self, VALUE in_lo_desc)
|
|
3901
3979
|
{
|
3902
3980
|
PGconn *conn = pg_get_pgconn(self);
|
3903
3981
|
int lo_desc = NUM2INT(in_lo_desc);
|
3982
|
+
int ret;
|
3983
|
+
|
3984
|
+
BLOCKING_BEGIN(conn)
|
3985
|
+
ret = lo_close(conn,lo_desc);
|
3986
|
+
BLOCKING_END(conn)
|
3904
3987
|
|
3905
|
-
if(
|
3988
|
+
if(ret < 0)
|
3906
3989
|
pg_raise_conn_error( rb_ePGerror, self, "lo_close failed");
|
3907
3990
|
|
3908
3991
|
return Qnil;
|
@@ -3919,8 +4002,13 @@ pgconn_lounlink(VALUE self, VALUE in_oid)
|
|
3919
4002
|
{
|
3920
4003
|
PGconn *conn = pg_get_pgconn(self);
|
3921
4004
|
Oid oid = NUM2UINT(in_oid);
|
4005
|
+
int ret;
|
4006
|
+
|
4007
|
+
BLOCKING_BEGIN(conn)
|
4008
|
+
ret = lo_unlink(conn,oid);
|
4009
|
+
BLOCKING_END(conn)
|
3922
4010
|
|
3923
|
-
if(
|
4011
|
+
if(ret < 0)
|
3924
4012
|
pg_raise_conn_error( rb_ePGerror, self, "lo_unlink failed");
|
3925
4013
|
|
3926
4014
|
return Qnil;
|
@@ -3978,6 +4066,7 @@ static VALUE pgconn_external_encoding(VALUE self);
|
|
3978
4066
|
static VALUE
|
3979
4067
|
pgconn_internal_encoding_set(VALUE self, VALUE enc)
|
3980
4068
|
{
|
4069
|
+
rb_check_frozen(self);
|
3981
4070
|
if (NIL_P(enc)) {
|
3982
4071
|
pgconn_sync_set_client_encoding( self, rb_usascii_str_new_cstr("SQL_ASCII") );
|
3983
4072
|
return enc;
|
@@ -4032,6 +4121,7 @@ pgconn_async_set_client_encoding(VALUE self, VALUE encname)
|
|
4032
4121
|
{
|
4033
4122
|
VALUE query_format, query;
|
4034
4123
|
|
4124
|
+
rb_check_frozen(self);
|
4035
4125
|
Check_Type(encname, T_STRING);
|
4036
4126
|
query_format = rb_str_new_cstr("set client_encoding to '%s'");
|
4037
4127
|
query = rb_funcall(query_format, rb_intern("%"), 1, encname);
|
@@ -4084,6 +4174,7 @@ pgconn_set_default_encoding( VALUE self )
|
|
4084
4174
|
rb_encoding *enc;
|
4085
4175
|
const char *encname;
|
4086
4176
|
|
4177
|
+
rb_check_frozen(self);
|
4087
4178
|
if (( enc = rb_default_internal_encoding() )) {
|
4088
4179
|
encname = pg_get_rb_encoding_as_pg_encoding( enc );
|
4089
4180
|
if ( pgconn_set_client_encoding_async(self, rb_str_new_cstr(encname)) != 0 )
|
@@ -4113,10 +4204,11 @@ pgconn_type_map_for_queries_set(VALUE self, VALUE typemap)
|
|
4113
4204
|
t_typemap *tm;
|
4114
4205
|
UNUSED(tm);
|
4115
4206
|
|
4207
|
+
rb_check_frozen(self);
|
4116
4208
|
/* Check type of method param */
|
4117
4209
|
TypedData_Get_Struct(typemap, t_typemap, &pg_typemap_type, tm);
|
4118
4210
|
|
4119
|
-
this->type_map_for_queries
|
4211
|
+
RB_OBJ_WRITE(self, &this->type_map_for_queries, typemap);
|
4120
4212
|
|
4121
4213
|
return typemap;
|
4122
4214
|
}
|
@@ -4153,8 +4245,9 @@ pgconn_type_map_for_results_set(VALUE self, VALUE typemap)
|
|
4153
4245
|
t_typemap *tm;
|
4154
4246
|
UNUSED(tm);
|
4155
4247
|
|
4248
|
+
rb_check_frozen(self);
|
4156
4249
|
TypedData_Get_Struct(typemap, t_typemap, &pg_typemap_type, tm);
|
4157
|
-
this->type_map_for_results
|
4250
|
+
RB_OBJ_WRITE(self, &this->type_map_for_results, typemap);
|
4158
4251
|
|
4159
4252
|
return typemap;
|
4160
4253
|
}
|
@@ -4192,13 +4285,14 @@ pgconn_encoder_for_put_copy_data_set(VALUE self, VALUE encoder)
|
|
4192
4285
|
{
|
4193
4286
|
t_pg_connection *this = pg_get_connection( self );
|
4194
4287
|
|
4288
|
+
rb_check_frozen(self);
|
4195
4289
|
if( encoder != Qnil ){
|
4196
4290
|
t_pg_coder *co;
|
4197
4291
|
UNUSED(co);
|
4198
4292
|
/* Check argument type */
|
4199
4293
|
TypedData_Get_Struct(encoder, t_pg_coder, &pg_coder_type, co);
|
4200
4294
|
}
|
4201
|
-
this->encoder_for_put_copy_data
|
4295
|
+
RB_OBJ_WRITE(self, &this->encoder_for_put_copy_data, encoder);
|
4202
4296
|
|
4203
4297
|
return encoder;
|
4204
4298
|
}
|
@@ -4240,13 +4334,14 @@ pgconn_decoder_for_get_copy_data_set(VALUE self, VALUE decoder)
|
|
4240
4334
|
{
|
4241
4335
|
t_pg_connection *this = pg_get_connection( self );
|
4242
4336
|
|
4337
|
+
rb_check_frozen(self);
|
4243
4338
|
if( decoder != Qnil ){
|
4244
4339
|
t_pg_coder *co;
|
4245
4340
|
UNUSED(co);
|
4246
4341
|
/* Check argument type */
|
4247
4342
|
TypedData_Get_Struct(decoder, t_pg_coder, &pg_coder_type, co);
|
4248
4343
|
}
|
4249
|
-
this->decoder_for_get_copy_data
|
4344
|
+
RB_OBJ_WRITE(self, &this->decoder_for_get_copy_data, decoder);
|
4250
4345
|
|
4251
4346
|
return decoder;
|
4252
4347
|
}
|
@@ -4292,6 +4387,7 @@ pgconn_field_name_type_set(VALUE self, VALUE sym)
|
|
4292
4387
|
{
|
4293
4388
|
t_pg_connection *this = pg_get_connection( self );
|
4294
4389
|
|
4390
|
+
rb_check_frozen(self);
|
4295
4391
|
this->flags &= ~PG_RESULT_FIELD_NAMES_MASK;
|
4296
4392
|
if( sym == sym_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_SYMBOL;
|
4297
4393
|
else if ( sym == sym_static_symbol ) this->flags |= PG_RESULT_FIELD_NAMES_STATIC_SYMBOL;
|