ffi-mysql 0.0.1 → 0.0.2
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/.hgtags +1 -0
- data/History.rdoc +6 -0
- data/README +12 -1
- data/README.rdoc +12 -1
- data/Rakefile +2 -2
- data/lib/{mysql → ffi-mysql}/constants.rb +0 -3
- data/lib/{mysql → ffi-mysql}/error.rb +0 -0
- data/lib/{mysql → ffi-mysql}/field.rb +0 -0
- data/lib/{mysql → ffi-mysql}/mysql.rb +1 -2
- data/lib/{mysql → ffi-mysql}/result.rb +5 -4
- data/lib/{mysql → ffi-mysql}/stmt.rb +7 -24
- data/lib/{mysql → ffi-mysql}/time.rb +0 -0
- data/lib/ffi-mysql/version.rb +17 -0
- data/lib/ffi-mysql.rb +34 -42
- data/test/test_mysql.rb +53 -56
- metadata +13 -11
data/.hgtags
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
afd66b4b7cda50c08a79f51574d46e49c4dc083b v0.0.1
|
data/History.rdoc
CHANGED
data/README
CHANGED
@@ -14,7 +14,18 @@ Pure Ruby FFI interface to MySQL.
|
|
14
14
|
|
15
15
|
== SYNOPSIS:
|
16
16
|
|
17
|
-
|
17
|
+
Use
|
18
|
+
|
19
|
+
require 'ffi-mysql'
|
20
|
+
|
21
|
+
instead of
|
22
|
+
|
23
|
+
require 'mysql'
|
24
|
+
|
25
|
+
ffi-mysql should be compatible with MySQL/Ruby, so have a look at
|
26
|
+
* http://www.tmtm.org/en/mysql/ruby and
|
27
|
+
* http://www.kitebird.com/articles/ruby-mysql.html
|
28
|
+
for examples.
|
18
29
|
|
19
30
|
== REQUIREMENTS:
|
20
31
|
|
data/README.rdoc
CHANGED
@@ -14,7 +14,18 @@ Pure Ruby FFI interface to MySQL.
|
|
14
14
|
|
15
15
|
== SYNOPSIS:
|
16
16
|
|
17
|
-
|
17
|
+
Use
|
18
|
+
|
19
|
+
require 'ffi-mysql'
|
20
|
+
|
21
|
+
instead of
|
22
|
+
|
23
|
+
require 'mysql'
|
24
|
+
|
25
|
+
ffi-mysql should be compatible with MySQL/Ruby, so have a look at
|
26
|
+
* http://www.tmtm.org/en/mysql/ruby and
|
27
|
+
* http://www.kitebird.com/articles/ruby-mysql.html
|
28
|
+
for examples.
|
18
29
|
|
19
30
|
== REQUIREMENTS:
|
20
31
|
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ rescue LoadError
|
|
6
6
|
end
|
7
7
|
|
8
8
|
ensure_in_path 'lib'
|
9
|
-
require 'ffi-mysql'
|
9
|
+
require 'ffi-mysql/version'
|
10
10
|
|
11
11
|
task :default => 'test:run'
|
12
12
|
task 'gem:release' => 'test:run'
|
@@ -15,7 +15,7 @@ Bones {
|
|
15
15
|
name 'ffi-mysql'
|
16
16
|
authors 'Frank Fischer'
|
17
17
|
email 'frank.fischer@mathematik.tu-chemnitz.de'
|
18
|
-
url 'http://bitbucket.org/lyro/ffi-mysql
|
18
|
+
url 'http://bitbucket.org/lyro/ffi-mysql'
|
19
19
|
ignore_file '.hgignore'
|
20
20
|
readme_file 'README.rdoc'
|
21
21
|
history_file 'History.rdoc'
|
File without changes
|
File without changes
|
@@ -45,13 +45,14 @@ class Mysql
|
|
45
45
|
def fetch_row
|
46
46
|
raise Error, "Result has been freed" unless @result
|
47
47
|
row = C::mysql_fetch_row(@result)
|
48
|
-
if row.null?
|
48
|
+
if row.nil? or row.null?
|
49
49
|
nil
|
50
50
|
else
|
51
51
|
lengths = fetch_lengths
|
52
|
-
|
53
|
-
(0...lengths.size).map{|i|
|
54
|
-
|
52
|
+
ptrs = row.get_array_of_pointer(0, lengths.size)
|
53
|
+
(0...lengths.size).map {|i|
|
54
|
+
ptr = ptrs[i]
|
55
|
+
ptr.nil? or ptr.null? ? nil : ptr.read_string(lengths[i])
|
55
56
|
}
|
56
57
|
end
|
57
58
|
end
|
@@ -136,34 +136,17 @@ class Mysql
|
|
136
136
|
else
|
137
137
|
case self[:buffer_type]
|
138
138
|
when Field::TYPE_TINY
|
139
|
-
|
140
|
-
if self[:is_unsigned] == 0 and b >= 2**7
|
141
|
-
b -= 2**8
|
142
|
-
end
|
143
|
-
b
|
139
|
+
self[:is_unsigned] == 0 ? @buf.get_int8(0) : @buf.get_uint8(0)
|
144
140
|
when Field::TYPE_SHORT, Field::TYPE_YEAR
|
145
|
-
|
146
|
-
if self[:is_unsigned] == 0 and b >= 2**15
|
147
|
-
b -= 2**16
|
148
|
-
end
|
149
|
-
b
|
141
|
+
self[:is_unsigned] == 0 ? @buf.get_int16(0) : @buf.get_uint16(0)
|
150
142
|
when Field::TYPE_INT24, Field::TYPE_LONG
|
151
|
-
|
152
|
-
@buf.read_long % (2**32)
|
153
|
-
else
|
154
|
-
@buf.read_long
|
155
|
-
end
|
143
|
+
self[:is_unsigned] == 0 ? @buf.get_int32(0) : @buf.get_uint32(0)
|
156
144
|
when Field::TYPE_LONGLONG
|
157
|
-
|
158
|
-
@buf.read_long_long % (2**64)
|
159
|
-
else
|
160
|
-
@buf.read_long_long
|
161
|
-
end
|
145
|
+
self[:is_unsigned] == 0 ? @buf.get_int64(0) : @buf.get_uint64(0)
|
162
146
|
when Field::TYPE_FLOAT
|
163
|
-
@buf.
|
147
|
+
@buf.get_float(0)
|
164
148
|
when Field::TYPE_DOUBLE
|
165
|
-
|
166
|
-
@buf.read_double
|
149
|
+
@buf.get_double(0)
|
167
150
|
when Field::TYPE_TIME, Field::TYPE_DATE, Field::TYPE_DATETIME, Field::TYPE_TIMESTAMP
|
168
151
|
time = C::Time.new(@buf)
|
169
152
|
Time.new( time[:year], time[:month], time[:day],
|
@@ -172,7 +155,7 @@ class Mysql
|
|
172
155
|
when Field::TYPE_DECIMAL, Field::TYPE_STRING, Field::TYPE_VAR_STRING,
|
173
156
|
Field::TYPE_TINY_BLOB, Field::TYPE_BLOB, Field::TYPE_MEDIUM_BLOB,
|
174
157
|
Field::TYPE_LONG_BLOB, Field::TYPE_NEWDECIMAL, Field::TYPE_BIT
|
175
|
-
@buf.read_string( @buflen.
|
158
|
+
@buf.read_string( @buflen.get_ulong(0) )
|
176
159
|
else
|
177
160
|
raise TypeError, "unknown buffer type: #{self[:buffer_type]}"
|
178
161
|
end
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Mysql
|
2
|
+
# Major version
|
3
|
+
MAJOR = 0
|
4
|
+
# Minor version
|
5
|
+
MINOR = 0
|
6
|
+
# Tiny version
|
7
|
+
TINY = 2
|
8
|
+
|
9
|
+
# Version string
|
10
|
+
VERSION = [MAJOR, MINOR, TINY].join('.')
|
11
|
+
|
12
|
+
# Returns the version string for the library.
|
13
|
+
#
|
14
|
+
def self.version
|
15
|
+
VERSION
|
16
|
+
end
|
17
|
+
end
|
data/lib/ffi-mysql.rb
CHANGED
@@ -1,49 +1,41 @@
|
|
1
|
-
|
2
1
|
class Mysql
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def self.require_all_libs_relative_to( fname, dir = nil )
|
38
|
-
dir ||= ::File.basename(fname, '.*')
|
39
|
-
search_me = ::File.expand_path(
|
40
|
-
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
41
|
-
|
42
|
-
Dir.glob(search_me).sort.each {|rb| require rb}
|
43
|
-
end
|
3
|
+
# @private
|
4
|
+
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
5
|
+
# @private
|
6
|
+
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
7
|
+
|
8
|
+
# Returns the library path for the module. If any arguments are given,
|
9
|
+
# they will be joined to the end of the libray path using
|
10
|
+
# <tt>File.join</tt>.
|
11
|
+
#
|
12
|
+
def self.libpath( *args )
|
13
|
+
args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns the lpath for the module. If any arguments are given,
|
17
|
+
# they will be joined to the end of the path using
|
18
|
+
# <tt>File.join</tt>.
|
19
|
+
#
|
20
|
+
def self.path( *args )
|
21
|
+
args.empty? ? PATH : ::File.join(PATH, args.flatten)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Utility method used to require all files ending in .rb that lie in the
|
25
|
+
# directory below this file that has the same name as the filename passed
|
26
|
+
# in. Optionally, a specific _directory_ name can be passed in such that
|
27
|
+
# the _filename_ does not have to be equivalent to the directory.
|
28
|
+
#
|
29
|
+
def self.require_all_libs_relative_to( fname, dir = nil )
|
30
|
+
dir ||= ::File.basename(fname, '.*')
|
31
|
+
search_me = ::File.expand_path(
|
32
|
+
::File.join(::File.dirname(fname), dir, '**', '*.rb'))
|
33
|
+
|
34
|
+
Dir.glob(search_me).sort.each {|rb| require rb}
|
35
|
+
end
|
44
36
|
|
45
37
|
end # class Mysql
|
46
38
|
|
47
|
-
Mysql.require_all_libs_relative_to(__FILE__
|
39
|
+
Mysql.require_all_libs_relative_to(__FILE__)
|
48
40
|
|
49
41
|
|
data/test/test_mysql.rb
CHANGED
@@ -522,18 +522,17 @@ class TC_MysqlStmt2 < Test::Unit::TestCase
|
|
522
522
|
end
|
523
523
|
=end
|
524
524
|
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
# end
|
525
|
+
def test_bind_result_nil()
|
526
|
+
if @m.server_version >= 40100 then
|
527
|
+
@m.query("create temporary table t (i int, c char(10), d double, t datetime)")
|
528
|
+
@m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
|
529
|
+
@s.prepare("select * from t")
|
530
|
+
@s.bind_result(nil,nil,nil,nil)
|
531
|
+
@s.execute
|
532
|
+
a = @s.fetch
|
533
|
+
assert_equal([123, "9abcdefg", 1.2345, Mysql::Time.new(2005,8,2,23,50,11)], a)
|
534
|
+
end
|
535
|
+
end
|
537
536
|
|
538
537
|
def test_bind_result_numeric()
|
539
538
|
if @m.server_version >= 40100 then
|
@@ -595,22 +594,21 @@ class TC_MysqlStmt2 < Test::Unit::TestCase
|
|
595
594
|
end
|
596
595
|
end
|
597
596
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
# end
|
597
|
+
def test_bind_result_float()
|
598
|
+
if @m.server_version >= 40100 then
|
599
|
+
@m.query("create temporary table t (i int, c char(10), d double, t datetime)")
|
600
|
+
@m.query("insert into t values (123, '9abcdefg', 1.2345, 20050802235011)")
|
601
|
+
@s.prepare("select * from t")
|
602
|
+
@s.bind_result(Float, Float, Float, Float)
|
603
|
+
@s.execute
|
604
|
+
a = @s.fetch
|
605
|
+
if Mysql.client_version < 50000 then
|
606
|
+
assert_equal([123.0, 9.0, 1.2345, 2005.0], a)
|
607
|
+
else
|
608
|
+
assert_equal([123.0, 9.0, 1.2345, 20050802235011.0], a)
|
609
|
+
end
|
610
|
+
end
|
611
|
+
end
|
614
612
|
|
615
613
|
def test_bind_result_mysqltime()
|
616
614
|
if @m.server_version >= 40100 then
|
@@ -961,34 +959,33 @@ class TC_MysqlStmt2 < Test::Unit::TestCase
|
|
961
959
|
end
|
962
960
|
end
|
963
961
|
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
# end
|
962
|
+
def test_fetch_double()
|
963
|
+
if @m.server_version >= 40100 then
|
964
|
+
@m.query("create temporary table t (i double)")
|
965
|
+
@m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
|
966
|
+
@s.prepare("select i from t")
|
967
|
+
@s.execute
|
968
|
+
assert_equal([0], @s.fetch)
|
969
|
+
assert_in_delta(-Float::MAX, @s.fetch[0], Float::EPSILON)
|
970
|
+
assert_in_delta(-Float::MIN, @s.fetch[0], Float::EPSILON)
|
971
|
+
assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
|
972
|
+
assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
|
973
|
+
end
|
974
|
+
end
|
975
|
+
|
976
|
+
def test_fetch_double_unsigned()
|
977
|
+
if @m.server_version >= 40100 then
|
978
|
+
@m.query("create temporary table t (i double unsigned)")
|
979
|
+
@m.query("insert into t values (0),(-1.7976931348623157E+308),(-2.2250738585072014E-308),(2.2250738585072014E-308),(1.7976931348623157E+308)")
|
980
|
+
@s.prepare("select i from t")
|
981
|
+
@s.execute
|
982
|
+
assert_equal([0], @s.fetch)
|
983
|
+
assert_equal([0], @s.fetch)
|
984
|
+
assert_equal([0], @s.fetch)
|
985
|
+
assert_in_delta(Float::MIN, @s.fetch[0], Float::EPSILON)
|
986
|
+
assert_in_delta(Float::MAX, @s.fetch[0], Float::EPSILON)
|
987
|
+
end
|
988
|
+
end
|
992
989
|
|
993
990
|
def test_fetch_decimal()
|
994
991
|
if (@m.server_version >= 50000 and Mysql.client_version >= 50000) or (@m.server_version >= 40100 and @m.server_version < 50000) then
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Frank Fischer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-08 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -55,21 +55,23 @@ extra_rdoc_files:
|
|
55
55
|
- History.rdoc
|
56
56
|
- README.rdoc
|
57
57
|
files:
|
58
|
+
- .hgtags
|
58
59
|
- History.rdoc
|
59
60
|
- README
|
60
61
|
- README.rdoc
|
61
62
|
- Rakefile
|
62
63
|
- lib/ffi-mysql.rb
|
63
|
-
- lib/mysql/constants.rb
|
64
|
-
- lib/mysql/error.rb
|
65
|
-
- lib/mysql/field.rb
|
66
|
-
- lib/mysql/mysql.rb
|
67
|
-
- lib/mysql/result.rb
|
68
|
-
- lib/mysql/stmt.rb
|
69
|
-
- lib/mysql/time.rb
|
64
|
+
- lib/ffi-mysql/constants.rb
|
65
|
+
- lib/ffi-mysql/error.rb
|
66
|
+
- lib/ffi-mysql/field.rb
|
67
|
+
- lib/ffi-mysql/mysql.rb
|
68
|
+
- lib/ffi-mysql/result.rb
|
69
|
+
- lib/ffi-mysql/stmt.rb
|
70
|
+
- lib/ffi-mysql/time.rb
|
71
|
+
- lib/ffi-mysql/version.rb
|
70
72
|
- test/test_mysql.rb
|
71
73
|
has_rdoc: yard
|
72
|
-
homepage: http://bitbucket.org/lyro/ffi-mysql
|
74
|
+
homepage: http://bitbucket.org/lyro/ffi-mysql
|
73
75
|
licenses: []
|
74
76
|
|
75
77
|
post_install_message:
|