do_sqlite3 0.9.11 → 0.9.12

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.
Files changed (41) hide show
  1. data/LICENSE +1 -1
  2. data/Manifest.txt +15 -4
  3. data/Rakefile +7 -207
  4. data/ext/do_sqlite3_ext/do_sqlite3_ext.c +187 -71
  5. data/ext/do_sqlite3_ext/extconf.rb +2 -0
  6. data/lib/do_sqlite3/version.rb +1 -1
  7. data/spec/command_spec.rb +8 -0
  8. data/spec/connection_spec.rb +18 -0
  9. data/spec/lib/rspec_immediate_feedback_formatter.rb +3 -0
  10. data/spec/reader_spec.rb +8 -0
  11. data/spec/result_spec.rb +9 -0
  12. data/spec/spec_helper.rb +88 -17
  13. data/spec/typecast/array_spec.rb +8 -0
  14. data/spec/typecast/bigdecimal_spec.rb +8 -0
  15. data/spec/typecast/boolean_spec.rb +8 -0
  16. data/spec/typecast/byte_array_spec.rb +9 -0
  17. data/spec/typecast/class_spec.rb +8 -0
  18. data/spec/typecast/date_spec.rb +8 -0
  19. data/spec/typecast/datetime_spec.rb +8 -0
  20. data/spec/typecast/float_spec.rb +8 -0
  21. data/spec/typecast/integer_spec.rb +8 -0
  22. data/spec/typecast/nil_spec.rb +10 -0
  23. data/spec/typecast/range_spec.rb +8 -0
  24. data/spec/typecast/string_spec.rb +8 -0
  25. data/spec/typecast/time_spec.rb +8 -0
  26. data/tasks/gem.rake +61 -0
  27. data/tasks/install.rake +15 -0
  28. data/tasks/native.rake +35 -0
  29. data/tasks/release.rake +75 -0
  30. data/tasks/retrieve.rake +104 -0
  31. data/tasks/spec.rake +18 -0
  32. metadata +71 -39
  33. data/.gitignore +0 -3
  34. data/buildfile +0 -27
  35. data/ext-java/src/main/java/DoSqlite3ExtService.java +0 -23
  36. data/ext-java/src/main/java/do_sqlite3/Sqlite3DriverDefinition.java +0 -26
  37. data/spec/integration/do_sqlite3_spec.rb +0 -278
  38. data/spec/integration/logging_spec.rb +0 -53
  39. data/spec/integration/quoting_spec.rb +0 -23
  40. data/spec/spec.opts +0 -2
  41. data/spec/unit/transaction_spec.rb +0 -34
