extralite 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -1
- data/ext/extralite/extralite.c +18 -13
- data/lib/extralite/version.rb +1 -1
- data/test/test_database.rb +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89b99ba7c6d26fc887574bf943f8e07f4c27f0c058a99723be73d7b64a90b3d5
|
4
|
+
data.tar.gz: 41c9bc62b91d78d0507d58b6a3e150608aae813b7b929410f23b0389a8b8c98f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c29b92468cdf3a2fe9f65088c579a901ff981b11c68d8dc32c99508c4ab7fae5a8d9a348e2310dcf18b0980edac9f3503889de76e097c6d27c6c3fb20480245
|
7
|
+
data.tar.gz: 49c703000e9285cff90dadd0d64f40690d96a6f6c59305021dca0561d41aff6fedcc64a4918ce16337acbb7537fd91c73f2b1d65953cdff8be591773844c3465
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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.
|
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]
|
data/ext/extralite/extralite.c
CHANGED
@@ -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(
|
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(
|
160
|
+
rb_raise(cBusyError, "Database is busy");
|
159
161
|
case SQLITE_ERROR:
|
160
|
-
rb_raise(
|
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(
|
204
|
+
rb_raise(cBusyError, "Database is busy");
|
203
205
|
case SQLITE_ERROR:
|
204
206
|
sqlite3_finalize(stmt);
|
205
|
-
rb_raise(
|
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(
|
252
|
+
rb_raise(cBusyError, "Database is busy");
|
251
253
|
case SQLITE_ERROR:
|
252
254
|
sqlite3_finalize(stmt);
|
253
|
-
rb_raise(
|
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(
|
294
|
+
rb_raise(cBusyError, "Database is busy");
|
293
295
|
case SQLITE_ERROR:
|
294
|
-
rb_raise(
|
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(
|
342
|
+
rb_raise(cBusyError, "Database is busy");
|
341
343
|
case SQLITE_ERROR:
|
342
344
|
sqlite3_finalize(stmt);
|
343
|
-
rb_raise(
|
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(
|
385
|
+
rb_raise(cBusyError, "Database is busy");
|
384
386
|
case SQLITE_ERROR:
|
385
|
-
rb_raise(
|
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
|
}
|
data/lib/extralite/version.rb
CHANGED
data/test/test_database.rb
CHANGED
@@ -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
|