sqlite3-full 1.3.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/API_CHANGES.rdoc +50 -0
  4. data/CHANGELOG.rdoc +278 -0
  5. data/ChangeLog.cvs +88 -0
  6. data/Gemfile +15 -0
  7. data/LICENSE +34 -0
  8. data/Manifest.txt +52 -0
  9. data/README.rdoc +90 -0
  10. data/Rakefile +10 -0
  11. data/ext/sqlite3/backup.c +168 -0
  12. data/ext/sqlite3/backup.h +15 -0
  13. data/ext/sqlite3/database.c +825 -0
  14. data/ext/sqlite3/database.h +15 -0
  15. data/ext/sqlite3/exception.c +94 -0
  16. data/ext/sqlite3/exception.h +8 -0
  17. data/ext/sqlite3/extconf.rb +86 -0
  18. data/ext/sqlite3/sqlite3.c +97 -0
  19. data/ext/sqlite3/sqlite3_ruby.h +52 -0
  20. data/ext/sqlite3/sqlite3amalgamation.c +153367 -0
  21. data/ext/sqlite3/statement.c +447 -0
  22. data/ext/sqlite3/statement.h +16 -0
  23. data/faq/faq.rb +145 -0
  24. data/faq/faq.yml +426 -0
  25. data/lib/sqlite3/constants.rb +49 -0
  26. data/lib/sqlite3/database.rb +590 -0
  27. data/lib/sqlite3/errors.rb +44 -0
  28. data/lib/sqlite3/pragmas.rb +280 -0
  29. data/lib/sqlite3/resultset.rb +195 -0
  30. data/lib/sqlite3/statement.rb +144 -0
  31. data/lib/sqlite3/translator.rb +118 -0
  32. data/lib/sqlite3/value.rb +57 -0
  33. data/lib/sqlite3/version.rb +25 -0
  34. data/lib/sqlite3.rb +10 -0
  35. data/setup.rb +1333 -0
  36. data/tasks/faq.rake +9 -0
  37. data/tasks/gem.rake +38 -0
  38. data/tasks/native.rake +52 -0
  39. data/tasks/vendor_sqlite3.rake +91 -0
  40. data/test/helper.rb +18 -0
  41. data/test/test_backup.rb +33 -0
  42. data/test/test_collation.rb +82 -0
  43. data/test/test_database.rb +367 -0
  44. data/test/test_database_readonly.rb +29 -0
  45. data/test/test_deprecated.rb +44 -0
  46. data/test/test_encoding.rb +153 -0
  47. data/test/test_integration.rb +572 -0
  48. data/test/test_integration_open_close.rb +30 -0
  49. data/test/test_integration_pending.rb +115 -0
  50. data/test/test_integration_resultset.rb +159 -0
  51. data/test/test_integration_statement.rb +194 -0
  52. data/test/test_result_set.rb +37 -0
  53. data/test/test_sqlite3.rb +9 -0
  54. data/test/test_statement.rb +260 -0
  55. data/test/test_statement_execute.rb +35 -0
  56. metadata +205 -0