@@ -0,0 +1,75 @@
1
+ begin
2
+ gem 'rubyforge', '~> 1.0.1'
3
+ require 'rubyforge'
4
+ rescue Exception
5
+ nil
6
+ end
7
+
8
+ if defined?(RubyForge) then
9
+ if defined?(GEM_SPEC) then
10
+ desc 'Package and upload to RubyForge'
11
+ task :release => [:package] do |t|
12
+ ver = ENV['VERSION'] or fail "Must supply VERSION (rake release VERSION=x.y.z)."
13
+
14
+ # compare versions to avoid mistakes
15
+ unless ver == GEM_SPEC.version.to_s then
16
+ fail "Version mismatch (supplied and specification versions differ)."
17
+ end
18
+
19
+ # no rubyforge project? no release for you!
20
+ if GEM_SPEC.rubyforge_project == 'TODO' or GEM_SPEC.rubyforge_project.nil? then
21
+ fail "Must define rubyforge_project in your gem specification."
22
+ end
23
+
24
+ # instantiate a RubyForge object
25
+ rf = RubyForge.new
26
+
27
+ # read project info and overview
28
+ notes = begin
29
+ r = File.read("README.rdoc")
30
+ r.split(/^(=+ .*)/)[1..4].join.strip
31
+ rescue
32
+ warn "Missing README.rdoc"
33
+ ''
34
+ end
35
+
36
+ # read changes
37
+ changes = begin
38
+ h = File.read("History.txt")
39
+ h.split(/^(==+ .*)/)[1..2].join.strip
40
+ rescue
41
+ warn "Missing History.txt"
42
+ ''
43
+ end
44
+
45
+ # build the configuration for the release
46
+ config = Hash.new
47
+ config["release_notes"] = notes
48
+ config["release_changes"] = changes
49
+ config["preformatted"] = true
50
+
51
+ # prepare configuration
52
+ rf.configure config
53
+
54
+ files = FileList["pkg/#{GEM_SPEC.name}-#{GEM_SPEC.version}*.*"].to_a
55
+ fail "No files found for the release." if files.empty?
56
+
57
+ puts "Logging in RubyForge..."
58
+ rf.login
59
+
60
+ puts "Files to upload:"
61
+ files.each do |f|
62
+ puts " * #{f}"
63
+ end
64
+
65
+ puts "Releasing #{GEM_SPEC.name} version #{GEM_SPEC.version}..."
66
+ rf.add_release GEM_SPEC.rubyforge_project, GEM_SPEC.name, GEM_SPEC.version, *files
67
+ puts "Done."
68
+ end
69
+ #Rake::Task['release'].prerequisites.unshift('clean', 'cross', 'native')
70
+ else
71
+ warn "no GEM_SPEC is found or defined. 'release' task cannot work without it."
72
+ end
73
+ else
74
+ warn "rubyforge gem is required to generate releases, please install it (gem install rubyforge)."
75
+ end
@@ -0,0 +1,104 @@
1
+ begin
2
+ gem('rake-compiler')
3
+ require 'rake/clean'
4
+ require 'rake/extensioncompiler'
5
+
6
+ # download sqlite3 library and headers
7
+
8
+ # only on Windows or cross platform compilation
9
+ def dlltool(dllname, deffile, libfile)
10
+ # define if we are using GCC or not
11
+ if Rake::ExtensionCompiler.mingw_gcc_executable then
12
+ dir = File.dirname(Rake::ExtensionCompiler.mingw_gcc_executable)
13
+ tool = case RUBY_PLATFORM
14
+ when /mingw/
15
+ File.join(dir, 'dlltool.exe')
16
+ when /linux|darwin/
17
+ File.join(dir, "#{Rake::ExtensionCompiler.mingw_host}-dlltool")
18
+ end
19
+ return "#{tool} --dllname #{dllname} --def #{deffile} --output-lib #{libfile}"
20
+ else
21
+ if RUBY_PLATFORM =~ /mswin/ then
22
+ tool = 'lib.exe'
23
+ else
24
+ fail "Unsupported platform for cross-compilation (please, contribute some patches)."
25
+ end
26
+ return "#{tool} /DEF:#{deffile} /OUT:#{libfile}"
27
+ end
28
+ end
29
+
30
+ # required folder structure for --with-sqlite3-dir (include + lib)
31
+ directory "vendor/sqlite3/lib"
32
+ directory "vendor/sqlite3/include"
33
+
34
+ # download amalgamation BINARY_VERSION (for include files)
35
+ file "vendor/sqlite-amalgamation-#{BINARY_VERSION}.zip" => ['vendor'] do |t|
36
+ url = "http://www.sqlite.org/#{File.basename(t.name)}"
37
+ when_writing "downloading #{t.name}" do
38
+ cd File.dirname(t.name) do
39
+ system "wget -c #{url} || curl -C - -O #{url}"
40
+ end
41
+ end
42
+ end
43
+
44
+ # download dll binaries
45
+ file "vendor/sqlitedll-#{BINARY_VERSION}.zip" => ['vendor'] do |t|
46
+ url = "http://www.sqlite.org/#{File.basename(t.name)}"
47
+ when_writing "downloading #{t.name}" do
48
+ cd File.dirname(t.name) do
49
+ system "wget -c #{url} || curl -C - -O #{url}"
50
+ end
51
+ end
52
+ end
53
+
54
+ # extract header files into include folder
55
+ file "vendor/sqlite3/include/sqlite3.h" => ['vendor/sqlite3/include', "vendor/sqlite-amalgamation-#{BINARY_VERSION}.zip"] do |t|
56
+ full_file = File.expand_path(t.prerequisites.last)
57
+ when_writing "creating #{t.name}" do
58
+ cd File.dirname(t.name) do
59
+ sh "unzip #{full_file}"
60
+ # update file timestamp to avoid Rake perform this extraction again.
61
+ touch File.basename(t.name)
62
+ end
63
+ end
64
+ end
65
+
66
+ # extract dll files into lib folder
67
+ file "vendor/sqlite3/lib/sqlite3.dll" => ['vendor/sqlite3/lib', "vendor/sqlitedll-#{BINARY_VERSION}.zip"] do |t|
68
+ full_file = File.expand_path(t.prerequisites.last)
69
+ when_writing "creating #{t.name}" do
70
+ cd File.dirname(t.name) do
71
+ sh "unzip #{full_file}"
72
+ # update file timestamp to avoid Rake perform this extraction again.
73
+ touch File.basename(t.name)
74
+ end
75
+ end
76
+ end
77
+
78
+ # generate import library from definition and dll file
79
+ file "vendor/sqlite3/lib/sqlite3.lib" => ["vendor/sqlite3/lib/sqlite3.dll"] do |t|
80
+ libfile = t.name
81
+ dllname = libfile.ext('dll')
82
+ deffile = libfile.ext('def')
83
+
84
+ when_writing "creating #{t.name}" do
85
+ sh dlltool(dllname, deffile, libfile)
86
+ end
87
+ end
88
+
89
+ # clobber vendored packages
90
+ CLOBBER.include('vendor')
91
+
92
+ # vendor:sqlite3
93
+ task 'vendor:sqlite3' => ["vendor/sqlite3/lib/sqlite3.lib", "vendor/sqlite3/include/sqlite3.h"]
94
+
95
+ # hook into cross compilation vendored sqlite3 dependency
96
+ if RUBY_PLATFORM =~ /mingw|mswin/ then
97
+ Rake::Task['compile'].prerequisites.unshift 'vendor:sqlite3'
98
+ else
99
+ if Rake::Task.tasks.map {|t| t.name }.include? 'cross'
100
+ Rake::Task['cross'].prerequisites.unshift 'vendor:sqlite3'
101
+ end
102
+ end
103
+ rescue LoadError
104
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,18 @@
1
+ # Specs
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Run specifications'
5
+ Spec::Rake::SpecTask.new(:spec => [ :clean, :compile ]) do |t|
6
+ t.spec_opts << '--options' << ROOT + 'spec/spec.opts'
7
+ t.spec_files = Pathname.glob(ENV['FILES'] || 'spec/**/*_spec.rb').map { |f| f.to_s }
8
+
9
+ begin
10
+ # RCov is run by default, except on the JRuby platform
11
+ t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
12
+ t.rcov_opts << '--exclude' << 'spec'
13
+ t.rcov_opts << '--text-summary'
14
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
15
+ rescue Exception
16
+ # rcov not installed
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_sqlite3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.9.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirkjan Bussink
@@ -9,9 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-19 00:00:00 +01:00
12
+ date: 2009-05-17 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: addressable
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: extlib
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.12
34
+ version:
15
35
  - !ruby/object:Gem::Dependency
