sqlite3 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -12
- data/lib/sqlite3.rb +1 -0
- data/lib/sqlite3/constants.rb +32 -0
- data/lib/sqlite3/database.rb +32 -0
- data/lib/sqlite3/driver.rb +8 -4
- data/lib/sqlite3/errors.rb +32 -0
- data/lib/sqlite3/pragmas.rb +32 -0
- data/lib/sqlite3/resultset.rb +32 -0
- data/lib/sqlite3/version.rb +3 -0
- metadata +55 -52
- data/.document +0 -5
- data/.gitignore +0 -22
- data/Rakefile +0 -67
- data/VERSION +0 -1
- data/sqlite3.gemspec +0 -89
- data/test/fixtures/SQLite.gif +0 -0
- data/test/helper.rb +0 -13
- data/test/test_active_record.rb +0 -158
- data/test/test_database_initialization.rb +0 -51
- data/test/test_database_queries_utf_16.rb +0 -80
- data/test/test_database_queries_utf_8.rb +0 -80
- data/test/test_statement.rb +0 -42
data/README.rdoc
CHANGED
@@ -1,17 +1,6 @@
|
|
1
1
|
= sqlite3
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
== Note on Patches/Pull Requests
|
6
|
-
|
7
|
-
* Fork the project.
|
8
|
-
* Make your feature addition or bug fix.
|
9
|
-
* Add tests for it. This is important so I don't break it in a
|
10
|
-
future version unintentionally.
|
11
|
-
* Commit, do not mess with rakefile, version, or history.
|
12
|
-
(if you want to have your own version, that is fine but
|
13
|
-
bump version in a commit by itself I can ignore when I pull)
|
14
|
-
* Send me a pull request. Bonus points for topic branches.
|
3
|
+
SQLite3 FFI bindings for Ruby 1.9.
|
15
4
|
|
16
5
|
== Copyright
|
17
6
|
|
data/lib/sqlite3.rb
CHANGED
data/lib/sqlite3/constants.rb
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
# Copyright (c) 2004, Jamis Buck (jamis@jamisbuck.org)
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in
|
13
|
+
# the documentation and/or other materials provided with the
|
14
|
+
# distribution.
|
15
|
+
|
16
|
+
# * The names of its contributors may not be used to endorse or
|
17
|
+
# promote products derived from this software without specific prior
|
18
|
+
# written permission.
|
19
|
+
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
23
|
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
26
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
27
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30
|
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
1
33
|
module SQLite3
|
2
34
|
module Constants
|
3
35
|
|
data/lib/sqlite3/database.rb
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
# Copyright (c) 2004, Jamis Buck (jamis@jamisbuck.org)
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in
|
13
|
+
# the documentation and/or other materials provided with the
|
14
|
+
# distribution.
|
15
|
+
|
16
|
+
# * The names of its contributors may not be used to endorse or
|
17
|
+
# promote products derived from this software without specific prior
|
18
|
+
# written permission.
|
19
|
+
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
23
|
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
26
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
27
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30
|
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
1
33
|
module SQLite3
|
2
34
|
|
3
35
|
# The Database class encapsulates a single connection to a SQLite3 database.
|
data/lib/sqlite3/driver.rb
CHANGED
@@ -5,10 +5,10 @@ module SQLite3
|
|
5
5
|
def open(filename, utf_16 = false)
|
6
6
|
handle = FFI::MemoryPointer.new(:pointer)
|
7
7
|
if utf_16
|
8
|
-
filename = filename.encode(Encoding.utf_16native)
|
8
|
+
filename = filename.encode(Encoding.utf_16native) if filename.respond_to?(:encode)
|
9
9
|
result = API.sqlite3_open16(c_string(filename), handle)
|
10
10
|
else
|
11
|
-
filename = filename.encode(Encoding.utf_8)
|
11
|
+
filename = filename.encode(Encoding.utf_8) if filename.respond_to?(:encode)
|
12
12
|
result = API.sqlite3_open(filename, handle)
|
13
13
|
end
|
14
14
|
[result, handle.get_pointer(0)]
|
@@ -17,9 +17,13 @@ module SQLite3
|
|
17
17
|
def errmsg(db, utf_16 = false)
|
18
18
|
if utf_16
|
19
19
|
ptr = API.sqlite3_errmsg16(db)
|
20
|
-
get_string_utf_16(ptr)
|
20
|
+
result = get_string_utf_16(ptr)
|
21
|
+
result.force_encoding(Encoding.utf_16native) if result.respond_to?(:force_encoding)
|
22
|
+
result
|
21
23
|
else
|
22
|
-
API.sqlite3_errmsg(db)
|
24
|
+
result = API.sqlite3_errmsg(db)
|
25
|
+
result.force_encoding(Encoding.utf_8) if result.respond_to?(:force_encoding)
|
26
|
+
result
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
data/lib/sqlite3/errors.rb
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
# Copyright (c) 2004, Jamis Buck (jamis@jamisbuck.org)
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in
|
13
|
+
# the documentation and/or other materials provided with the
|
14
|
+
# distribution.
|
15
|
+
|
16
|
+
# * The names of its contributors may not be used to endorse or
|
17
|
+
# promote products derived from this software without specific prior
|
18
|
+
# written permission.
|
19
|
+
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
23
|
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
26
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
27
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30
|
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
1
33
|
module SQLite3
|
2
34
|
|
3
35
|
class Exception < ::StandardError
|
data/lib/sqlite3/pragmas.rb
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
# Copyright (c) 2004, Jamis Buck (jamis@jamisbuck.org)
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in
|
13
|
+
# the documentation and/or other materials provided with the
|
14
|
+
# distribution.
|
15
|
+
|
16
|
+
# * The names of its contributors may not be used to endorse or
|
17
|
+
# promote products derived from this software without specific prior
|
18
|
+
# written permission.
|
19
|
+
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
23
|
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
26
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
27
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30
|
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
1
33
|
module SQLite3
|
2
34
|
|
3
35
|
# This module is intended for inclusion solely by the Database class. It
|
data/lib/sqlite3/resultset.rb
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
# Copyright (c) 2004, Jamis Buck (jamis@jamisbuck.org)
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions
|
6
|
+
# are met:
|
7
|
+
|
8
|
+
# * Redistributions of source code must retain the above copyright
|
9
|
+
# notice, this list of conditions and the following disclaimer.
|
10
|
+
|
11
|
+
# * Redistributions in binary form must reproduce the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer in
|
13
|
+
# the documentation and/or other materials provided with the
|
14
|
+
# distribution.
|
15
|
+
|
16
|
+
# * The names of its contributors may not be used to endorse or
|
17
|
+
# promote products derived from this software without specific prior
|
18
|
+
# written permission.
|
19
|
+
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
23
|
+
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24
|
+
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
25
|
+
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
26
|
+
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
27
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29
|
+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30
|
+
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
32
|
+
|
1
33
|
module SQLite3
|
2
34
|
|
3
35
|
# The ResultSet object encapsulates the enumerability of a query's output.
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlite3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- "Jakub Ku\xC5\xBAma"
|
@@ -9,74 +14,73 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-02
|
17
|
+
date: 2010-05-02 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: ffi
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 6
|
30
|
+
- 3
|
31
|
+
version: 0.6.3
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: test-unit
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 0
|
33
44
|
version: "2.0"
|
34
|
-
|
45
|
+
type: :development
|
46
|
+
version_requirements: *id002
|
35
47
|
- !ruby/object:Gem::Dependency
|
36
48
|
name: activerecord
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
51
|
requirements:
|
41
52
|
- - ">="
|
42
53
|
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 2
|
56
|
+
- 3
|
57
|
+
- 5
|
43
58
|
version: 2.3.5
|
44
|
-
|
59
|
+
type: :development
|
60
|
+
version_requirements: *id003
|
45
61
|
description: SQLite3 FFI bindings for Ruby 1.9
|
46
62
|
email: qoobaa@gmail.com
|
47
63
|
executables: []
|
48
64
|
|
49
65
|
extensions: []
|
50
66
|
|
51
|
-
extra_rdoc_files:
|
52
|
-
|
53
|
-
- README.rdoc
|
67
|
+
extra_rdoc_files: []
|
68
|
+
|
54
69
|
files:
|
55
|
-
- .
|
56
|
-
- .
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
-
- lib/sqlite3.rb
|
70
|
+
- lib/sqlite3/driver.rb
|
71
|
+
- lib/sqlite3/resultset.rb
|
72
|
+
- lib/sqlite3/pragmas.rb
|
73
|
+
- lib/sqlite3/database.rb
|
74
|
+
- lib/sqlite3/version.rb
|
75
|
+
- lib/sqlite3/extensions.rb
|
76
|
+
- lib/sqlite3/errors.rb
|
62
77
|
- lib/sqlite3/api.rb
|
63
78
|
- lib/sqlite3/constants.rb
|
64
|
-
- lib/sqlite3/database.rb
|
65
|
-
- lib/sqlite3/driver.rb
|
66
79
|
- lib/sqlite3/encoding.rb
|
67
|
-
- lib/sqlite3/errors.rb
|
68
|
-
- lib/sqlite3/extensions.rb
|
69
|
-
- lib/sqlite3/pragmas.rb
|
70
|
-
- lib/sqlite3/resultset.rb
|
71
80
|
- lib/sqlite3/statement.rb
|
72
|
-
- sqlite3.
|
73
|
-
-
|
74
|
-
-
|
75
|
-
- test/test_active_record.rb
|
76
|
-
- test/test_database_initialization.rb
|
77
|
-
- test/test_database_queries_utf_16.rb
|
78
|
-
- test/test_database_queries_utf_8.rb
|
79
|
-
- test/test_statement.rb
|
81
|
+
- lib/sqlite3.rb
|
82
|
+
- LICENSE
|
83
|
+
- README.rdoc
|
80
84
|
has_rdoc: true
|
81
85
|
homepage: http://github.com/qoobaa/sqlite3
|
82
86
|
licenses: []
|
@@ -92,33 +96,32 @@ post_install_message: |
|
|
92
96
|
Thank you for installing sqlite3 gem! Suggestions: qoobaa@gmail.com
|
93
97
|
================================================================================
|
94
98
|
|
95
|
-
rdoc_options:
|
96
|
-
|
99
|
+
rdoc_options: []
|
100
|
+
|
97
101
|
require_paths:
|
98
102
|
- lib
|
99
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
104
|
requirements:
|
101
105
|
- - ">="
|
102
106
|
- !ruby/object:Gem::Version
|
107
|
+
segments:
|
108
|
+
- 0
|
103
109
|
version: "0"
|
104
|
-
version:
|
105
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
111
|
requirements:
|
107
112
|
- - ">="
|
108
113
|
- !ruby/object:Gem::Version
|
109
|
-
|
110
|
-
|
114
|
+
segments:
|
115
|
+
- 1
|
116
|
+
- 3
|
117
|
+
- 6
|
118
|
+
version: 1.3.6
|
111
119
|
requirements: []
|
112
120
|
|
113
121
|
rubyforge_project:
|
114
|
-
rubygems_version: 1.3.
|
122
|
+
rubygems_version: 1.3.6
|
115
123
|
signing_key:
|
116
124
|
specification_version: 3
|
117
125
|
summary: SQLite3 FFI bindings for Ruby 1.9
|
118
|
-
test_files:
|
119
|
-
|
120
|
-
- test/test_statement.rb
|
121
|
-
- test/test_active_record.rb
|
122
|
-
- test/test_database_queries_utf_16.rb
|
123
|
-
- test/test_database_initialization.rb
|
124
|
-
- test/helper.rb
|
126
|
+
test_files: []
|
127
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/Rakefile
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'rake'
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'jeweler'
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = "sqlite3"
|
10
|
-
gem.summary = %Q{SQLite3 FFI bindings for Ruby 1.9}
|
11
|
-
gem.description = %Q{SQLite3 FFI bindings for Ruby 1.9}
|
12
|
-
gem.email = "qoobaa@gmail.com"
|
13
|
-
gem.homepage = "http://github.com/qoobaa/sqlite3"
|
14
|
-
gem.authors = ["Jakub Kuźma"]
|
15
|
-
gem.add_dependency "ffi", ">= 0.6.0"
|
16
|
-
gem.add_development_dependency "test-unit", ">= 2.0"
|
17
|
-
gem.add_development_dependency "activerecord", ">= 2.3.5"
|
18
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
-
gem.post_install_message = <<-EOM
|
20
|
-
==== WARNING ===================================================================
|
21
|
-
This is an early alpha version of SQLite3/Ruby FFI bindings!
|
22
|
-
Currently we support Ruby 1.9 ONLY.
|
23
|
-
|
24
|
-
If you need native bindings for Ruby 1.8 - install sqlite3-ruby instead.
|
25
|
-
You may need to uninstall this sqlite3 gem as well.
|
26
|
-
|
27
|
-
Thank you for installing sqlite3 gem! Suggestions: qoobaa@gmail.com
|
28
|
-
================================================================================
|
29
|
-
EOM
|
30
|
-
end
|
31
|
-
rescue LoadError
|
32
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
33
|
-
end
|
34
|
-
|
35
|
-
require 'rake/testtask'
|
36
|
-
Rake::TestTask.new(:test) do |test|
|
37
|
-
test.libs << 'lib' << 'test'
|
38
|
-
test.pattern = 'test/**/test_*.rb'
|
39
|
-
test.verbose = true
|
40
|
-
end
|
41
|
-
|
42
|
-
begin
|
43
|
-
require 'rcov/rcovtask'
|
44
|
-
Rcov::RcovTask.new do |test|
|
45
|
-
test.libs << 'test'
|
46
|
-
test.pattern = 'test/**/test_*.rb'
|
47
|
-
test.verbose = true
|
48
|
-
end
|
49
|
-
rescue LoadError
|
50
|
-
task :rcov do
|
51
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
task :test => :check_dependencies
|
56
|
-
|
57
|
-
task :default => :test
|
58
|
-
|
59
|
-
require 'rake/rdoctask'
|
60
|
-
Rake::RDocTask.new do |rdoc|
|
61
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
62
|
-
|
63
|
-
rdoc.rdoc_dir = 'rdoc'
|
64
|
-
rdoc.title = "sqlite3 #{version}"
|
65
|
-
rdoc.rdoc_files.include('README*')
|
66
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
67
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.8
|
data/sqlite3.gemspec
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{sqlite3}
|
8
|
-
s.version = "0.0.8"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Jakub Kuźma"]
|
12
|
-
s.date = %q{2010-02-09}
|
13
|
-
s.description = %q{SQLite3 FFI bindings for Ruby 1.9}
|
14
|
-
s.email = %q{qoobaa@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/sqlite3.rb",
|
27
|
-
"lib/sqlite3/api.rb",
|
28
|
-
"lib/sqlite3/constants.rb",
|
29
|
-
"lib/sqlite3/database.rb",
|
30
|
-
"lib/sqlite3/driver.rb",
|
31
|
-
"lib/sqlite3/encoding.rb",
|
32
|
-
"lib/sqlite3/errors.rb",
|
33
|
-
"lib/sqlite3/extensions.rb",
|
34
|
-
"lib/sqlite3/pragmas.rb",
|
35
|
-
"lib/sqlite3/resultset.rb",
|
36
|
-
"lib/sqlite3/statement.rb",
|
37
|
-
"sqlite3.gemspec",
|
38
|
-
"test/fixtures/SQLite.gif",
|
39
|
-
"test/helper.rb",
|
40
|
-
"test/test_active_record.rb",
|
41
|
-
"test/test_database_initialization.rb",
|
42
|
-
"test/test_database_queries_utf_16.rb",
|
43
|
-
"test/test_database_queries_utf_8.rb",
|
44
|
-
"test/test_statement.rb"
|
45
|
-
]
|
46
|
-
s.homepage = %q{http://github.com/qoobaa/sqlite3}
|
47
|
-
s.post_install_message = %q{==== WARNING ===================================================================
|
48
|
-
This is an early alpha version of SQLite3/Ruby FFI bindings!
|
49
|
-
Currently we support Ruby 1.9 ONLY.
|
50
|
-
|
51
|
-
If you need native bindings for Ruby 1.8 - install sqlite3-ruby instead.
|
52
|
-
You may need to uninstall this sqlite3 gem as well.
|
53
|
-
|
54
|
-
Thank you for installing sqlite3 gem! Suggestions: qoobaa@gmail.com
|
55
|
-
================================================================================
|
56
|
-
}
|
57
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
58
|
-
s.require_paths = ["lib"]
|
59
|
-
s.rubygems_version = %q{1.3.5}
|
60
|
-
s.summary = %q{SQLite3 FFI bindings for Ruby 1.9}
|
61
|
-
s.test_files = [
|
62
|
-
"test/test_database_queries_utf_8.rb",
|
63
|
-
"test/test_statement.rb",
|
64
|
-
"test/test_active_record.rb",
|
65
|
-
"test/test_database_queries_utf_16.rb",
|
66
|
-
"test/test_database_initialization.rb",
|
67
|
-
"test/helper.rb"
|
68
|
-
]
|
69
|
-
|
70
|
-
if s.respond_to? :specification_version then
|
71
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
72
|
-
s.specification_version = 3
|
73
|
-
|
74
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
75
|
-
s.add_runtime_dependency(%q<ffi>, [">= 0.6.0"])
|
76
|
-
s.add_development_dependency(%q<test-unit>, [">= 2.0"])
|
77
|
-
s.add_development_dependency(%q<activerecord>, [">= 2.3.5"])
|
78
|
-
else
|
79
|
-
s.add_dependency(%q<ffi>, [">= 0.6.0"])
|
80
|
-
s.add_dependency(%q<test-unit>, [">= 2.0"])
|
81
|
-
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
82
|
-
end
|
83
|
-
else
|
84
|
-
s.add_dependency(%q<ffi>, [">= 0.6.0"])
|
85
|
-
s.add_dependency(%q<test-unit>, [">= 2.0"])
|
86
|
-
s.add_dependency(%q<activerecord>, [">= 2.3.5"])
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
data/test/fixtures/SQLite.gif
DELETED
Binary file
|
data/test/helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
gem "test-unit"
|
3
|
-
require "test/unit"
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
6
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
require "sqlite3"
|
8
|
-
|
9
|
-
class Test::Unit::TestCase
|
10
|
-
def fixture(filename)
|
11
|
-
File.join(File.dirname(__FILE__), "fixtures", filename)
|
12
|
-
end
|
13
|
-
end
|
data/test/test_active_record.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
require "active_record"
|
3
|
-
|
4
|
-
class CreateUsers < ActiveRecord::Migration
|
5
|
-
def self.up
|
6
|
-
create_table :users do |t|
|
7
|
-
t.string :login
|
8
|
-
t.integer :login_count
|
9
|
-
t.binary :avatar
|
10
|
-
t.float :ranking
|
11
|
-
t.date :birthdate
|
12
|
-
t.boolean :active
|
13
|
-
t.datetime :expires_at
|
14
|
-
t.text :about_me
|
15
|
-
t.timestamps
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.down
|
20
|
-
drop_table :users
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class User < ActiveRecord::Base; end
|
25
|
-
|
26
|
-
class TestActiveRecord < Test::Unit::TestCase
|
27
|
-
def setup
|
28
|
-
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
29
|
-
ActiveRecord::Base.default_timezone = :utc
|
30
|
-
ActiveRecord::Migration.verbose = false
|
31
|
-
CreateUsers.migrate(:up)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_user_count
|
35
|
-
assert_equal 0, User.count
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_user_columns
|
39
|
-
column_names = User.column_names
|
40
|
-
assert column_names.include?("id")
|
41
|
-
assert column_names.include?("login")
|
42
|
-
assert column_names.include?("login_count")
|
43
|
-
assert column_names.include?("avatar")
|
44
|
-
assert column_names.include?("ranking")
|
45
|
-
assert column_names.include?("birthdate")
|
46
|
-
assert column_names.include?("active")
|
47
|
-
assert column_names.include?("expires_at")
|
48
|
-
assert column_names.include?("about_me")
|
49
|
-
assert column_names.include?("created_at")
|
50
|
-
assert column_names.include?("updated_at")
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_user_create
|
54
|
-
login = "bob"
|
55
|
-
avatar = open(fixture("SQLite.gif"), "rb").read
|
56
|
-
login_count = 0
|
57
|
-
ranking = 1.0
|
58
|
-
active = true
|
59
|
-
birthdate = Date.new(1969, 12, 1)
|
60
|
-
expires_at = DateTime.new(2100, 12, 1, 12, 54, 22)
|
61
|
-
about_me = "aboutme" * 500
|
62
|
-
|
63
|
-
User.create!(:login => login,
|
64
|
-
:login_count => login_count,
|
65
|
-
:avatar => avatar,
|
66
|
-
:ranking => ranking,
|
67
|
-
:active => active,
|
68
|
-
:birthdate => birthdate,
|
69
|
-
:expires_at => expires_at,
|
70
|
-
:about_me => about_me)
|
71
|
-
|
72
|
-
user = User.first
|
73
|
-
|
74
|
-
assert_equal login, user.login
|
75
|
-
assert_equal login_count, user.login_count
|
76
|
-
assert_equal avatar, user.avatar
|
77
|
-
assert_equal ranking, user.ranking
|
78
|
-
assert_equal active, user.active
|
79
|
-
assert_equal birthdate, user.birthdate
|
80
|
-
assert_equal expires_at, user.expires_at
|
81
|
-
assert_equal about_me, user.about_me
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_user_update
|
85
|
-
User.create!(:login => "bob")
|
86
|
-
user = User.first
|
87
|
-
assert_equal "bob", user.login
|
88
|
-
user.update_attributes(:login => "alice")
|
89
|
-
user = User.first
|
90
|
-
assert_equal "alice", user.login
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_user_delete
|
94
|
-
User.create!(:login => "bob")
|
95
|
-
user = User.first
|
96
|
-
assert_equal "bob", user.login
|
97
|
-
user.destroy
|
98
|
-
assert_equal 0, User.count
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_user_dirty_attributes
|
102
|
-
User.create!(:login => "bob")
|
103
|
-
user = User.first
|
104
|
-
assert_equal "bob", user.login
|
105
|
-
user.login = "alice"
|
106
|
-
assert user.login_changed?
|
107
|
-
assert_equal "alice", user.login
|
108
|
-
assert_equal "bob", user.login_was
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_transaction_commit
|
112
|
-
User.transaction do
|
113
|
-
User.create!
|
114
|
-
end
|
115
|
-
assert_equal 1, User.count
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_transaction_rollback
|
119
|
-
User.transaction do
|
120
|
-
User.create!
|
121
|
-
raise ActiveRecord::Rollback
|
122
|
-
end
|
123
|
-
assert_equal 0, User.count
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_reload
|
127
|
-
User.create!(:login => "bob")
|
128
|
-
user = User.first
|
129
|
-
assert_equal "bob", user.login
|
130
|
-
user.login = "alice"
|
131
|
-
assert_equal "alice", user.login
|
132
|
-
user.reload
|
133
|
-
assert_equal "bob", user.login
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_save
|
137
|
-
user = User.new(:login => "alice")
|
138
|
-
user.save
|
139
|
-
assert_equal 1, User.count
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_save_with_bang
|
143
|
-
user = User.new(:login => "alice")
|
144
|
-
user.save!
|
145
|
-
assert_equal 1, User.count
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_attribute_assignment
|
149
|
-
user = User.new
|
150
|
-
avatar = open(fixture("SQLite.gif"), "rb").read
|
151
|
-
user.avatar = avatar
|
152
|
-
user.avatar = nil
|
153
|
-
user.save!
|
154
|
-
user.avatar = avatar
|
155
|
-
user.reload
|
156
|
-
assert_equal 1, User.count
|
157
|
-
end
|
158
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestDatabaseInitialization < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@db_filename = "test_database.db"
|
6
|
-
File.delete(@db_filename) if File.exists?(@db_filename)
|
7
|
-
@db = SQLite3::Database.new(@db_filename)
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
File.delete(@db_filename) if File.exists?(@db_filename)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_database_file_exists
|
15
|
-
assert File.exists?(@db_filename)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_database_opened
|
19
|
-
assert_false @db.closed?
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_database_closing
|
23
|
-
@db.close
|
24
|
-
assert @db.closed?
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_encoding_conversion_from_utf_16_to_utf_8
|
28
|
-
expected_string = "test"
|
29
|
-
db_filename = "test_database_encoding.db"
|
30
|
-
File.delete(db_filename) if File.exists?(db_filename)
|
31
|
-
db = SQLite3::Database.new(db_filename, :encoding => "utf-16le")
|
32
|
-
db.execute("CREATE TABLE t1(t TEXT)")
|
33
|
-
db.execute("INSERT INTO t1 VALUES (?)", expected_string.encode(Encoding::UTF_8))
|
34
|
-
db.execute("INSERT INTO t1 VALUES (?)", expected_string.encode(Encoding::UTF_16LE))
|
35
|
-
rows = db.execute("SELECT * FROM t1")
|
36
|
-
assert_equal 2, rows.size
|
37
|
-
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[0][0]
|
38
|
-
assert_equal Encoding::UTF_16LE, rows[0][0].encoding
|
39
|
-
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[1][0]
|
40
|
-
assert_equal Encoding::UTF_16LE, rows[1][0].encoding
|
41
|
-
db.close
|
42
|
-
db = SQLite3::Database.new(db_filename)
|
43
|
-
rows = db.execute("SELECT * FROM t1")
|
44
|
-
assert_equal 2, rows.size
|
45
|
-
assert_equal expected_string, rows[0][0]
|
46
|
-
assert_equal Encoding::UTF_8, rows[0][0].encoding
|
47
|
-
assert_equal expected_string, rows[1][0]
|
48
|
-
assert_equal Encoding::UTF_8, rows[1][0].encoding
|
49
|
-
File.delete(db_filename) if File.exists?(db_filename)
|
50
|
-
end
|
51
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestDatabaseQueriesUtf16 < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@db = SQLite3::Database.new(":memory:", :encoding => "utf-16")
|
6
|
-
@db.execute("CREATE TABLE t1(id INTEGER PRIMARY KEY ASC, t TEXT, nu1 NUMERIC, i1 INTEGER, i2 INTEGER, no BLOB)")
|
7
|
-
end
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
@db.close
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_tables_empty
|
14
|
-
assert_equal [], @db.execute("SELECT * FROM t1")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_execute
|
18
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, 'text1', 1.22, 42, 4294967296, NULL)")
|
19
|
-
rows = @db.execute("SELECT * FROM t1")
|
20
|
-
assert_equal 1, rows.size
|
21
|
-
row = rows[0]
|
22
|
-
assert_equal "text1".encode(Encoding::UTF_16LE), row[1]
|
23
|
-
assert_equal Encoding::UTF_16LE, row[1].encoding
|
24
|
-
assert_equal 1.22, row[2]
|
25
|
-
assert_equal 42, row[3]
|
26
|
-
assert_equal 4294967296, row[4]
|
27
|
-
assert_nil row[5]
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_execute_with_bindings
|
31
|
-
blob = open("test/fixtures/SQLite.gif", "rb").read
|
32
|
-
@db.execute("INSERT INTO t1 VALUES(?, ?, ?, ?, ?, ?)", nil, "text1", 1.22, 42, 4294967296, blob)
|
33
|
-
rows = @db.execute("SELECT * FROM t1")
|
34
|
-
assert_equal 1, rows.size
|
35
|
-
row = rows[0]
|
36
|
-
assert_equal "text1".encode(Encoding::UTF_16LE), row[1]
|
37
|
-
assert_equal Encoding::UTF_16LE, row[1].encoding
|
38
|
-
assert_equal 1.22, row[2]
|
39
|
-
assert_equal 42, row[3]
|
40
|
-
assert_equal 4294967296, row[4]
|
41
|
-
assert_equal blob, row[5]
|
42
|
-
assert_equal Encoding::ASCII_8BIT, row[5].encoding
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_execute_with_different_encodings
|
46
|
-
expected_string = "text1"
|
47
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::ASCII_8BIT))
|
48
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_8))
|
49
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16LE))
|
50
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16BE))
|
51
|
-
rows = @db.execute("SELECT * FROM t1")
|
52
|
-
assert_equal 4, rows.size
|
53
|
-
assert_equal expected_string, rows[0][1]
|
54
|
-
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[1][1]
|
55
|
-
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[2][1]
|
56
|
-
assert_equal expected_string.encode(Encoding::UTF_16LE), rows[3][1]
|
57
|
-
assert_equal Encoding::ASCII_8BIT, rows[0][1].encoding
|
58
|
-
assert_equal Encoding::UTF_16LE, rows[1][1].encoding
|
59
|
-
assert_equal Encoding::UTF_16LE, rows[2][1].encoding
|
60
|
-
assert_equal Encoding::UTF_16LE, rows[3][1].encoding
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_execute_with_bad_query
|
64
|
-
assert_raise(SQLite3::SQLException) { @db.execute("bad query") }
|
65
|
-
assert_equal %Q{near "bad": syntax error}, @db.errmsg
|
66
|
-
assert_equal 1, @db.errcode
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_last_insert_row_id
|
70
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, NULL, NULL, NULL, NULL, NULL)")
|
71
|
-
id = @db.last_insert_row_id
|
72
|
-
rows = @db.execute("SELECT * FROM t1 WHERE id = #{id}")
|
73
|
-
assert_equal 1, rows.size
|
74
|
-
end
|
75
|
-
|
76
|
-
# def test_execute_with_closed_database
|
77
|
-
# @db.close
|
78
|
-
# @db.execute("SELECT * FROM t1")
|
79
|
-
# end
|
80
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestDatabaseQueriesUtf8 < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@db = SQLite3::Database.new(":memory:")
|
6
|
-
@db.execute("CREATE TABLE t1(id INTEGER PRIMARY KEY ASC, t TEXT, nu1 NUMERIC, i1 INTEGER, i2 INTEGER, no BLOB)")
|
7
|
-
end
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
@db.close
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_tables_empty
|
14
|
-
assert_equal [], @db.execute("SELECT * FROM t1")
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_execute
|
18
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, 'text1', 1.22, 42, 4294967296, NULL)")
|
19
|
-
rows = @db.execute("SELECT * FROM t1")
|
20
|
-
assert_equal 1, rows.size
|
21
|
-
row = rows[0]
|
22
|
-
assert_equal "text1", row[1]
|
23
|
-
assert_equal Encoding::UTF_8, row[1].encoding
|
24
|
-
assert_equal 1.22, row[2]
|
25
|
-
assert_equal 42, row[3]
|
26
|
-
assert_equal 4294967296, row[4]
|
27
|
-
assert_nil row[5]
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_execute_with_bindings
|
31
|
-
blob = open("test/fixtures/SQLite.gif", "rb").read
|
32
|
-
@db.execute("INSERT INTO t1 VALUES(?, ?, ?, ?, ?, ?)", nil, "text1", 1.22, 42, 4294967296, blob)
|
33
|
-
rows = @db.execute("SELECT * FROM t1")
|
34
|
-
assert_equal 1, rows.size
|
35
|
-
row = rows[0]
|
36
|
-
assert_equal "text1", row[1]
|
37
|
-
assert_equal Encoding::UTF_8, row[1].encoding
|
38
|
-
assert_equal 1.22, row[2]
|
39
|
-
assert_equal 42, row[3]
|
40
|
-
assert_equal 4294967296, row[4]
|
41
|
-
assert_equal blob, row[5]
|
42
|
-
assert_equal Encoding::ASCII_8BIT, row[5].encoding
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_execute_with_different_encodings
|
46
|
-
expected_string = "text1"
|
47
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::ASCII_8BIT))
|
48
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_8))
|
49
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16LE))
|
50
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, ?, NULL, NULL, NULL, NULL)", expected_string.encode(Encoding::UTF_16BE))
|
51
|
-
rows = @db.execute("SELECT * FROM t1")
|
52
|
-
assert_equal 4, rows.size
|
53
|
-
assert_equal expected_string, rows[0][1]
|
54
|
-
assert_equal expected_string, rows[1][1]
|
55
|
-
assert_equal expected_string, rows[2][1]
|
56
|
-
assert_equal expected_string, rows[3][1]
|
57
|
-
assert_equal Encoding::ASCII_8BIT, rows[0][1].encoding
|
58
|
-
assert_equal Encoding::UTF_8, rows[1][1].encoding
|
59
|
-
assert_equal Encoding::UTF_8, rows[2][1].encoding
|
60
|
-
assert_equal Encoding::UTF_8, rows[3][1].encoding
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_execute_with_bad_query
|
64
|
-
assert_raise(SQLite3::SQLException) { @db.execute("bad query") }
|
65
|
-
assert_equal %Q{near "bad": syntax error}, @db.errmsg
|
66
|
-
assert_equal 1, @db.errcode
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_last_insert_row_id
|
70
|
-
@db.execute("INSERT INTO t1 VALUES(NULL, NULL, NULL, NULL, NULL, NULL)")
|
71
|
-
id = @db.last_insert_row_id
|
72
|
-
rows = @db.execute("SELECT * FROM t1 WHERE id = #{id}")
|
73
|
-
assert_equal 1, rows.size
|
74
|
-
end
|
75
|
-
|
76
|
-
# def test_execute_with_closed_database
|
77
|
-
# @db.close
|
78
|
-
# @db.execute("SELECT * FROM t1")
|
79
|
-
# end
|
80
|
-
end
|
data/test/test_statement.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
class TestStatement < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@db = SQLite3::Database.new(":memory:")
|
6
|
-
@db.execute("CREATE TABLE t1(id INTEGER PRIMARY KEY ASC, t TEXT, nu1 NUMERIC, i1 INTEGER, i2 INTEGER, no BLOB)")
|
7
|
-
@statement = @db.prepare("INSERT INTO t1 VALUES(:ID, :T, :NU1, :I1, :I2, :NO)")
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
@statement.close
|
12
|
-
@db.close
|
13
|
-
end
|
14
|
-
|
15
|
-
test "bind param by name" do
|
16
|
-
@statement.bind_param("T", "test")
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
test "bind param by name with colon" do
|
21
|
-
@statement.bind_param(":T", "test")
|
22
|
-
end
|
23
|
-
|
24
|
-
test "bind param by number" do
|
25
|
-
@statement.bind_param(1, "test")
|
26
|
-
end
|
27
|
-
|
28
|
-
test "bind non existing param name" do
|
29
|
-
assert_raises(SQLite3::Exception) { @statement.bind_param(":NONEXISTING", "test") }
|
30
|
-
end
|
31
|
-
|
32
|
-
test "execute statement" do
|
33
|
-
@statement.execute
|
34
|
-
end
|
35
|
-
|
36
|
-
test "execute statement multiple times" do
|
37
|
-
@statement.bind_param("T", "test")
|
38
|
-
@statement.execute
|
39
|
-
@statement.bind_param("NU1", 500)
|
40
|
-
@statement.execute
|
41
|
-
end
|
42
|
-
end
|