@@ -0,0 +1,15 @@
1
+ #ifndef SQLITE3_DATABASE_RUBY
2
+ #define SQLITE3_DATABASE_RUBY
3
+
4
+ #include <sqlite3_ruby.h>
5
+
6
+ struct _sqlite3Ruby {
7
+ sqlite3 *db;
8
+ };
9
+
10
+ typedef struct _sqlite3Ruby sqlite3Ruby;
11
+ typedef sqlite3Ruby * sqlite3RubyPtr;
12
+
13
+ void init_sqlite3_database();
14
+
15
+ #endif
@@ -0,0 +1,94 @@
1
+ #include <sqlite3_ruby.h>
2
+
3
+ void rb_sqlite3_raise(sqlite3 * db, int status)
4
+ {
5
+ VALUE klass = Qnil;
6
+
7
+ switch(status) {
8
+ case SQLITE_OK:
9
+ return;
10
+ break;
11
+ case SQLITE_ERROR:
12
+ klass = rb_path2class("SQLite3::SQLException");
13
+ break;
14
+ case SQLITE_INTERNAL:
15
+ klass = rb_path2class("SQLite3::InternalException");
16
+ break;
17
+ case SQLITE_PERM:
18
+ klass = rb_path2class("SQLite3::PermissionException");
19
+ break;
20
+ case SQLITE_ABORT:
21
+ klass = rb_path2class("SQLite3::AbortException");
22
+ break;
23
+ case SQLITE_BUSY:
24
+ klass = rb_path2class("SQLite3::BusyException");
25
+ break;
26
+ case SQLITE_LOCKED:
27
+ klass = rb_path2class("SQLite3::LockedException");
28
+ break;
29
+ case SQLITE_NOMEM:
30
+ klass = rb_path2class("SQLite3::MemoryException");
31
+ break;
32
+ case SQLITE_READONLY:
33
+ klass = rb_path2class("SQLite3::ReadOnlyException");
34
+ break;
35
+ case SQLITE_INTERRUPT:
36
+ klass = rb_path2class("SQLite3::InterruptException");
37
+ break;
38
+ case SQLITE_IOERR:
39
+ klass = rb_path2class("SQLite3::IOException");
40
+ break;
41
+ case SQLITE_CORRUPT:
42
+ klass = rb_path2class("SQLite3::CorruptException");
43
+ break;
44
+ case SQLITE_NOTFOUND:
45
+ klass = rb_path2class("SQLite3::NotFoundException");
46
+ break;
47
+ case SQLITE_FULL:
48
+ klass = rb_path2class("SQLite3::FullException");
49
+ break;
50
+ case SQLITE_CANTOPEN:
51
+ klass = rb_path2class("SQLite3::CantOpenException");
52
+ break;
53
+ case SQLITE_PROTOCOL:
54
+ klass = rb_path2class("SQLite3::ProtocolException");
55
+ break;
56
+ case SQLITE_EMPTY:
57
+ klass = rb_path2class("SQLite3::EmptyException");
58
+ break;
59
+ case SQLITE_SCHEMA:
60
+ klass = rb_path2class("SQLite3::SchemaChangedException");
61
+ break;
62
+ case SQLITE_TOOBIG:
63
+ klass = rb_path2class("SQLite3::TooBigException");
64
+ break;
65
+ case SQLITE_CONSTRAINT:
66
+ klass = rb_path2class("SQLite3::ConstraintException");
67
+ break;
68
+ case SQLITE_MISMATCH:
69
+ klass = rb_path2class("SQLite3::MismatchException");
70
+ break;
71
+ case SQLITE_MISUSE:
72
+ klass = rb_path2class("SQLite3::MisuseException");
73
+ break;
74
+ case SQLITE_NOLFS:
75
+ klass = rb_path2class("SQLite3::UnsupportedException");
76
+ break;
77
+ case SQLITE_AUTH:
78
+ klass = rb_path2class("SQLite3::AuthorizationException");
79
+ break;
80
+ case SQLITE_FORMAT:
81
+ klass = rb_path2class("SQLite3::FormatException");
82
+ break;
83
+ case SQLITE_RANGE:
84
+ klass = rb_path2class("SQLite3::RangeException");
85
+ break;
86
+ case SQLITE_NOTADB:
87
+ klass = rb_path2class("SQLite3::NotADatabaseException");
88
+ break;
89
+ default:
90
+ klass = rb_eRuntimeError;
91
+ }
92
+
93
+ rb_raise(klass, "%s", sqlite3_errmsg(db));
94
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef SQLITE3_EXCEPTION_RUBY
2
+ #define SQLITE3_EXCEPTION_RUBY
3
+
4
+ #define CHECK(_db, _status) rb_sqlite3_raise(_db, _status);
5
+
6
+ void rb_sqlite3_raise(sqlite3 * db, int status);
7
+
8
+ #endif
@@ -0,0 +1,86 @@
1
+ ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/
2
+
3
+ require 'mkmf'
4
+
5
+ # :stopdoc:
6
+
7
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
8
+
9
+ # sqlite3 settings:
10
+ #
11
+ # The following settings taken from a more-or-less default OSX 10.10 sqlite installation.
12
+ #
13
+ # The only difference: we include FTS3 *and* FTS4
14
+ $defs.push "-DSQLITE_ENABLE_FTS4"
15
+ $defs.push "-DSQLITE_ENABLE_FTS3_PARENTHESIS"
16
+ $defs.push "-DSQLITE_ENABLE_LOCKING_STYLE=1"
17
+ $defs.push "-DSQLITE_ENABLE_RTREE"
18
+ $defs.push "-DSQLITE_SYSTEM_MALLOC"
19
+ $defs.push "-DSQLITE_THREADSAFE=2"
20
+
21
+ # additional settings
22
+ $defs.push "-DSQLITE_ENABLE_COLUMN_METADATA"
23
+ $defs.push "-DSQLITE_ENABLE_MEMORY_MANAGEMENT"
24
+ $defs.push "-DSQLITE_ENABLE_RTREE"
25
+ $defs.push "-DSQLITE_SOUNDEX"
26
+
27
+ # Some additional warnings: on my machine compiling the sqlite3 amalgation spits out some
28
+ # warnings. As we don't hack sqlite3, but only the rubygem, we don't need these.
29
+ $warnflags += " -Wno-incompatible-pointer-types-discards-qualifiers"
30
+ $warnflags += " -Wno-unused-const-variable"
31
+ $warnflags += " -Wno-shorten-64-to-32"
32
+ $warnflags += " -Wno-typedef-redefinition"
33
+
34
+ $CFLAGS << " -I#{File.dirname(__FILE__)}"
35
+
36
+ if RbConfig::CONFIG["host_os"] =~ /mswin/
37
+ $CFLAGS << ' -W3'
38
+ end
39
+
40
+ def asplode missing
41
+ if RUBY_PLATFORM =~ /mingw|mswin/
42
+ abort "#{missing} is missing. Install SQLite3 from " +
43
+ "http://www.sqlite.org/ first."
44
+ else
45
+ abort <<-error
46
+ #{missing} is missing. Try 'port install sqlite3 +universal',
47
+ 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
48
+ and check your shared library search path (the
49
+ location where your sqlite3 shared library is located).
50
+ error
51
+ end
52
+ end
53
+
54
+ # -- sqlite3 platform configuration, see http://www.sqlite.org/compile.html
55
+ have_func('fdatasync')
56
+ have_func('gmtime_r')
57
+ have_func('isnan')
58
+ have_func('localtime_r')
59
+ have_func('localtime_s')
60
+ have_func('malloc_usable_size')
61
+ have_func('strchrnul')
62
+ have_func('usleep')
63
+ have_func('utime')
64
+
65
+ # -- ruby feature detection
66
+
67
+ # Functions defined in 1.9 but not 1.8
68
+ have_func('rb_proc_arity')
69
+
70
+ # Functions defined in 2.1 but not 2.0
71
+ have_func('rb_integer_pack')
72
+
73
+ # These functions may not be defined in a standard sqlite3-ruby build -
74
+ # they are here. We still need to define the test macros, as they are used
75
+ # in the upstream (i.e. sqlite3-ruby) code.
76
+ $defs.push "-DHAVE_SQLITE3_INITIALIZE"
77
+ $defs.push "-DHAVE_SQLITE3_BACKUP_INIT"
78
+ $defs.push "-DHAVE_SQLITE3_COLUMN_DATABASE_NAME"
79
+ $defs.push "-DHAVE_SQLITE3_ENABLE_LOAD_EXTENSION"
80
+ $defs.push "-DHAVE_SQLITE3_LOAD_EXTENSION"
81
+ $defs.push "-DHAVE_SQLITE3_OPEN_V2"
82
+ $defs.push "-DHAVE_SQLITE3_PREPARE_V2"
83
+ $defs.push "-DHAVE_SQLITE3_INT64"
84
+ $defs.push "-DHAVE_SQLITE3_UINT64"
85
+
86
+ create_makefile('sqlite3/sqlite3_native')
@@ -0,0 +1,97 @@
1
+ #include <sqlite3_ruby.h>
2
+
3
+ VALUE mSqlite3;
4
+ VALUE cSqlite3Blob;
5
+
6
+ int bignum_to_int64(VALUE value, sqlite3_int64 *result)
7
+ {
8
+ #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;
19
+ }
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
+ #else
32
+ # ifndef RBIGNUM_LEN
33
+ # define RBIGNUM_LEN(x) RBIGNUM(x)->len
34
+ # 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
+ }
56
+ }
57
+ }
58
+ *result = (sqlite3_int64)NUM2LL(value);
59
+ return 1;
60
+ #endif
61
+ }
62
+
63
+ static VALUE libversion(VALUE UNUSED(klass))
64
+ {
65
+ return INT2NUM(sqlite3_libversion_number());
66
+ }
67
+
68
+ void Init_sqlite3_native()
69
+ {
70
+ /*
71
+ * SQLite3 is a wrapper around the popular database
72
+ * sqlite[http://sqlite.org].
73
+ *
74
+ * For an example of usage, see SQLite3::Database.
75
+ */
76
+ mSqlite3 = rb_define_module("SQLite3");
77
+
78
+ /* A class for differentiating between strings and blobs, when binding them
79
+ * into statements.
80
+ */
81
+ cSqlite3Blob = rb_define_class_under(mSqlite3, "Blob", rb_cString);
82
+
83
+ /* Initialize the sqlite3 library */
84
+ #ifdef HAVE_SQLITE3_INITIALIZE
85
+ sqlite3_initialize();
86
+ #endif
87
+
88
+ init_sqlite3_database();
89
+ init_sqlite3_statement();
90
+ #ifdef HAVE_SQLITE3_BACKUP_INIT
91
+ init_sqlite3_backup();
92
+ #endif
93
+
94
+ rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
95
+ rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
96
+ rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
97
+ }
@@ -0,0 +1,52 @@
1
+ #ifndef SQLITE3_RUBY
2
+ #define SQLITE3_RUBY
3
+
4
+ #include <ruby.h>
5
+
6
+ #ifdef UNUSED
7
+ #elif defined(__GNUC__)
8
+ # define UNUSED(x) UNUSED_ ## x __attribute__((unused))
9
+ #elif defined(__LCLINT__)
10
+ # define UNUSED(x) /*@unused@*/ x
11
+ #else
12
+ # define UNUSED(x) x
13
+ #endif
14
+
15
+ #ifdef HAVE_RUBY_ENCODING_H
16
+ #include <ruby/encoding.h>
17
+
18
+ #define USASCII_P(_obj) (rb_enc_get_index(_obj) == rb_usascii_encindex())
19
+ #define UTF8_P(_obj) (rb_enc_get_index(_obj) == rb_utf8_encindex())
20
+ #define UTF16_LE_P(_obj) (rb_enc_get_index(_obj) == rb_enc_find_index("UTF-16LE"))
21
+ #define UTF16_BE_P(_obj) (rb_enc_get_index(_obj) == rb_enc_find_index("UTF-16BE"))
22
+ #define SQLITE3_UTF8_STR_NEW2(_obj) \
23
+ (rb_enc_associate_index(rb_str_new2(_obj), rb_utf8_encindex()))
24
+
25
+ #else
26
+
27
+ #define SQLITE3_UTF8_STR_NEW2(_obj) (rb_str_new2(_obj))
28
+
29
+ #endif
30
+
31
+
32
+ #include <sqlite3.h>
33
+
34
+ #ifndef HAVE_TYPE_SQLITE3_INT64
35
+ typedef sqlite_int64 sqlite3_int64;
36
+ #endif
37
+
38
+ #ifndef HAVE_TYPE_SQLITE3_UINT64
39
+ typedef sqlite_uint64 sqlite3_uint64;
40
+ #endif
41
+
42
+ extern VALUE mSqlite3;
43
+ extern VALUE cSqlite3Blob;
44
+
45
+ #include <database.h>
46
+ #include <statement.h>
47
+ #include <exception.h>
48
+ #include <backup.h>
49
+
50
+ int bignum_to_int64(VALUE big, sqlite3_int64 *result);
51
+
52
+ #endif