16
36
  name: data_objects
17
37
  type: :runtime
@@ -20,59 +40,71 @@ dependencies:
20
40
  requirements:
21
41
  - - "="
22
42
  - !ruby/object:Gem::Version
23
- version: 0.9.11
43
+ version: 0.9.12
24
44
  version:
25
45
  - !ruby/object:Gem::Dependency
26
- name: hoe
46
+ name: rspec
27
47
  type: :development
28
48
  version_requirement:
29
49
  version_requirements: !ruby/object:Gem::Requirement
30
50
  requirements:
31
- - - ">="
51
+ - - ~>
32
52
  - !ruby/object:Gem::Version
33
- version: 1.8.2
53
+ version: 1.2.0
34
54
  version:
35
- description: A DataObject.rb driver for Sqlite3
36
- email:
37
- - d.bussink@gmail.com
55
+ description: Implements the DataObjects API for Sqlite3
56
+ email: d.bussink@gmail.com
38
57
  executables: []
39
58
 
40
59
  extensions:
41
60
  - ext/do_sqlite3_ext/extconf.rb
42
- extra_rdoc_files:
43
- - History.txt
44
- - Manifest.txt
45
- - README.txt
61
+ extra_rdoc_files: []
62
+
46
63
  files:
47
- - .gitignore
48
- - History.txt
49
- - LICENSE
50
- - Manifest.txt
51
- - README.txt
52
- - Rakefile
53
- - buildfile
54
- - ext-java/src/main/java/DoSqlite3ExtService.java
55
- - ext-java/src/main/java/do_sqlite3/Sqlite3DriverDefinition.java
56
- - ext/do_sqlite3_ext/do_sqlite3_ext.c
57
- - ext/do_sqlite3_ext/extconf.rb
58
- - lib/do_sqlite3.rb
59
64
  - lib/do_sqlite3/transaction.rb
