do_mysql 0.2.3 → 0.2.4
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.
- data/Rakefile +2 -2
- data/ext/mysql_c.i +1 -1
- data/lib/do_mysql.rb +46 -4
- metadata +4 -4
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
|
|
3
3
|
|
4
4
|
PLUGIN = "do_mysql"
|
5
5
|
NAME = "do_mysql"
|
6
|
-
VERSION = "0.2.
|
6
|
+
VERSION = "0.2.4"
|
7
7
|
AUTHOR = "Yehuda Katz"
|
8
8
|
EMAIL = "wycats@gmail.com"
|
9
9
|
HOMEPAGE = "http://dataobjects.devjavu.com"
|
@@ -20,7 +20,7 @@ spec = Gem::Specification.new do |s|
|
|
20
20
|
s.author = AUTHOR
|
21
21
|
s.email = EMAIL
|
22
22
|
s.homepage = HOMEPAGE
|
23
|
-
s.add_dependency('data_objects')
|
23
|
+
s.add_dependency('data_objects', ["<=0.2.0"])
|
24
24
|
s.require_path = 'lib'
|
25
25
|
s.autorequire = PLUGIN
|
26
26
|
s.extensions = ["ext/extconf.rb"]
|
data/ext/mysql_c.i
CHANGED
@@ -38,7 +38,7 @@
|
|
38
38
|
%}
|
39
39
|
|
40
40
|
%ignore st_mysql_options;
|
41
|
-
%include "/usr/local/mysql
|
41
|
+
%include "/usr/local/mysql/include/mysql.h"
|
42
42
|
|
43
43
|
VALUE mysql_c_fetch_field_names(MYSQL_RES *reader, int count);
|
44
44
|
VALUE mysql_c_fetch_field_types(MYSQL_RES *reader, int count);
|
data/lib/do_mysql.rb
CHANGED
@@ -50,6 +50,10 @@ module DataObject
|
|
50
50
|
def create_command(text)
|
51
51
|
Command.new(self, text)
|
52
52
|
end
|
53
|
+
|
54
|
+
def begin_transaction
|
55
|
+
Transaction.new(self)
|
56
|
+
end
|
53
57
|
|
54
58
|
end
|
55
59
|
|
@@ -60,6 +64,44 @@ module DataObject
|
|
60
64
|
@name, @type = ptr.name.to_s, ptr.type.to_s
|
61
65
|
end
|
62
66
|
end
|
67
|
+
|
68
|
+
class Transaction
|
69
|
+
|
70
|
+
attr_reader :connection
|
71
|
+
|
72
|
+
def initialize(conn)
|
73
|
+
@connection = conn
|
74
|
+
exec_sql("BEGIN")
|
75
|
+
end
|
76
|
+
|
77
|
+
# Commits the transaction
|
78
|
+
def commit
|
79
|
+
exec_sql("COMMIT")
|
80
|
+
end
|
81
|
+
|
82
|
+
# Rolls back the transaction
|
83
|
+
def rollback(savepoint = nil)
|
84
|
+
raise NotImplementedError, "MySQL does not support savepoints" if savepoint
|
85
|
+
exec_sql("ROLLBACK")
|
86
|
+
end
|
87
|
+
|
88
|
+
# Creates a savepoint for rolling back later (not commonly supported)
|
89
|
+
def save(name)
|
90
|
+
raise NotImplementedError, "MySQL does not support savepoints"
|
91
|
+
end
|
92
|
+
|
93
|
+
def create_command(*args)
|
94
|
+
@connection.create_command(*args)
|
95
|
+
end
|
96
|
+
|
97
|
+
protected
|
98
|
+
|
99
|
+
def exec_sql(sql)
|
100
|
+
@connection.logger.debug(sql)
|
101
|
+
Mysql_c.mysql_query(@connection.db, sql)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
63
105
|
|
64
106
|
class Reader < DataObject::Reader
|
65
107
|
|
@@ -141,15 +183,17 @@ module DataObject
|
|
141
183
|
end
|
142
184
|
|
143
185
|
def typecast(val, idx)
|
144
|
-
return nil if val.nil?
|
186
|
+
return nil if val.nil? || val == "NULL"
|
145
187
|
field = @native_fields[idx]
|
146
188
|
case TYPES[field]
|
189
|
+
when "NULL"
|
190
|
+
nil
|
147
191
|
when "TINY"
|
148
192
|
val != "0"
|
149
193
|
when "BIT"
|
150
194
|
val.to_i(2)
|
151
195
|
when "SHORT", "LONG", "INT24", "LONGLONG"
|
152
|
-
val.to_i
|
196
|
+
val == '' ? nil : val.to_i
|
153
197
|
when "DECIMAL", "NEWDECIMAL", "FLOAT", "DOUBLE", "YEAR"
|
154
198
|
val.to_f
|
155
199
|
when "TIMESTAMP", "DATETIME"
|
@@ -158,8 +202,6 @@ module DataObject
|
|
158
202
|
DateTime.parse(val).to_time rescue nil
|
159
203
|
when "DATE"
|
160
204
|
Date.parse(val) rescue nil
|
161
|
-
when "NULL"
|
162
|
-
nil
|
163
205
|
else
|
164
206
|
val
|
165
207
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: do_mysql
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2008-
|
6
|
+
version: 0.2.4
|
7
|
+
date: 2008-04-17 00:00:00 -07:00
|
8
8
|
summary: A DataObject.rb driver for mysql
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
version_requirement:
|
58
58
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - <=
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
62
|
+
version: 0.2.0
|
63
63
|
version:
|