extralite 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fa0672decf076e478bfd52359196baecbcf837e00cec91c7f9cf963b103af68
4
- data.tar.gz: e54364225b96fc355a8198eab73c7a27848a672e04479a7eed06f724991ae238
3
+ metadata.gz: 89b99ba7c6d26fc887574bf943f8e07f4c27f0c058a99723be73d7b64a90b3d5
4
+ data.tar.gz: 41c9bc62b91d78d0507d58b6a3e150608aae813b7b929410f23b0389a8b8c98f
5
5
  SHA512:
6
- metadata.gz: 9606a7e0154d61adc29150161a44018638f7e05a3c17f4f8e8b992e166ad0cd46705cb4eab2e9e6f7cc7f4d9eece8406e468822ff8a84116ff6f58cc493a89dd
7
- data.tar.gz: fa5e4e1425187986ec097990f84ae103428645f94caaa41471305b414c78f15fb9522311b4eb50d40bc91c715f9e20e1c2fac18c0fd02892b41e75994602691d
6
+ metadata.gz: 6c29b92468cdf3a2fe9f65088c579a901ff981b11c68d8dc32c99508c4ab7fae5a8d9a348e2310dcf18b0980edac9f3503889de76e097c6d27c6c3fb20480245
7
+ data.tar.gz: 49c703000e9285cff90dadd0d64f40690d96a6f6c59305021dca0561d41aff6fedcc64a4918ce16337acbb7537fd91c73f2b1d65953cdff8be591773844c3465
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.6 2021-05-25
2
+
3
+ - Add more specific errors: `SQLError`, `BusyError`
4
+
1
5
  ## 0.5 2021-05-25
2
6
 
3
7
  - Implement `Database#query_single_row`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- extralite (0.5)
