swift-db-postgres 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.2 (2012-07-30)
2
+
3
+ * removed rb_gc_mark called outside mark phase.
4
+
1
5
  == 0.2.1 (2012-07-30)
2
6
 
3
7
  * rb_protect yielding result tuples.
@@ -39,7 +39,6 @@ VALUE db_postgres_adapter_deallocate(Adapter *a) {
39
39
 
40
40
  VALUE db_postgres_adapter_allocate(VALUE klass) {
41
41
  Adapter *a = (Adapter*)malloc(sizeof(Adapter));
42
-
43
42
  memset(a, 0, sizeof(Adapter));
44
43
  return Data_Wrap_Struct(klass, 0, db_postgres_adapter_deallocate, a);
45
44
  }
@@ -125,7 +124,7 @@ VALUE nogvl_pq_exec_params(void *ptr) {
125
124
  VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
126
125
  char **bind_args_data = 0;
127
126
  int n, *bind_args_size = 0, *bind_args_fmt = 0;
128
- PGresult *pg_result;
127
+ PGresult *result;
129
128
  VALUE sql, bind, data;
130
129
  Adapter *a = db_postgres_adapter_handle_safe(self);
131
130
 
@@ -167,7 +166,7 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
167
166
  .format = bind_args_fmt
168
167
  };
169
168
 
170
- pg_result = (PGresult *)rb_thread_blocking_region(nogvl_pq_exec_params, &q, RUBY_UBF_IO, 0);
169
+ result = (PGresult *)rb_thread_blocking_region(nogvl_pq_exec_params, &q, RUBY_UBF_IO, 0);
171
170
  rb_gc_unregister_address(&bind);
172
171
  free(bind_args_size);
173
172
  free(bind_args_data);
@@ -175,11 +174,11 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
175
174
  }
176
175
  else {
177
176
  Query q = {.connection = a->connection, .command = CSTRING(sql)};
178
- pg_result = (PGresult *)rb_thread_blocking_region(nogvl_pq_exec, &q, RUBY_UBF_IO, 0);
177
+ result = (PGresult *)rb_thread_blocking_region(nogvl_pq_exec, &q, RUBY_UBF_IO, 0);
179
178
  }
180
179
 
181
- db_postgres_check_result(pg_result);
182
- return db_postgres_result_load(db_postgres_result_allocate(cDPR), pg_result);
180
+ db_postgres_check_result(result);
181
+ return db_postgres_result_load(db_postgres_result_allocate(cDPR), result);
183
182
  }
184
183
 
185
184
  VALUE db_postgres_adapter_begin(int argc, VALUE *argv, VALUE self) {
@@ -11,7 +11,6 @@ typedef struct Result {
11
11
  PGresult *result;
12
12
  VALUE fields;
13
13
  VALUE types;
14
- VALUE rows;
15
14
  size_t selected;
16
15
  size_t affected;
17
16
  size_t insert_id;
@@ -98,6 +97,7 @@ VALUE db_postgres_result_load(VALUE self, PGresult *result) {
98
97
  }
99
98
 
100
99
  VALUE db_postgres_result_each(VALUE self) {
100
+ VALUE tuple;
101
101
  int row, col, status;
102
102
  Result *r = db_postgres_result_handle(self);
103
103
 
@@ -105,7 +105,7 @@ VALUE db_postgres_result_each(VALUE self) {
105
105
  return Qnil;
106
106
 
107
107
  for (row = 0; row < PQntuples(r->result); row++) {
108
- VALUE tuple = rb_hash_new();
108
+ tuple = rb_hash_new();
109
109
  for (col = 0; col < PQnfields(r->result); col++) {
110
110
  if (PQgetisnull(r->result, row, col))
111
111
  rb_hash_aset(tuple, rb_ary_entry(r->fields, col), Qnil);
@@ -121,13 +121,11 @@ VALUE db_postgres_result_each(VALUE self) {
121
121
  );
122
122
  }
123
123
  }
124
- rb_gc_register_address(&tuple);
125
124
  rb_protect(rb_yield, tuple, &status);
126
- rb_gc_unregister_address(&tuple);
127
125
  if (status != 0)
128
126
  rb_jump_tag(status);
129
127
  }
130
- return Qtrue;
128
+ return Qnil;
131
129
  }
132
130
 
133
131
  VALUE db_postgres_result_selected_rows(VALUE self) {
@@ -15,7 +15,7 @@ VALUE db_postgres_result_load(VALUE, PGresult*);
15
15
  Adapter* db_postgres_adapter_handle_safe(VALUE);
16
16
 
17
17
  typedef struct Statement {
18
- char id[64];
18
+ char id[128];
19
19
  VALUE adapter;
20
20
  } Statement;
21
21
 
@@ -57,9 +57,8 @@ VALUE db_postgres_statement_initialize(VALUE self, VALUE adapter, VALUE sql) {
57
57
  Statement *s = db_postgres_statement_handle(self);
58
58
  Adapter *a = db_postgres_adapter_handle_safe(adapter);
59
59
 
60
- snprintf(s->id, 64, "s%s", CSTRING(rb_uuid_string()));
60
+ snprintf(s->id, 128, "s%s", CSTRING(rb_uuid_string()));
61
61
  s->adapter = adapter;
62
- rb_gc_mark(s->adapter);
63
62
 
64
63
  if (!a->native)
65
64
  sql = db_postgres_normalized_sql(sql);
@@ -71,7 +70,7 @@ VALUE db_postgres_statement_initialize(VALUE self, VALUE adapter, VALUE sql) {
71
70
  }
72
71
 
73
72
  VALUE db_postgres_statement_release(VALUE self) {
74
- char command[128];
73
+ char command[256];
75
74
  PGresult *result;
76
75
  PGconn *connection;
77
76
 
@@ -79,7 +78,7 @@ VALUE db_postgres_statement_release(VALUE self) {
79
78
  connection = db_postgres_adapter_handle_safe(s->adapter)->connection;
80
79
 
81
80
  if (connection && PQstatus(connection) == CONNECTION_OK) {
82
- snprintf(command, 128, "deallocate %s", s->id);
81
+ snprintf(command, 256, "deallocate %s", s->id);
83
82
  result = PQexec(connection, command);
84
83
  db_postgres_check_result(result);
85
84
  PQclear(result);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift-db-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -36,12 +36,12 @@ extensions:
36
36
  extra_rdoc_files: []
37
37
  files:
38
38
  - ext/swift/db/postgres/datetime.c
39
- - ext/swift/db/postgres/statement.c
39
+ - ext/swift/db/postgres/result.c
40
40
  - ext/swift/db/postgres/adapter.c
41
41
  - ext/swift/db/postgres/typecast.c
42
42
  - ext/swift/db/postgres/common.c
43
43
  - ext/swift/db/postgres/main.c
44
- - ext/swift/db/postgres/result.c
44
+ - ext/swift/db/postgres/statement.c
45
45
  - ext/swift/db/postgres/typecast.h
46
46
  - ext/swift/db/postgres/common.h
47
47
  - ext/swift/db/postgres/datetime.h