sqlite3 1.4.2 → 1.7.2
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.
- checksums.yaml +4 -4
- data/{API_CHANGES.rdoc → API_CHANGES.md} +3 -4
- data/CHANGELOG.md +641 -0
- data/CONTRIBUTING.md +34 -0
- data/FAQ.md +431 -0
- data/Gemfile +7 -14
- data/INSTALLATION.md +259 -0
- data/LICENSE-DEPENDENCIES +20 -0
- data/README.md +110 -0
- data/dependencies.yml +14 -0
- data/ext/sqlite3/aggregator.c +10 -10
- data/ext/sqlite3/backup.c +26 -13
- data/ext/sqlite3/database.c +89 -38
- data/ext/sqlite3/database.h +2 -0
- data/ext/sqlite3/extconf.rb +269 -84
- data/ext/sqlite3/sqlite3.c +5 -2
- data/ext/sqlite3/sqlite3_ruby.h +5 -2
- data/ext/sqlite3/statement.c +37 -28
- data/lib/sqlite3/constants.rb +1 -1
- data/lib/sqlite3/database.rb +55 -30
- data/lib/sqlite3/pragmas.rb +13 -6
- data/lib/sqlite3/resultset.rb +4 -12
- data/lib/sqlite3/statement.rb +2 -1
- data/lib/sqlite3/translator.rb +2 -3
- data/lib/sqlite3/version.rb +3 -5
- data/ports/archives/sqlite-autoconf-3450100.tar.gz +0 -0
- data/test/helper.rb +9 -0
- data/test/test_database.rb +182 -17
- data/test/test_deprecated.rb +10 -5
- data/test/test_encoding.rb +10 -0
- data/test/test_integration_resultset.rb +2 -2
- data/test/test_integration_statement.rb +2 -2
- data/test/test_pragmas.rb +22 -0
- data/test/test_result_set.rb +18 -8
- data/test/test_sqlite3.rb +9 -0
- data/test/test_statement.rb +28 -1
- data/test/test_statement_execute.rb +4 -0
- metadata +36 -144
- data/.travis.yml +0 -33
- data/CHANGELOG.rdoc +0 -318
- data/Manifest.txt +0 -60
- data/README.rdoc +0 -118
- data/Rakefile +0 -8
- data/appveyor.yml +0 -36
- data/faq/faq.rb +0 -145
- data/faq/faq.yml +0 -426
- data/rakelib/faq.rake +0 -9
- data/rakelib/gem.rake +0 -40
- data/rakelib/native.rake +0 -56
- data/rakelib/vendor_sqlite3.rake +0 -97
- data/setup.rb +0 -1333
data/ext/sqlite3/extconf.rb
CHANGED
@@ -1,100 +1,285 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'mkmf'
|
4
|
-
|
5
|
-
# :stopdoc:
|
6
|
-
|
7
|
-
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
8
|
-
|
9
|
-
ldflags = cppflags = nil
|
10
|
-
if RbConfig::CONFIG["host_os"] =~ /darwin/
|
11
|
-
begin
|
12
|
-
if with_config('sqlcipher')
|
13
|
-
brew_prefix = `brew --prefix sqlcipher`.chomp
|
14
|
-
ldflags = "#{brew_prefix}/lib"
|
15
|
-
cppflags = "#{brew_prefix}/include/sqlcipher"
|
16
|
-
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
|
17
|
-
else
|
18
|
-
brew_prefix = `brew --prefix sqlite3`.chomp
|
19
|
-
ldflags = "#{brew_prefix}/lib"
|
20
|
-
cppflags = "#{brew_prefix}/include"
|
21
|
-
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
|
22
|
-
end
|
1
|
+
require "mkmf"
|
2
|
+
require "yaml"
|
23
3
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
ENV['PKG_CONFIG_PATH'] ||= pkg_conf
|
28
|
-
rescue
|
29
|
-
end
|
30
|
-
end
|
4
|
+
module Sqlite3
|
5
|
+
module ExtConf
|
6
|
+
ENV_ALLOWLIST = ["CC", "CFLAGS", "LDFLAGS", "LIBS", "CPPFLAGS", "LT_SYS_LIBRARY_PATH", "CPP"]
|
31
7
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
pkg_config("sqlite3")
|
36
|
-
end
|
8
|
+
class << self
|
9
|
+
def configure
|
10
|
+
configure_cross_compiler
|
37
11
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
12
|
+
if system_libraries?
|
13
|
+
message "Building sqlite3-ruby using system #{libname}.\n"
|
14
|
+
configure_system_libraries
|
15
|
+
else
|
16
|
+
message "Building sqlite3-ruby using packaged sqlite3.\n"
|
17
|
+
configure_packaged_libraries
|
18
|
+
end
|
45
19
|
|
46
|
-
|
47
|
-
$CFLAGS << ' -W3'
|
48
|
-
end
|
20
|
+
configure_extension
|
49
21
|
|
50
|
-
|
51
|
-
|
52
|
-
end
|
22
|
+
create_makefile('sqlite3/sqlite3_native')
|
23
|
+
end
|
53
24
|
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
else
|
59
|
-
abort <<-error
|
60
|
-
#{missing} is missing. Try 'brew install sqlite3',
|
61
|
-
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
|
62
|
-
and check your shared library search path (the
|
63
|
-
location where your sqlite3 shared library is located).
|
64
|
-
error
|
65
|
-
end
|
66
|
-
end
|
25
|
+
def configure_cross_compiler
|
26
|
+
RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
|
27
|
+
ENV["CC"] = RbConfig::CONFIG["CC"]
|
28
|
+
end
|
67
29
|
|
68
|
-
|
69
|
-
|
30
|
+
def system_libraries?
|
31
|
+
sqlcipher? || enable_config("system-libraries")
|
32
|
+
end
|
70
33
|
|
71
|
-
|
34
|
+
def libname
|
35
|
+
sqlcipher? ? "sqlcipher" : "sqlite3"
|
36
|
+
end
|
72
37
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
38
|
+
def sqlcipher?
|
39
|
+
with_config("sqlcipher") ||
|
40
|
+
with_config("sqlcipher-dir") ||
|
41
|
+
with_config("sqlcipher-include") ||
|
42
|
+
with_config("sqlcipher-lib")
|
43
|
+
end
|
44
|
+
|
45
|
+
def configure_system_libraries
|
46
|
+
pkg_config(libname)
|
47
|
+
append_cppflags("-DUSING_SQLCIPHER") if sqlcipher?
|
48
|
+
end
|
49
|
+
|
50
|
+
def configure_packaged_libraries
|
51
|
+
minimal_recipe.tap do |recipe|
|
52
|
+
recipe.configure_options += [
|
53
|
+
"--enable-shared=no",
|
54
|
+
"--enable-static=yes",
|
55
|
+
"--enable-fts5",
|
56
|
+
]
|
57
|
+
ENV.to_h.tap do |env|
|
58
|
+
user_cflags = with_config("sqlite-cflags")
|
59
|
+
more_cflags = [
|
60
|
+
"-fPIC", # needed for linking the static library into a shared library
|
61
|
+
"-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
|
62
|
+
"-fvisibility=hidden", # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
|
63
|
+
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
|
64
|
+
]
|
65
|
+
env["CFLAGS"] = [user_cflags, env["CFLAGS"], more_cflags].flatten.join(" ")
|
66
|
+
recipe.configure_options += env.select { |k,v| ENV_ALLOWLIST.include?(k) }
|
67
|
+
.map { |key, value| "#{key}=#{value.strip}" }
|
68
|
+
end
|
69
|
+
|
70
|
+
unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
|
71
|
+
recipe.cook
|
72
|
+
end
|
73
|
+
recipe.activate
|
74
|
+
|
75
|
+
# on macos, pkg-config will not return --cflags without this
|
76
|
+
ENV["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "t"
|
77
|
+
|
78
|
+
# only needed for Ruby 3.1.3, see https://bugs.ruby-lang.org/issues/19233
|
79
|
+
RbConfig::CONFIG["PKG_CONFIG"] = config_string("PKG_CONFIG") || "pkg-config"
|
80
|
+
|
81
|
+
lib_path = File.join(recipe.path, "lib")
|
82
|
+
pcfile = File.join(lib_path, "pkgconfig", "sqlite3.pc")
|
83
|
+
abort_pkg_config("pkg_config") unless pkg_config(pcfile)
|
84
|
+
|
85
|
+
# see https://bugs.ruby-lang.org/issues/18490
|
86
|
+
ldflags = xpopen(["pkg-config", "--libs", "--static", pcfile], err: [:child, :out], &:read)
|
87
|
+
abort_pkg_config("xpopen") unless $?.success?
|
88
|
+
ldflags = ldflags.split
|
89
|
+
|
90
|
+
# see https://github.com/flavorjones/mini_portile/issues/118
|
91
|
+
"-L#{lib_path}".tap do |lib_path_flag|
|
92
|
+
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
|
93
|
+
end
|
94
|
+
|
95
|
+
ldflags.each { |ldflag| append_ldflags(ldflag) }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def configure_extension
|
100
|
+
if Gem::Requirement.new("< 2.7").satisfied_by?(Gem::Version.new(RUBY_VERSION))
|
101
|
+
append_cppflags("-DTAINTING_SUPPORT")
|
102
|
+
end
|
103
|
+
|
104
|
+
append_cflags("-fvisibility=hidden") # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
|
105
|
+
|
106
|
+
if find_header("sqlite3.h")
|
107
|
+
# noop
|
108
|
+
elsif sqlcipher? && find_header("sqlcipher/sqlite3.h")
|
109
|
+
append_cppflags("-DUSING_SQLCIPHER_INC_SUBDIR")
|
110
|
+
else
|
111
|
+
abort_could_not_find("sqlite3.h")
|
112
|
+
end
|
113
|
+
|
114
|
+
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
|
115
|
+
|
116
|
+
# Functions defined in 1.9 but not 1.8
|
117
|
+
have_func('rb_proc_arity')
|
118
|
+
|
119
|
+
# Functions defined in 2.1 but not 2.0
|
120
|
+
have_func('rb_integer_pack')
|
121
|
+
|
122
|
+
# These functions may not be defined
|
123
|
+
have_func('sqlite3_initialize')
|
124
|
+
have_func('sqlite3_backup_init')
|
125
|
+
have_func('sqlite3_column_database_name')
|
126
|
+
have_func('sqlite3_enable_load_extension')
|
127
|
+
have_func('sqlite3_load_extension')
|
128
|
+
|
129
|
+
unless have_func('sqlite3_open_v2') # https://www.sqlite.org/releaselog/3_5_0.html
|
130
|
+
abort("\nPlease use a version of SQLite3 >= 3.5.0\n\n")
|
131
|
+
end
|
132
|
+
|
133
|
+
have_func('sqlite3_prepare_v2')
|
134
|
+
have_type('sqlite3_int64', 'sqlite3.h')
|
135
|
+
have_type('sqlite3_uint64', 'sqlite3.h')
|
136
|
+
end
|
137
|
+
|
138
|
+
def minimal_recipe
|
139
|
+
require "mini_portile2"
|
140
|
+
|
141
|
+
MiniPortile.new(libname, sqlite3_config[:version]).tap do |recipe|
|
142
|
+
if sqlite_source_dir
|
143
|
+
recipe.source_directory = sqlite_source_dir
|
144
|
+
else
|
145
|
+
recipe.files = sqlite3_config[:files]
|
146
|
+
recipe.target = File.join(package_root_dir, "ports")
|
147
|
+
recipe.patch_files = Dir[File.join(package_root_dir, "patches", "*.patch")].sort
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def package_root_dir
|
153
|
+
File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
|
154
|
+
end
|
155
|
+
|
156
|
+
def sqlite3_config
|
157
|
+
mini_portile_config[:sqlite3]
|
158
|
+
end
|
159
|
+
|
160
|
+
def mini_portile_config
|
161
|
+
# TODO: once Ruby 2.7 is no longer supported, use symbolize_names: true
|
162
|
+
YAML.load_file(File.join(package_root_dir, "dependencies.yml"))
|
163
|
+
end
|
164
|
+
|
165
|
+
def abort_could_not_find(missing)
|
166
|
+
abort("\nCould not find #{missing}.\nPlease visit https://github.com/sparklemotion/sqlite3-ruby for installation instructions.\n\n")
|
167
|
+
end
|
78
168
|
|
79
|
-
|
80
|
-
|
169
|
+
def abort_pkg_config(id)
|
170
|
+
abort("\nCould not configure the build properly (#{id}). Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n\n")
|
171
|
+
end
|
81
172
|
|
82
|
-
|
83
|
-
|
173
|
+
def cross_build?
|
174
|
+
enable_config("cross-build")
|
175
|
+
end
|
84
176
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
have_func('sqlite3_column_database_name')
|
89
|
-
have_func('sqlite3_enable_load_extension')
|
90
|
-
have_func('sqlite3_load_extension')
|
177
|
+
def sqlite_source_dir
|
178
|
+
arg_config("--with-sqlite-source-dir")
|
179
|
+
end
|
91
180
|
|
92
|
-
|
93
|
-
|
181
|
+
def download
|
182
|
+
minimal_recipe.download
|
183
|
+
end
|
184
|
+
|
185
|
+
def darwin?
|
186
|
+
RbConfig::CONFIG["target_os"].include?("darwin")
|
187
|
+
end
|
188
|
+
|
189
|
+
def print_help
|
190
|
+
print(<<~TEXT)
|
191
|
+
USAGE: ruby #{$PROGRAM_NAME} [options]
|
192
|
+
|
193
|
+
Flags that are always valid:
|
194
|
+
|
195
|
+
--disable-system-libraries
|
196
|
+
Use the packaged libraries, and ignore the system libraries.
|
197
|
+
(This is the default behavior.)
|
198
|
+
|
199
|
+
--enable-system-libraries
|
200
|
+
Use system libraries instead of building and using the packaged libraries.
|
201
|
+
|
202
|
+
--with-sqlcipher
|
203
|
+
Use libsqlcipher instead of libsqlite3.
|
204
|
+
(Implies `--enable-system-libraries`.)
|
205
|
+
|
206
|
+
--with-sqlite-source-dir=DIRECTORY
|
207
|
+
(dev only) Build sqlite from the source code in DIRECTORY
|
208
|
+
|
209
|
+
--help
|
210
|
+
Display this message.
|
211
|
+
|
212
|
+
|
213
|
+
Flags only used when using system libraries:
|
214
|
+
|
215
|
+
General (applying to all system libraries):
|
216
|
+
|
217
|
+
--with-opt-dir=DIRECTORY
|
218
|
+
Look for headers and libraries in DIRECTORY.
|
219
|
+
|
220
|
+
--with-opt-lib=DIRECTORY
|
221
|
+
Look for libraries in DIRECTORY.
|
222
|
+
|
223
|
+
--with-opt-include=DIRECTORY
|
224
|
+
Look for headers in DIRECTORY.
|
225
|
+
|
226
|
+
Related to sqlcipher:
|
227
|
+
|
228
|
+
--with-sqlcipher-dir=DIRECTORY
|
229
|
+
Look for sqlcipher headers and library in DIRECTORY.
|
230
|
+
(Implies `--with-sqlcipher` and `--enable-system-libraries`.)
|
231
|
+
|
232
|
+
--with-sqlcipher-lib=DIRECTORY
|
233
|
+
Look for sqlcipher library in DIRECTORY.
|
234
|
+
(Implies `--with-sqlcipher` and `--enable-system-libraries`.)
|
235
|
+
|
236
|
+
--with-sqlcipher-include=DIRECTORY
|
237
|
+
Look for sqlcipher headers in DIRECTORY.
|
238
|
+
(Implies `--with-sqlcipher` and `--enable-system-libraries`.)
|
239
|
+
|
240
|
+
|
241
|
+
Flags only used when building and using the packaged libraries:
|
242
|
+
|
243
|
+
--with-sqlite-cflags=CFLAGS
|
244
|
+
Explicitly pass compiler flags to the sqlite library build. These flags will
|
245
|
+
appear on the commandline before any flags set in the CFLAGS environment
|
246
|
+
variable. This is useful for setting compilation options in your project's
|
247
|
+
bundler config. See INSTALLATION.md for more information.
|
248
|
+
|
249
|
+
--enable-cross-build
|
250
|
+
Enable cross-build mode. (You probably do not want to set this manually.)
|
251
|
+
|
252
|
+
|
253
|
+
Environment variables used for compiling the gem's C extension:
|
254
|
+
|
255
|
+
CC
|
256
|
+
Use this path to invoke the compiler instead of `RbConfig::CONFIG['CC']`
|
257
|
+
|
258
|
+
|
259
|
+
Environment variables passed through to the compilation of sqlite:
|
260
|
+
|
261
|
+
CC
|
262
|
+
CPPFLAGS
|
263
|
+
CFLAGS
|
264
|
+
LDFLAGS
|
265
|
+
LIBS
|
266
|
+
LT_SYS_LIBRARY_PATH
|
267
|
+
CPP
|
268
|
+
|
269
|
+
TEXT
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
if arg_config("--help")
|
276
|
+
Sqlite3::ExtConf.print_help
|
277
|
+
exit!(0)
|
94
278
|
end
|
95
279
|
|
96
|
-
|
97
|
-
|
98
|
-
|
280
|
+
if arg_config("--download-dependencies")
|
281
|
+
Sqlite3::ExtConf.download
|
282
|
+
exit!(0)
|
283
|
+
end
|
99
284
|
|
100
|
-
|
285
|
+
Sqlite3::ExtConf.configure
|
data/ext/sqlite3/sqlite3.c
CHANGED
@@ -82,7 +82,7 @@ static VALUE threadsafe_p(VALUE UNUSED(klass))
|
|
82
82
|
return INT2NUM(sqlite3_threadsafe());
|
83
83
|
}
|
84
84
|
|
85
|
-
void init_sqlite3_constants()
|
85
|
+
void init_sqlite3_constants(void)
|
86
86
|
{
|
87
87
|
VALUE mSqlite3Constants;
|
88
88
|
VALUE mSqlite3Open;
|
@@ -127,7 +127,8 @@ void init_sqlite3_constants()
|
|
127
127
|
#endif
|
128
128
|
}
|
129
129
|
|
130
|
-
|
130
|
+
RUBY_FUNC_EXPORTED
|
131
|
+
void Init_sqlite3_native(void)
|
131
132
|
{
|
132
133
|
/*
|
133
134
|
* SQLite3 is a wrapper around the popular database
|
@@ -158,4 +159,6 @@ void Init_sqlite3_native()
|
|
158
159
|
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
|
159
160
|
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
|
160
161
|
rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
|
162
|
+
rb_define_const(mSqlite3, "SQLITE_LOADED_VERSION", rb_str_new2(sqlite3_libversion()));
|
163
|
+
|
161
164
|
}
|
data/ext/sqlite3/sqlite3_ruby.h
CHANGED
@@ -21,8 +21,11 @@
|
|
21
21
|
#define SQLITE3_UTF8_STR_NEW2(_obj) \
|
22
22
|
(rb_enc_associate_index(rb_str_new2(_obj), rb_utf8_encindex()))
|
23
23
|
|
24
|
-
|
25
|
-
#include <sqlite3.h>
|
24
|
+
#ifdef USING_SQLCIPHER_INC_SUBDIR
|
25
|
+
# include <sqlcipher/sqlite3.h>
|
26
|
+
#else
|
27
|
+
# include <sqlite3.h>
|
28
|
+
#endif
|
26
29
|
|
27
30
|
#ifndef HAVE_TYPE_SQLITE3_INT64
|
28
31
|
typedef sqlite_int64 sqlite3_int64;
|
data/ext/sqlite3/statement.c
CHANGED
@@ -6,19 +6,29 @@
|
|
6
6
|
|
7
7
|
VALUE cSqlite3Statement;
|
8
8
|
|
9
|
-
static
|
9
|
+
static size_t statement_memsize(const void *data)
|
10
10
|
{
|
11
|
-
sqlite3StmtRubyPtr
|
12
|
-
|
11
|
+
const sqlite3StmtRubyPtr s = (const sqlite3StmtRubyPtr)data;
|
12
|
+
// NB: can't account for s->st because the type is incomplete.
|
13
|
+
return sizeof(*s);
|
13
14
|
}
|
14
15
|
|
16
|
+
static const rb_data_type_t statement_type = {
|
17
|
+
"SQLite3::Backup",
|
18
|
+
{
|
19
|
+
NULL,
|
20
|
+
RUBY_TYPED_DEFAULT_FREE,
|
21
|
+
statement_memsize,
|
22
|
+
},
|
23
|
+
0,
|
24
|
+
0,
|
25
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
26
|
+
};
|
27
|
+
|
15
28
|
static VALUE allocate(VALUE klass)
|
16
29
|
{
|
17
|
-
sqlite3StmtRubyPtr ctx
|
18
|
-
ctx
|
19
|
-
ctx->done_p = 0;
|
20
|
-
|
21
|
-
return Data_Wrap_Struct(klass, NULL, deallocate, ctx);
|
30
|
+
sqlite3StmtRubyPtr ctx;
|
31
|
+
return TypedData_Make_Struct(klass, sqlite3StmtRuby, &statement_type, ctx);
|
22
32
|
}
|
23
33
|
|
24
34
|
/* call-seq: SQLite3::Statement.new(db, sql)
|
@@ -30,15 +40,14 @@ static VALUE allocate(VALUE klass)
|
|
30
40
|
*/
|
31
41
|
static VALUE initialize(VALUE self, VALUE db, VALUE sql)
|
32
42
|
{
|
33
|
-
sqlite3RubyPtr db_ctx;
|
43
|
+
sqlite3RubyPtr db_ctx = sqlite3_database_unwrap(db);
|
34
44
|
sqlite3StmtRubyPtr ctx;
|
35
45
|
const char *tail = NULL;
|
36
46
|
int status;
|
37
47
|
|
38
48
|
StringValue(sql);
|
39
49
|
|
40
|
-
|
41
|
-
Data_Get_Struct(self, sqlite3StmtRuby, ctx);
|
50
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
42
51
|
|
43
52
|
if(!db_ctx->db)
|
44
53
|
rb_raise(rb_eArgError, "prepare called on a closed database");
|
@@ -78,7 +87,7 @@ static VALUE sqlite3_rb_close(VALUE self)
|
|
78
87
|
{
|
79
88
|
sqlite3StmtRubyPtr ctx;
|
80
89
|
|
81
|
-
|
90
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
82
91
|
|
83
92
|
REQUIRE_OPEN_STMT(ctx);
|
84
93
|
|
@@ -95,7 +104,7 @@ static VALUE sqlite3_rb_close(VALUE self)
|
|
95
104
|
static VALUE closed_p(VALUE self)
|
96
105
|
{
|
97
106
|
sqlite3StmtRubyPtr ctx;
|
98
|
-
|
107
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
99
108
|
|
100
109
|
if(!ctx->st) return Qtrue;
|
101
110
|
|
@@ -110,7 +119,7 @@ static VALUE step(VALUE self)
|
|
110
119
|
VALUE list;
|
111
120
|
rb_encoding * internal_encoding;
|
112
121
|
|
113
|
-
|
122
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
114
123
|
|
115
124
|
REQUIRE_OPEN_STMT(ctx);
|
116
125
|
|
@@ -206,7 +215,7 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
|
|
206
215
|
int status;
|
207
216
|
int index;
|
208
217
|
|
209
|
-
|
218
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
210
219
|
REQUIRE_OPEN_STMT(ctx);
|
211
220
|
|
212
221
|
switch(TYPE(key)) {
|
@@ -290,13 +299,13 @@ static VALUE bind_param(VALUE self, VALUE key, VALUE value)
|
|
290
299
|
/* call-seq: stmt.reset!
|
291
300
|
*
|
292
301
|
* Resets the statement. This is typically done internally, though it might
|
293
|
-
*
|
302
|
+
* occasionally be necessary to manually reset the statement.
|
294
303
|
*/
|
295
304
|
static VALUE reset_bang(VALUE self)
|
296
305
|
{
|
297
306
|
sqlite3StmtRubyPtr ctx;
|
298
307
|
|
299
|
-
|
308
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
300
309
|
REQUIRE_OPEN_STMT(ctx);
|
301
310
|
|
302
311
|
sqlite3_reset(ctx->st);
|
@@ -309,13 +318,13 @@ static VALUE reset_bang(VALUE self)
|
|
309
318
|
/* call-seq: stmt.clear_bindings!
|
310
319
|
*
|
311
320
|
* Resets the statement. This is typically done internally, though it might
|
312
|
-
*
|
321
|
+
* occasionally be necessary to manually reset the statement.
|
313
322
|
*/
|
314
323
|
static VALUE clear_bindings_bang(VALUE self)
|
315
324
|
{
|
316
325
|
sqlite3StmtRubyPtr ctx;
|
317
326
|
|
318
|
-
|
327
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
319
328
|
REQUIRE_OPEN_STMT(ctx);
|
320
329
|
|
321
330
|
sqlite3_clear_bindings(ctx->st);
|
@@ -332,7 +341,7 @@ static VALUE clear_bindings_bang(VALUE self)
|
|
332
341
|
static VALUE done_p(VALUE self)
|
333
342
|
{
|
334
343
|
sqlite3StmtRubyPtr ctx;
|
335
|
-
|
344
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
336
345
|
|
337
346
|
if(ctx->done_p) return Qtrue;
|
338
347
|
return Qfalse;
|
@@ -345,10 +354,10 @@ static VALUE done_p(VALUE self)
|
|
345
354
|
static VALUE column_count(VALUE self)
|
346
355
|
{
|
347
356
|
sqlite3StmtRubyPtr ctx;
|
348
|
-
|
357
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
349
358
|
REQUIRE_OPEN_STMT(ctx);
|
350
359
|
|
351
|
-
return INT2NUM(
|
360
|
+
return INT2NUM(sqlite3_column_count(ctx->st));
|
352
361
|
}
|
353
362
|
|
354
363
|
/* call-seq: stmt.column_name(index)
|
@@ -360,7 +369,7 @@ static VALUE column_name(VALUE self, VALUE index)
|
|
360
369
|
sqlite3StmtRubyPtr ctx;
|
361
370
|
const char * name;
|
362
371
|
|
363
|
-
|
372
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
364
373
|
REQUIRE_OPEN_STMT(ctx);
|
365
374
|
|
366
375
|
name = sqlite3_column_name(ctx->st, (int)NUM2INT(index));
|
@@ -378,7 +387,7 @@ static VALUE column_decltype(VALUE self, VALUE index)
|
|
378
387
|
sqlite3StmtRubyPtr ctx;
|
379
388
|
const char * name;
|
380
389
|
|
381
|
-
|
390
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
382
391
|
REQUIRE_OPEN_STMT(ctx);
|
383
392
|
|
384
393
|
name = sqlite3_column_decltype(ctx->st, (int)NUM2INT(index));
|
@@ -394,10 +403,10 @@ static VALUE column_decltype(VALUE self, VALUE index)
|
|
394
403
|
static VALUE bind_parameter_count(VALUE self)
|
395
404
|
{
|
396
405
|
sqlite3StmtRubyPtr ctx;
|
397
|
-
|
406
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
398
407
|
REQUIRE_OPEN_STMT(ctx);
|
399
408
|
|
400
|
-
return INT2NUM(
|
409
|
+
return INT2NUM(sqlite3_bind_parameter_count(ctx->st));
|
401
410
|
}
|
402
411
|
|
403
412
|
#ifdef HAVE_SQLITE3_COLUMN_DATABASE_NAME
|
@@ -409,7 +418,7 @@ static VALUE bind_parameter_count(VALUE self)
|
|
409
418
|
static VALUE database_name(VALUE self, VALUE index)
|
410
419
|
{
|
411
420
|
sqlite3StmtRubyPtr ctx;
|
412
|
-
|
421
|
+
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
|
413
422
|
REQUIRE_OPEN_STMT(ctx);
|
414
423
|
|
415
424
|
return SQLITE3_UTF8_STR_NEW2(
|
@@ -418,7 +427,7 @@ static VALUE database_name(VALUE self, VALUE index)
|
|
418
427
|
|
419
428
|
#endif
|
420
429
|
|
421
|
-
void init_sqlite3_statement()
|
430
|
+
void init_sqlite3_statement(void)
|
422
431
|
{
|
423
432
|
cSqlite3Statement = rb_define_class_under(mSqlite3, "Statement", rb_cObject);
|
424
433
|
|
data/lib/sqlite3/constants.rb
CHANGED
@@ -37,7 +37,7 @@ module SQLite3 ; module Constants
|
|
37
37
|
EMPTY = 16 # (Internal Only) Database table is empty
|
38
38
|
SCHEMA = 17 # The database schema changed
|
39
39
|
TOOBIG = 18 # Too much data for one row of a table
|
40
|
-
CONSTRAINT = 19 # Abort due to
|
40
|
+
CONSTRAINT = 19 # Abort due to constraint violation
|
41
41
|
MISMATCH = 20 # Data type mismatch
|
42
42
|
MISUSE = 21 # Library used incorrectly
|
43
43
|
NOLFS = 22 # Uses OS features not supported on host
|