amalgalite 0.5.1-x86-mswin32-60 → 0.6.0-x86-mswin32-60
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/HISTORY +15 -2
- data/README +3 -0
- data/examples/define_aggregate.rb +75 -0
- data/examples/define_function.rb +104 -0
- data/examples/gems.db +0 -0
- data/ext/amalgalite3.h +28 -2
- data/ext/amalgalite3_blob.c +1 -2
- data/ext/amalgalite3_database.c +567 -46
- data/ext/amalgalite3_requires_bootstrap.c +1 -3
- data/ext/amalgalite3_statement.c +2 -2
- data/ext/extconf.rb +1 -0
- data/ext/sqlite3.c +6521 -4518
- data/ext/sqlite3.h +50 -43
- data/ext/test_error.c +77 -0
- data/lib/amalgalite.rb +5 -0
- data/lib/amalgalite/aggregate.rb +67 -0
- data/lib/amalgalite/busy_timeout.rb +47 -0
- data/lib/amalgalite/column.rb +1 -1
- data/lib/amalgalite/database.rb +271 -2
- data/lib/amalgalite/function.rb +61 -0
- data/lib/amalgalite/progress_handler.rb +21 -0
- data/lib/amalgalite/sqlite3.rb +1 -0
- data/lib/amalgalite/sqlite3/database/function.rb +48 -0
- data/lib/amalgalite/version.rb +2 -2
- data/lib/amalgalite3.so +0 -0
- data/spec/aggregate_spec.rb +168 -0
- data/spec/busy_handler.rb +164 -0
- data/spec/database_spec.rb +97 -3
- data/spec/function_spec.rb +86 -0
- data/spec/progress_handler_spec.rb +103 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/sqlite3/version_spec.rb +2 -2
- metadata +21 -3
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
|
5
|
+
require 'amalgalite'
|
6
|
+
require 'amalgalite/database'
|
7
|
+
|
8
|
+
describe "Scalar SQL Functions" do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@schema = IO.read( SpecInfo.test_schema_file )
|
12
|
+
@iso_db_file = SpecInfo.make_iso_db
|
13
|
+
@iso_db = Amalgalite::Database.new( SpecInfo.make_iso_db )
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:each) do
|
17
|
+
File.unlink SpecInfo.test_db if File.exist?( SpecInfo.test_db )
|
18
|
+
@iso_db.close
|
19
|
+
File.unlink @iso_db_file if File.exist?( @iso_db_file )
|
20
|
+
end
|
21
|
+
|
22
|
+
it "can define a custom SQL function as a block with 0 params" do
|
23
|
+
@iso_db.define_function("foo") do
|
24
|
+
"foo"
|
25
|
+
end
|
26
|
+
r = @iso_db.execute("SELECT foo() AS f");
|
27
|
+
r.first['f'].should == "foo"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has a signature" do
|
31
|
+
::Amalgalite::Function.new( "testing_name", 42 ).signature.should == "testing_name/42"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can define a custom SQL function as a lambda with 2 param" do
|
35
|
+
@iso_db.define_function("foo2", lambda{ |x,y| "foo2 -> #{x} #{y}" } )
|
36
|
+
r = @iso_db.execute("SELECT foo2( 'bar', 'baz' ) as f")
|
37
|
+
r.first['f'].should == "foo2 -> bar baz"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can define a custom SQL function as a class with N params" do
|
41
|
+
class FunctionTest1 < ::Amalgalite::Function
|
42
|
+
def initialize
|
43
|
+
super('ftest', -1)
|
44
|
+
end
|
45
|
+
def call( *args )
|
46
|
+
"#{args.length} args #{args.join(', ')}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
@iso_db.define_function("ftest1", FunctionTest1.new )
|
51
|
+
r = @iso_db.execute("SELECT ftest1(1,2,3,'baz') as f")
|
52
|
+
r.first['f'].should == "4 args 1, 2, 3, baz"
|
53
|
+
end
|
54
|
+
|
55
|
+
[ [ 1, lambda { true } ],
|
56
|
+
[ 0, lambda { false } ],
|
57
|
+
[ nil, lambda { nil } ],
|
58
|
+
[ "foo", lambda { "foo" } ],
|
59
|
+
[ 42, lambda { 42 } ],
|
60
|
+
[ 42.2 , lambda { 42.2 } ], ].each do |expected, func|
|
61
|
+
it "returns the appropriate class #{expected.class} " do
|
62
|
+
@iso_db.define_function("ctest", func )
|
63
|
+
r = @iso_db.execute( "SELECT ctest() AS c" )
|
64
|
+
r.first['c'].should == expected
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "raises an error if the function returns a complex Ruby object" do
|
69
|
+
l = lambda { Hash.new }
|
70
|
+
@iso_db.define_function("htest", l)
|
71
|
+
begin
|
72
|
+
@iso_db.execute( "SELECT htest() AS h" )
|
73
|
+
rescue => e
|
74
|
+
e.should be_instance_of( ::Amalgalite::SQLite3::Error )
|
75
|
+
e.message.should =~ /Unable to convert ruby object to an SQL function result/
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "an error raised during the sql function is handled correctly" do
|
80
|
+
@iso_db.define_function( "etest" ) do
|
81
|
+
raise "error from within an sql function"
|
82
|
+
end
|
83
|
+
lambda { @iso_db.execute( "SELECT etest() AS e" ) }.should raise_error( ::Amalgalite::SQLite3::Error, /error from within an sql function/ )
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
|
5
|
+
require 'amalgalite'
|
6
|
+
require 'amalgalite/database'
|
7
|
+
class PH < ::Amalgalite::ProgressHandler
|
8
|
+
attr_reader :call_count
|
9
|
+
def initialize( max = nil )
|
10
|
+
@call_count = 0
|
11
|
+
@max = max
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
@call_count += 1
|
16
|
+
if @max && ( @call_count >= @max ) then
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def query_thread( db )
|
24
|
+
Thread.new( db ) do |db|
|
25
|
+
begin
|
26
|
+
db.execute("select count(id) from country")
|
27
|
+
rescue => e
|
28
|
+
had_error = e
|
29
|
+
Thread.current[:exception] = e
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "Progress Handlers" do
|
35
|
+
before(:each) do
|
36
|
+
@db_name = SpecInfo.make_iso_db
|
37
|
+
@iso_db = Amalgalite::Database.new( @db_name )
|
38
|
+
end
|
39
|
+
|
40
|
+
after(:each) do
|
41
|
+
@iso_db.close
|
42
|
+
File.unlink @db_name if File.exist?( @db_name )
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises NotImplemented if #call is not overwritten" do
|
46
|
+
bh = ::Amalgalite::ProgressHandler.new
|
47
|
+
lambda { bh.call }.should raise_error( ::NotImplementedError, /The progress handler call\(\) method must be implemented/ )
|
48
|
+
end
|
49
|
+
|
50
|
+
it "can be registered as block" do
|
51
|
+
call_count = 0
|
52
|
+
@iso_db.progress_handler( 50 ) do ||
|
53
|
+
call_count += 1
|
54
|
+
true
|
55
|
+
end
|
56
|
+
qt = query_thread( @iso_db )
|
57
|
+
qt.join
|
58
|
+
call_count.should > 10
|
59
|
+
end
|
60
|
+
|
61
|
+
it "can be registered as lambda" do
|
62
|
+
call_count = 0
|
63
|
+
callable = lambda { || call_count += 1; true }
|
64
|
+
@iso_db.progress_handler( 42, callable )
|
65
|
+
qt = query_thread( @iso_db )
|
66
|
+
qt.join
|
67
|
+
call_count.should > 10
|
68
|
+
end
|
69
|
+
|
70
|
+
it "can be registered as a class" do
|
71
|
+
ph = PH.new
|
72
|
+
@iso_db.progress_handler( 5, ph )
|
73
|
+
qt = query_thread( @iso_db )
|
74
|
+
qt.join
|
75
|
+
ph.call_count.should > 100
|
76
|
+
end
|
77
|
+
|
78
|
+
it "behaves like #interrupt! if returning a false value" do
|
79
|
+
ph = PH.new( 25 )
|
80
|
+
@iso_db.progress_handler( 5, ph )
|
81
|
+
qt = query_thread( @iso_db )
|
82
|
+
qt.join
|
83
|
+
ph.call_count.should == 25
|
84
|
+
qt[:exception].should be_instance_of( ::Amalgalite::SQLite3::Error )
|
85
|
+
qt[:exception].message.should =~ /interrupted/
|
86
|
+
end
|
87
|
+
|
88
|
+
it "cannot register a block with the wrong arity" do
|
89
|
+
lambda do
|
90
|
+
@iso_db.define_progress_handler { |x,y| puts "What!" }
|
91
|
+
end.should raise_error( ::Amalgalite::Database::ProgressHandlerError, /A progress handler expects 0 arguments, not 2/)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "can remove a progress handler" do
|
95
|
+
ph = PH.new
|
96
|
+
@iso_db.progress_handler( 5, ph )
|
97
|
+
@iso_db.remove_progress_handler
|
98
|
+
qt = query_thread( @iso_db )
|
99
|
+
qt.join
|
100
|
+
ph.call_count.should == 0
|
101
|
+
qt[:exception].should be_nil
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,10 +5,10 @@ describe "Amalgalite::SQLite3::Version" do
|
|
5
5
|
it "should have the sqlite3 version" do
|
6
6
|
Amalgalite::SQLite3::VERSION.should =~ /\d\.\d\.\d/
|
7
7
|
Amalgalite::SQLite3::Version.to_s.should =~ /\d\.\d\.\d/
|
8
|
-
Amalgalite::SQLite3::Version.to_i.should ==
|
8
|
+
Amalgalite::SQLite3::Version.to_i.should == 3006007
|
9
9
|
Amalgalite::SQLite3::Version::MAJOR.should == 3
|
10
10
|
Amalgalite::SQLite3::Version::MINOR.should == 6
|
11
|
-
Amalgalite::SQLite3::Version::RELEASE.should ==
|
11
|
+
Amalgalite::SQLite3::Version::RELEASE.should == 7
|
12
12
|
Amalgalite::SQLite3::Version.to_a.should have(3).items
|
13
13
|
end
|
14
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amalgalite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: x86-mswin32-60
|
6
6
|
authors:
|
7
7
|
- Jeremy Hinegardner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 4.5.0
|
34
34
|
version:
|
35
|
-
description: Amalgalite embeds the SQLite database engine in a ruby extension. There is no need to install SQLite separately. Look in the examples/ directory to see * general usage * blob io * schema information Also Scroll through Amalgalite::Database for a quick example, and a general overview of the API.
|
35
|
+
description: Amalgalite embeds the SQLite database engine in a ruby extension. There is no need to install SQLite separately. Look in the examples/ directory to see * general usage * blob io * schema information * custom functions * custom aggregates * requiring ruby code from a database Also Scroll through Amalgalite::Database for a quick example, and a general overview of the API.
|
36
36
|
email: jeremy@hinegardner.org
|
37
37
|
executables:
|
38
38
|
- amalgalite-pack
|
@@ -42,18 +42,23 @@ extra_rdoc_files:
|
|
42
42
|
- README
|
43
43
|
- HISTORY
|
44
44
|
- LICENSE
|
45
|
+
- lib/amalgalite/aggregate.rb
|
45
46
|
- lib/amalgalite/blob.rb
|
46
47
|
- lib/amalgalite/boolean.rb
|
48
|
+
- lib/amalgalite/busy_timeout.rb
|
47
49
|
- lib/amalgalite/column.rb
|
48
50
|
- lib/amalgalite/core_ext/kernel/require.rb
|
49
51
|
- lib/amalgalite/database.rb
|
52
|
+
- lib/amalgalite/function.rb
|
50
53
|
- lib/amalgalite/index.rb
|
51
54
|
- lib/amalgalite/packer.rb
|
52
55
|
- lib/amalgalite/paths.rb
|
53
56
|
- lib/amalgalite/profile_tap.rb
|
57
|
+
- lib/amalgalite/progress_handler.rb
|
54
58
|
- lib/amalgalite/requires.rb
|
55
59
|
- lib/amalgalite/schema.rb
|
56
60
|
- lib/amalgalite/sqlite3/constants.rb
|
61
|
+
- lib/amalgalite/sqlite3/database/function.rb
|
57
62
|
- lib/amalgalite/sqlite3/database/status.rb
|
58
63
|
- lib/amalgalite/sqlite3/status.rb
|
59
64
|
- lib/amalgalite/sqlite3/version.rb
|
@@ -86,6 +91,7 @@ files:
|
|
86
91
|
- ext/amalgalite3_requires_bootstrap.c
|
87
92
|
- ext/amalgalite3_statement.c
|
88
93
|
- ext/sqlite3.c
|
94
|
+
- ext/test_error.c
|
89
95
|
- ext/amalgalite3.h
|
90
96
|
- ext/sqlite3.h
|
91
97
|
- ext/sqlite3_options.h
|
@@ -95,22 +101,30 @@ files:
|
|
95
101
|
- examples/a.rb
|
96
102
|
- examples/blob.rb
|
97
103
|
- examples/bootstrap.rb
|
104
|
+
- examples/define_aggregate.rb
|
105
|
+
- examples/define_function.rb
|
98
106
|
- examples/gem-db.rb
|
107
|
+
- examples/gems.db
|
99
108
|
- examples/require_me.rb
|
100
109
|
- examples/requires.rb
|
101
110
|
- examples/schema-info.rb
|
111
|
+
- lib/amalgalite/aggregate.rb
|
102
112
|
- lib/amalgalite/blob.rb
|
103
113
|
- lib/amalgalite/boolean.rb
|
114
|
+
- lib/amalgalite/busy_timeout.rb
|
104
115
|
- lib/amalgalite/column.rb
|
105
116
|
- lib/amalgalite/core_ext/kernel/require.rb
|
106
117
|
- lib/amalgalite/database.rb
|
118
|
+
- lib/amalgalite/function.rb
|
107
119
|
- lib/amalgalite/index.rb
|
108
120
|
- lib/amalgalite/packer.rb
|
109
121
|
- lib/amalgalite/paths.rb
|
110
122
|
- lib/amalgalite/profile_tap.rb
|
123
|
+
- lib/amalgalite/progress_handler.rb
|
111
124
|
- lib/amalgalite/requires.rb
|
112
125
|
- lib/amalgalite/schema.rb
|
113
126
|
- lib/amalgalite/sqlite3/constants.rb
|
127
|
+
- lib/amalgalite/sqlite3/database/function.rb
|
114
128
|
- lib/amalgalite/sqlite3/database/status.rb
|
115
129
|
- lib/amalgalite/sqlite3/status.rb
|
116
130
|
- lib/amalgalite/sqlite3/version.rb
|
@@ -128,14 +142,18 @@ files:
|
|
128
142
|
- lib/amalgalite/version.rb
|
129
143
|
- lib/amalgalite/view.rb
|
130
144
|
- lib/amalgalite.rb
|
145
|
+
- spec/aggregate_spec.rb
|
131
146
|
- spec/amalgalite_spec.rb
|
132
147
|
- spec/blob_spec.rb
|
133
148
|
- spec/boolean_spec.rb
|
149
|
+
- spec/busy_handler.rb
|
134
150
|
- spec/database_spec.rb
|
135
151
|
- spec/default_map_spec.rb
|
152
|
+
- spec/function_spec.rb
|
136
153
|
- spec/integeration_spec.rb
|
137
154
|
- spec/packer_spec.rb
|
138
155
|
- spec/paths_spec.rb
|
156
|
+
- spec/progress_handler_spec.rb
|
139
157
|
- spec/requires_spec.rb
|
140
158
|
- spec/schema_spec.rb
|
141
159
|
- spec/spec_helper.rb
|