sqlite3 1.7.2-arm64-darwin → 2.0.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +160 -1
  3. data/CONTRIBUTING.md +23 -1
  4. data/FAQ.md +0 -43
  5. data/INSTALLATION.md +13 -5
  6. data/LICENSE +18 -22
  7. data/README.md +75 -4
  8. data/dependencies.yml +10 -11
  9. data/ext/sqlite3/aggregator.c +142 -145
  10. data/ext/sqlite3/aggregator.h +2 -4
  11. data/ext/sqlite3/backup.c +74 -65
  12. data/ext/sqlite3/backup.h +2 -2
  13. data/ext/sqlite3/database.c +535 -482
  14. data/ext/sqlite3/database.h +7 -4
  15. data/ext/sqlite3/exception.c +111 -92
  16. data/ext/sqlite3/exception.h +3 -1
  17. data/ext/sqlite3/extconf.rb +21 -22
  18. data/ext/sqlite3/sqlite3.c +159 -115
  19. data/ext/sqlite3/sqlite3_ruby.h +2 -2
  20. data/ext/sqlite3/statement.c +516 -300
  21. data/ext/sqlite3/statement.h +3 -3
  22. data/ext/sqlite3/timespec.h +20 -0
  23. data/lib/sqlite3/3.0/sqlite3_native.bundle +0 -0
  24. data/lib/sqlite3/3.1/sqlite3_native.bundle +0 -0
  25. data/lib/sqlite3/3.2/sqlite3_native.bundle +0 -0
  26. data/lib/sqlite3/3.3/sqlite3_native.bundle +0 -0
  27. data/lib/sqlite3/constants.rb +171 -47
  28. data/lib/sqlite3/database.rb +105 -165
  29. data/lib/sqlite3/errors.rb +26 -1
  30. data/lib/sqlite3/pragmas.rb +126 -136
  31. data/lib/sqlite3/resultset.rb +14 -97
  32. data/lib/sqlite3/statement.rb +58 -13
  33. data/lib/sqlite3/value.rb +17 -20
  34. data/lib/sqlite3/version.rb +1 -21
  35. data/lib/sqlite3.rb +6 -4
  36. metadata +3 -28
  37. data/API_CHANGES.md +0 -49
  38. data/ChangeLog.cvs +0 -88
  39. data/Gemfile +0 -10
  40. data/LICENSE-DEPENDENCIES +0 -20
  41. data/lib/sqlite3/translator.rb +0 -117
  42. data/test/helper.rb +0 -27
  43. data/test/test_backup.rb +0 -33
  44. data/test/test_collation.rb +0 -82
  45. data/test/test_database.rb +0 -668
  46. data/test/test_database_flags.rb +0 -95
  47. data/test/test_database_readonly.rb +0 -36
  48. data/test/test_database_readwrite.rb +0 -41
  49. data/test/test_deprecated.rb +0 -49
  50. data/test/test_encoding.rb +0 -165
  51. data/test/test_integration.rb +0 -507
  52. data/test/test_integration_aggregate.rb +0 -336
  53. data/test/test_integration_open_close.rb +0 -30
  54. data/test/test_integration_pending.rb +0 -115
  55. data/test/test_integration_resultset.rb +0 -142
  56. data/test/test_integration_statement.rb +0 -194
  57. data/test/test_pragmas.rb +0 -22
  58. data/test/test_result_set.rb +0 -47
  59. data/test/test_sqlite3.rb +0 -30
  60. data/test/test_statement.rb +0 -290
  61. data/test/test_statement_execute.rb +0 -39
@@ -4,16 +4,19 @@
4
4
  #include <sqlite3_ruby.h>
5
5
 
6
6
  struct _sqlite3Ruby {
7
- sqlite3 *db;
7
+ sqlite3 *db;
8
+ VALUE busy_handler;
9
+ int stmt_timeout;
10
+ struct timespec stmt_deadline;
8
11
  };
9
12
 
10
13
  typedef struct _sqlite3Ruby sqlite3Ruby;
11
- typedef sqlite3Ruby * sqlite3RubyPtr;
14
+ typedef sqlite3Ruby *sqlite3RubyPtr;
12
15
 
13
16
  void init_sqlite3_database();
14
- void set_sqlite3_func_result(sqlite3_context * ctx, VALUE result);
17
+ void set_sqlite3_func_result(sqlite3_context *ctx, VALUE result);
15
18
 
