antage-postgres 0.7.9.2009.05.12 → 0.7.9.2009.05.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Contributors +1 -0
  2. data/ext/postgres.c +19 -68
  3. metadata +2 -2
data/Contributors CHANGED
@@ -26,3 +26,4 @@ Yuta TSUBOI <yuuta-t@is.aist-nara.ac.jp>
26
26
  Lugovoi Nikolai <meadow.nnick@gmail.com>
27
27
  Jeff Davis <ruby@j-davis.com>
28
28
  Bertram Scharpf <software@bertram-scharpf.de>
29
+ Anton Ageev <antage@gmail.com>
data/ext/postgres.c CHANGED
@@ -25,11 +25,11 @@
25
25
 
26
26
 
27
27
  #ifdef RUBY_18_COMPAT
28
- #include "st.h"
29
- #include "intern.h"
28
+ #include "st.h"
29
+ #include "intern.h"
30
30
  #else
31
- #include "ruby/st.h"
32
- #include "ruby/intern.h"
31
+ #include "ruby/st.h"
32
+ #include "ruby/intern.h"
33
33
  #endif
34
34
 
35
35
  /* grep '^#define' $(pg_config --includedir)/server/catalog/pg_type.h | grep OID */
@@ -49,27 +49,35 @@ PQserverVersion(const PGconn *conn)
49
49
  #endif /* HAVE_PQSERVERVERSION */
50
50
 
51
51
  #ifndef RHASH_SIZE
52
- #define RHASH_SIZE(x) RHASH((x))->tbl->num_entries
52
+ #define RHASH_SIZE(x) RHASH((x))->tbl->num_entries
53
53
  #endif /* RHASH_SIZE */
54
54
 
55
55
  #ifndef RSTRING_LEN
56
- #define RSTRING_LEN(x) RSTRING((x))->len
56
+ #define RSTRING_LEN(x) RSTRING((x))->len
57
57
  #endif /* RSTRING_LEN */
58
58
 
59
59
  #ifndef RSTRING_PTR
60
- #define RSTRING_PTR(x) RSTRING((x))->ptr
60
+ #define RSTRING_PTR(x) RSTRING((x))->ptr
61
61
  #endif /* RSTRING_PTR */
62
62
 
63
+ #ifndef RARRAY_LEN
64
+ #define RARRAY_LEN(x) RARRAY((x))->len
65
+ #endif /* RARRAY_LEN */
66
+
67
+ #ifndef RARRAY_PTR
68
+ #define RARRAY_PTR(x) RARRAY((x))->ptr
69
+ #endif /* RARRAY_PTR */
70
+
63
71
  #ifndef HAVE_PG_ENCODING_TO_CHAR
64
- #define pg_encoding_to_char(x) "SQL_ASCII"
72
+ #define pg_encoding_to_char(x) "SQL_ASCII"
65
73
  #endif
66
74
 
67
75
  #ifndef HAVE_PQFREEMEM
68
- #define PQfreemem(ptr) free(ptr)
76
+ #define PQfreemem(ptr) free(ptr)
69
77
  #endif
70
78
 
71
79
  #ifndef StringValuePtr
72
- #define StringValuePtr(x) STR2CSTR(x)
80
+ #define StringValuePtr(x) STR2CSTR(x)
73
81
  #endif
74
82
 
75
83
  #define AssignCheckedStringValue(cstring, rstring) do { \
@@ -80,7 +88,7 @@ PQserverVersion(const PGconn *conn)
80
88
  } while (0)
81
89
 
82
90
  #if RUBY_VERSION_CODE < 180
83
- #define rb_check_string_type(x) rb_check_convert_type(x, T_STRING, "String", "to_str")
91
+ #define rb_check_string_type(x) rb_check_convert_type(x, T_STRING, "String", "to_str")
84
92
  #endif
85
93
 
86
94
  #define rb_check_hash_type(x) rb_check_convert_type(x, T_HASH, "Hash", "to_hash")
@@ -197,11 +205,7 @@ pgconn_connect(argc, argv, self)
197
205
  PGconn *conn = NULL;
198
206
 
199
207
  rb_scan_args(argc, argv, "0*", &args);
