do_sqlite3 0.10.0-java → 0.10.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ static struct errcodes {
2
+ int error_no;
3
+ const char *error_name;
4
+ const char *exception;
5
+ } errors [] = {
6
+ #ifdef SQLITE_ERROR
7
+ { SQLITE_ERROR,
8
+ "SQLITE_ERROR", "SyntaxError"},
9
+ #endif
10
+ #ifdef SQLITE_INTERNAL
11
+ { SQLITE_INTERNAL,
12
+ "SQLITE_INTERNAL", "SQLError"},
13
+ #endif
14
+ #ifdef SQLITE_PERM
15
+ { SQLITE_PERM,
16
+ "SQLITE_PERM", "ConnectionError"},
17
+ #endif
18
+ #ifdef SQLITE_ABORT
19
+ { SQLITE_ABORT,
20
+ "SQLITE_ABORT", "ConnectionError"},
21
+ #endif
22
+ #ifdef SQLITE_BUSY
23
+ { SQLITE_BUSY,
24
+ "SQLITE_BUSY", "ConnectionError"},
25
+ #endif
26
+
27
+ #ifdef SQLITE_LOCKED
28
+ { SQLITE_LOCKED,
29
+ "SQLITE_LOCKED", "ConnectionError"},
30
+ #endif
31
+ #ifdef SQLITE_NOMEM
32
+ { SQLITE_NOMEM,
33
+ "SQLITE_NOMEM", "ConnectionError"},
34
+ #endif
35
+ #ifdef SQLITE_READONLY
36
+ { SQLITE_READONLY,
37
+ "SQLITE_READONLY", "ConnectionError"},
38
+ #endif
39
+ #ifdef SQLITE_INTERRUPT
40
+ { SQLITE_INTERRUPT,
41
+ "SQLITE_INTERRUPT", "ConnectionError"},
42
+ #endif
43
+ #ifdef SQLITE_IOERR
44
+ { SQLITE_IOERR,
45
+ "SQLITE_IOERR", "ConnectionError"},
46
+ #endif
47
+ #ifdef SQLITE_CORRUPT
48
+ { SQLITE_CORRUPT,
49
+ "SQLITE_CORRUPT", "ConnectionError"},
50
+ #endif
51
+ #ifdef SQLITE_FULL
52
+ { SQLITE_FULL,
53
+ "SQLITE_FULL", "ConnectionError"},
54
+ #endif
55
+ #ifdef SQLITE_CANTOPEN
56
+ { SQLITE_CANTOPEN,
57
+ "SQLITE_CANTOPEN", "ConnectionError"},
58
+ #endif
59
+ #ifdef SQLITE_EMPTY
60
+ { SQLITE_EMPTY,
61
+ "SQLITE_EMPTY", "ConnectionError"},
62
+ #endif
63
+ #ifdef SQLITE_SCHEMA
64
+ { SQLITE_SCHEMA,
65
+ "SQLITE_SCHEMA", "DataError"},
66
+ #endif
67
+ #ifdef SQLITE_TOOBIG
68
+ { SQLITE_TOOBIG,
69
+ "SQLITE_TOOBIG", "DataError"},
70
+ #endif
71
+ #ifdef SQLITE_MISMATCH
72
+ { SQLITE_MISMATCH,
73
+ "SQLITE_MISMATCH", "DataError"},
74
+ #endif
75
+ #ifdef SQLITE_CONSTRAINT
76
+ { SQLITE_CONSTRAINT,
77
+ "SQLITE_CONSTRAINT", "IntegrityError"},
78
+ #endif
79
+ #ifdef SQLITE_MISUSE
80
+ { SQLITE_MISUSE,
81
+ "SQLITE_MISUSE", "SQLError"},
82
+ #endif
83
+
84
+ #ifdef SQLITE_NOLFS
85
+ { SQLITE_NOLFS,
86
+ "SQLITE_NOLFS", "ConnectionError"},
87
+ #endif
88
+ #ifdef SQLITE_FORMAT
89
+ { SQLITE_FORMAT,
90
+ "SQLITE_FORMAT", "SyntaxError"},
91
+ #endif
92
+ #ifdef SQLITE_RANGE
93
+ { SQLITE_RANGE,
94
+ "SQLITE_RANGE", "DataError"},
95
+ #endif
96
+ #ifdef SQLITE_NOTADB
97
+ { SQLITE_NOTADB,
98
+ "SQLITE_NOTADB", "ConnectionError"},
99
+ #endif
100
+
101
+ #ifdef SQLITE_ROW
102
+ { SQLITE_ROW,
103
+ "SQLITE_ROW", "SyntaxError"},
104
+ #endif
105
+ {0, NULL, NULL}
106
+ };
@@ -0,0 +1,26 @@
1
+ ENV["RC_ARCHS"] = "" if RUBY_PLATFORM =~ /darwin/
2
+
3
+ # Loads mkmf which is used to make makefiles for Ruby extensions
4
+ require 'mkmf'
5
+
6
+ # Allow for custom compiler to be specified.
7
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
8
+
9
+ # Use some default search paths
10
+ dir_config("sqlite3", ["/usr/local", "/opt/local", "/usr"])
11
+
12
+ # NOTE: use GCC flags unless Visual C compiler is used
13
+ $CFLAGS << ' -Wall ' unless RUBY_PLATFORM =~ /mswin/
14
+
15
+ if RUBY_VERSION < '1.8.6'
16
+ $CFLAGS << ' -DRUBY_LESS_THAN_186'
17
+ end
18
+
19
+ # Do the work
20
+ # create_makefile(extension_name)
21
+ if have_header( "sqlite3.h" ) && have_library( "sqlite3", "sqlite3_open" )
22
+ have_func("sqlite3_prepare_v2")
23
+ have_func("sqlite3_open_v2")
24
+
25
+ create_makefile('do_sqlite3/do_sqlite3')
26
+ end
data/lib/do_sqlite3.rb CHANGED
@@ -18,22 +18,30 @@ if RUBY_PLATFORM =~ /java/
18
18
  java_import driver