16
19
  sqlite3RubyPtr sqlite3_database_unwrap(VALUE database);
17
- VALUE sqlite3val2rb(sqlite3_value * val);
20
+ VALUE sqlite3val2rb(sqlite3_value *val);
18
21
 
19
22
  #endif
@@ -1,98 +1,117 @@
1
1
  #include <sqlite3_ruby.h>
2
2
 
3
- void rb_sqlite3_raise(sqlite3 * db, int status)
3
+ void
4
+ rb_sqlite3_raise(sqlite3 *db, int status)
4
5
  {
5
- VALUE klass = Qnil;
6
+ VALUE klass = Qnil;
6
7
 
7
- /* Consider only lower 8 bits, to work correctly when
8
- extended result codes are enabled. */
9
- switch(status & 0xff) {
10
- case SQLITE_OK:
11
- return;
12
- break;
13
- case SQLITE_ERROR:
14
- klass = rb_path2class("SQLite3::SQLException");
15
- break;
16
- case SQLITE_INTERNAL:
17
- klass = rb_path2class("SQLite3::InternalException");
18
- break;
19
- case SQLITE_PERM:
20
- klass = rb_path2class("SQLite3::PermissionException");
21
- break;
22
- case SQLITE_ABORT:
23
- klass = rb_path2class("SQLite3::AbortException");
24
- break;
25
- case SQLITE_BUSY:
26
- klass = rb_path2class("SQLite3::BusyException");
27
- break;
28
- case SQLITE_LOCKED:
29
- klass = rb_path2class("SQLite3::LockedException");
30
- break;
31
- case SQLITE_NOMEM:
32
- klass = rb_path2class("SQLite3::MemoryException");
33
- break;
34
- case SQLITE_READONLY:
35
- klass = rb_path2class("SQLite3::ReadOnlyException");
36
- break;
37
- case SQLITE_INTERRUPT:
38
- klass = rb_path2class("SQLite3::InterruptException");
39
- break;
40
- case SQLITE_IOERR:
41
- klass = rb_path2class("SQLite3::IOException");
42
- break;
43
- case SQLITE_CORRUPT:
44
- klass = rb_path2class("SQLite3::CorruptException");
45
- break;
46
- case SQLITE_NOTFOUND:
47
- klass = rb_path2class("SQLite3::NotFoundException");
48
- break;
49
- case SQLITE_FULL:
50
- klass = rb_path2class("SQLite3::FullException");
51
- break;
52
- case SQLITE_CANTOPEN:
53
- klass = rb_path2class("SQLite3::CantOpenException");
54
- break;
55
- case SQLITE_PROTOCOL:
56
- klass = rb_path2class("SQLite3::ProtocolException");
57
- break;
58
- case SQLITE_EMPTY:
59
- klass = rb_path2class("SQLite3::EmptyException");
60
- break;
61
- case SQLITE_SCHEMA:
62
- klass = rb_path2class("SQLite3::SchemaChangedException");
63
- break;
64
- case SQLITE_TOOBIG:
65
- klass = rb_path2class("SQLite3::TooBigException");
66
- break;
67
- case SQLITE_CONSTRAINT:
68
- klass = rb_path2class("SQLite3::ConstraintException");
69
- break;
70
- case SQLITE_MISMATCH:
71
- klass = rb_path2class("SQLite3::MismatchException");
72
- break;
73
- case SQLITE_MISUSE:
74
- klass = rb_path2class("SQLite3::MisuseException");
75
- break;
76
- case SQLITE_NOLFS:
77
- klass = rb_path2class("SQLite3::UnsupportedException");
78
- break;
79
- case SQLITE_AUTH:
80
- klass = rb_path2class("SQLite3::AuthorizationException");
81
- break;
82
- case SQLITE_FORMAT:
83
- klass = rb_path2class("SQLite3::FormatException");
84
- break;
85
- case SQLITE_RANGE:
86
- klass = rb_path2class("SQLite3::RangeException");
87
- break;
88
- case SQLITE_NOTADB:
89
- klass = rb_path2class("SQLite3::NotADatabaseException");
90
- break;
91
- default:
92
- klass = rb_eRuntimeError;
93
- }
8
+ /* Consider only lower 8 bits, to work correctly when
9
+ extended result codes are enabled. */
10
+ switch (status & 0xff) {
11
+ case SQLITE_OK:
12
+ return;
13
+ break;
14
+ case SQLITE_ERROR:
15
+ klass = rb_path2class("SQLite3::SQLException");
16
+ break;
17
+ case SQLITE_INTERNAL:
18
+ klass = rb_path2class("SQLite3::InternalException");
19
+ break;
20
+ case SQLITE_PERM:
21
+ klass = rb_path2class("SQLite3::PermissionException");
22
+ break;
23
+ case SQLITE_ABORT:
24
+ klass = rb_path2class("SQLite3::AbortException");
25
+ break;
26
+ case SQLITE_BUSY:
27
+ klass = rb_path2class("SQLite3::BusyException");
28
+ break;
29
+ case SQLITE_LOCKED:
30
+ klass = rb_path2class("SQLite3::LockedException");
31
+ break;
32
+ case SQLITE_NOMEM:
33
+ klass = rb_path2class("SQLite3::MemoryException");
34
+ break;
35
+ case SQLITE_READONLY:
36
+ klass = rb_path2class("SQLite3::ReadOnlyException");
37
+ break;
38
+ case SQLITE_INTERRUPT:
39
+ klass = rb_path2class("SQLite3::InterruptException");
40
+ break;
41
+ case SQLITE_IOERR:
42
+ klass = rb_path2class("SQLite3::IOException");
43
+ break;
44
+ case SQLITE_CORRUPT:
45
+ klass = rb_path2class("SQLite3::CorruptException");
46
+ break;
47
+ case SQLITE_NOTFOUND:
48
+ klass = rb_path2class("SQLite3::NotFoundException");
49
+ break;
50
+ case SQLITE_FULL:
51
+ klass = rb_path2class("SQLite3::FullException");
52
+ break;
53
+ case SQLITE_CANTOPEN:
54
+ klass = rb_path2class("SQLite3::CantOpenException");
55
+ break;
56
+ case SQLITE_PROTOCOL:
57
+ klass = rb_path2class("SQLite3::ProtocolException");
58
+ break;
59
+ case SQLITE_EMPTY:
60
+ klass = rb_path2class("SQLite3::EmptyException");
61
+ break;
62
+ case SQLITE_SCHEMA:
63
+ klass = rb_path2class("SQLite3::SchemaChangedException");
64
+ break;
65
+ case SQLITE_TOOBIG:
66
+ klass = rb_path2class("SQLite3::TooBigException");
67
+ break;
68
+ case SQLITE_CONSTRAINT:
69
+ klass = rb_path2class("SQLite3::ConstraintException");
70
+ break;
71
+ case SQLITE_MISMATCH:
72
+ klass = rb_path2class("SQLite3::MismatchException");
73
+ break;
74
+ case SQLITE_MISUSE:
75
+ klass = rb_path2class("SQLite3::MisuseException");
76
+ break;
77
+ case SQLITE_NOLFS:
78
+ klass = rb_path2class("SQLite3::UnsupportedException");
79
+ break;
80
+ case SQLITE_AUTH:
81
+ klass = rb_path2class("SQLite3::AuthorizationException");
82
+ break;
83
+ case SQLITE_FORMAT:
84
+ klass = rb_path2class("SQLite3::FormatException");
85
+ break;
86
+ case SQLITE_RANGE:
87
+ klass = rb_path2class("SQLite3::RangeException");
88
+ break;
89
+ case SQLITE_NOTADB:
90
+ klass = rb_path2class("SQLite3::NotADatabaseException");
91
+ break;
92
+ default:
93
+ klass = rb_path2class("SQLite3::Exception");
94
+ }
94
95
 
95
- klass = rb_exc_new2(klass, sqlite3_errmsg(db));
96
- rb_iv_set(klass, "@code", INT2FIX(status));
97
- rb_exc_raise(klass);
96
+ klass = rb_exc_new2(klass, sqlite3_errmsg(db));
97
+ rb_iv_set(klass, "@code", INT2FIX(status));
98
+ rb_exc_raise(klass);
99
+ }
100
+
101
+ /*
102
+ * accepts a sqlite3 error message as the final argument, which will be `sqlite3_free`d
103
+ */
104
+ void
105
+ rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg)
106
+ {
107
+ VALUE exception;
108
+
109
+ if (status == SQLITE_OK) {
110
+ return;
111
+ }
112
+
113
+ exception = rb_exc_new2(rb_path2class("SQLite3::Exception"), msg);
114
+ sqlite3_free((void *)msg);
115
+ rb_iv_set(exception, "@code", INT2FIX(status));
116
+ rb_exc_raise(exception);
98
117
  }
