unqlite 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +13 -0
- data/Gemfile +2 -0
- data/README.md +23 -5
- data/ext/unqlite/unqlite_codes.c +3 -3
- data/ext/unqlite/unqlite_database.c +90 -19
- data/ext/unqlite/unqlite_exception.c +87 -0
- data/ext/unqlite/unqlite_exception.h +10 -0
- data/ext/unqlite/unqlite_ruby.h +1 -0
- data/lib/unqlite.rb +1 -0
- data/lib/unqlite/errors.rb +33 -0
- data/lib/unqlite/version.rb +1 -1
- data/test/test_database.rb +65 -5
- data/test/test_errors.rb +36 -0
- data/unqlite.gemspec +5 -5
- metadata +20 -14
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDc2MzhlMjEzMDdmYWZhOWQ0N2EwM2FjNjBjYjE5MzU4MzBkOGNlMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTlmOWViMzNkNWViNjgwY2I3NGE5OGE5NGM4YjY3NGMxODdlY2U4MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTlkODc5NTc2OTA4ZGRjZWNlZWQ3MjhlZWQwMjYyOGJhZTg2MWQxZTk4NjBk
|
10
|
+
OWY3YjBmM2NiYjQ3Y2Y4M2VmNGQ4MWU3ZDZjYjQxM2RkMjg4ODBlODQwMDI3
|
11
|
+
NDRkNjZjNDdmMzI0ZWE2YmVmOWUwOGZlMmM3ZTZhYzRlOWQ3MTA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTJhODNhMTI4ZDlkZTdlYjhjMjAyOWJiZTg4ZGUyNDBjM2Q4YzBhMzNkZWFi
|
14
|
+
MGNkYWU0MWI1N2EzYzg0MzNmNzc4OGZmYjkxODVmODBlOTE0MTFmMTJkYzU1
|
15
|
+
MTYyMzJiYzRlYmZiMTVkYWM5M2EzNGRhNDRjM2FmNjU2YzgxNGI=
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
=== 0.1.0 / 08 Jun 2013
|
2
|
+
|
3
|
+
* Database file support (readonly not supported yet)
|
4
|
+
* Exception handling
|
5
|
+
* Transaction support
|
6
|
+
* API change:
|
7
|
+
* Database#store doesn't return an unqlite_return_code anymore (but still a truthy value).
|
8
|
+
|
9
|
+
=== 0.0.1 / 02 Jun 2013
|
10
|
+
|
11
|
+
* First version
|
12
|
+
* Only basic methods implemented (#new #store #fetch)
|
13
|
+
* Only in-memory database support
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -12,8 +12,9 @@ UnQLite doesn't have a Makefile (or something like that) to automate that step.
|
|
12
12
|
linux, you can check [this gist](https://gist.github.com/danieltdt/5693070) and compile it using gcc.
|
13
13
|
|
14
14
|
After installing UnQLite, add this line to your application's Gemfile:
|
15
|
-
|
16
|
-
|
15
|
+
```ruby
|
16
|
+
gem 'unqlite'
|
17
|
+
```
|
17
18
|
|
18
19
|
And then execute:
|
19
20
|
|
@@ -25,9 +26,26 @@ Or install it yourself as:
|
|
25
26
|
|
26
27
|
## Usage
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
For in-memory databases
|
30
|
+
```ruby
|
31
|
+
db = UnQLite::Database.new(":mem:")
|
32
|
+
db.store("key", "wabba")
|
33
|
+
db.fetch("key") # => "wabba"
|
34
|
+
db.close
|
35
|
+
```
|
36
|
+
|
37
|
+
For regular databases
|
38
|
+
```ruby
|
39
|
+
db = UnQLite::Database.new("database.db") # You may also give a full path
|
40
|
+
db.store("key", "wabba")
|
41
|
+
db.fetch("key") # => "wabba"
|
42
|
+
|
43
|
+
# Now you have to commit your changes or close your database
|
44
|
+
db.commit
|
45
|
+
|
46
|
+
db.store("key2", "wabba2")
|
47
|
+
db.close # Will automatically commit
|
48
|
+
```
|
31
49
|
|
32
50
|
## Contributing
|
33
51
|
|
data/ext/unqlite/unqlite_codes.c
CHANGED
@@ -20,15 +20,15 @@ void Init_unqlite_codes()
|
|
20
20
|
rb_define_const(mUnQLiteCodes, "PERM", INT2FIX(UNQLITE_PERM));
|
21
21
|
rb_define_const(mUnQLiteCodes, "NOTIMPLEMENTED", INT2FIX(UNQLITE_NOTIMPLEMENTED));
|
22
22
|
rb_define_const(mUnQLiteCodes, "NOTFOUND", INT2FIX(UNQLITE_NOTFOUND));
|
23
|
-
rb_define_const(mUnQLiteCodes, "NOOP", INT2FIX(UNQLITE_NOOP));
|
23
|
+
rb_define_const(mUnQLiteCodes, "NOOP", INT2FIX(UNQLITE_NOOP)); // Used only for jx9 (unqlite v1.1.6)
|
24
24
|
rb_define_const(mUnQLiteCodes, "INVALID", INT2FIX(UNQLITE_INVALID));
|
25
25
|
rb_define_const(mUnQLiteCodes, "EOF", INT2FIX(UNQLITE_EOF));
|
26
26
|
rb_define_const(mUnQLiteCodes, "UNKNOWN", INT2FIX(UNQLITE_UNKNOWN));
|
27
27
|
rb_define_const(mUnQLiteCodes, "LIMIT", INT2FIX(UNQLITE_LIMIT));
|
28
28
|
rb_define_const(mUnQLiteCodes, "EXISTS", INT2FIX(UNQLITE_EXISTS));
|
29
29
|
rb_define_const(mUnQLiteCodes, "EMPTY", INT2FIX(UNQLITE_EMPTY));
|
30
|
-
rb_define_const(mUnQLiteCodes, "COMPILE_ERR", INT2FIX(UNQLITE_COMPILE_ERR));
|
31
|
-
rb_define_const(mUnQLiteCodes, "VM_ERR", INT2FIX(UNQLITE_VM_ERR));
|
30
|
+
rb_define_const(mUnQLiteCodes, "COMPILE_ERR", INT2FIX(UNQLITE_COMPILE_ERR)); // Used only for jx9 (unqlite v1.1.6)
|
31
|
+
rb_define_const(mUnQLiteCodes, "VM_ERR", INT2FIX(UNQLITE_VM_ERR)); // Used only for jx9 (unqlite v1.1.6)
|
32
32
|
rb_define_const(mUnQLiteCodes, "FULL", INT2FIX(UNQLITE_FULL));
|
33
33
|
rb_define_const(mUnQLiteCodes, "CANTOPEN", INT2FIX(UNQLITE_CANTOPEN));
|
34
34
|
rb_define_const(mUnQLiteCodes, "READ_ONLY", INT2FIX(UNQLITE_READ_ONLY));
|
@@ -36,20 +36,33 @@ static VALUE initialize(VALUE self, VALUE rb_string)
|
|
36
36
|
memcpy(c_string, StringValuePtr(rb_string), RSTRING_LEN(rb_string));
|
37
37
|
|
38
38
|
// Open database
|
39
|
-
// TODO:
|
40
|
-
rc = unqlite_open(&ctx->pDb, c_string,
|
39
|
+
// TODO: Accept others open mode (read-only + mmap, etc. Check http://unqlite.org/c_api/unqlite_open.html)
|
40
|
+
rc = unqlite_open(&ctx->pDb, c_string, UNQLITE_OPEN_CREATE);
|
41
41
|
|
42
|
-
//
|
43
|
-
|
44
|
-
// TODO: Return error code with a better message raising a UnQLite exception.
|
45
|
-
rb_raise(rb_eRuntimeError, "Couldn't open database");
|
46
|
-
|
47
|
-
return self;
|
48
|
-
}
|
42
|
+
// Check if any exception should be raised
|
43
|
+
CHECK(ctx->pDb, rc);
|
49
44
|
|
50
45
|
return self;
|
51
46
|
}
|
52
47
|
|
48
|
+
static VALUE unqlite_database_close(VALUE self)
|
49
|
+
{
|
50
|
+
int rc;
|
51
|
+
unqliteRubyPtr ctx;
|
52
|
+
|
53
|
+
// Get class context
|
54
|
+
Data_Get_Struct(self, unqliteRuby, ctx);
|
55
|
+
|
56
|
+
// Close database
|
57
|
+
rc = unqlite_close(ctx->pDb);
|
58
|
+
|
59
|
+
// Check for errors
|
60
|
+
CHECK(ctx->pDb, rc);
|
61
|
+
|
62
|
+
return Qtrue;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
53
66
|
static VALUE unqlite_database_store(VALUE self, VALUE key, VALUE value)
|
54
67
|
{
|
55
68
|
void *c_key;
|
@@ -71,15 +84,13 @@ static VALUE unqlite_database_store(VALUE self, VALUE key, VALUE value)
|
|
71
84
|
c_value = calloc(RSTRING_LEN(value), sizeof(char));
|
72
85
|
memcpy(c_value, StringValuePtr(value), RSTRING_LEN(value));
|
73
86
|
|
87
|
+
// Store it
|
74
88
|
rc = unqlite_kv_store(ctx->pDb, c_key, -1, c_value, sizeof(c_value));
|
75
89
|
|
76
|
-
|
77
|
-
|
78
|
-
unqlite_rollback(ctx->pDb);
|
79
|
-
}
|
80
|
-
}
|
90
|
+
// Check for errors
|
91
|
+
CHECK(ctx->pDb, rc);
|
81
92
|
|
82
|
-
return
|
93
|
+
return Qtrue;
|
83
94
|
}
|
84
95
|
|
85
96
|
static VALUE unqlite_database_fetch(VALUE self, VALUE collection_name)
|
@@ -100,16 +111,71 @@ static VALUE unqlite_database_fetch(VALUE self, VALUE collection_name)
|
|
100
111
|
c_collection_name = calloc(RSTRING_LEN(collection_name), sizeof(char));
|
101
112
|
memcpy(c_collection_name, StringValuePtr(collection_name), RSTRING_LEN(collection_name));
|
102
113
|
|
114
|
+
// Extract the data size, check for errors and return if any
|
103
115
|
rc = unqlite_kv_fetch(ctx->pDb, c_collection_name, -1, NULL, &n_bytes);
|
104
|
-
|
116
|
+
CHECK(ctx->pDb, rc);
|
117
|
+
if( rc != UNQLITE_OK ) { return Qnil; }
|
105
118
|
|
119
|
+
// Data is empty
|
106
120
|
fetched_data = (char *)malloc(n_bytes);
|
107
|
-
if( fetched_data == NULL ) { return
|
121
|
+
if( fetched_data == NULL ) { return rb_str_new2(""); }
|
108
122
|
|
123
|
+
// Now, fetch the data
|
109
124
|
rc = unqlite_kv_fetch(ctx->pDb, c_collection_name, -1, fetched_data, &n_bytes);
|
110
|
-
|
125
|
+
CHECK(ctx->pDb, rc);
|
126
|
+
|
127
|
+
return rb_str_new2((char *)fetched_data);
|
128
|
+
}
|
129
|
+
|
130
|
+
static VALUE unqlite_database_begin_transaction(VALUE self)
|
131
|
+
{
|
132
|
+
int rc;
|
133
|
+
unqliteRubyPtr ctx;
|
134
|
+
|
135
|
+
// Get class context
|
136
|
+
Data_Get_Struct(self, unqliteRuby, ctx);
|
137
|
+
|
138
|
+
// Begin write-transaction manually
|
139
|
+
rc = unqlite_begin(ctx->pDb);
|
140
|
+
|
141
|
+
// Check for errors
|
142
|
+
CHECK(ctx->pDb, rc);
|
111
143
|
|
112
|
-
return
|
144
|
+
return Qtrue;
|
145
|
+
}
|
146
|
+
|
147
|
+
static VALUE unqlite_database_commit(VALUE self)
|
148
|
+
{
|
149
|
+
int rc;
|
150
|
+
unqliteRubyPtr ctx;
|
151
|
+
|
152
|
+
// Get class context
|
153
|
+
Data_Get_Struct(self, unqliteRuby, ctx);
|
154
|
+
|
155
|
+
// Commit transaction
|
156
|
+
rc = unqlite_commit(ctx->pDb);
|
157
|
+
|
158
|
+
// Check for errors
|
159
|
+
CHECK(ctx->pDb, rc);
|
160
|
+
|
161
|
+
return Qtrue;
|
162
|
+
}
|
163
|
+
|
164
|
+
static VALUE unqlite_database_rollback(VALUE self)
|
165
|
+
{
|
166
|
+
int rc;
|
167
|
+
unqliteRubyPtr ctx;
|
168
|
+
|
169
|
+
// Get class context
|
170
|
+
Data_Get_Struct(self, unqliteRuby, ctx);
|
171
|
+
|
172
|
+
// Rollback transaction
|
173
|
+
rc = unqlite_rollback(ctx->pDb);
|
174
|
+
|
175
|
+
// Check for errors
|
176
|
+
CHECK(ctx->pDb, rc);
|
177
|
+
|
178
|
+
return Qtrue;
|
113
179
|
}
|
114
180
|
|
115
181
|
void Init_unqlite_database()
|
@@ -126,5 +192,10 @@ void Init_unqlite_database()
|
|
126
192
|
rb_define_method(cUnQLiteDatabase, "store", unqlite_database_store, 2);
|
127
193
|
rb_define_method(cUnQLiteDatabase, "fetch", unqlite_database_fetch, 1);
|
128
194
|
|
195
|
+
rb_define_method(cUnQLiteDatabase, "begin_transaction", unqlite_database_begin_transaction, 0);
|
196
|
+
rb_define_method(cUnQLiteDatabase, "commit", unqlite_database_commit, 0);
|
197
|
+
rb_define_method(cUnQLiteDatabase, "rollback", unqlite_database_rollback, 0);
|
198
|
+
|
129
199
|
rb_define_method(cUnQLiteDatabase, "initialize", initialize, 1);
|
200
|
+
rb_define_method(cUnQLiteDatabase, "close", unqlite_database_close, 0);
|
130
201
|
}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#include <unqlite_exception.h>
|
2
|
+
|
3
|
+
void rb_unqlite_raise(unqlite *db, int rc)
|
4
|
+
{
|
5
|
+
VALUE klass = Qnil;
|
6
|
+
|
7
|
+
switch(rc) {
|
8
|
+
case UNQLITE_NOMEM:
|
9
|
+
klass = rb_path2class("UnQLite::MemoryException");
|
10
|
+
break;
|
11
|
+
case UNQLITE_ABORT:
|
12
|
+
klass = rb_path2class("UnQLite::AbortException");
|
13
|
+
break;
|
14
|
+
case UNQLITE_IOERR:
|
15
|
+
klass = rb_path2class("UnQLite::IOException");
|
16
|
+
break;
|
17
|
+
case UNQLITE_CORRUPT:
|
18
|
+
klass = rb_path2class("UnQLite::CorruptException");
|
19
|
+
break;
|
20
|
+
case UNQLITE_LOCKED:
|
21
|
+
klass = rb_path2class("UnQLite::LockedException");
|
22
|
+
break;
|
23
|
+
case UNQLITE_BUSY:
|
24
|
+
klass = rb_path2class("UnQLite::BusyException");
|
25
|
+
break;
|
26
|
+
/* Not sure if it is an error or not (check lib/unqlite/errors.rb)
|
27
|
+
case UNQLITE_DONE:
|
28
|
+
klass = rb_path2class("UnQLite::DoneException");
|
29
|
+
break;
|
30
|
+
*/
|
31
|
+
case UNQLITE_PERM:
|
32
|
+
klass = rb_path2class("UnQLite::PermissionException");
|
33
|
+
break;
|
34
|
+
case UNQLITE_NOTIMPLEMENTED:
|
35
|
+
klass = rb_path2class("UnQLite::NotImplementedException");
|
36
|
+
break;
|
37
|
+
case UNQLITE_NOTFOUND:
|
38
|
+
klass = rb_path2class("UnQLite::NotFoundException");
|
39
|
+
break;
|
40
|
+
case UNQLITE_EMPTY:
|
41
|
+
klass = rb_path2class("UnQLite::EmptyException");
|
42
|
+
break;
|
43
|
+
case UNQLITE_INVALID:
|
44
|
+
klass = rb_path2class("UnQLite::InvalidParameterException");
|
45
|
+
break;
|
46
|
+
case UNQLITE_EOF:
|
47
|
+
klass = rb_path2class("UnQLite::EOFException");
|
48
|
+
break;
|
49
|
+
case UNQLITE_UNKNOWN:
|
50
|
+
klass = rb_path2class("UnQLite::UnknownConfigurationException");
|
51
|
+
break;
|
52
|
+
case UNQLITE_LIMIT:
|
53
|
+
klass = rb_path2class("UnQLite::LimitReachedException");
|
54
|
+
break;
|
55
|
+
case UNQLITE_FULL:
|
56
|
+
klass = rb_path2class("UnQLite::FullDatabaseException");
|
57
|
+
break;
|
58
|
+
case UNQLITE_CANTOPEN:
|
59
|
+
klass = rb_path2class("UnQLite::CantOpenDatabaseException");
|
60
|
+
break;
|
61
|
+
case UNQLITE_READ_ONLY:
|
62
|
+
klass = rb_path2class("UnQLite::ReadOnlyException");
|
63
|
+
break;
|
64
|
+
case UNQLITE_LOCKERR:
|
65
|
+
klass = rb_path2class("UnQLite::LockProtocolException");
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
|
69
|
+
if( !NIL_P(klass) ) { // Is really an error?
|
70
|
+
const char *buffer;
|
71
|
+
int length;
|
72
|
+
|
73
|
+
// Rollback, please.
|
74
|
+
if( rc != UNQLITE_BUSY && rc != UNQLITE_NOTIMPLEMENTED ) {
|
75
|
+
unqlite_rollback(db);
|
76
|
+
}
|
77
|
+
|
78
|
+
/* Get error from log */
|
79
|
+
unqlite_config(db, UNQLITE_CONFIG_ERR_LOG, &buffer, &length);
|
80
|
+
|
81
|
+
// Raise it!
|
82
|
+
if( length > 0 )
|
83
|
+
rb_raise(klass, "%s", buffer);
|
84
|
+
else
|
85
|
+
rb_raise(klass, "(couldn't retrieve the error message)");
|
86
|
+
}
|
87
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#ifndef UNQLITE_RUBY_EXCEPTION
|
2
|
+
#define UNQLITE_RUBY_EXCEPTION
|
3
|
+
|
4
|
+
#include <unqlite_ruby.h>
|
5
|
+
|
6
|
+
/* Macro to raise the proper exception given a return code */
|
7
|
+
#define CHECK(_db, _rc) rb_unqlite_raise(_db, _rc);
|
8
|
+
void rb_unqlite_raise(unqlite *db, int rc);
|
9
|
+
|
10
|
+
#endif
|
data/ext/unqlite/unqlite_ruby.h
CHANGED
data/lib/unqlite.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module UnQLite
|
2
|
+
class Exception < ::StandardError
|
3
|
+
@code = 0
|
4
|
+
|
5
|
+
def self.code
|
6
|
+
@code
|
7
|
+
end
|
8
|
+
|
9
|
+
def code
|
10
|
+
self.class.code
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class MemoryException < Exception; end
|
15
|
+
class AbortException < Exception; end
|
16
|
+
class IOException < Exception; end
|
17
|
+
class CorruptException < Exception; end
|
18
|
+
class LockedException < Exception; end # Forbidden operation
|
19
|
+
class BusyException < Exception; end
|
20
|
+
#class DoneException < Exception; end # It is not clear on docs if it's an error or not
|
21
|
+
class PermissionException < Exception; end
|
22
|
+
class NotImplementedException < Exception; end
|
23
|
+
class NotFoundException < Exception; end # It is a quite confusing if is an error or an acceptable behavior (unqlite v1.1.6)
|
24
|
+
class EmptyException < Exception; end # Empty key (and some jx9 functions)
|
25
|
+
class InvalidParameterException < Exception; end
|
26
|
+
class EOFException < Exception; end
|
27
|
+
class UnknownConfigurationException < Exception; end
|
28
|
+
class LimitReachedException < Exception; end
|
29
|
+
class FullDatabaseException < Exception; end
|
30
|
+
class CantOpenDatabaseException < Exception; end
|
31
|
+
class ReadOnlyException < Exception; end
|
32
|
+
class LockProtocolException < Exception; end
|
33
|
+
end
|
data/lib/unqlite/version.rb
CHANGED
data/test/test_database.rb
CHANGED
@@ -1,21 +1,81 @@
|
|
1
|
+
require 'tempfile'
|
1
2
|
require 'helper'
|
2
3
|
|
3
4
|
module UnQLite
|
4
|
-
|
5
|
-
|
5
|
+
module CommonTestsForDatabase
|
6
|
+
def self.included(klass)
|
7
|
+
klass.class_eval { attr_reader :db_path }
|
8
|
+
end
|
6
9
|
|
7
10
|
def setup
|
8
|
-
@db = UnQLite::Database.new(
|
11
|
+
@db = UnQLite::Database.new(db_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
@db.close
|
9
16
|
end
|
10
17
|
|
11
18
|
def test_store
|
12
|
-
|
19
|
+
assert @db.store("key", "stored content")
|
13
20
|
end
|
14
21
|
|
15
22
|
def test_fetch
|
16
23
|
@db.store("key", "wabba")
|
17
24
|
|
18
|
-
assert_equal
|
25
|
+
assert_equal("wabba", @db.fetch("key"))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_exceptions
|
29
|
+
# TODO: Test other errors
|
30
|
+
assert_raises(UnQLite::NotFoundException) { @db.fetch("xxx") }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class TestInMemoryDatabase < Minitest::Test
|
35
|
+
include CommonTestsForDatabase
|
36
|
+
|
37
|
+
def initialize(*args)
|
38
|
+
@db_path = ":mem:"
|
39
|
+
super(*args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class TestDatabase < Minitest::Test
|
44
|
+
include CommonTestsForDatabase
|
45
|
+
|
46
|
+
def setup
|
47
|
+
@tmp = Tempfile.new("test_db")
|
48
|
+
@db_path = @tmp.path
|
49
|
+
@tmp.close
|
50
|
+
super()
|
51
|
+
end
|
52
|
+
|
53
|
+
def teardown
|
54
|
+
super()
|
55
|
+
@tmp.unlink
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_automatic_transaction
|
59
|
+
@db.store("auto", "wabba")
|
60
|
+
@db.rollback
|
61
|
+
|
62
|
+
assert_raises(UnQLite::NotFoundException) { @db.fetch("auto") }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_manual_transaction
|
66
|
+
@db.begin_transaction
|
67
|
+
@db.store("manual", "wabba")
|
68
|
+
@db.rollback
|
69
|
+
|
70
|
+
assert_raises(UnQLite::NotFoundException) { @db.fetch("manual") }
|
71
|
+
|
72
|
+
@db.store("manual2", "wabba")
|
73
|
+
@db.commit
|
74
|
+
@db.store("will_disapper", "wabba")
|
75
|
+
@db.rollback
|
76
|
+
|
77
|
+
assert_equal("wabba", @db.fetch("manual2"))
|
78
|
+
assert_raises(UnQLite::NotFoundException) { @db.fetch("will_disapper") }
|
19
79
|
end
|
20
80
|
end
|
21
81
|
end
|
data/test/test_errors.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module UnQLite
|
4
|
+
class TestErros < Minitest::Test
|
5
|
+
attr_reader :exceptions
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@exceptions = [
|
9
|
+
UnQLite::MemoryException,
|
10
|
+
UnQLite::AbortException,
|
11
|
+
UnQLite::IOException,
|
12
|
+
UnQLite::CorruptException,
|
13
|
+
UnQLite::LockedException,
|
14
|
+
UnQLite::BusyException,
|
15
|
+
UnQLite::PermissionException,
|
16
|
+
UnQLite::NotImplementedException,
|
17
|
+
UnQLite::NotFoundException,
|
18
|
+
UnQLite::EmptyException,
|
19
|
+
UnQLite::InvalidParameterException,
|
20
|
+
UnQLite::EOFException,
|
21
|
+
UnQLite::UnknownConfigurationException,
|
22
|
+
UnQLite::LimitReachedException,
|
23
|
+
UnQLite::FullDatabaseException,
|
24
|
+
UnQLite::CantOpenDatabaseException,
|
25
|
+
UnQLite::ReadOnlyException,
|
26
|
+
UnQLite::LockedException
|
27
|
+
] # + [UnQLite::DoneException]
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_respond_to_code
|
31
|
+
exceptions.each do |exception|
|
32
|
+
assert true, exception.respond_to?(:code)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/unqlite.gemspec
CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler",
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "ZenTest"
|
25
|
-
spec.add_development_dependency "rake-compiler"
|
26
|
-
spec.add_development_dependency "minitest",
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0.4"
|
24
|
+
spec.add_development_dependency "ZenTest", "~> 4.9.2"
|
25
|
+
spec.add_development_dependency "rake-compiler", "~> 0.8.3"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.0.3"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unqlite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Teixeira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,44 +28,44 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.0.4
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 10.0.4
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ZenTest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.9.2
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.9.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake-compiler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.8.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.8.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,6 +90,7 @@ extra_rdoc_files: []
|
|
90
90
|
files:
|
91
91
|
- .autotest
|
92
92
|
- .gitignore
|
93
|
+
- CHANGELOG.md
|
93
94
|
- Gemfile
|
94
95
|
- LICENSE.txt
|
95
96
|
- README.md
|
@@ -100,11 +101,15 @@ files:
|
|
100
101
|
- ext/unqlite/unqlite_codes.h
|
101
102
|
- ext/unqlite/unqlite_database.c
|
102
103
|
- ext/unqlite/unqlite_database.h
|
104
|
+
- ext/unqlite/unqlite_exception.c
|
105
|
+
- ext/unqlite/unqlite_exception.h
|
103
106
|
- ext/unqlite/unqlite_ruby.h
|
104
107
|
- lib/unqlite.rb
|
108
|
+
- lib/unqlite/errors.rb
|
105
109
|
- lib/unqlite/version.rb
|
106
110
|
- test/helper.rb
|
107
111
|
- test/test_database.rb
|
112
|
+
- test/test_errors.rb
|
108
113
|
- unqlite.gemspec
|
109
114
|
homepage: https://github.com/danieltdt/unqlite-ruby
|
110
115
|
licenses:
|
@@ -133,3 +138,4 @@ summary: UnQLite for ruby (using C extension)
|
|
133
138
|
test_files:
|
134
139
|
- test/helper.rb
|
135
140
|
- test/test_database.rb
|
141
|
+
- test/test_errors.rb
|