19
19
  end
20
20
 
21
- require 'do_sqlite3_ext'
21
+ begin
22
+ require 'do_sqlite3/do_sqlite3'
23
+ rescue LoadError
24
+ if RUBY_PLATFORM =~ /mingw|mswin/ then
25
+ RUBY_VERSION =~ /(\d+.\d+)/
26
+ require "do_sqlite3/#{$1}/do_sqlite3"
27
+ else
28
+ raise
29
+ end
30
+ end
31
+
22
32
  require 'do_sqlite3/version'
23
- require 'do_sqlite3/transaction'
33
+ require 'do_sqlite3/transaction' if RUBY_PLATFORM !~ /java/
24
34
 
25
35
  if RUBY_PLATFORM =~ /java/
26
36
 
27
- module DataObjects
28
- module Sqlite3
29
- class Connection
30
- def self.pool_size
31
- # sqlite3 can have only one write access at a time, with this
32
- # concurrent write access will result in "Database locked" errors
33
- 1
34
- end
35
- end
37
+ DataObjects::Sqlite3::Connection.class_eval do
38
+
39
+ def self.pool_size
40
+ # sqlite3 can have only one write access at a time, with this
41
+ # concurrent write access will result in "Database locked" errors
42
+ 1
36
43
  end
44
+
37
45
  end
38
46
 
39
47
  end
Binary file
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Sqlite3
3
- VERSION = "0.10.0"
3
+ VERSION = '0.10.1'.freeze
4
4
  end
5
5
  end
data/spec/command_spec.rb CHANGED
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/command_spec'
5
5
 
6
6
  describe DataObjects::Sqlite3::Command do
7
- it_should_behave_like 'a Command'
7
+ behaves_like 'a Command'
8
8
  end
@@ -5,14 +5,16 @@ require 'data_objects/spec/connection_spec'
5
5
 
6
6
  describe DataObjects::Sqlite3::Connection do
7
7
 
8
- before :all do
9
- @driver = CONFIG.scheme
10
- @user = CONFIG.user
8
+ before do
9
+ @driver = CONFIG.scheme
10
+ @user = CONFIG.user
11
11
  @password = CONFIG.pass
12
- @host = CONFIG.host
13
- @port = CONFIG.port
12
+ @host = CONFIG.host
13
+ @port = CONFIG.port
14
14
  @database = CONFIG.database
15
15
  end
16
16
 
17
- it_should_behave_like 'a Connection'
17
+ behaves_like 'a Connection'
18
+ behaves_like 'a Connection via JDNI' if JRUBY
19
+ # FIXME: behaves_like 'a Connection with JDBC URL support' if JRUBY
18
20
  end
data/spec/reader_spec.rb CHANGED
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/reader_spec'
5
5
 
6
6
  describe DataObjects::Sqlite3::Reader do
7
- it_should_behave_like 'a Reader'
7
+ behaves_like 'a Reader'
8
8
  end
data/spec/result_spec.rb CHANGED
@@ -4,16 +4,16 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
4
  require 'data_objects/spec/result_spec'
5
5
 
6
6
  # splitting the descibe into two separate declaration avoids
7
- # concurrent execution of the "it_should_behave_like ....." calls
7
+ # concurrent execution of the "behaves_like ....." calls
8
8
  # which would lock the database
9
9
 
10
10
  # TODO
11
11
  # the locked database created a deadlock which is worth exploring since
12
12
  # such situation could appear in the wild too
13
13
  describe DataObjects::Sqlite3::Result do
14
- it_should_behave_like 'a Result'
14
+ behaves_like 'a Result'
15
15
  end