4
+ extralite (0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -11,6 +11,7 @@ class with a minimal set of methods to interact with an SQLite3 database.
11
11
  - Parameter binding.
12
12
  - Get last insert rowid.
13
13
  - Get number of rows changed by last query.
14
+ - Load extensions.
14
15
 
15
16
  ### Usage
16
17
 
@@ -35,7 +36,7 @@ db.query_ary('select 1, 2, 3') { |r| p r }
35
36
  # [1, 2, 3]
36
37
 
37
38
  # get a single row as a hash
38
- db.query_single_column("select 1 as foo") #=> { :foo => 1 }
39
+ db.query_single_row("select 1 as foo") #=> { :foo => 1 }
39
40
 
40
41
  # get single column query results as array of values
41
42
  db.query_single_column('select 42') #=> [42]
@@ -3,6 +3,8 @@
3
3
  #include "../sqlite3/sqlite3.h"
4
4
 
5
5
  VALUE cError;
6
+ VALUE cSQLError;
7
+ VALUE cBusyError;
6
8
  ID ID_STRIP;
7
9
 
8
10
  typedef struct Database_t {
@@ -145,7 +147,7 @@ inline void prepare_multi_stmt(sqlite3 *db, sqlite3_stmt **stmt, VALUE sql) {
145
147
  int rc = sqlite3_prepare(db, ptr, end - ptr, stmt, &rest);
146
148
  if (rc) {
147
149
  sqlite3_finalize(*stmt);
148
- rb_raise(cError, "%s", sqlite3_errmsg(db));
150
+ rb_raise(cSQLError, "%s", sqlite3_errmsg(db));
149
151
  }
150
152
 
151
153
  if (rest == end) return;
@@ -155,9 +157,9 @@ inline void prepare_multi_stmt(sqlite3 *db, sqlite3_stmt **stmt, VALUE sql) {
155
157
  sqlite3_finalize(*stmt);
156
158
  switch (rc) {
157
159
  case SQLITE_BUSY:
158
- rb_raise(cError, "Database is busy");
160
+ rb_raise(cBusyError, "Database is busy");
159
161
  case SQLITE_ERROR:
160
- rb_raise(cError, "%s", sqlite3_errmsg(db));
162
+ rb_raise(cSQLError, "%s", sqlite3_errmsg(db));
161
163
  }
162
164
  ptr = rest;
163
165
  }
@@ -199,10 +201,10 @@ step:
199
201
  break;
200
202
  case SQLITE_BUSY:
201
203
  sqlite3_finalize(stmt);
202
- rb_raise(cError, "Database is busy");
204
+ rb_raise(cBusyError, "Database is busy");
203
205
  case SQLITE_ERROR:
204
206
  sqlite3_finalize(stmt);
205
- rb_raise(cError, "%s", sqlite3_errmsg(db->sqlite3_db));
207
+ rb_raise(cSQLError, "%s", sqlite3_errmsg(db->sqlite3_db));
206
208
  default:
207
209
  sqlite3_finalize(stmt);
208
210
  rb_raise(cError, "Invalid return code for sqlite3_step: %d", rc);
@@ -247,10 +249,10 @@ step:
247
249
  break;
248
250
  case SQLITE_BUSY:
249
251
  sqlite3_finalize(stmt);
250
- rb_raise(cError, "Database is busy");
252
+ rb_raise(cBusyError, "Database is busy");
251
253
  case SQLITE_ERROR:
252
254
  sqlite3_finalize(stmt);
253
- rb_raise(cError, "%s", sqlite3_errmsg(db->sqlite3_db));
255
+ rb_raise(cSQLError, "%s", sqlite3_errmsg(db->sqlite3_db));
254
256
  default:
255
257
  sqlite3_finalize(stmt);
256
258
  rb_raise(cError, "Invalid return code for sqlite3_step: %d", rc);
@@ -289,9 +291,9 @@ VALUE Database_query_single_row(int argc, VALUE *argv, VALUE self) {
289
291
  case SQLITE_DONE:
290
292
  break;
291
293
  case SQLITE_BUSY:
292
- rb_raise(cError, "Database is busy");
294
+ rb_raise(cBusyError, "Database is busy");
293
295
  case SQLITE_ERROR:
294
- rb_raise(cError, "%s", sqlite3_errmsg(db->sqlite3_db));
296
+ rb_raise(cSQLError, "%s", sqlite3_errmsg(db->sqlite3_db));
295
297
  default:
296
298
  rb_raise(cError, "Invalid return code for sqlite3_step: %d", rc);
297
299
  }
@@ -337,10 +339,10 @@ step:
337
339
  break;
338
340
  case SQLITE_BUSY:
339
341
  sqlite3_finalize(stmt);
340
- rb_raise(cError, "Database is busy");
342
+ rb_raise(cBusyError, "Database is busy");
341
343
  case SQLITE_ERROR:
342
344
  sqlite3_finalize(stmt);
343
- rb_raise(cError, "%s", sqlite3_errmsg(db->sqlite3_db));
345
+ rb_raise(cSQLError, "%s", sqlite3_errmsg(db->sqlite3_db));
344
346
  default:
345
347
  sqlite3_finalize(stmt);
346
348
  rb_raise(cError, "Invalid return code for sqlite3_step: %d", rc);
@@ -380,9 +382,9 @@ VALUE Database_query_single_value(int argc, VALUE *argv, VALUE self) {
380
382
  case SQLITE_DONE:
381
383
  break;
382
384
  case SQLITE_BUSY:
383
- rb_raise(cError, "Database is busy");
385
+ rb_raise(cBusyError, "Database is busy");
384
386
  case SQLITE_ERROR:
385
- rb_raise(cError, "%s", sqlite3_errmsg(db->sqlite3_db));
387
+ rb_raise(cSQLError, "%s", sqlite3_errmsg(db->sqlite3_db));
386
388
  default:
387
389
  rb_raise(cError, "Invalid return code for sqlite3_step: %d", rc);
388
390
  }
@@ -461,5 +463,8 @@ void Init_Extralite() {
461
463
  rb_define_method(cDatabase, "load_extension", Database_load_extension, 1);
462
464
 
463
465
  cError = rb_define_class_under(mExtralite, "Error", rb_eRuntimeError);
466
+ cSQLError = rb_define_class_under(mExtralite, "SQLError", cError);
467
+ cBusyError = rb_define_class_under(mExtralite, "BusyError", cError);
468
+
464
469
  ID_STRIP = rb_intern("strip");
465
470
  }
@@ -1,3 +1,3 @@
1
1
  module Extralite
2
- VERSION = '0.5'
2
+ VERSION = '0.6'
3
3
  end
@@ -24,6 +24,10 @@ class DatabaseTest < MiniTest::Test
24
24
  assert_equal [], r
25
25
  end
26
26
 
27
+ def test_invalid_query
28
+ assert_raises(Extralite::SQLError) { @db.query('blah') }
29
+ end
30
+
27
31
  def test_query_hash
28
32
  r = @db.query_hash('select * from t')
29
33
  assert_equal [{x: 1, y: 2, z: 3}, {x: 4, y: 5, z: 6}], r
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extralite
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner