swift-db-sqlite3 0.1.0 → 0.1.1

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.1.1 (2012-07-26)
2
+
3
+ * Type parsing should be case insensitive.
4
+
1
5
  == 0.1.0 (2012-07-20)
2
6
 
3
7
  * Initial version.
data/README.md CHANGED
@@ -20,6 +20,7 @@ MRI adapter for sqlite3 for use in Swift ORM.
20
20
  #commit(savepoint = nil)
21
21
  #rollback(savepoint = nil)
22
22
  #transaction(savepoint = nil, &block)
23
+ #ping
23
24
  #close
24
25
  #closed?
25
26
  #escape(text)
@@ -60,6 +61,11 @@ Don't read too much into it. Each library has its advantages and disadvantages.
60
61
  ```
61
62
  # insert 1000 rows and read them back 100 times with typecasting enabled.
62
63
 
64
+ $ ruby -v
65
+
66
+ ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
67
+
68
+ $ ruby check.rb
63
69
  user system total real
64
70
  do_sqlite3 insert 0.050000 0.020000 0.070000 ( 0.062814)
65
71
  do_sqlite3 select 0.720000 0.000000 0.720000 ( 0.723628)
@@ -205,6 +205,11 @@ VALUE db_sqlite3_adapter_closed_q(VALUE self) {
205
205
  return a->connection ? Qfalse : Qtrue;
206
206
  }
207
207
 
208
+ VALUE db_sqlite3_adapter_ping(VALUE self) {
209
+ Adapter *a = db_sqlite3_adapter_handle(self);
210
+ return a->connection ? Qtrue : Qfalse;
211
+ }
212
+
208
213
  VALUE db_sqlite3_adapter_escape(VALUE self, VALUE text) {
209
214
  VALUE escaped;
210
215
  Adapter *a = db_sqlite3_adapter_handle_safe(self);
@@ -225,6 +230,7 @@ void init_swift_db_sqlite3_adapter() {
225
230
  rb_define_method(cDSA, "commit", db_sqlite3_adapter_commit, -1);
226
231
  rb_define_method(cDSA, "rollback", db_sqlite3_adapter_rollback, -1);
227
232
  rb_define_method(cDSA, "transaction", db_sqlite3_adapter_transaction, -1);
233
+ rb_define_method(cDSA, "ping", db_sqlite3_adapter_ping, 0);
228
234
  rb_define_method(cDSA, "close", db_sqlite3_adapter_close, 0);
229
235
  rb_define_method(cDSA, "closed?", db_sqlite3_adapter_closed_q, 0);
230
236
  rb_define_method(cDSA, "escape", db_sqlite3_adapter_escape, 1);
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'mkmf'
4
4
 
5
+ $CFLAGS = '-std=c99 -Os'
6
+
5
7
  find_library('sqlite3', 'main', '/usr/lib /usr/local/lib /opt/lib /opt/local/lib')
6
8
  find_library('uuid', 'main', '/usr/lib /usr/local/lib /opt/lib /opt/local/lib')
7
9
  create_makefile('swift_db_sqlite3_ext')
@@ -118,7 +118,7 @@ VALUE db_sqlite3_result_consume(VALUE self) {
118
118
  }
119
119
 
120
120
  for (i = 0; i < (int)ntypes; i++) {
121
- if (strcmp(type, types[i].definition) == 0 || types[i].value == SWIFT_TYPE_UNKNOWN) {
121
+ if (strcasecmp(type, types[i].definition) == 0 || types[i].value == SWIFT_TYPE_UNKNOWN) {
122
122
  rb_ary_push(r->types, INT2NUM(types[i].value));
123
123
  break;
124
124
  }
@@ -183,6 +183,7 @@ VALUE db_sqlite3_result_each(VALUE self) {
183
183
 
184
184
  if (!r->rows) return Qnil;
185
185
 
186
+ rb_gc_register_address(&r->rows);
186
187
  for (n = 0; n < RARRAY_LEN(r->rows); n++) {
187
188
  VALUE tuple = rb_hash_new();
188
189
  VALUE row = rb_ary_entry(r->rows, n);
@@ -190,6 +191,7 @@ VALUE db_sqlite3_result_each(VALUE self) {
190
191
  rb_hash_aset(tuple, rb_ary_entry(r->fields, f), rb_ary_entry(row, f));
191
192
  rb_yield(tuple);
192
193
  }
194
+ rb_gc_unregister_address(&r->rows);
193
195
  }
194
196
 
195
197
  VALUE db_sqlite3_result_selected_rows(VALUE self) {
data/test/test_adapter.rb CHANGED
@@ -43,9 +43,11 @@ describe 'sqlite3 adapter' do
43
43
  end
44
44
 
45
45
  it 'should close handle' do
46
+ assert db.ping
46
47
  assert !db.closed?
47
48
  assert db.close
48
49
  assert db.closed?
50
+ assert !db.ping
49
51
 
50
52
  assert_raises(Swift::ConnectionError) { db.execute("select * from users") }
51
53
  end
@@ -65,4 +67,11 @@ describe 'sqlite3 adapter' do
65
67
  it 'should escape whatever' do
66
68
  assert_equal "foo''bar", db.escape("foo'bar")
67
69
  end
70
+
71
+ it 'should parse types in a case-insensitive manner' do
72
+ assert db.execute("create table users(id INT, name text)")
73
+ assert db.execute("insert into users (id, name) values (?, ?)", 1, "test")
74
+
75
+ assert_equal 1, db.execute("select * from users").first[:id]
76
+ end
68
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift-db-sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-20 00:00:00.000000000 Z
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -35,13 +35,13 @@ extensions:
35
35
  - ext/swift/db/sqlite3/extconf.rb
36
36
  extra_rdoc_files: []
37
37
  files:
38
- - ext/swift/db/sqlite3/adapter.c
38
+ - ext/swift/db/sqlite3/statement.c
39
+ - ext/swift/db/sqlite3/result.c
39
40
  - ext/swift/db/sqlite3/datetime.c
40
41
  - ext/swift/db/sqlite3/typecast.c
41
42
  - ext/swift/db/sqlite3/common.c
42
43
  - ext/swift/db/sqlite3/main.c
43
- - ext/swift/db/sqlite3/statement.c
44
- - ext/swift/db/sqlite3/result.c
44
+ - ext/swift/db/sqlite3/adapter.c
45
45
  - ext/swift/db/sqlite3/adapter.h
46
46
  - ext/swift/db/sqlite3/statement.h
47
47
  - ext/swift/db/sqlite3/typecast.h