16
16
 
17
17
  describe DataObjects::Sqlite3::Result do
18
- it_should_behave_like 'a Result which returns inserted keys'
18
+ behaves_like 'a Result which returns inserted keys'
19
19
  end
data/spec/spec_helper.rb CHANGED
@@ -2,51 +2,36 @@ $TESTING=true
2
2
  JRUBY = RUBY_PLATFORM =~ /java/
3
3
 
4
4
  require 'rubygems'
5
-
6
- gem 'rspec', '>1.1.12'
7
- require 'spec'
8
-
9
5
  require 'date'
10
6
  require 'ostruct'
11
- require 'pathname'
12
7
  require 'fileutils'
8
+ require 'win32console' if RUBY_PLATFORM =~ /mingw|mswin/
9
+
10
+ driver_lib = File.expand_path('../../lib', __FILE__)
11
+ $LOAD_PATH.unshift(driver_lib) unless $LOAD_PATH.include?(driver_lib)
13
12
 
14
- dir = File.dirname(__FILE__)
15
- lib_path = File.expand_path("#{dir}/../lib")
16
- $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
17
- # put data_objects from repository in the load path
18
- # DO NOT USE installed gem of data_objects!
19
- do_lib_path = File.expand_path("#{dir}/../../data_objects/lib")
20
- $LOAD_PATH.unshift do_lib_path unless $LOAD_PATH.include?(do_lib_path)
21
-
22
- if JRUBY
23
- jdbc_lib_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'do_jdbc', 'lib'))
24
- $LOAD_PATH.unshift jdbc_lib_path unless $LOAD_PATH.include?(jdbc_lib_path)
25
- require 'do_jdbc'
13
+ # Prepend data_objects/do_jdbc in the repository to the load path.
14
+ # DO NOT USE installed gems, except when running the specs from gem.
15
+ repo_root = File.expand_path('../../..', __FILE__)
16
+ (['data_objects'] << ('do_jdbc' if JRUBY)).compact.each do |lib|
17
+ lib_path = "#{repo_root}/#{lib}/lib"
18
+ $LOAD_PATH.unshift(lib_path) if File.directory?(lib_path) && !$LOAD_PATH.include?(lib_path)
26
19
  end
27
20
 
28
21
  require 'data_objects'
29
-
30
- DATAOBJECTS_SPEC_ROOT = Pathname(__FILE__).dirname.parent.parent + 'data_objects' + 'spec'
31
- Pathname.glob((DATAOBJECTS_SPEC_ROOT + 'lib/**/*.rb').to_s).each { |f| require f }
22
+ require 'data_objects/spec/bacon'
32
23
  require 'do_sqlite3'
33
24
 
34
- log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'log', 'do.log'))
35
- FileUtils.mkdir_p(File.dirname(log_path))
36
-
37
- DataObjects::Sqlite3.logger = DataObjects::Logger.new(log_path, :debug)
38
-
25
+ DataObjects::Sqlite3.logger = DataObjects::Logger.new(STDOUT, :off)
39
26
  at_exit { DataObjects.logger.flush }
40
27
 
41
- Spec::Runner.configure do |config|
42
- config.include(DataObjects::Spec::PendingHelpers)
43
- end
44
-
45
28
  CONFIG = OpenStruct.new
46
29
  CONFIG.scheme = 'sqlite3'
47
- CONFIG.database = ENV['DO_SQLITE3_DATABASE'] || "#{File.expand_path(File.dirname(__FILE__))}/test.db"
30
+ CONFIG.database = ENV['DO_SQLITE3_DATABASE'] || ":memory:"
48
31
 
49
- CONFIG.uri = ENV["DO_SQLITE3_SPEC_URI"] || "#{CONFIG.scheme}://#{CONFIG.database}"
32
+ CONFIG.uri = ENV["DO_SQLITE3_SPEC_URI"] || "#{CONFIG.scheme}:#{CONFIG.database}"
33
+ CONFIG.jdbc_driver = 'org.sqlite.JDBC'
34
+ CONFIG.jdbc_uri = CONFIG.uri.sub(/sqlite3/,"jdbc:sqlite")
50
35
 
51
36
  module DataObjectsSpecHelpers
52
37
 
@@ -111,7 +96,7 @@ module DataObjectsSpecHelpers
111
96
 
112
97
  1.upto(16) do |n|
113
98
  conn.create_command(<<-EOF).execute_non_query