60
65
  - lib/do_sqlite3/version.rb
61
- - spec/integration/do_sqlite3_spec.rb
62
- - spec/integration/logging_spec.rb
63
- - spec/integration/quoting_spec.rb
64
- - spec/spec.opts
66
+ - lib/do_sqlite3.rb
67
+ - spec/command_spec.rb
68
+ - spec/connection_spec.rb
69
+ - spec/lib/rspec_immediate_feedback_formatter.rb
70
+ - spec/reader_spec.rb
71
+ - spec/result_spec.rb
65
72
  - spec/spec_helper.rb
66
- - spec/unit/transaction_spec.rb
67
- has_rdoc: false
68
- homepage: http://rubyforge.org/projects/dorb
69
- post_install_message:
70
- rdoc_options:
71
- - --main
73
+ - spec/typecast/array_spec.rb
74
+ - spec/typecast/bigdecimal_spec.rb
75
+ - spec/typecast/boolean_spec.rb
76
+ - spec/typecast/byte_array_spec.rb
77
+ - spec/typecast/class_spec.rb
78
+ - spec/typecast/date_spec.rb
79
+ - spec/typecast/datetime_spec.rb
80
+ - spec/typecast/float_spec.rb
81
+ - spec/typecast/integer_spec.rb
82
+ - spec/typecast/nil_spec.rb
83
+ - spec/typecast/range_spec.rb
84
+ - spec/typecast/string_spec.rb
85
+ - spec/typecast/time_spec.rb
86
+ - tasks/gem.rake
87
+ - tasks/install.rake
88
+ - tasks/native.rake
89
+ - tasks/release.rake
90
+ - tasks/retrieve.rake
91
+ - tasks/spec.rake
92
+ - ext/do_sqlite3_ext/extconf.rb
93
+ - ext/do_sqlite3_ext/do_sqlite3_ext.c
94
+ - LICENSE
95
+ - Rakefile
96
+ - History.txt
97
+ - Manifest.txt
72
98
  - README.txt
99
+ has_rdoc: true
100
+ homepage: http://github.com/datamapper/do
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options: []
105
+
73
106
  require_paths:
74
107
  - lib
75
- - ext
76
108
  required_ruby_version: !ruby/object:Gem::Requirement
77
109
  requirements:
78
110
  - - ">="
@@ -88,9 +120,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
120
  requirements: []
89
121
 
90
122
  rubyforge_project: dorb
91
- rubygems_version: 1.3.1
123
+ rubygems_version: 1.3.3
92
124
  signing_key:
93
- specification_version: 2
94
- summary: A DataObject.rb driver for Sqlite3
125
+ specification_version: 3
126
+ summary: DataObjects Sqlite3 Driver
95
127
  test_files: []
