do_sqlite3 0.10.3-x86-mingw32 → 0.10.4.rc1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,57 +9,11 @@
9
9
  #include <sqlite3.h>
10
10
  #include "compat.h"
11
11
 
12
- #ifdef HAVE_RUBY_ENCODING_H
13
- #include <ruby/encoding.h>
14
-
15
- #define DO_STR_NEW2(str, encoding, internal_encoding) \
16
- ({ \
17
- VALUE _string = rb_str_new2((const char *)str); \
18
- if(encoding != -1) { \
19
- rb_enc_associate_index(_string, encoding); \
20
- } \
21
- if(internal_encoding) { \
22
- _string = rb_str_export_to_enc(_string, internal_encoding); \
23
- } \
24
- _string; \
25
- })
26
-
27
- #define DO_STR_NEW(str, len, encoding, internal_encoding) \
28
- ({ \
29
- VALUE _string = rb_str_new((const char *)str, (long)len); \
30
- if(encoding != -1) { \
31
- rb_enc_associate_index(_string, encoding); \
32
- } \
33
- if(internal_encoding) { \
34
- _string = rb_str_export_to_enc(_string, internal_encoding); \
35
- } \
36
- _string; \
37
- })
38
-
39
- #else
40
-
41
- #define DO_STR_NEW2(str, encoding, internal_encoding) \
42
- rb_str_new2((const char *)str)
43
-
44
- #define DO_STR_NEW(str, len, encoding, internal_encoding) \
45
- rb_str_new((const char *)str, (long)len)
46
- #endif
47
-
48
- #define CONST_GET(scope, constant) (rb_funcall(scope, ID_CONST_GET, 1, rb_str_new2(constant)))
49
- #define DRIVER_CLASS(klass, parent) (rb_define_class_under(mSqlite3, klass, parent))
50
-
51
- #ifdef _WIN32
52
- #define do_int64 signed __int64
53
- #else
54
- #define do_int64 signed long long int
55
- #endif
56
-
57
12
  #ifndef HAVE_SQLITE3_PREPARE_V2
58
13
  #define sqlite3_prepare_v2 sqlite3_prepare
59
14
  #endif
60
15
 
61
- static ID ID_CONST_GET;
62
-
63
- void Init_do_sqlite3_extension();
16
+ extern VALUE mSqlite3;
17
+ extern void Init_do_sqlite3_extension();
64
18
 
65
- #endif
19
+ #endif
@@ -1,22 +1,16 @@
1
+ #include <ruby.h>
2
+ #include "do_common.h"
1
3
  #include "do_sqlite3.h"
2
4
 
3
- static VALUE ID_CONST_GET;
4
- static VALUE mDO;
5
- static VALUE mSqlite3;
6
- static VALUE eConnectionError;
7
- static VALUE cDO_Extension;
8
- static VALUE cExtension;
5
+ VALUE cExtension;
9
6
 
10
7
  /*****************************************************/
11
8
  /* File used for providing extensions on the default */
12
9
  /* API that are driver specific. */
13
10
  /*****************************************************/