@@ -2,7 +2,9 @@
2
2
  #define SQLITE3_EXCEPTION_RUBY
3
3
 
4
4
  #define CHECK(_db, _status) rb_sqlite3_raise(_db, _status);
5
+ #define CHECK_MSG(_db, _status, _msg) rb_sqlite3_raise_msg(_db, _status, _msg);
5
6
 
6
- void rb_sqlite3_raise(sqlite3 * db, int status);
7
+ void rb_sqlite3_raise(sqlite3 *db, int status);
8
+ void rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg);
7
9
 
8
10
  #endif
@@ -19,7 +19,7 @@ module Sqlite3
19
19
 
20
20
  configure_extension
21
21
 
22
- create_makefile('sqlite3/sqlite3_native')
22
+ create_makefile("sqlite3/sqlite3_native")
23
23
  end
24
24
 
25
25
  def configure_cross_compiler
@@ -52,7 +52,7 @@ module Sqlite3
52
52
  recipe.configure_options += [
53
53
  "--enable-shared=no",
54
54
  "--enable-static=yes",
55
- "--enable-fts5",
55
+ "--enable-fts5"
56
56
  ]
57
57
  ENV.to_h.tap do |env|
58
58
  user_cflags = with_config("sqlite-cflags")
@@ -60,11 +60,11 @@ module Sqlite3
60
60
  "-fPIC", # needed for linking the static library into a shared library
