swift-db-postgres 0.1.1 → 0.1.2

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.1.2 (2012-07-29)
2
+
3
+ * gc guard bind parameters during execute.
4
+
1
5
  == 0.1.1 (2012-07-26)
2
6
 
3
7
  * Updated compile flags.
@@ -70,7 +70,7 @@ VALUE db_postgres_adapter_initialize(VALUE self, VALUE options) {
70
70
 
71
71
  db = rb_hash_aref(options, ID2SYM(rb_intern("db")));
72
72
  user = rb_hash_aref(options, ID2SYM(rb_intern("user")));
73
- pass = rb_hash_aref(options, ID2SYM(rb_intern("pass")));
73
+ pass = rb_hash_aref(options, ID2SYM(rb_intern("password")));
74
74
  host = rb_hash_aref(options, ID2SYM(rb_intern("host")));
75
75
  port = rb_hash_aref(options, ID2SYM(rb_intern("port")));
76
76
  ssl = rb_hash_aref(options, ID2SYM(rb_intern("ssl")));
@@ -137,6 +137,7 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
137
137
  bind_args_fmt = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
138
138
  bind_args_data = (char **) malloc(sizeof(char *) * RARRAY_LEN(bind));
139
139
 
140
+ rb_gc_register_address(&bind);
140
141
  for (n = 0; n < RARRAY_LEN(bind); n++) {
141
142
  data = rb_ary_entry(bind, n);
142
143
  if (NIL_P(data)) {
@@ -166,6 +167,7 @@ VALUE db_postgres_adapter_execute(int argc, VALUE *argv, VALUE self) {
166
167
  };
167
168
 
168
169
  pg_result = (PGresult *)rb_thread_blocking_region(nogvl_pq_exec_params, &q, RUBY_UBF_IO, 0);
170
+ rb_gc_unregister_address(&bind);
169
171
  free(bind_args_size);
170
172
  free(bind_args_data);
171
173
  free(bind_args_fmt);
@@ -110,6 +110,7 @@ VALUE db_postgres_statement_execute(int argc, VALUE *argv, VALUE self) {
110
110
  bind_args_fmt = (int *) malloc(sizeof(int) * RARRAY_LEN(bind));
111
111
  bind_args_data = (char **) malloc(sizeof(char *) * RARRAY_LEN(bind));
112
112
 
113
+ rb_gc_register_address(&bind);
113
114
  for (n = 0; n < RARRAY_LEN(bind); n++) {
114
115
  data = rb_ary_entry(bind, n);
115
116
  if (NIL_P(data)) {
@@ -138,6 +139,7 @@ VALUE db_postgres_statement_execute(int argc, VALUE *argv, VALUE self) {
138
139
  };
139
140
 
140
141
  result = (PGresult *)rb_thread_blocking_region(nogvl_pq_exec_prepared, &q, RUBY_UBF_IO, 0);
142
+ rb_gc_unregister_address(&bind);
141
143
  free(bind_args_fmt);
142
144
  free(bind_args_size);
143
145
  free(bind_args_data);
data/test/test_adapter.rb CHANGED
@@ -46,6 +46,9 @@ require 'helper'
46
46
  result = db.execute('select * from users')
47
47
  assert_equal %w(id name age created_at).map(&:to_sym), result.fields
48
48
  assert_equal %w(integer text integer timestamp), result.types
49
+
50
+ # like query
51
+ assert db.execute('select * from users where name like ?', '%foo%')
49
52
  end
50
53
 
51
54
  it 'should close handle' do
@@ -105,4 +108,20 @@ require 'helper'
105
108
  assert_raises(Swift::RuntimeError) { db.write("users", "bar") }
106
109
  assert_raises(Swift::RuntimeError) { db.write("users", %w(name), "bar") }
107
110
  end
111
+
112
+ # TODO
113
+ it 'should not change the hstore ? operator' do
114
+ skip
115
+ assert db.execute('create extension if not exists hstore')
116
+ assert db.execute('drop table if exists hstore_test')
117
+ assert db.execute('create table hstore_test(id int, payload hstore)')
118
+ assert db.execute('insert into hstore_test values(1, ?)', 'a => 1, b => 2')
119
+
120
+ assert_equal 1, db.execute('select * from hstore_test where payload ? $1', 'a').selected_rows
121
+ assert_equal 0, db.execute('select * from hstore_test where payload ? $1', 'c').selected_rows
122
+ assert_equal 1, db.execute('select * from hstore_test where payload ? ?', 'a').selected_rows
123
+
124
+ assert_equal 1, db.execute('select * from hstore_test where payload ?| ARRAY[?, ?]', 'a', 'b').selected_rows
125
+ assert_equal 1, db.execute('select * from hstore_test where payload ?& ARRAY[?, ?]', 'a', 'b').selected_rows
126
+ end
108
127
  end
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.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-26 00:00:00.000000000 Z
12
+ date: 2012-07-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -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/result.c
40
- - ext/swift/db/postgres/common.c
41
- - ext/swift/db/postgres/typecast.c
42
39
  - ext/swift/db/postgres/statement.c
43
- - ext/swift/db/postgres/adapter.c
40
+ - ext/swift/db/postgres/typecast.c
41
+ - ext/swift/db/postgres/common.c
44
42
  - ext/swift/db/postgres/main.c
43
+ - ext/swift/db/postgres/result.c
44
+ - ext/swift/db/postgres/adapter.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
@@ -52,8 +52,8 @@ files:
52
52
  - test/test_ssl.rb
53
53
  - test/test_adapter.rb
54
54
  - test/test_encoding.rb
55
- - test/helper.rb
56
55
  - test/test_async.rb
56
+ - test/helper.rb
57
57
  - lib/swift/db/postgres.rb
58
58
  - lib/swift-db-postgres.rb
59
59
  - README.md
@@ -84,4 +84,3 @@ signing_key:
84
84
  specification_version: 3
85
85
  summary: Swift postgres adapter
86
86
  test_files: []
87
- has_rdoc: