sequel_pg 1.7.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +12 -0
- data/README.rdoc +0 -1
- data/ext/sequel_pg/extconf.rb +1 -10
- data/ext/sequel_pg/sequel_pg.c +67 -114
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12f6ab4a1eb1aefe52198b01d2b32ff5e1108dd3
|
4
|
+
data.tar.gz: d70c53a25c1af4d132bf63c7887f096efa0754e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ed2744dc9f5e9620bf463ad85baca278b84a20ea0368f36e2c65243cb9cc38c1ea7746cce9c9b881d78ff26ee1ef35341f788a5d919f613aeebe32c3d11b470
|
7
|
+
data.tar.gz: 59a2b4123aae9e61b025b1b9006c1f6700b5b876fd6de28bdbd27d2123c3d7d71e428ce559273a69a7376cd757658fb6960ff452ebb9dcf730e8bace0284b746
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 1.8.0 (2017-10-18)
|
2
|
+
|
3
|
+
* Handle timezone offsets with seconds when parsing timestamps (jeremyevans)
|
4
|
+
|
5
|
+
* Parse BC dates and timestamps correctly (jeremyevans)
|
6
|
+
|
7
|
+
* Drop Sequel <4.34.0 support (jeremyevans)
|
8
|
+
|
9
|
+
* Drop pg <0.18.0 support (jeremyevans)
|
10
|
+
|
11
|
+
* Drop ruby <1.9.3 support (jeremyevans)
|
12
|
+
|
1
13
|
=== 1.7.1 (2017-08-25)
|
2
14
|
|
3
15
|
* Handle case where PGconn#get_result returns nil in single row mode (jeremyevans)
|
data/README.rdoc
CHANGED
data/ext/sequel_pg/extconf.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
require 'mkmf'
|
2
|
-
$CFLAGS << " -O0 -g
|
2
|
+
$CFLAGS << " -O0 -g" if ENV['DEBUG']
|
3
3
|
$CFLAGS << " -Wall " unless RUBY_PLATFORM =~ /solaris/
|
4
4
|
dir_config('pg', ENV["POSTGRES_INCLUDE"] || (IO.popen("pg_config --includedir").readline.chomp rescue nil),
|
5
5
|
ENV["POSTGRES_LIB"] || (IO.popen("pg_config --libdir").readline.chomp rescue nil))
|
6
6
|
|
7
|
-
if enable_config("static-build")
|
8
|
-
# Link against all required libraries for static build, if they are available
|
9
|
-
have_library('gdi32', 'CreateDC')
|
10
|
-
have_library('secur32')
|
11
|
-
have_library('ws2_32')
|
12
|
-
have_library('eay32')
|
13
|
-
have_library('ssleay32', 'SSL_pending')
|
14
|
-
end
|
15
|
-
|
16
7
|
if (have_library('pq') || have_library('libpq') || have_library('ms/libpq')) && have_header('libpq-fe.h')
|
17
8
|
have_func 'PQsetSingleRowMode'
|
18
9
|
create_makefile("sequel_pg")
|
data/ext/sequel_pg/sequel_pg.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#define SEQUEL_PG_VERSION_INTEGER
|
1
|
+
#define SEQUEL_PG_VERSION_INTEGER 10800
|
2
2
|
|
3
3
|
#include <string.h>
|
4
4
|
#include <stdio.h>
|
@@ -6,23 +6,15 @@
|
|
6
6
|
#include <libpq-fe.h>
|
7
7
|
#include <ruby.h>
|
8
8
|
|
9
|
-
#if defined(HAVE_RUBY_ENCODING_H) && HAVE_RUBY_ENCODING_H
|
10
|
-
#define SPG_ENCODING 1
|
11
9
|
#include <ruby/encoding.h>
|
12
|
-
#define ENC_INDEX ,enc_index
|
13
|
-
#else
|
14
|
-
#define ENC_INDEX
|
15
|
-
#endif
|
16
10
|
|
17
11
|
#ifndef SPG_MAX_FIELDS
|
18
12
|
#define SPG_MAX_FIELDS 256
|
19
13
|
#endif
|
20
|
-
#define SPG_MICROSECONDS_PER_DAY_LL 86400000000ULL
|
21
|
-
#define SPG_MICROSECONDS_PER_DAY 86400000000.0
|
22
14
|
#define SPG_MINUTES_PER_DAY 1440.0
|
23
15
|
#define SPG_SECONDS_PER_DAY 86400.0
|
24
16
|
|
25
|
-
#define SPG_DT_ADD_USEC if (usec != 0) { dt = rb_funcall(dt, spg_id_op_plus, 1,
|
17
|
+
#define SPG_DT_ADD_USEC if (usec != 0) { dt = rb_funcall(dt, spg_id_op_plus, 1, rb_Rational2(INT2NUM(usec), spg_usec_per_day)); }
|
26
18
|
|
27
19
|
#define SPG_NO_TZ 0
|
28
20
|
#define SPG_DB_LOCAL 1
|
@@ -45,18 +37,10 @@
|
|
45
37
|
#define SPG_YIELD_KMV_HASH_GROUPS 12
|
46
38
|
#define SPG_YIELD_MKMV_HASH_GROUPS 13
|
47
39
|
|
48
|
-
/* Whether the data objects are structs instead of just pointers */
|
49
|
-
static int unwrap_structs;
|
50
|
-
static int use_columns_method;
|
51
|
-
|
52
40
|
/* External functions defined by ruby-pg when data objects are structs */
|
53
41
|
PGconn* pg_get_pgconn(VALUE);
|
54
42
|
PGresult* pgresult_get(VALUE);
|
55
43
|
|
56
|
-
/* Normalize access to data objects for both old and new versions of pg gem */
|
57
|
-
#define GetPGconn(_val, _var) if (unwrap_structs) {Check_Type(_val, T_DATA); _var = pg_get_pgconn(_val);} else {Data_Get_Struct(_val, PGconn, _var);}
|
58
|
-
#define GetPGresult(_val, _var) if (unwrap_structs) {Check_Type(_val, T_DATA); _var = pgresult_get(_val);} else {Data_Get_Struct(_val, PGresult, _var);}
|
59
|
-
|
60
44
|
static VALUE spg_Sequel;
|
61
45
|
static VALUE spg_Blob;
|
62
46
|
static VALUE spg_BigDecimal;
|
@@ -78,8 +62,8 @@ static VALUE spg_sym__sequel_pg_value;
|
|
78
62
|
static VALUE spg_nan;
|
79
63
|
static VALUE spg_pos_inf;
|
80
64
|
static VALUE spg_neg_inf;
|
65
|
+
static VALUE spg_usec_per_day;
|
81
66
|
|
82
|
-
static ID spg_id_Rational;
|
83
67
|
static ID spg_id_new;
|
84
68
|
static ID spg_id_local;
|
85
69
|
static ID spg_id_year;
|
@@ -116,23 +100,15 @@ static ID spg_id_clear;
|
|
116
100
|
static ID spg_id_check;
|
117
101
|
#endif
|
118
102
|
|
119
|
-
|
120
|
-
static int enc_get_index(VALUE val)
|
121
|
-
{
|
103
|
+
static int enc_get_index(VALUE val) {
|
122
104
|
int i = ENCODING_GET_INLINED(val);
|
123
105
|
if (i == ENCODING_INLINE_MAX) {
|
124
106
|
i = NUM2INT(rb_ivar_get(val, spg_id_encoding));
|
125
107
|
}
|
126
108
|
return i;
|
127
109
|
}
|
128
|
-
#endif
|
129
110
|
|
130
|
-
static VALUE read_array(int *index, char *c_pg_array_string, int array_string_length, VALUE buf, VALUE converter
|
131
|
-
#ifdef SPG_ENCODING
|
132
|
-
, int enc_index
|
133
|
-
#endif
|
134
|
-
)
|
135
|
-
{
|
111
|
+
static VALUE read_array(int *index, char *c_pg_array_string, int array_string_length, VALUE buf, VALUE converter, int enc_index) {
|
136
112
|
int word_index = 0;
|
137
113
|
char *word = RSTRING_PTR(buf);
|
138
114
|
|
@@ -178,9 +154,7 @@ static VALUE read_array(int *index, char *c_pg_array_string, int array_string_le
|
|
178
154
|
VALUE rword = rb_tainted_str_new(word, word_index);
|
179
155
|
RB_GC_GUARD(rword);
|
180
156
|
|
181
|
-
#ifdef SPG_ENCODING
|
182
157
|
rb_enc_associate_index(rword, enc_index);
|
183
|
-
#endif
|
184
158
|
|
185
159
|
if (RTEST(converter)) {
|
186
160
|
rword = rb_funcall(converter, spg_id_call, 1, rword);
|
@@ -204,11 +178,7 @@ static VALUE read_array(int *index, char *c_pg_array_string, int array_string_le
|
|
204
178
|
else if(c == '{')
|
205
179
|
{
|
206
180
|
(*index)++;
|
207
|
-
rb_ary_push(array, read_array(index, c_pg_array_string, array_string_length, buf, converter
|
208
|
-
#ifdef SPG_ENCODING
|
209
|
-
, enc_index
|
210
|
-
#endif
|
211
|
-
));
|
181
|
+
rb_ary_push(array, read_array(index, c_pg_array_string, array_string_length, buf, converter, enc_index));
|
212
182
|
escapeNext = 1;
|
213
183
|
}
|
214
184
|
else
|
@@ -273,9 +243,7 @@ static VALUE parse_pg_array(VALUE self, VALUE pg_array_string, VALUE converter)
|
|
273
243
|
}
|
274
244
|
|
275
245
|
return read_array(&index, c_pg_array_string, array_string_length, buf, converter
|
276
|
-
#ifdef SPG_ENCODING
|
277
246
|
, enc_get_index(pg_array_string)
|
278
|
-
#endif
|
279
247
|
);
|
280
248
|
}
|
281
249
|
|
@@ -320,13 +288,18 @@ static VALUE spg_date(const char *s, VALUE self) {
|
|
320
288
|
return spg_timestamp_error(s, self, "unexpected date format");
|
321
289
|
}
|
322
290
|
|
291
|
+
if(s[10] == ' ' && s[11] == 'B' && s[12] == 'C') {
|
292
|
+
year = -year;
|
293
|
+
year++;
|
294
|
+
}
|
295
|
+
|
323
296
|
return rb_funcall(spg_Date, spg_id_new, 3, INT2NUM(year), INT2NUM(month), INT2NUM(day));
|
324
297
|
}
|
325
298
|
|
326
299
|
static VALUE spg_timestamp(const char *s, VALUE self) {
|
327
300
|
VALUE dtc, dt, rtz, db;
|
328
301
|
int tz = SPG_NO_TZ;
|
329
|
-
int year, month, day, hour, min, sec, usec, tokens, utc_offset;
|
302
|
+
int year, month, day, hour, min, sec, usec, tokens, utc_offset, len;
|
330
303
|
int usec_start, usec_stop;
|
331
304
|
char offset_sign = 0;
|
332
305
|
int offset_hour = 0;
|
@@ -358,18 +331,18 @@ static VALUE spg_timestamp(const char *s, VALUE self) {
|
|
358
331
|
}
|
359
332
|
|
360
333
|
if (0 != strchr(s, '.')) {
|
361
|
-
tokens = sscanf(s, "%d-%2d-%2d %2d:%2d:%2d.%n%d%n%c%02d:%02d",
|
362
|
-
|
363
|
-
|
364
|
-
|
334
|
+
tokens = sscanf(s, "%d-%2d-%2d %2d:%2d:%2d.%n%d%n%c%02d:%02d:%02d",
|
335
|
+
&year, &month, &day, &hour, &min, &sec,
|
336
|
+
&usec_start, &usec, &usec_stop,
|
337
|
+
&offset_sign, &offset_hour, &offset_minute, &offset_seconds);
|
365
338
|
if(tokens < 7) {
|
366
339
|
return spg_timestamp_error(s, self, "unexpected datetime format");
|
367
340
|
}
|
368
341
|
usec *= (int) pow(10, (6 - (usec_stop - usec_start)));
|
369
342
|
} else {
|
370
|
-
tokens = sscanf(s, "%d-%2d-%2d %2d:%2d:%2d%c%02d:%02d",
|
371
|
-
|
372
|
-
|
343
|
+
tokens = sscanf(s, "%d-%2d-%2d %2d:%2d:%2d%c%02d:%02d:%02d",
|
344
|
+
&year, &month, &day, &hour, &min, &sec,
|
345
|
+
&offset_sign, &offset_hour, &offset_minute, &offset_seconds);
|
373
346
|
if (tokens == 3) {
|
374
347
|
hour = 0;
|
375
348
|
min = 0;
|
@@ -380,9 +353,16 @@ static VALUE spg_timestamp(const char *s, VALUE self) {
|
|
380
353
|
usec = 0;
|
381
354
|
}
|
382
355
|
|
356
|
+
len = strlen(s);
|
357
|
+
if(s[len-3] == ' ' && s[len-2] == 'B' && s[len-1] == 'C') {
|
358
|
+
year = -year;
|
359
|
+
year++;
|
360
|
+
}
|
361
|
+
|
383
362
|
if (offset_sign == '-') {
|
384
363
|
offset_hour *= -1;
|
385
364
|
offset_minute *= -1;
|
365
|
+
offset_seconds *= -1;
|
386
366
|
}
|
387
367
|
|
388
368
|
dtc = rb_funcall(spg_Sequel, spg_id_datetime_class, 0);
|
@@ -394,7 +374,7 @@ static VALUE spg_timestamp(const char *s, VALUE self) {
|
|
394
374
|
*/
|
395
375
|
dt = rb_funcall(rb_cTime, spg_id_local, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), INT2NUM(usec));
|
396
376
|
utc_offset = NUM2INT(rb_funcall(dt, spg_id_utc_offset, 0));
|
397
|
-
offset_seconds
|
377
|
+
offset_seconds += offset_hour * 3600 + offset_minute * 60;
|
398
378
|
if (utc_offset != offset_seconds) {
|
399
379
|
dt = rb_funcall(dt, spg_id_op_plus, 1, INT2NUM(utc_offset - offset_seconds));
|
400
380
|
}
|
@@ -429,7 +409,7 @@ static VALUE spg_timestamp(const char *s, VALUE self) {
|
|
429
409
|
/* Offset given, handle correct local time.
|
430
410
|
* While PostgreSQL generally returns timestamps in local time, it's unwise to rely on this.
|
431
411
|
*/
|
432
|
-
offset_fraction = offset_hour/24.0 + offset_minute/SPG_MINUTES_PER_DAY;
|
412
|
+
offset_fraction = offset_hour/24.0 + offset_minute/SPG_MINUTES_PER_DAY + offset_seconds/SPG_SECONDS_PER_DAY;
|
433
413
|
dt = rb_funcall(dtc, spg_id_new, 7, INT2NUM(year), INT2NUM(month), INT2NUM(day), INT2NUM(hour), INT2NUM(min), INT2NUM(sec), rb_float_new(offset_fraction));
|
434
414
|
SPG_DT_ADD_USEC
|
435
415
|
|
@@ -473,11 +453,7 @@ static VALUE spg_fetch_rows_set_cols(VALUE self, VALUE ignore) {
|
|
473
453
|
return Qnil;
|
474
454
|
}
|
475
455
|
|
476
|
-
static VALUE spg__col_value(VALUE self, PGresult *res, long i, long j, VALUE* colconvert
|
477
|
-
#ifdef SPG_ENCODING
|
478
|
-
, int enc_index
|
479
|
-
#endif
|
480
|
-
) {
|
456
|
+
static VALUE spg__col_value(VALUE self, PGresult *res, long i, long j, VALUE* colconvert, int enc_index) {
|
481
457
|
char *v;
|
482
458
|
VALUE rv;
|
483
459
|
size_t l;
|
@@ -532,15 +508,11 @@ static VALUE spg__col_value(VALUE self, PGresult *res, long i, long j, VALUE* co
|
|
532
508
|
case 25: /* text */
|
533
509
|
case 1043: /* varchar*/
|
534
510
|
rv = rb_tainted_str_new(v, PQgetlength(res, i, j));
|
535
|
-
#ifdef SPG_ENCODING
|
536
511
|
rb_enc_associate_index(rv, enc_index);
|
537
|
-
#endif
|
538
512
|
break;
|
539
513
|
default:
|
540
514
|
rv = rb_tainted_str_new(v, PQgetlength(res, i, j));
|
541
|
-
#ifdef SPG_ENCODING
|
542
515
|
rb_enc_associate_index(rv, enc_index);
|
543
|
-
#endif
|
544
516
|
if (colconvert[j] != Qnil) {
|
545
517
|
rv = rb_funcall(colconvert[j], spg_id_call, 1, rv);
|
546
518
|
}
|
@@ -549,18 +521,14 @@ static VALUE spg__col_value(VALUE self, PGresult *res, long i, long j, VALUE* co
|
|
549
521
|
return rv;
|
550
522
|
}
|
551
523
|
|
552
|
-
static VALUE spg__col_values(VALUE self, VALUE v, VALUE *colsyms, long nfields, PGresult *res, long i, VALUE *colconvert
|
553
|
-
#ifdef SPG_ENCODING
|
554
|
-
, int enc_index
|
555
|
-
#endif
|
556
|
-
) {
|
524
|
+
static VALUE spg__col_values(VALUE self, VALUE v, VALUE *colsyms, long nfields, PGresult *res, long i, VALUE *colconvert, int enc_index) {
|
557
525
|
long j;
|
558
526
|
VALUE cur;
|
559
527
|
long len = RARRAY_LEN(v);
|
560
528
|
VALUE a = rb_ary_new2(len);
|
561
529
|
for (j=0; j<len; j++) {
|
562
530
|
cur = rb_ary_entry(v, j);
|
563
|
-
rb_ary_store(a, j, cur == Qnil ? Qnil : spg__col_value(self, res, i, NUM2LONG(cur), colconvert
|
531
|
+
rb_ary_store(a, j, cur == Qnil ? Qnil : spg__col_value(self, res, i, NUM2LONG(cur), colconvert, enc_index));
|
564
532
|
}
|
565
533
|
return a;
|
566
534
|
}
|
@@ -589,14 +557,6 @@ static VALUE spg__field_ids(VALUE v, VALUE *colsyms, long nfields) {
|
|
589
557
|
return pg_columns;
|
590
558
|
}
|
591
559
|
|
592
|
-
static void spg_set_columns(VALUE self, VALUE cols) {
|
593
|
-
if (use_columns_method) {
|
594
|
-
rb_funcall(self, spg_id_columns_equal, 1, cols);
|
595
|
-
} else {
|
596
|
-
rb_ivar_set(self, spg_id_columns, cols);
|
597
|
-
}
|
598
|
-
}
|
599
|
-
|
600
560
|
static void spg_set_column_info(VALUE self, PGresult *res, VALUE *colsyms, VALUE *colconvert) {
|
601
561
|
long i;
|
602
562
|
long j;
|
@@ -637,7 +597,8 @@ static void spg_set_column_info(VALUE self, PGresult *res, VALUE *colsyms, VALUE
|
|
637
597
|
break;
|
638
598
|
}
|
639
599
|
}
|
640
|
-
|
600
|
+
|
601
|
+
rb_funcall(self, spg_id_columns_equal, 1, rb_ary_new4(nfields, colsyms));
|
641
602
|
}
|
642
603
|
|
643
604
|
static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
@@ -657,12 +618,11 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
657
618
|
if (!RTEST(rres)) {
|
658
619
|
return self;
|
659
620
|
}
|
660
|
-
|
621
|
+
Check_Type(rres, T_DATA);
|
622
|
+
res = pgresult_get(rres);
|
661
623
|
|
662
|
-
#ifdef SPG_ENCODING
|
663
624
|
int enc_index;
|
664
625
|
enc_index = enc_get_index(rres);
|
665
|
-
#endif
|
666
626
|
|
667
627
|
ntuples = PQntuples(res);
|
668
628
|
nfields = PQnfields(res);
|
@@ -716,7 +676,7 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
716
676
|
for(i=0; i<ntuples; i++) {
|
717
677
|
h = rb_hash_new();
|
718
678
|
for(j=0; j<nfields; j++) {
|
719
|
-
rb_hash_aset(h, colsyms[j], spg__col_value(self, res, i, j, colconvert
|
679
|
+
rb_hash_aset(h, colsyms[j], spg__col_value(self, res, i, j, colconvert, enc_index));
|
720
680
|
}
|
721
681
|
rb_yield(h);
|
722
682
|
}
|
@@ -730,7 +690,7 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
730
690
|
}
|
731
691
|
} else {
|
732
692
|
for(i=0; i<ntuples; i++) {
|
733
|
-
rb_yield(spg__col_value(self, res, i, j, colconvert
|
693
|
+
rb_yield(spg__col_value(self, res, i, j, colconvert, enc_index));
|
734
694
|
}
|
735
695
|
}
|
736
696
|
break;
|
@@ -738,13 +698,13 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
738
698
|
/* Multiple columns as an array */
|
739
699
|
h = spg__field_ids(pg_value, colsyms, nfields);
|
740
700
|
for(i=0; i<ntuples; i++) {
|
741
|
-
rb_yield(spg__col_values(self, h, colsyms, nfields, res, i, colconvert
|
701
|
+
rb_yield(spg__col_values(self, h, colsyms, nfields, res, i, colconvert, enc_index));
|
742
702
|
}
|
743
703
|
break;
|
744
704
|
case SPG_YIELD_FIRST:
|
745
705
|
/* First column */
|
746
706
|
for(i=0; i<ntuples; i++) {
|
747
|
-
rb_yield(spg__col_value(self, res, i, 0, colconvert
|
707
|
+
rb_yield(spg__col_value(self, res, i, 0, colconvert, enc_index));
|
748
708
|
}
|
749
709
|
break;
|
750
710
|
case SPG_YIELD_ARRAY:
|
@@ -752,7 +712,7 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
752
712
|
for(i=0; i<ntuples; i++) {
|
753
713
|
h = rb_ary_new2(nfields);
|
754
714
|
for(j=0; j<nfields; j++) {
|
755
|
-
rb_ary_store(h, j, spg__col_value(self, res, i, j, colconvert
|
715
|
+
rb_ary_store(h, j, spg__col_value(self, res, i, j, colconvert, enc_index));
|
756
716
|
}
|
757
717
|
rb_yield(h);
|
758
718
|
}
|
@@ -767,13 +727,13 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
767
727
|
v = spg__field_id(rb_ary_entry(pg_value, 1), colsyms, nfields);
|
768
728
|
if(type == SPG_YIELD_KV_HASH) {
|
769
729
|
for(i=0; i<ntuples; i++) {
|
770
|
-
rb_hash_aset(h, spg__col_value(self, res, i, k, colconvert
|
730
|
+
rb_hash_aset(h, spg__col_value(self, res, i, k, colconvert, enc_index), spg__col_value(self, res, i, v, colconvert, enc_index));
|
771
731
|
}
|
772
732
|
} else {
|
773
733
|
VALUE kv, vv, a;
|
774
734
|
for(i=0; i<ntuples; i++) {
|
775
|
-
kv = spg__col_value(self, res, i, k, colconvert
|
776
|
-
vv = spg__col_value(self, res, i, v, colconvert
|
735
|
+
kv = spg__col_value(self, res, i, k, colconvert, enc_index);
|
736
|
+
vv = spg__col_value(self, res, i, v, colconvert, enc_index);
|
777
737
|
a = rb_hash_lookup(h, kv);
|
778
738
|
if(!RTEST(a)) {
|
779
739
|
rb_hash_aset(h, kv, rb_ary_new3(1, vv));
|
@@ -795,13 +755,13 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
795
755
|
v = spg__field_id(rb_ary_entry(pg_value, 1), colsyms, nfields);
|
796
756
|
if(type == SPG_YIELD_MKV_HASH) {
|
797
757
|
for(i=0; i<ntuples; i++) {
|
798
|
-
rb_hash_aset(h, spg__col_values(self, k, colsyms, nfields, res, i, colconvert
|
758
|
+
rb_hash_aset(h, spg__col_values(self, k, colsyms, nfields, res, i, colconvert, enc_index), spg__col_value(self, res, i, v, colconvert, enc_index));
|
799
759
|
}
|
800
760
|
} else {
|
801
761
|
VALUE kv, vv, a;
|
802
762
|
for(i=0; i<ntuples; i++) {
|
803
|
-
kv = spg__col_values(self, k, colsyms, nfields, res, i, colconvert
|
804
|
-
vv = spg__col_value(self, res, i, v, colconvert
|
763
|
+
kv = spg__col_values(self, k, colsyms, nfields, res, i, colconvert, enc_index);
|
764
|
+
vv = spg__col_value(self, res, i, v, colconvert, enc_index);
|
805
765
|
a = rb_hash_lookup(h, kv);
|
806
766
|
if(!RTEST(a)) {
|
807
767
|
rb_hash_aset(h, kv, rb_ary_new3(1, vv));
|
@@ -823,13 +783,13 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
823
783
|
v = spg__field_ids(rb_ary_entry(pg_value, 1), colsyms, nfields);
|
824
784
|
if(type == SPG_YIELD_KMV_HASH) {
|
825
785
|
for(i=0; i<ntuples; i++) {
|
826
|
-
rb_hash_aset(h, spg__col_value(self, res, i, k, colconvert
|
786
|
+
rb_hash_aset(h, spg__col_value(self, res, i, k, colconvert, enc_index), spg__col_values(self, v, colsyms, nfields, res, i, colconvert, enc_index));
|
827
787
|
}
|
828
788
|
} else {
|
829
789
|
VALUE kv, vv, a;
|
830
790
|
for(i=0; i<ntuples; i++) {
|
831
|
-
kv = spg__col_value(self, res, i, k, colconvert
|
832
|
-
vv = spg__col_values(self, v, colsyms, nfields, res, i, colconvert
|
791
|
+
kv = spg__col_value(self, res, i, k, colconvert, enc_index);
|
792
|
+
vv = spg__col_values(self, v, colsyms, nfields, res, i, colconvert, enc_index);
|
833
793
|
a = rb_hash_lookup(h, kv);
|
834
794
|
if(!RTEST(a)) {
|
835
795
|
rb_hash_aset(h, kv, rb_ary_new3(1, vv));
|
@@ -851,13 +811,13 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
851
811
|
v = spg__field_ids(rb_ary_entry(pg_value, 1), colsyms, nfields);
|
852
812
|
if(type == SPG_YIELD_MKMV_HASH) {
|
853
813
|
for(i=0; i<ntuples; i++) {
|
854
|
-
rb_hash_aset(h, spg__col_values(self, k, colsyms, nfields, res, i, colconvert
|
814
|
+
rb_hash_aset(h, spg__col_values(self, k, colsyms, nfields, res, i, colconvert, enc_index), spg__col_values(self, v, colsyms, nfields, res, i, colconvert, enc_index));
|
855
815
|
}
|
856
816
|
} else {
|
857
817
|
VALUE kv, vv, a;
|
858
818
|
for(i=0; i<ntuples; i++) {
|
859
|
-
kv = spg__col_values(self, k, colsyms, nfields, res, i, colconvert
|
860
|
-
vv = spg__col_values(self, v, colsyms, nfields, res, i, colconvert
|
819
|
+
kv = spg__col_values(self, k, colsyms, nfields, res, i, colconvert, enc_index);
|
820
|
+
vv = spg__col_values(self, v, colsyms, nfields, res, i, colconvert, enc_index);
|
861
821
|
a = rb_hash_lookup(h, kv);
|
862
822
|
if(!RTEST(a)) {
|
863
823
|
rb_hash_aset(h, kv, rb_ary_new3(1, vv));
|
@@ -874,7 +834,7 @@ static VALUE spg_yield_hash_rows(VALUE self, VALUE rres, VALUE ignore) {
|
|
874
834
|
for(i=0; i<ntuples; i++) {
|
875
835
|
h = rb_hash_new();
|
876
836
|
for(j=0; j<nfields; j++) {
|
877
|
-
rb_hash_aset(h, colsyms[j], spg__col_value(self, res, i, j, colconvert
|
837
|
+
rb_hash_aset(h, colsyms[j], spg__col_value(self, res, i, j, colconvert, enc_index));
|
878
838
|
}
|
879
839
|
/* Abuse local variable */
|
880
840
|
pg_type = rb_obj_alloc(pg_value);
|
@@ -898,7 +858,8 @@ static VALUE spg_supports_streaming_p(VALUE self) {
|
|
898
858
|
#if HAVE_PQSETSINGLEROWMODE
|
899
859
|
static VALUE spg_set_single_row_mode(VALUE self) {
|
900
860
|
PGconn *conn;
|
901
|
-
|
861
|
+
Check_Type(self, T_DATA);
|
862
|
+
conn = pg_get_pgconn(self);
|
902
863
|
if (PQsetSingleRowMode(conn) != 1) {
|
903
864
|
rb_raise(spg_PGError, "cannot set single row mode");
|
904
865
|
}
|
@@ -922,19 +883,19 @@ static VALUE spg__yield_each_row(VALUE self) {
|
|
922
883
|
|
923
884
|
rconn = rb_ary_entry(self, 1);
|
924
885
|
self = rb_ary_entry(self, 0);
|
925
|
-
|
886
|
+
Check_Type(rconn, T_DATA);
|
887
|
+
conn = pg_get_pgconn(rconn);
|
926
888
|
|
927
889
|
rres = rb_funcall(rconn, spg_id_get_result, 0);
|
928
890
|
if (rres == Qnil) {
|
929
891
|
goto end_yield_each_row;
|
930
892
|
}
|
931
893
|
rb_funcall(rres, spg_id_check, 0);
|
932
|
-
|
894
|
+
Check_Type(rres, T_DATA);
|
895
|
+
res = pgresult_get(rres);
|
933
896
|
|
934
|
-
#ifdef SPG_ENCODING
|
935
897
|
int enc_index;
|
936
898
|
enc_index = enc_get_index(rres);
|
937
|
-
#endif
|
938
899
|
|
939
900
|
/* Only handle regular and model types. All other types require compiling all
|
940
901
|
* of the results at once, which is not a use case for streaming. The streaming
|
@@ -959,7 +920,7 @@ static VALUE spg__yield_each_row(VALUE self) {
|
|
959
920
|
while (PQntuples(res) != 0) {
|
960
921
|
h = rb_hash_new();
|
961
922
|
for(j=0; j<nfields; j++) {
|
962
|
-
rb_hash_aset(h, colsyms[j], spg__col_value(self, res, 0, j, colconvert
|
923
|
+
rb_hash_aset(h, colsyms[j], spg__col_value(self, res, 0, j, colconvert , enc_index));
|
963
924
|
}
|
964
925
|
|
965
926
|
rb_funcall(rres, spg_id_clear, 0);
|
@@ -978,7 +939,8 @@ static VALUE spg__yield_each_row(VALUE self) {
|
|
978
939
|
goto end_yield_each_row;
|
979
940
|
}
|
980
941
|
rb_funcall(rres, spg_id_check, 0);
|
981
|
-
|
942
|
+
Check_Type(rres, T_DATA);
|
943
|
+
res = pgresult_get(rres);
|
982
944
|
}
|
983
945
|
rb_funcall(rres, spg_id_clear, 0);
|
984
946
|
|
@@ -990,7 +952,8 @@ static VALUE spg__flush_results(VALUE rconn) {
|
|
990
952
|
PGconn *conn;
|
991
953
|
PGresult *res;
|
992
954
|
VALUE error = 0;
|
993
|
-
|
955
|
+
Check_Type(rconn, T_DATA);
|
956
|
+
conn = pg_get_pgconn(rconn);
|
994
957
|
|
995
958
|
while ((res = PQgetResult(conn)) != NULL) {
|
996
959
|
if (!error) {
|
@@ -1085,11 +1048,12 @@ void Init_sequel_pg(void) {
|
|
1085
1048
|
spg_SQLTime= rb_funcall(spg_Sequel, cg, 1, rb_str_new2("SQLTime"));
|
1086
1049
|
spg_BigDecimal = rb_funcall(rb_cObject, cg, 1, rb_str_new2("BigDecimal"));
|
1087
1050
|
spg_Date = rb_funcall(rb_cObject, cg, 1, rb_str_new2("Date"));
|
1088
|
-
spg_PGError =
|
1051
|
+
spg_PGError = rb_funcall(rb_funcall(rb_cObject, cg, 1, rb_str_new2("PG")), cg, 1, rb_str_new2("Error"));
|
1089
1052
|
|
1090
1053
|
spg_nan = rb_eval_string("0.0/0.0");
|
1091
1054
|
spg_pos_inf = rb_eval_string("1.0/0.0");
|
1092
1055
|
spg_neg_inf = rb_eval_string("-1.0/0.0");
|
1056
|
+
spg_usec_per_day = ULL2NUM(86400000000ULL);
|
1093
1057
|
|
1094
1058
|
rb_global_variable(&spg_Sequel);
|
1095
1059
|
rb_global_variable(&spg_Blob);
|
@@ -1100,14 +1064,7 @@ void Init_sequel_pg(void) {
|
|
1100
1064
|
rb_global_variable(&spg_nan);
|
1101
1065
|
rb_global_variable(&spg_pos_inf);
|
1102
1066
|
rb_global_variable(&spg_neg_inf);
|
1103
|
-
|
1104
|
-
/* Check for 1.8-1.9.2 stdlib date that needs Rational for usec accuracy */
|
1105
|
-
if (rb_attr_get(rb_eval_string("Date.today"), rb_intern("@ajd")) != Qnil) {
|
1106
|
-
spg_id_Rational = rb_intern("Rational");
|
1107
|
-
}
|
1108
|
-
if (rb_eval_string("defined?(PG::TypeMapAllStrings)") != Qnil) {
|
1109
|
-
unwrap_structs = 1;
|
1110
|
-
}
|
1067
|
+
rb_global_variable(&spg_usec_per_day);
|
1111
1068
|
|
1112
1069
|
c = rb_funcall(spg_Postgres, cg, 1, rb_str_new2("Dataset"));
|
1113
1070
|
rb_undef_method(c, "yield_hash_rows");
|
@@ -1115,10 +1072,6 @@ void Init_sequel_pg(void) {
|
|
1115
1072
|
rb_undef_method(c, "fetch_rows_set_cols");
|
1116
1073
|
rb_define_private_method(c, "fetch_rows_set_cols", spg_fetch_rows_set_cols, 1);
|
1117
1074
|
|
1118
|
-
if (rb_eval_string("Sequel::Dataset.private_method_defined?(:columns=)") == Qtrue) {
|
1119
|
-
use_columns_method = 1;
|
1120
|
-
}
|
1121
|
-
|
1122
1075
|
rb_define_singleton_method(spg_Postgres, "supports_streaming?", spg_supports_streaming_p, 0);
|
1123
1076
|
|
1124
1077
|
#if HAVE_PQSETSINGLEROWMODE
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_pg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.18.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.18.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sequel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.
|
33
|
+
version: 4.34.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.
|
40
|
+
version: 4.34.0
|
41
41
|
description: |
|
42
42
|
sequel_pg overwrites the inner loop of the Sequel postgres
|
43
43
|
adapter row fetching code with a C version. The C version
|
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
requirements:
|
84
84
|
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: 1.
|
86
|
+
version: 1.9.3
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
89
|
- - ">="
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.6.
|
94
|
+
rubygems_version: 2.6.13
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Faster SELECTs when using Sequel with pg
|