114
- insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number, weight) VALUES ('W#{n.to_s.rjust(7,"0")}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'String', 'CAD DRAWING', 1234, 13.4);
99
+ insert into widgets(code, name, shelf_location, description, image_data, ad_description, ad_image, whitepaper_text, cad_drawing, super_number, weight) VALUES ('W#{n.to_s.rjust(7,"0")}', 'Widget #{n}', 'A14', 'This is a description', 'IMAGE DATA', 'Buy this product now!', 'AD IMAGE DATA', 'String', X'434144200120002044524157494e47', 1234, 13.4);
115
100
  EOF
116
101
  end
117
102
 
@@ -151,3 +136,5 @@ module DataObjectsSpecHelpers
151
136
  end
152
137
 
153
138
  end
139
+
140
+ include DataObjectsSpecHelpers
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/array_spec'
5
5
 
6
6
  describe 'DataObjects::Sqlite3 with Array' do
7
- it_should_behave_like 'supporting Array'
7
+ behaves_like 'supporting Array'
8
8
  end
@@ -7,5 +7,5 @@ require 'data_objects/spec/typecast/bigdecimal_spec'
7
7
  # http://www.sqlite.org/datatype3.html
8
8
 
9
9
  describe 'DataObjects::Sqlite3 with BigDecimal' do
10
- it_should_behave_like 'supporting BigDecimal'
10
+ behaves_like 'supporting BigDecimal'
11
11
  end
@@ -7,5 +7,5 @@ require 'data_objects/spec/typecast/boolean_spec'
7
7
  # http://www.sqlite.org/datatype3.html
8
8
 
9
9
  describe 'DataObjects::Sqlite3 with Boolean' do
10
- it_should_behave_like 'supporting Boolean'
10
+ behaves_like 'supporting Boolean'
11
11
  end
@@ -4,6 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/byte_array_spec'
5
5
 
6
6
  describe 'DataObjects::Sqlite3 with ByteArray' do
7
- # We need to switch to using parameter binding for this to work with Sqlite3
8
- # it_should_behave_like 'supporting ByteArray'
7
+ behaves_like 'supporting ByteArray'
9
8
  end
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/class_spec'
5
5
 
6
6
  describe 'DataObjects::Sqlite3 with Class' do
7
- it_should_behave_like 'supporting Class'
7
+ behaves_like 'supporting Class'
8
8
  end
@@ -7,5 +7,5 @@ require 'data_objects/spec/typecast/date_spec'
7
7
  # http://www.sqlite.org/datatype3.html
8
8
 
9
9
  describe 'DataObjects::Sqlite3 with Date' do
10
- it_should_behave_like 'supporting Date'
10
+ behaves_like 'supporting Date'
11
11
  end
@@ -7,5 +7,5 @@ require 'data_objects/spec/typecast/datetime_spec'
7
7
  # http://www.sqlite.org/datatype3.html
8
8
 
9
9
  describe 'DataObjects::Sqlite3 with DateTime' do
10
- it_should_behave_like 'supporting DateTime'
10
+ behaves_like 'supporting DateTime'
11
11
  end
@@ -4,9 +4,9 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/float_spec'
5
5
 
6
6
  describe 'DataObjects::Sqlite3 with Float' do
7
- it_should_behave_like 'supporting Float'
7
+ behaves_like 'supporting Float'
8
8
  end
9
9
 
10
10
  describe 'DataObjects::Sqlite3 with Float' do
11
- it_should_behave_like 'supporting Float autocasting'
11
+ behaves_like 'supporting Float autocasting'
12
12
  end
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/integer_spec'
5
5
 
6
6
  describe 'DataObjects::Sqlite3 with Integer' do
7
- it_should_behave_like 'supporting Integer'
7
+ behaves_like 'supporting Integer'
8
8
  end
@@ -4,17 +4,17 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/nil_spec'
5
5
 
6
6
  # splitting the descibe into two separate declaration avoids
7
- # concurrent execution of the "it_should_behave_like ....." calls
7
+ # concurrent execution of the "behaves_like ....." calls
8
8
  # which would lock the database
9
9
 
10
10
  describe 'DataObjects::Sqlite3 with Nil' do
11
- it_should_behave_like 'supporting Nil'
11
+ behaves_like 'supporting Nil'
12
12
  end
13
13
 
14
14
  describe 'DataObjects::Sqlite3 with Nil' do
15
- it_should_behave_like 'supporting writing an Nil'
15
+ behaves_like 'supporting writing an Nil'
16
16
  end
17
17
 
18
18
  describe 'DataObjects::Sqlite3 with Nil' do
19
- it_should_behave_like 'supporting Nil autocasting'
19
+ behaves_like 'supporting Nil autocasting'
20
20
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
+ require 'data_objects/spec/typecast/other_spec'
5
+
6
+ describe 'DataObjects::H2 with other (unknown) type' do
7
+ behaves_like 'supporting other (unknown) type'
8
+ end
@@ -4,5 +4,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
4
  require 'data_objects/spec/typecast/range_spec'
5
5
 
6
6
  describe 'DataObjects::Sqlite3 with Range' do
7
- it_should_behave_like 'supporting Range'
7
+ behaves_like 'supporting Range'
8
8
  end