200
- #ifdef RUBY_18_COMPAT
201
- if (RARRAY(args)->len == 1) {
202
- #else
203
208
  if (RARRAY_LEN(args) == 1) {
204
- #endif
205
209
  conn = try_connectdb(rb_ary_entry(args, 0));
206
210
  }
207
211
  if (conn == NULL) {
@@ -729,26 +733,14 @@ pgconn_exec(argc, argv, obj)
729
733
 
730
734
  Check_Type(command, T_STRING);
731
735
 
732
- #ifdef RUBY_18_COMPAT
733
- if (RARRAY(params)->len <= 0) {
734
- #else
735
736
  if (RARRAY_LEN(params) <= 0) {
736
- #endif
737
737
  result = PQexec(conn, StringValuePtr(command));
738
738
  }
739
739
  else {
740
- #ifdef RUBY_18_COMPAT
741
- int len = RARRAY(params)->len;
742
- #else
743
740
  int len = RARRAY_LEN(params);
744
- #endif
745
741
  int i;
746
742
  #ifdef HAVE_PQEXECPARAMS
747
- #ifdef RUBY_18_COMPAT
748
- VALUE* ptr = RARRAY(params)->ptr;
749
- #else
750
743
  VALUE* ptr = RARRAY_PTR(params);
751
- #endif
752
744
  char const** values = ALLOCA_N(char const*, len);
753
745
  int* lengths = ALLOCA_N(int, len);
754
746
  int* formats = ALLOCA_N(int, len);
@@ -968,17 +960,9 @@ pgconn_insert_table(obj, table, values)
968
960
 
969
961
  Check_Type(table, T_STRING);
970
962
  Check_Type(values, T_ARRAY);
971
- #ifdef RUBY_18_COMPAT
972
- i = RARRAY(values)->len;
973
- #else
974
963
  i = RARRAY_LEN(values);
975
- #endif
976
964
  while (i--) {
977
- #ifdef RUBY_18_COMPAT
978
- if (TYPE(RARRAY(RARRAY(values)->ptr[i])) != T_ARRAY) {
979
- #else
980
965
  if (TYPE(RARRAY(RARRAY_PTR(values)[i])) != T_ARRAY) {
981
- #endif
982
966
  rb_raise(rb_ePGError, "second arg must contain some kind of arrays.");
983
967
  }
984
968
  }
@@ -993,32 +977,15 @@ pgconn_insert_table(obj, table, values)
993
977
  }
994
978
  PQclear(result);
995
979
 
996
- #ifdef RUBY_18_COMPAT
997
- for (i = 0; i < RARRAY(values)->len; i++) {
998
- struct RArray *row = RARRAY(RARRAY(values)->ptr[i]);
999
- #else
1000
980
  for (i = 0; i < RARRAY_LEN(values); i++) {
1001
981
  struct RArray *row = RARRAY(RARRAY_PTR(values)[i]);
1002
- #endif
1003
982
  buffer = rb_tainted_str_new(0,0);
1004
- #ifdef RUBY_18_COMPAT
1005
- for (j = 0; j < row->len; j++) {
1006
- #else
1007
983
  for (j = 0; j < RARRAY_LEN(row); j++) {
1008
- #endif
1009
984
  if (j > 0) rb_str_cat(buffer, "\t", 1);
1010
- #ifdef RUBY_18_COMPAT
1011
- if (NIL_P(row->ptr[j])) {
1012
- #else
1013
985
  if (NIL_P(RARRAY_PTR(row)[j])) {
1014
- #endif
1015
986
  rb_str_cat(buffer, "\\N",2);
1016
987
  } else {
1017
- #ifdef RUBY_18_COMPAT
1018
- s = rb_obj_as_string(row->ptr[j]);
1019
- #else
1020
988
  s = rb_obj_as_string(RARRAY_PTR(row)[j]);
1021
- #endif
1022
989
  rb_funcall(s,pg_gsub_bang_id,2,
1023
990
  rb_str_new("([\\t\\n\\\\])", 10),pg_escape_str);
1024
991
  rb_str_cat(buffer, StringValuePtr(s), RSTRING_LEN(s));
@@ -1536,11 +1503,7 @@ fetch_pgrow(self, fields, row_num)
1536
1503
  PGresult *result = get_pgresult(self);
1537
1504
  VALUE row = rb_funcall(rb_cPGrow, rb_intern("new"), 1, fields);
1538
1505
  int field_num;
1539
- #ifdef RUBY_18_COMPAT
1540
- for (field_num = 0; field_num < RARRAY(fields)->len; field_num++) {
1541
- #else
1542
1506
  for (field_num = 0; field_num < RARRAY_LEN(fields); field_num++) {
1543
- #endif
1544
1507
  /* don't use push, PGrow is sized with nils in #new */
1545
1508
  rb_ary_store(row, field_num, fetch_pgresult(result, row_num, field_num));
1546
1509
  }
@@ -2475,11 +2438,7 @@ static VALUE
2475
2438
  pgrow_init(self, keys)
2476
2439
  VALUE self, keys;
2477
2440
  {
2478
- #ifdef RUBY_18_COMPAT
2479
- VALUE args[1] = { LONG2NUM(RARRAY(keys)->len) };
2480
- #else
2481
2441
  VALUE args[1] = { LONG2NUM(RARRAY_LEN(keys)) };
2482
- #endif
2483
2442
  rb_call_super(1, args);
2484
2443
  rb_iv_set(self, "@keys", keys);
2485
2444
  return self;
@@ -2563,11 +2522,7 @@ pgrow_each_pair(self)
2563
2522
  {
2564
2523
  VALUE keys = pgrow_keys(self);
2565
2524
  int i;
2566
- #ifdef RUBY_18_COMPAT
2567
- for (i = 0; i < RARRAY(keys)->len; ++i) {
2568
- #else
2569
2525
  for (i = 0; i < RARRAY_LEN(keys); ++i) {
2570
- #endif
2571
2526
  rb_yield(rb_assoc_new(rb_ary_entry(keys, i), rb_ary_entry(self, i)));
2572
2527
  }
2573
2528
  return self;
@@ -2622,11 +2577,7 @@ pgrow_to_hash(self)
2622
2577
  VALUE result = rb_hash_new();
2623
2578
  VALUE keys = pgrow_keys(self);
2624
2579
  int i;
2625
- #ifdef RUBY_18_COMPAT
2626
- for (i = 0; i < RARRAY(self)->len; ++i) {
2627
- #else
2628
2580
  for (i = 0; i < RARRAY_LEN(self); ++i) {
2629
- #endif
2630
2581
  rb_hash_aset(result, rb_ary_entry(keys, i), rb_ary_entry(self, i));
2631
2582
  }
2632
2583
  return result;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: antage-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9.2009.05.12
4
+ version: 0.7.9.2009.05.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2009-05-12 00:00:00 -07:00
17
+ date: 2009-05-13 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies: []
20
20