14
- static VALUE cExtension_enable_load_extension(VALUE self, VALUE on) {
11
+ VALUE cExtension_enable_load_extension(VALUE self, VALUE on) {
15
12
  VALUE id_connection = rb_intern("connection");
16
-
17
13
  VALUE connection = rb_funcall(self, id_connection, 0);
18
- sqlite3 *db;
19
- int status;
20
14
 
21
15
  if (connection == Qnil) { return Qfalse; }
22
16
 
@@ -25,26 +19,24 @@ static VALUE cExtension_enable_load_extension(VALUE self, VALUE on) {
25
19
 
26
20
  if (connection == Qnil) { return Qfalse; }
27
21
 
28
- db = DATA_PTR(connection);
22
+ sqlite3 *db;
29
23
 
30
- if(db == NULL) { return Qfalse; }
24
+ if (!(db = DATA_PTR(connection))) {
25
+ return Qfalse;
26
+ }
31
27
 
32
- status = sqlite3_enable_load_extension(db, on == Qtrue ? 1 : 0);
28
+ int status = sqlite3_enable_load_extension(db, on == Qtrue ? 1 : 0);
33
29
 
34
- if ( status != SQLITE_OK ) {
30
+ if (status != SQLITE_OK) {
35
31
  rb_raise(eConnectionError, "Couldn't enable extension loading");
36
32
  }
33
+
37
34
  return Qtrue;
38
35
  }
39
36
 
40
- static VALUE cExtension_load_extension(VALUE self, VALUE path) {
37
+ VALUE cExtension_load_extension(VALUE self, VALUE path) {
41
38
  VALUE id_connection = rb_intern("connection");
42
-
43
39
  VALUE connection = rb_funcall(self, id_connection, 0);
44
- sqlite3 *db;
45
- const char *extension_path = rb_str_ptr_readonly(path);
46
- char* errmsg = sqlite3_malloc(1024);
47
- int status;
48
40
 
49
41
  if (connection == Qnil) { return Qfalse; }
50
42
 
@@ -53,26 +45,33 @@ static VALUE cExtension_load_extension(VALUE self, VALUE path) {
53
45
 
54
46
  if (connection == Qnil) { return Qfalse; }
55
47
 
56
- db = DATA_PTR(connection);
48
+ sqlite3 *db;
49
+
50
+ if (!(db = DATA_PTR(connection))) {
51
+ return Qfalse;
52
+ }
53
+
54
+ const char *extension_path = rb_str_ptr_readonly(path);
55
+ char *errmsg;
57
56
 
58
- if(db == NULL) { return Qfalse; }
57
+ if (!(errmsg = sqlite3_malloc(1024))) {
58
+ return Qfalse;
59
+ }
59
60
 
60
- status = sqlite3_load_extension(db, extension_path, 0, &errmsg);
61
+ int status = sqlite3_load_extension(db, extension_path, 0, &errmsg);
61
62
 
62
- if ( status != SQLITE_OK ) {
63
+ if (status != SQLITE_OK) {
63
64
  VALUE errexp = rb_exc_new2(eConnectionError, errmsg);
65
+
64
66
  sqlite3_free(errmsg);
65
67
  rb_exc_raise(errexp);
66
68
  }
69
+
67
70
  return Qtrue;
68
71
  }
69
72
 
70
73
  void Init_do_sqlite3_extension() {
71
- ID_CONST_GET = rb_intern("const_get");
72
- mDO = CONST_GET(rb_mKernel, "DataObjects");
73
- cDO_Extension = CONST_GET(mDO, "Extension");
74
- mSqlite3 = rb_define_module_under(mDO, "Sqlite3");
75
- cExtension = DRIVER_CLASS("Extension", cDO_Extension);
74
+ cExtension = rb_define_class_under(mSqlite3, "Extension", cDO_Extension);
76
75
  rb_define_method(cExtension, "load_extension", cExtension_load_extension, 1);
77
76
  rb_define_method(cExtension, "enable_load_extension", cExtension_enable_load_extension, 1);
78
77
  }
@@ -1,111 +1,85 @@
1
- #ifndef DO_SQLITE3_ERROR_H
2
- #define DO_SQLITE3_ERROR_H
1
+ #ifndef _DO_SQLITE3_ERROR_H_
2
+ #define _DO_SQLITE3_ERROR_H_
3
3
 
4
- static struct errcodes {
5
- int error_no;
6
- const char *error_name;
7
- const char *exception;
8
- } errors [] = {
4
+ #include "do_common.h"
5
+
6
+ static struct errcodes errors[] = {
9
7
  #ifdef SQLITE_ERROR
10
- { SQLITE_ERROR,
11
- "SQLITE_ERROR", "SyntaxError"},
8
+ ERRCODE(SQLITE_ERROR, "SyntaxError"),
12
9
  #endif
13
10
  #ifdef SQLITE_INTERNAL
14
- { SQLITE_INTERNAL,
15
- "SQLITE_INTERNAL", "SQLError"},
11
+ ERRCODE(SQLITE_INTERNAL, "SQLError"),
16
12
  #endif
17
13
  #ifdef SQLITE_PERM
18
- { SQLITE_PERM,
19
- "SQLITE_PERM", "ConnectionError"},
14
+ ERRCODE(SQLITE_PERM, "ConnectionError"),
20
15
  #endif
21
16
  #ifdef SQLITE_ABORT
22
- { SQLITE_ABORT,
23
- "SQLITE_ABORT", "ConnectionError"},
17
+ ERRCODE(SQLITE_ABORT, "ConnectionError"),
24
18
  #endif
25
19
  #ifdef SQLITE_BUSY
26
- { SQLITE_BUSY,
27
- "SQLITE_BUSY", "ConnectionError"},
20
+ ERRCODE(SQLITE_BUSY, "ConnectionError"),
28
21
  #endif
29
22
 
30
23
  #ifdef SQLITE_LOCKED
31
- { SQLITE_LOCKED,
32
- "SQLITE_LOCKED", "ConnectionError"},
24
+ ERRCODE(SQLITE_LOCKED, "ConnectionError"),
33
25
  #endif
34
26
  #ifdef SQLITE_NOMEM
35
- { SQLITE_NOMEM,
36
- "SQLITE_NOMEM", "ConnectionError"},
27
+ ERRCODE(SQLITE_NOMEM, "ConnectionError"),
37
28
  #endif
38
29
  #ifdef SQLITE_READONLY
39
- { SQLITE_READONLY,
40
- "SQLITE_READONLY", "ConnectionError"},
30
+ ERRCODE(SQLITE_READONLY, "ConnectionError"),
41
31
  #endif
42
32
  #ifdef SQLITE_INTERRUPT
43
- { SQLITE_INTERRUPT,
44
- "SQLITE_INTERRUPT", "ConnectionError"},
33
+ ERRCODE(SQLITE_INTERRUPT, "ConnectionError"),
45
34
  #endif
46
35
  #ifdef SQLITE_IOERR
47
- { SQLITE_IOERR,
48
- "SQLITE_IOERR", "ConnectionError"},
36
+ ERRCODE(SQLITE_IOERR, "ConnectionError"),
49
37
  #endif
50
38
  #ifdef SQLITE_CORRUPT
51
- { SQLITE_CORRUPT,
52
- "SQLITE_CORRUPT", "ConnectionError"},
39
+ ERRCODE(SQLITE_CORRUPT, "ConnectionError"),
53
40
  #endif
54
41
  #ifdef SQLITE_FULL
55
- { SQLITE_FULL,
56
- "SQLITE_FULL", "ConnectionError"},
42
+ ERRCODE(SQLITE_FULL, "ConnectionError"),
57
43
  #endif
58
44
  #ifdef SQLITE_CANTOPEN
59
- { SQLITE_CANTOPEN,
60
- "SQLITE_CANTOPEN", "ConnectionError"},
45
+ ERRCODE(SQLITE_CANTOPEN, "ConnectionError"),
61
46
  #endif
62
47
  #ifdef SQLITE_EMPTY
63
- { SQLITE_EMPTY,
64
- "SQLITE_EMPTY", "ConnectionError"},
48
+ ERRCODE(SQLITE_EMPTY, "ConnectionError"),
65
49
  #endif
66
50
  #ifdef SQLITE_SCHEMA
67
- { SQLITE_SCHEMA,
68
- "SQLITE_SCHEMA", "DataError"},
51
+ ERRCODE(SQLITE_SCHEMA, "DataError"),
69
52
  #endif
70
53
  #ifdef SQLITE_TOOBIG
71
- { SQLITE_TOOBIG,
72
- "SQLITE_TOOBIG", "DataError"},
54
+ ERRCODE(SQLITE_TOOBIG, "DataError"),
73
55
  #endif
74
56
  #ifdef SQLITE_MISMATCH
75
- { SQLITE_MISMATCH,
76
- "SQLITE_MISMATCH", "DataError"},
57
+ ERRCODE(SQLITE_MISMATCH, "DataError"),
77
58
  #endif
78
59
  #ifdef SQLITE_CONSTRAINT
79
- { SQLITE_CONSTRAINT,
80
- "SQLITE_CONSTRAINT", "IntegrityError"},
60
+ ERRCODE(SQLITE_CONSTRAINT, "IntegrityError"),
81
61
  #endif
82
62
  #ifdef SQLITE_MISUSE
83
- { SQLITE_MISUSE,
84
- "SQLITE_MISUSE", "SQLError"},
63
+ ERRCODE(SQLITE_MISUSE, "SQLError"),
85
64
  #endif
86
65
 
87
66
  #ifdef SQLITE_NOLFS
88
- { SQLITE_NOLFS,
89
- "SQLITE_NOLFS", "ConnectionError"},
67
+ ERRCODE(SQLITE_NOLFS, "ConnectionError"),
90
68
  #endif
91
69
  #ifdef SQLITE_FORMAT
92
- { SQLITE_FORMAT,
93
- "SQLITE_FORMAT", "SyntaxError"},
70
+ ERRCODE(SQLITE_FORMAT, "SyntaxError"),
94
71
  #endif
95
72
  #ifdef SQLITE_RANGE
96
- { SQLITE_RANGE,
97
- "SQLITE_RANGE", "DataError"},
73
+ ERRCODE(SQLITE_RANGE, "DataError"),
98
74
  #endif
99
75
  #ifdef SQLITE_NOTADB
100
- { SQLITE_NOTADB,
101
- "SQLITE_NOTADB", "ConnectionError"},
76
+ ERRCODE(SQLITE_NOTADB, "ConnectionError"),
102
77
  #endif
103
78
 
104
79
  #ifdef SQLITE_ROW
105
- { SQLITE_ROW,
106
- "SQLITE_ROW", "SyntaxError"},
80
+ ERRCODE(SQLITE_ROW, "SyntaxError"),
107
81
  #endif
108
82
  {0, NULL, NULL}
109
83
  };
110
84
 
111
- #endif
85
+ #endif
@@ -3,9 +3,14 @@ if RUBY_PLATFORM =~ /java/
3
3
  require 'do_jdbc'
4
4
  require 'java'
5
5
 
6
- driver = 'org.sqlite.JDBC'
6
+ module DataObjects
7
+ module Sqlite3
8
+ JDBC_DRIVER = 'org.sqlite.JDBC'
9
+ end
10
+ end
11
+
7
12
  begin
8
- java.lang.Thread.currentThread.getContextClassLoader().loadClass(driver, true)
13
+ java.lang.Thread.currentThread.getContextClassLoader().loadClass(DataObjects::Sqlite3::JDBC_DRIVER, true)
9
14
  rescue
10
15
  require 'jdbc/sqlite3' # the JDBC driver, packaged as a gem
11
16
  end
@@ -15,7 +20,7 @@ if RUBY_PLATFORM =~ /java/
15
20
  # Thread.currentThread.getContextClassLoader().loadClass() within the
16
21
  # data_objects.Connection Java class, which is currently not working as
17
22
  # expected.
18
- java_import driver
23
+ java_import DataObjects::Sqlite3::JDBC_DRIVER
19
24
  end
20
25
 
21
26
  begin
@@ -1,5 +1,5 @@
1
1
  module DataObjects
2
2
  module Sqlite3
3
- VERSION = '0.10.3'
3
+ VERSION = '0.10.4.rc1'
4
4
  end
5
5
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
- require 'data_objects/spec/command_spec'
4
+ require 'data_objects/spec/shared/command_spec'
5
5
 
6
6
  describe DataObjects::Sqlite3::Command do
7
- behaves_like 'a Command'
7
+ it_should_behave_like 'a Command'
8
8
  end
@@ -1,20 +1,20 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
- require 'data_objects/spec/connection_spec'
4
+ require 'data_objects/spec/shared/connection_spec'
5
5
 
6
6
  describe DataObjects::Sqlite3::Connection do
7
7
 
8
- before do
9
- @driver = CONFIG.scheme
10
- @user = CONFIG.user
8
+ before :all do
9
+ @driver = CONFIG.scheme
10
+ @user = CONFIG.user
11
11
  @password = CONFIG.pass
12
- @host = CONFIG.host
13
- @port = CONFIG.port
12
+ @host = CONFIG.host
13
+ @port = CONFIG.port
14
14
  @database = CONFIG.database
15
15
  end
16
16
 
17
- behaves_like 'a Connection'
18
- behaves_like 'a Connection via JDNI' if JRUBY
19
- # FIXME: behaves_like 'a Connection with JDBC URL support' if JRUBY
17
+ it_should_behave_like 'a Connection'
18
+ it_should_behave_like 'a Connection via JDNI' if JRUBY
19
+ it_should_behave_like 'a Connection with JDBC URL support' if JRUBY
20
20
  end
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
- require 'data_objects/spec/encoding_spec'
4
+ require 'data_objects/spec/shared/encoding_spec'
5
5
 
6
6
  describe DataObjects::Sqlite3::Connection do
7
- behaves_like 'returning correctly encoded strings for the default database encoding'
8
- behaves_like 'returning correctly encoded strings for the default internal encoding'
7
+ it_should_behave_like 'returning correctly encoded strings for the default database encoding'
8
+ it_should_behave_like 'returning correctly encoded strings for the default internal encoding'
9
9
  end
@@ -1,9 +1,9 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
4
- require 'data_objects/spec/error/sql_error_spec'
4
+ require 'data_objects/spec/shared/error/sql_error_spec'
5
5
 
6
6
  describe 'DataObjects::Sqlite3 raising SQLError' do
7
7
  # This fails for now, need to think of a query that also exposes the issue on sqlite :S
8
- # behaves_like 'raising a SQLError'
8
+ # it_should_behave_like 'raising a SQLError'
9
9
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
- require 'data_objects/spec/reader_spec'
4
+ require 'data_objects/spec/shared/reader_spec'
5
5
 
6
6
  describe DataObjects::Sqlite3::Reader do
7
- behaves_like 'a Reader'
7
+ it_should_behave_like 'a Reader'
8
8
  end
@@ -1,19 +1,19 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
4
- require 'data_objects/spec/result_spec'
4
+ require 'data_objects/spec/shared/result_spec'
5
5
 
6
6
  # splitting the descibe into two separate declaration avoids
7
- # concurrent execution of the "behaves_like ....." calls
7
+ # concurrent execution of the "it_should_behave_like ....." calls
8
8
  # which would lock the database
9
9
 
10
10
  # TODO
11
11
  # the locked database created a deadlock which is worth exploring since
12
12
  # such situation could appear in the wild too
13
13
  describe DataObjects::Sqlite3::Result do
14
- behaves_like 'a Result'
14
+ it_should_behave_like 'a Result'
15
15
  end
16
16
 
17
17
  describe DataObjects::Sqlite3::Result do
18
- behaves_like 'a Result which returns inserted key with sequences'
18
+ it_should_behave_like 'a Result which returns inserted key with sequences'
19
19
  end