96
128
 
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- test.db
2
- test.db-journal
3
- tmp/
data/buildfile DELETED
@@ -1,27 +0,0 @@
1
- # Apache Buildr buildfile for do_sqlite3
2
- # see http://incubator.apache.org/buildr/ for more information on Apache Buildr
3
- require 'buildr'
4
- require 'pathname'
5
-
6
- VERSION_NUMBER = '1.0'
7
- JDBC_SUPPORT = ['data_objects:jdbc:jar:1.0']
8
- TARGET_DIR = 'pkg/classes'
9
- repositories.remote << 'http://www.ibiblio.org/maven2/'
10
-
11
- define 'do_sqlite3' do
12
- project.version = VERSION_NUMBER
13
- project.group = 'data_objects.rb'
14
-
15
- manifest['Copyright'] = 'Alex Coles (C) 2008-2009'
16
-
17
- compile.using :target => '1.5', :lint => 'all', :deprecation => 'true'
18
-
19
- define 'ext-java' do
20
- package(:jar).clean.include(TARGET_DIR)
21
-
22
- jdbc_support_jar = file('../../do_jdbc/lib/do_jdbc_internal.jar')
23
- jdbc_support = artifact('data_objects:jdbc:jar:1.0').from(jdbc_support_jar)
24
-
25
- compile.into(TARGET_DIR).with(JDBC_SUPPORT)
26
- end
27
- end
@@ -1,23 +0,0 @@
1
- import data_objects.drivers.DriverDefinition;
2
- import do_sqlite3.Sqlite3DriverDefinition;
3
-
4
- public class DoSqlite3ExtService extends AbstractDataObjectsExtService {
5
-
6
- private final static DriverDefinition driver = new Sqlite3DriverDefinition();
7
- public final static String RUBY_MODULE_NAME = "Sqlite3";
8
- public final static String RUBY_ERROR_NAME = "Sqlite3Error";
9
-
10
- public String getModuleName() {
11
- return RUBY_MODULE_NAME;
12
- }
13
-
14
- @Override
15
- public String getErrorName() {
16
- return RUBY_ERROR_NAME;
17
- }
18
-
19
- public DriverDefinition getDriverDefinition() {
20
- return driver;
21
- }
22
-
23
- }
@@ -1,26 +0,0 @@
1
- package do_sqlite3;
2
-
3
- import data_objects.drivers.AbstractDriverDefinition;
4
-
5
- public class Sqlite3DriverDefinition extends AbstractDriverDefinition {
6
-
7
- public boolean supportsJdbcGeneratedKeys()
8
- {
9
- return true;
10
- }
11
-
12
- public boolean supportsConnectionPrepareStatementMethodWithGKFlag()
13
- {
14
- return false;
15
- }
16
-
17
- //@Override
18
- public String quoteString(String str) {
19
- StringBuffer quotedValue = new StringBuffer(str.length() + 2);
20
- quotedValue.append("\'");
21
- quotedValue.append(str.replaceAll("'", "''"));
22
- quotedValue.append("\'");
23
- return quotedValue.toString();
24
- }
25
-
26
- }
@@ -1,278 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe "DataObjects::Sqlite3" do
5
- include Sqlite3SpecHelpers
6
-
7
- it "should raise error on bad connection string" do
8
- pending
9
- # lambda { DataObjects::Connection.new("sqlite3:///ac0d9iopalmsdcasd/asdc9pomasd/test.db") }.should raise_error("unable to open database file")
10
- end
11
-
12
- if JRUBY
13
- it "should accept either DO or JDBC style URLs on JRuby" do
14
- pending
15
- @connection = DataObjects::Connection.new("jdbc:sqlite:test.db") # note the sqlite not sqlite3!
16
- @connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
17
- end
18
- end
19
-
20
- end
21
-
22
- NOW = DateTime.now
23
-
24
- describe "DataObjects::Sqlite3::Result" do
25
- include Sqlite3SpecHelpers
26
-
27
- before(:all) do
28
- @connection = DataObjects::Connection.new("sqlite3://#{File.expand_path(File.dirname(__FILE__))}/test.db")
29
- end
30
-
31
- before do
32
- class ::Person; end
33
- end
34
-
35
- after :all do
36
- @connection.close
37
- end
38
-
39
- after do
40
- Object.send(:remove_const, :Person)
41
- end
42
-
43
- it "should raise an error for a bad query" do
44
- command = @connection.create_command("INSER INTO table_which_doesnt_exist (id) VALUES (1)")
45
- lambda { command.execute_non_query }.should raise_error(Sqlite3Error, /near "INSER": syntax error/)
46
-
47
- command = @connection.create_command("INSERT INTO table_which_doesnt_exist (id) VALUES (1)")
48
- lambda { command.execute_non_query }.should raise_error(Sqlite3Error, /no such table: table_which_doesnt_exist/)
49
-
50
- command = @connection.create_command("SELECT * FROM table_which_doesnt_exist")
51
- lambda { command.execute_reader }.should raise_error(Sqlite3Error, /no such table: table_which_doesnt_exist/)
52
- end
53
-
54
- it "should return the affected rows and insert_id" do
55
- command = @connection.create_command("DROP TABLE users")
56
- command.execute_non_query rescue nil
57
- command = @connection.create_command("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, type TEXT, age INTEGER, created_at DATETIME, balance DECIMAL default '0.00')")
58
- result = command.execute_non_query
59
- command = @connection.create_command("INSERT INTO users (name) VALUES ('test')")
60
- result = command.execute_non_query
61
- result.insert_id.should == 1
62
- result.to_i.should == 1
63
- end
64
-
65
- it "should do a reader query" do
66
- command = @connection.create_command("SELECT * FROM users")
67
- reader = command.execute_reader
68
-
69
- lambda { reader.values }.should raise_error(Sqlite3Error, /Reader is not initialized/)
70
-
71
- while ( reader.next! )
72
- lambda { reader.values }.should_not raise_error
73
- reader.values.should be_a_kind_of(Array)
74
- end
75
-
76
- lambda { reader.values }.should raise_error(Sqlite3Error, /Reader is not initialized/)
77
-
78
- reader.close
79
- end
80
-
81
- it "should do a parameterized reader query" do
82
- command = @connection.create_command("SELECT * FROM users WHERE id = ?")
83
- reader = command.execute_reader(1)
84
- reader.next!
85
-
86
- reader.values[0].should == 1
87
-
88
- reader.next!
89
-
90
- lambda { reader.values }.should raise_error(Sqlite3Error, /Reader is not initialized/)
91
-
92
- reader.close
93
- end
94
-
95
- it "should do a custom typecast reader" do
96
- command = @connection.create_command("SELECT name, id FROM users")
97
- command.set_types [String, String]
98
- reader = command.execute_reader
99
-
100
- while ( reader.next! )
101
- reader.fields.should == ["name", "id"]
102
- reader.values.each { |v| v.should be_a_kind_of(String) }
103
- end
104
-
105
- reader.close
106
-
107
- end
108
-
109
- it "should handle a null value" do
110
- id = insert("INSERT INTO users (name) VALUES (NULL)")
111
- select("SELECT name from users WHERE name is null") do |reader|
112
- reader.values[0].should == nil
113
- end
114
- end
115
-
116
- it "should not convert empty strings to null" do
117
- id = insert("INSERT INTO users (name) VALUES ('')")
118
- select("SELECT name FROM users WHERE id = ?", [String], id) do |reader|
119
- reader.values.first.should == ''
120
- end
121
- end
122
-
123
- it "should raise an error when you pass too many or too few types for the expected result set" do
124
- lambda { select("SELECT name, id FROM users", [String, Integer, String]) }.should raise_error(Sqlite3Error, /Field-count mismatch. Expected 3 fields, but the query yielded 2/)
125
- end
126
-
127
- it "should do a custom typecast reader with Class" do
128
- id = insert("INSERT INTO users (name, age, type) VALUES (?, ?, ?)", 'Sam', 30, Person)
129
-
130
- select("SELECT name, age, type FROM users WHERE id = ?", [String, Integer, Class], id) do |reader|
131
- reader.fields.should == ["name", "age", "type"]
132
- reader.values.should == ["Sam", 30, Person]
133
- end
134
-
135
- exec("DELETE FROM users WHERE id = ?", id)
136
- end
137
-
138
- [
139
- NOW.strftime('%Y-%m-%dT%H:%M:%S'),
140
- NOW.strftime('%Y-%m-%d %H:%M:%S')
141
- ].each do |raw_value|
142
- it "should return #{NOW.to_s} using the LOCAL timezone when typecasting '#{raw_value}'" do
143
-
144
- # Insert a timezone-less DateTime into the DB
145
- id = insert("INSERT INTO users (name, age, type, created_at) VALUES (?, ?, ?, ?)", 'Sam', 30, Person, raw_value)
146
-
147
- select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
148
- reader.values.last.to_s.should == NOW.to_s
149
- end
150
-
151
- exec("DELETE FROM users WHERE id = ?", id)
152
- end
153
- end
154
-
155
- it "should not blow up when an empty string for a timestamp is used" do
156
- id = insert("INSERT INTO users (name, age, type, created_at) VALUES (?, ?, ?, ?)", 'Sam', 30, Person, "")
157
-
158
- select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
159
- reader.values.last.should == nil
160
- end
161
- end
162
-
163
- it "should return DateTimes using the same timezone that was used to insert it" do
164
- pending "improved support for timezone checking"
165
-
166
- dates = [
167
- NOW,
168
- NOW.new_offset( (-11 * 3600).to_r / 86400), # GMT -11:00
169
- NOW.new_offset( (-9 * 3600 + 10 * 60).to_r / 86400), # GMT -9:10
170
- NOW.new_offset( (-8 * 3600).to_r / 86400), # GMT -08:00
171
- NOW.new_offset( (+3 * 3600).to_r / 86400), # GMT +03:00
172
- NOW.new_offset( (+5 * 3600 + 30 * 60).to_r / 86400) # GMT +05:30 (New Delhi)
173
- ]
174
-
175
- dates.each do |date|
176
- id = insert("INSERT INTO users (name, age, type, created_at) VALUES (?, ?, ?, ?)", 'Sam', 30, Person, date)
177
-
178
- select("SELECT created_at FROM users WHERE id = ?", [DateTime], id) do |reader|
179
- reader.values.last.year.should == date.year
180
- reader.values.last.month.should == date.month
181
- reader.values.last.day.should == date.day
182
- reader.values.last.hour.should == date.hour
183
- reader.values.last.min.should == date.min
184
- reader.values.last.sec.should == date.sec
185
- reader.values.last.zone.should == date.zone
186
- end
187
-
188
- exec("DELETE FROM users WHERE id = ?", id)
189
- end
190
- end
191
-
192
- it "should return a BigDecimal" do
193
- pending "We need to introduce something like Proxy for typeasting where each SQL type will have _rules_ of casting" if JRUBY
194
- balance = BigDecimal.new('10000000000.00')
195
-
196
- #looks like inserting BigDecimals is not implemented in SQLITE's jdbc driver http://zentus.com/sqlitejdbc/src/src/org/sqlite/Unused.java
197
- id = insert("INSERT INTO users (name, age, type, created_at, balance) VALUES (?, ?, ?, ?, ?)", 'Scott', 27, Person, DateTime.now, balance)
198
-
199
- select("SELECT balance FROM users WHERE id = ?", [BigDecimal], id) do |reader|
200
- reader.values.last.should == balance
201
- end
202
- end
203
-
204
- unless JRUBY
205
-
206
- describe "quoting" do
207
-
208
- before do
209
- @connection.create_command("DROP TABLE IF EXISTS sail_boats").execute_non_query
210
- @connection.create_command("CREATE TABLE sail_boats ( id INTEGER PRIMARY KEY, name VARCHAR(50), port VARCHAR(50), notes VARCHAR(50), vintage BOOLEAN )").execute_non_query
211
- command = @connection.create_command("INSERT INTO sail_boats (id, name, port, name, vintage) VALUES (?, ?, ?, ?, ?)")
212
- command.execute_non_query(1, "A", "C", "Fortune Pig!", false)
213
- command.execute_non_query(2, "B", "B", "Happy Cow!", true)
214
- command.execute_non_query(3, "C", "A", "Spoon", true)
215
- end
216
-
217
- after do
218
- @connection.create_command("DROP TABLE sail_boats").execute_non_query
219
- end
220
-
221
- it "should quote a String" do
222
- command = @connection.create_command("INSERT INTO users (name) VALUES (?)")
223
- result = command.execute_non_query("John Doe")
224
- result.to_i.should == 1
225
- end
226
-
227
- it "should quote multiple values" do
228
- command = @connection.create_command("INSERT INTO users (name, age) VALUES (?, ?)")
229
- result = command.execute_non_query("Sam Smoot", 1)
230
- result.to_i.should == 1
231
- end
232
-
233
-
234
- it "should handle boolean columns gracefully" do
235
- command = @connection.create_command("INSERT INTO sail_boats (id, name, port, name, vintage) VALUES (?, ?, ?, ?, ?)")
236
- result = command.execute_non_query(4, "Scooner", "Port au Prince", "This is one gangster boat!", true)
237
- result.to_i.should == 1
238
- end
239
-
240
- it "should quote an Array" do
241
- command = @connection.create_command("SELECT id, notes FROM sail_boats WHERE (id IN ?)")
242
- reader = command.execute_reader([1, 2, 3])
243
-
244
- i = 1
245
- while(reader.next!)
246
- reader.values[0].should == i
247
- i += 1
248
- end
249
- end
250
-
251
- it "should quote an Array with NULL values returned" do
252
- command = @connection.create_command("SELECT id, NULL AS notes FROM sail_boats WHERE (id IN ?)")
253
- reader = command.execute_reader([1, 2, 3])
254
-
255
- i = 1
256
- while(reader.next!)
257
- reader.values[0].should == i
258
- i += 1
259
- end
260
- end
261
-
262
- it "should quote an Array with NULL values returned AND set_types called" do
263
- command = @connection.create_command("SELECT id, NULL AS notes FROM sail_boats WHERE (id IN ?)")
264
- command.set_types [ Integer, String ]
265
-
266
- reader = command.execute_reader([1, 2, 3])
267
-
268
- i = 1
269
- while(reader.next!)
270
- reader.values[0].should == i
271
- i += 1
272
- end
273
- end
274
-
275
- end # describe "quoting"
276
-
277
- end
278
- end