swift-db-mysql 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/README.md +5 -0
- data/ext/swift/db/mysql/adapter.c +7 -2
- data/ext/swift/db/mysql/common.h +3 -7
- data/test/test_adapter.rb +8 -0
- metadata +6 -6
data/CHANGELOG
CHANGED
data/README.md
CHANGED
@@ -88,7 +88,7 @@ char *ssl_option(VALUE ssl, char *key) {
|
|
88
88
|
|
89
89
|
VALUE db_mysql_adapter_initialize(VALUE self, VALUE options) {
|
90
90
|
char MYSQL_BOOL_TRUE = 1;
|
91
|
-
VALUE db, user, pass, host, port, ssl;
|
91
|
+
VALUE db, user, pass, host, port, ssl, enc;
|
92
92
|
Adapter *a = db_mysql_adapter_handle(self);
|
93
93
|
|
94
94
|
if (TYPE(options) != T_HASH)
|
@@ -100,6 +100,7 @@ VALUE db_mysql_adapter_initialize(VALUE self, VALUE options) {
|
|
100
100
|
host = rb_hash_aref(options, ID2SYM(rb_intern("host")));
|
101
101
|
port = rb_hash_aref(options, ID2SYM(rb_intern("port")));
|
102
102
|
ssl = rb_hash_aref(options, ID2SYM(rb_intern("ssl")));
|
103
|
+
enc = rb_hash_aref(options, ID2SYM(rb_intern("encoding")));
|
103
104
|
|
104
105
|
if (NIL_P(db))
|
105
106
|
rb_raise(eSwiftConnectionError, "Invalid db name");
|
@@ -109,6 +110,8 @@ VALUE db_mysql_adapter_initialize(VALUE self, VALUE options) {
|
|
109
110
|
port = rb_str_new2("3306");
|
110
111
|
if (NIL_P(user))
|
111
112
|
user = sUser;
|
113
|
+
if (NIL_P(enc))
|
114
|
+
enc = rb_str_new2("utf8");
|
112
115
|
|
113
116
|
a->connection = mysql_init(0);
|
114
117
|
mysql_options(a->connection, MYSQL_OPT_RECONNECT, &MYSQL_BOOL_TRUE);
|
@@ -132,7 +135,9 @@ VALUE db_mysql_adapter_initialize(VALUE self, VALUE options) {
|
|
132
135
|
CSTRING(host), CSTRING(user), CSTRING(pass), CSTRING(db), atoi(CSTRING(port)), 0, CLIENT_FOUND_ROWS))
|
133
136
|
rb_raise(eSwiftConnectionError, "%s", mysql_error(a->connection));
|
134
137
|
|
135
|
-
mysql_set_character_set(a->connection,
|
138
|
+
if (mysql_set_character_set(a->connection, CSTRING(enc)) != 0)
|
139
|
+
rb_raise(eSwiftConnectionError, "%s", mysql_error(a->connection));
|
140
|
+
|
136
141
|
mysql_set_local_infile_handler(
|
137
142
|
a->connection,
|
138
143
|
db_mysql_adapter_infile_init, db_mysql_adapter_infile_read, db_mysql_adapter_infile_end, db_mysql_adapter_infile_error,
|
data/ext/swift/db/mysql/common.h
CHANGED
@@ -27,12 +27,8 @@ DLL_PRIVATE VALUE rb_uuid_string();
|
|
27
27
|
DLL_PRIVATE VALUE db_mysql_bind_sql(VALUE, VALUE, VALUE);
|
28
28
|
|
29
29
|
typedef struct Command {
|
30
|
-
union {
|
31
|
-
struct {
|
32
|
-
MYSQL *connection;
|
33
|
-
VALUE sql;
|
34
|
-
};
|
35
|
-
MYSQL_STMT *statement;
|
36
|
-
};
|
37
30
|
int status;
|
31
|
+
VALUE sql;
|
32
|
+
MYSQL *connection;
|
33
|
+
MYSQL_STMT *statement;
|
38
34
|
} Command;
|
data/test/test_adapter.rb
CHANGED
@@ -5,6 +5,14 @@ describe 'mysql adapter' do
|
|
5
5
|
assert db
|
6
6
|
end
|
7
7
|
|
8
|
+
it 'it should allow custom encoding' do
|
9
|
+
assert Swift::DB::Mysql.new(db: 'swift_test', encoding: 'utf8mb4')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should raise connection error on not so awesome encoding' do
|
13
|
+
assert_raises(Swift::ConnectionError) {Swift::DB::Mysql.new(db: 'swift_test', encoding: 'not_awesome')}
|
14
|
+
end
|
15
|
+
|
8
16
|
it 'should execute sql' do
|
9
17
|
assert db.execute("select * from information_schema.tables limit 1")
|
10
18
|
end
|
metadata
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swift-db-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.2
|
5
4
|
prerelease:
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Bharanee Rathna
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
15
|
+
type: :development
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
|
-
type: :development
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
@@ -27,6 +26,7 @@ dependencies:
|
|
27
26
|
- - ! '>='
|
28
27
|
- !ruby/object:Gem::Version
|
29
28
|
version: '0'
|
29
|
+
name: rake
|
30
30
|
description: Swift adapter for MySQL database
|
31
31
|
email:
|
32
32
|
- deepfryed@gmail.com
|
@@ -44,11 +44,11 @@ files:
|
|
44
44
|
- ext/swift/db/mysql/common.c
|
45
45
|
- ext/swift/db/mysql/typecast.h
|
46
46
|
- ext/swift/db/mysql/datetime.h
|
47
|
-
- ext/swift/db/mysql/gvl.h
|
48
47
|
- ext/swift/db/mysql/result.h
|
49
|
-
- ext/swift/db/mysql/common.h
|
50
48
|
- ext/swift/db/mysql/statement.h
|
51
49
|
- ext/swift/db/mysql/adapter.h
|
50
|
+
- ext/swift/db/mysql/gvl.h
|
51
|
+
- ext/swift/db/mysql/common.h
|
52
52
|
- ext/swift/db/mysql/extconf.rb
|
53
53
|
- test/helper.rb
|
54
54
|
- test/test_ssl.rb
|