61
61
  "-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
62
62
  "-fvisibility=hidden", # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
63
- "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
63
+ "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1"
64
64
  ]
65
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}" }
66
+ recipe.configure_options += env.select { |k, v| ENV_ALLOWLIST.include?(k) }
67
+ .map { |key, value| "#{key}=#{value.strip}" }
68
68
  end
69
69
 
70
70
  unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
@@ -97,10 +97,6 @@ module Sqlite3
97
97
  end
98
98
 
99
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
100
  append_cflags("-fvisibility=hidden") # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
105
101
 
106
102
  if find_header("sqlite3.h")
@@ -113,26 +109,30 @@ module Sqlite3
113
109
 
114
110
  abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
115
111
 
112
+ # Truffle Ruby doesn't support this yet:
113
+ # https://github.com/oracle/truffleruby/issues/3408
114
+ have_func("rb_enc_interned_str_cstr")
115
+
116
116
  # Functions defined in 1.9 but not 1.8
117
- have_func('rb_proc_arity')
117
+ have_func("rb_proc_arity")
118
118
 
119
119
  # Functions defined in 2.1 but not 2.0
120
- have_func('rb_integer_pack')
120
+ have_func("rb_integer_pack")
121
121
 
122
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')
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
128
 
129
- unless have_func('sqlite3_open_v2') # https://www.sqlite.org/releaselog/3_5_0.html
129
+ unless have_func("sqlite3_open_v2") # https://www.sqlite.org/releaselog/3_5_0.html
130
130
  abort("\nPlease use a version of SQLite3 >= 3.5.0\n\n")
131
131
  end
132
132
 
133
- have_func('sqlite3_prepare_v2')
134
- have_type('sqlite3_int64', 'sqlite3.h')
135
- have_type('sqlite3_uint64', 'sqlite3.h')
133
+ have_func("sqlite3_prepare_v2")
134
+ have_type("sqlite3_int64", "sqlite3.h")
135
+ have_type("sqlite3_uint64", "sqlite3.h")
136
136
  end
137
137
 
138
138
  def minimal_recipe
@@ -158,8 +158,7 @@ module Sqlite3
158
158
  end
159
159
 
160
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"))
161
+ YAML.load_file(File.join(package_root_dir, "dependencies.yml"), symbolize_names: true)
163
162
  end
164
163
 
165
164
  def abort_could_not_find(missing)
@@ -3,162 +3,206 @@
3
3
  VALUE mSqlite3;
4
4
  VALUE cSqlite3Blob;
5
5
 
6
- int bignum_to_int64(VALUE value, sqlite3_int64 *result)
6
+ int
7
+ bignum_to_int64(VALUE value, sqlite3_int64 *result)
7
8
  {
8
9
  #ifdef HAVE_RB_INTEGER_PACK
9
- const int nails = 0;
10
- int t = rb_integer_pack(value, result, 1, sizeof(*result), nails,
11
- INTEGER_PACK_NATIVE_BYTE_ORDER|
12
- INTEGER_PACK_2COMP);
13
- switch (t) {
14
- case -2: case +2:
15
- return 0;
16
- case +1:
17
- if (!nails) {
18
- if (*result < 0) return 0;
10
+ const int nails = 0;
11
+ int t = rb_integer_pack(value, result, 1, sizeof(*result), nails,
12
+ INTEGER_PACK_NATIVE_BYTE_ORDER |
13
+ INTEGER_PACK_2COMP);
14
+ switch (t) {
15
+ case -2:
16
+ case +2:
17
+ return 0;
18
+ case +1:
19
+ if (!nails) {
20
+ if (*result < 0) { return 0; }
21
+ }
22
+ break;
23
+ case -1:
24
+ if (!nails) {
25
+ if (*result >= 0) { return 0; }
26
+ } else {
27
+ *result += INT64_MIN;
28
+ }
29
+ break;
19
30
  }
20
- break;
21
- case -1:
22
- if (!nails) {
23
- if (*result >= 0) return 0;
24
- }
25
- else {
26
- *result += INT64_MIN;
27
- }
28
- break;
29
- }
30
- return 1;
31
+ return 1;
31
32
  #else
32
33
  # ifndef RBIGNUM_LEN
33
34
  # define RBIGNUM_LEN(x) RBIGNUM(x)->len
34
35
  # endif
35
- const long len = RBIGNUM_LEN(value);
36
- if (len == 0) {
37
- *result = 0;
38
- return 1;
39
- }
40
- if (len > 63 / (SIZEOF_BDIGITS * CHAR_BIT) + 1) return 0;
41
- if (len == 63 / (SIZEOF_BDIGITS * CHAR_BIT) + 1) {
42
- const BDIGIT *digits = RBIGNUM_DIGITS(value);
43
- BDIGIT blast = digits[len-1];
44
- BDIGIT bmax = (BDIGIT)1UL << (63 % (CHAR_BIT * SIZEOF_BDIGITS));
45
- if (blast > bmax) return 0;
46
- if (blast == bmax) {
47
- if (RBIGNUM_POSITIVE_P(value)) {
48
- return 0;
49
- }
50
- else {
51
- long i = len-1;
52
- while (i) {
53
- if (digits[--i]) return 0;
54
- }
55
- }
36
+ const long len = RBIGNUM_LEN(value);
37
+ if (len == 0) {
38
+ *result = 0;
39
+ return 1;
40
+ }
41
+ if (len > 63 / (SIZEOF_BDIGITS * CHAR_BIT) + 1) { return 0; }
42
+ if (len == 63 / (SIZEOF_BDIGITS * CHAR_BIT) + 1) {
43
+ const BDIGIT *digits = RBIGNUM_DIGITS(value);
44
+ BDIGIT blast = digits[len - 1];
45
+ BDIGIT bmax = (BDIGIT)1UL << (63 % (CHAR_BIT * SIZEOF_BDIGITS));
46
+ if (blast > bmax) { return 0; }
47
+ if (blast == bmax) {
48
+ if (RBIGNUM_POSITIVE_P(value)) {
49
+ return 0;
50
+ } else {
51
+ long i = len - 1;
52
+ while (i) {
53
+ if (digits[--i]) { return 0; }
54
+ }
55
+ }
56
+ }
56
57
  }
57
- }
58
- *result = (sqlite3_int64)NUM2LL(value);
59
- return 1;
58
+ *result = (sqlite3_int64)NUM2LL(value);
59
+ return 1;
60
60
  #endif
61
61
  }
62
62
 
63
- static VALUE libversion(VALUE UNUSED(klass))
63
+ static VALUE
64
+ libversion(VALUE UNUSED(klass))
64
65
  {
65
- return INT2NUM(sqlite3_libversion_number());
66
+ return INT2NUM(sqlite3_libversion_number());
66
67
  }
67
68
 
68
- static VALUE using_sqlcipher(VALUE UNUSED(klass))
69
+ static VALUE
70
+ using_sqlcipher(VALUE UNUSED(klass))
69
71
  {
70
72
  #ifdef USING_SQLCIPHER
71
- return Qtrue;
73
+ return Qtrue;
72
74
  #else
73
- return Qfalse;
75
+ return Qfalse;
74
76
  #endif
75
77
  }
76
78
 
77
79
  /* Returns the compile time setting of the SQLITE_THREADSAFE flag.
78
80
  * See: https://www.sqlite.org/c3ref/threadsafe.html
79
81
  */
80
- static VALUE threadsafe_p(VALUE UNUSED(klass))
82
+ static VALUE
83
+ threadsafe_p(VALUE UNUSED(klass))
84
+ {
85
+ return INT2NUM(sqlite3_threadsafe());
86
+ }
87
+
88
+ /*
89
+ * call-seq:
90
+ * status(parameter) → Hash
91
+ * status(parameter, reset_flag = false) → Hash
92
+ *
93
+ * Queries the SQLite3 library for run-time status information. Passing a truthy +reset_flag+ will
94
+ * reset the highwater mark to the current value.
95
+ *
96
+ * [Parameters]
97
+ * - +parameter+ (Integer, SQLite3::Constants::Status): The status parameter to query.
98
+ * - +reset_flag+ (Boolean): Whether to reset the highwater mark. (default is +false+)
99
+ *
100
+ * [Returns]
101
+ * A Hash containing +:current+ and +:highwater+ keys for integer values.
102
+ */
103
+ static VALUE
104
+ rb_sqlite3_status(int argc, VALUE *argv, VALUE klass)
81
105
  {
82
- return INT2NUM(sqlite3_threadsafe());
106
+ VALUE opArg, resetFlagArg;
107
+
108
+ rb_scan_args(argc, argv, "11", &opArg, &resetFlagArg);
109
+
110
+ int op = NUM2INT(opArg);
111
+ bool resetFlag = RTEST(resetFlagArg);
112
+
113
+ int pCurrent = 0;
114
+ int pHighwater = 0;
115
+ sqlite3_status(op, &pCurrent, &pHighwater, resetFlag);
116
+
117
+ VALUE hash = rb_hash_new();
118
+ rb_hash_aset(hash, ID2SYM(rb_intern("current")), INT2FIX(pCurrent));
119
+ rb_hash_aset(hash, ID2SYM(rb_intern("highwater")), INT2FIX(pHighwater));
120
+
121
+ return hash;
83
122
  }
84
123
 
85
- void init_sqlite3_constants(void)
124
+ void
125
+ init_sqlite3_constants(void)
86
126
  {
87
- VALUE mSqlite3Constants;
88
- VALUE mSqlite3Open;
89
-
90
- mSqlite3Constants = rb_define_module_under(mSqlite3, "Constants");
91
-
92
- /* sqlite3_open_v2 flags for Database::new */
93
- mSqlite3Open = rb_define_module_under(mSqlite3Constants, "Open");
94
-
95
- /* symbols = IO.readlines('sqlite3.h').map { |n| /\A#define\s+(SQLITE_OPEN_\w+)\s/ =~ n && $1 }.compact
96
- * pad = symbols.map(&:length).max - 9
97
- * symbols.each { |s| printf %Q{ rb_define_const(mSqlite3Open, %-#{pad}s INT2FIX(#{s}));\n}, '"' + s[12..-1] + '",' }
98
- */
99
- rb_define_const(mSqlite3Open, "READONLY", INT2FIX(SQLITE_OPEN_READONLY));
100
- rb_define_const(mSqlite3Open, "READWRITE", INT2FIX(SQLITE_OPEN_READWRITE));
101
- rb_define_const(mSqlite3Open, "CREATE", INT2FIX(SQLITE_OPEN_CREATE));
102
- rb_define_const(mSqlite3Open, "DELETEONCLOSE", INT2FIX(SQLITE_OPEN_DELETEONCLOSE));
103
- rb_define_const(mSqlite3Open, "EXCLUSIVE", INT2FIX(SQLITE_OPEN_EXCLUSIVE));
104
- rb_define_const(mSqlite3Open, "MAIN_DB", INT2FIX(SQLITE_OPEN_MAIN_DB));
105
- rb_define_const(mSqlite3Open, "TEMP_DB", INT2FIX(SQLITE_OPEN_TEMP_DB));
106
- rb_define_const(mSqlite3Open, "TRANSIENT_DB", INT2FIX(SQLITE_OPEN_TRANSIENT_DB));
107
- rb_define_const(mSqlite3Open, "MAIN_JOURNAL", INT2FIX(SQLITE_OPEN_MAIN_JOURNAL));
108
- rb_define_const(mSqlite3Open, "TEMP_JOURNAL", INT2FIX(SQLITE_OPEN_TEMP_JOURNAL));
109
- rb_define_const(mSqlite3Open, "SUBJOURNAL", INT2FIX(SQLITE_OPEN_SUBJOURNAL));
110
- rb_define_const(mSqlite3Open, "MASTER_JOURNAL", INT2FIX(SQLITE_OPEN_MASTER_JOURNAL));
111
- rb_define_const(mSqlite3Open, "NOMUTEX", INT2FIX(SQLITE_OPEN_NOMUTEX));
112
- rb_define_const(mSqlite3Open, "FULLMUTEX", INT2FIX(SQLITE_OPEN_FULLMUTEX));
127
+ VALUE mSqlite3Constants;
128
+ VALUE mSqlite3Open;
129
+
130
+ mSqlite3Constants = rb_define_module_under(mSqlite3, "Constants");
131
+
132
+ /* sqlite3_open_v2 flags for Database::new */
133
+ mSqlite3Open = rb_define_module_under(mSqlite3Constants, "Open");
134
+
135
+ /* symbols = IO.readlines('sqlite3.h').map { |n| /\A#define\s+(SQLITE_OPEN_\w+)\s/ =~ n && $1 }.compact
136
+ * pad = symbols.map(&:length).max - 9
137
+ * symbols.each { |s| printf %Q{ rb_define_const(mSqlite3Open, %-#{pad}s INT2FIX(#{s}));\n}, '"' + s[12..-1] + '",' }
138
+ */
139
+ rb_define_const(mSqlite3Open, "READONLY", INT2FIX(SQLITE_OPEN_READONLY));
140
+ rb_define_const(mSqlite3Open, "READWRITE", INT2FIX(SQLITE_OPEN_READWRITE));
141
+ rb_define_const(mSqlite3Open, "CREATE", INT2FIX(SQLITE_OPEN_CREATE));
142
+ rb_define_const(mSqlite3Open, "DELETEONCLOSE", INT2FIX(SQLITE_OPEN_DELETEONCLOSE));
143
+ rb_define_const(mSqlite3Open, "EXCLUSIVE", INT2FIX(SQLITE_OPEN_EXCLUSIVE));
144
+ rb_define_const(mSqlite3Open, "MAIN_DB", INT2FIX(SQLITE_OPEN_MAIN_DB));
145
+ rb_define_const(mSqlite3Open, "TEMP_DB", INT2FIX(SQLITE_OPEN_TEMP_DB));
146
+ rb_define_const(mSqlite3Open, "TRANSIENT_DB", INT2FIX(SQLITE_OPEN_TRANSIENT_DB));
147
+ rb_define_const(mSqlite3Open, "MAIN_JOURNAL", INT2FIX(SQLITE_OPEN_MAIN_JOURNAL));
148
+ rb_define_const(mSqlite3Open, "TEMP_JOURNAL", INT2FIX(SQLITE_OPEN_TEMP_JOURNAL));
149
+ rb_define_const(mSqlite3Open, "SUBJOURNAL", INT2FIX(SQLITE_OPEN_SUBJOURNAL));
150
+ rb_define_const(mSqlite3Open, "MASTER_JOURNAL",
151
+ INT2FIX(SQLITE_OPEN_MASTER_JOURNAL)); /* pre-3.33.0 */
152
+ rb_define_const(mSqlite3Open, "SUPER_JOURNAL", INT2FIX(SQLITE_OPEN_MASTER_JOURNAL));
153
+ rb_define_const(mSqlite3Open, "NOMUTEX", INT2FIX(SQLITE_OPEN_NOMUTEX));
154
+ rb_define_const(mSqlite3Open, "FULLMUTEX", INT2FIX(SQLITE_OPEN_FULLMUTEX));
113
155
  #ifdef SQLITE_OPEN_AUTOPROXY
114
- /* SQLITE_VERSION_NUMBER>=3007002 */
115
- rb_define_const(mSqlite3Open, "AUTOPROXY", INT2FIX(SQLITE_OPEN_AUTOPROXY));
116
- rb_define_const(mSqlite3Open, "SHAREDCACHE", INT2FIX(SQLITE_OPEN_SHAREDCACHE));
117
- rb_define_const(mSqlite3Open, "PRIVATECACHE", INT2FIX(SQLITE_OPEN_PRIVATECACHE));
118
- rb_define_const(mSqlite3Open, "WAL", INT2FIX(SQLITE_OPEN_WAL));
156
+ /* SQLITE_VERSION_NUMBER>=3007002 */
157
+ rb_define_const(mSqlite3Open, "AUTOPROXY", INT2FIX(SQLITE_OPEN_AUTOPROXY));
158
+ rb_define_const(mSqlite3Open, "SHAREDCACHE", INT2FIX(SQLITE_OPEN_SHAREDCACHE));
159
+ rb_define_const(mSqlite3Open, "PRIVATECACHE", INT2FIX(SQLITE_OPEN_PRIVATECACHE));
160
+ rb_define_const(mSqlite3Open, "WAL", INT2FIX(SQLITE_OPEN_WAL));
119
161
  #endif
120
162
  #ifdef SQLITE_OPEN_URI
121
- /* SQLITE_VERSION_NUMBER>=3007007 */
122
- rb_define_const(mSqlite3Open, "URI", INT2FIX(SQLITE_OPEN_URI));
163
+ /* SQLITE_VERSION_NUMBER>=3007007 */
164
+ rb_define_const(mSqlite3Open, "URI", INT2FIX(SQLITE_OPEN_URI));
123
165
  #endif
124
166
  #ifdef SQLITE_OPEN_MEMORY
125
- /* SQLITE_VERSION_NUMBER>=3007013 */
126
- rb_define_const(mSqlite3Open, "MEMORY", INT2FIX(SQLITE_OPEN_MEMORY));
167
+ /* SQLITE_VERSION_NUMBER>=3007013 */
168
+ rb_define_const(mSqlite3Open, "MEMORY", INT2FIX(SQLITE_OPEN_MEMORY));
127
169
  #endif
128
170
  }
129
171
 
130
172
  RUBY_FUNC_EXPORTED
131
- void Init_sqlite3_native(void)
173
+ void
174
+ Init_sqlite3_native(void)
132
175
  {
133
- /*
134
- * SQLite3 is a wrapper around the popular database
135
- * sqlite[http://sqlite.org].
136
- *
137
- * For an example of usage, see SQLite3::Database.
138
- */
139
- mSqlite3 = rb_define_module("SQLite3");
140
-
141
- /* A class for differentiating between strings and blobs, when binding them
142
- * into statements.
143
- */
144
- cSqlite3Blob = rb_define_class_under(mSqlite3, "Blob", rb_cString);
145
-
146
- /* Initialize the sqlite3 library */
176
+ /*
177
+ * SQLite3 is a wrapper around the popular database
178
+ * sqlite[http://sqlite.org].
179
+ *
180
+ * For an example of usage, see SQLite3::Database.
181
+ */
182
+ mSqlite3 = rb_define_module("SQLite3");
183
+
184
+ /* A class for differentiating between strings and blobs, when binding them
185
+ * into statements.
186
+ */
187
+ cSqlite3Blob = rb_define_class_under(mSqlite3, "Blob", rb_cString);
188
+
189
+ /* Initialize the sqlite3 library */
147
190
  #ifdef HAVE_SQLITE3_INITIALIZE
148
- sqlite3_initialize();
191
+ sqlite3_initialize();
149
192
  #endif
150
193
 
151
- init_sqlite3_constants();
152
- init_sqlite3_database();
153
- init_sqlite3_statement();
194
+ init_sqlite3_constants();
195
+ init_sqlite3_database();
196
+ init_sqlite3_statement();
154
197
  #ifdef HAVE_SQLITE3_BACKUP_INIT
155
- init_sqlite3_backup();
198
+ init_sqlite3_backup();
156
199
  #endif
157
- rb_define_singleton_method(mSqlite3, "sqlcipher?", using_sqlcipher, 0);
158
- rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
159
- rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
160
- rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
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()));
200
+ rb_define_singleton_method(mSqlite3, "sqlcipher?", using_sqlcipher, 0);
201
+ rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
202
+ rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
203
+ rb_define_singleton_method(mSqlite3, "status", rb_sqlite3_status, -1);
204
+ rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
205
+ rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
206
+ rb_define_const(mSqlite3, "SQLITE_LOADED_VERSION", rb_str_new2(sqlite3_libversion()));
163
207
 
164
208
  }