jdbc-helper 0.2.0 → 0.2.1
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/README.rdoc +19 -15
- data/lib/jdbc-helper/connection/row.rb +14 -5
- data/test/test_connection.rb +9 -0
- metadata +100 -95
data/README.rdoc
CHANGED
@@ -29,21 +29,25 @@ Add JDBC driver of the DBMS you're willing to use to your CLASSPATH
|
|
29
29
|
:user => 'mysql',
|
30
30
|
:password => '')
|
31
31
|
conn.close
|
32
|
-
|
33
|
-
|
32
|
+
|
33
|
+
|
34
34
|
# MySQL shortcut connector
|
35
35
|
conn = JDBCHelper::MySQLConnector.connect('localhost', 'mysql', '', 'test')
|
36
36
|
conn.close
|
37
|
-
|
37
|
+
|
38
38
|
== Querying database table
|
39
39
|
|
40
40
|
conn.query("SELECT a, b, c FROM T") do | row |
|
41
|
-
|
42
|
-
|
41
|
+
row.labels
|
42
|
+
row.rownum
|
43
|
+
|
44
|
+
row.a, row.b, row.c # Dot-notation
|
45
|
+
row[0], row[1], row[2] # Numeric index
|
46
|
+
row['a'], row['b'], row['c'] # String index. Case-insensitive.
|
47
|
+
row[:a], row[:b], row[:c] # Symbol index. Case-insensitive.
|
43
48
|
|
44
|
-
|
45
|
-
|
46
|
-
puts row['a'], row['b'], row['c']
|
49
|
+
row[0..-1] # Range index. Returns an array of values.
|
50
|
+
row[0, 3] # Offset and length. Returns an array of values.
|
47
51
|
end
|
48
52
|
|
49
53
|
# Returns an array of rows when block is not given
|
@@ -62,9 +66,9 @@ Add JDBC driver of the DBMS you're willing to use to your CLASSPATH
|
|
62
66
|
# chain enumerators, `enumerate' is much preferred over `query'. (which returns the
|
63
67
|
# array of the entire rows)
|
64
68
|
conn.enumerate("SELECT * FROM LARGE_T").each_slice(1000) do | slice |
|
65
|
-
|
66
|
-
|
67
|
-
|
69
|
+
slice.each do | row |
|
70
|
+
# ...
|
71
|
+
end
|
68
72
|
end
|
69
73
|
|
70
74
|
== Updating database table
|
@@ -75,7 +79,7 @@ Add JDBC driver of the DBMS you're willing to use to your CLASSPATH
|
|
75
79
|
# ...
|
76
80
|
# Transaction logic here
|
77
81
|
# ...
|
78
|
-
|
82
|
+
|
79
83
|
if success
|
80
84
|
tx.commit
|
81
85
|
else
|
@@ -88,7 +92,7 @@ Add JDBC driver of the DBMS you're willing to use to your CLASSPATH
|
|
88
92
|
conn.execute_batch
|
89
93
|
conn.add_batch("DELETE FROM T");
|
90
94
|
conn.clear_batch
|
91
|
-
|
95
|
+
|
92
96
|
== Using prepared statements
|
93
97
|
p_sel = conn.prepare("SELECT * FROM T WHERE b = ? and c = ?")
|
94
98
|
p_sel.query(100, 200) do | row |
|
@@ -110,7 +114,7 @@ Add JDBC driver of the DBMS you're willing to use to your CLASSPATH
|
|
110
114
|
|
111
115
|
== Using table wrappers (since 0.2.0)
|
112
116
|
# For more complex examples, refer to test/test_object_wrapper.rb
|
113
|
-
|
117
|
+
|
114
118
|
conn.table('test.data').count
|
115
119
|
conn.table('test.data').empty?
|
116
120
|
conn.table('test.data').select(:c => 3) do |row|
|
@@ -125,7 +129,7 @@ Add JDBC driver of the DBMS you're willing to use to your CLASSPATH
|
|
125
129
|
conn.table('test.data').drop_table!
|
126
130
|
|
127
131
|
== Contributing to jdbc-helper
|
128
|
-
|
132
|
+
|
129
133
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
130
134
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
131
135
|
* Fork the project
|
@@ -12,6 +12,7 @@ class Connection
|
|
12
12
|
# puts row.a
|
13
13
|
# puts row[1]
|
14
14
|
# puts row['c']
|
15
|
+
# puts row[:a]
|
15
16
|
#
|
16
17
|
# row.each do | value |
|
17
18
|
# # ...
|
@@ -33,16 +34,24 @@ class Row
|
|
33
34
|
|
34
35
|
include Enumerable
|
35
36
|
|
36
|
-
# @
|
37
|
-
#
|
38
|
-
|
37
|
+
# @overload [](idx)
|
38
|
+
# @param [Fixnum/String/Symbol/Range] idx Access index
|
39
|
+
# @return [Object]
|
40
|
+
# @overload [](offset, len)
|
41
|
+
# @param [Fixnum] offset Start offset
|
42
|
+
# @param [Fixnum] len Length of Array
|
43
|
+
# @return [Array]
|
44
|
+
def [](*idx)
|
45
|
+
return @values[*idx] if idx.length > 1
|
46
|
+
|
47
|
+
idx = idx.first
|
39
48
|
case idx
|
40
49
|
when Fixnum
|
41
50
|
raise RangeError.new("Index out of bound") if idx >= @values.length
|
42
51
|
@values[idx]
|
43
|
-
when String
|
52
|
+
when String, Symbol
|
44
53
|
# case-insensitive, assuming no duplicate labels
|
45
|
-
vidx = @labels_d.index(idx.downcase) or
|
54
|
+
vidx = @labels_d.index(idx.to_s.downcase) or
|
46
55
|
raise NameError.new("Unknown column label: #{idx}")
|
47
56
|
@values[vidx]
|
48
57
|
else
|
data/test/test_connection.rb
CHANGED
@@ -25,10 +25,19 @@ class TestConnection < Test::Unit::TestCase
|
|
25
25
|
assert_equal 1, rec.one
|
26
26
|
assert_equal 1, rec[0]
|
27
27
|
assert_equal 1, rec['one']
|
28
|
+
assert_equal 1, rec[:one]
|
29
|
+
assert_equal [1], rec[0...1]
|
30
|
+
assert_equal [1], rec[0, 1]
|
28
31
|
|
29
32
|
assert_equal 'two', rec.two
|
30
33
|
assert_equal 'two', rec[1]
|
31
34
|
assert_equal 'two', rec['two']
|
35
|
+
assert_equal ['two'], rec[1..-1]
|
36
|
+
assert_equal ['two'], rec[1, 1]
|
37
|
+
|
38
|
+
assert_equal [1, 'two'], rec[0..1]
|
39
|
+
assert_equal [1, 'two'], rec[0..-1]
|
40
|
+
assert_equal [1, 'two'], rec[0, 2]
|
32
41
|
|
33
42
|
assert_raise(NoMethodError) { rec.three }
|
34
43
|
assert_raise(NameError) { rec['three'] }
|
metadata
CHANGED
@@ -1,113 +1,118 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jdbc-helper
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.2.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
- Junegunn Choi
|
7
|
+
authors:
|
8
|
+
- Junegunn Choi
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
12
|
+
|
13
|
+
date: 2011-05-19 00:00:00 +09:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
requirement: *id001
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.5.2
|
35
|
+
requirement: *id002
|
36
|
+
prerelease: false
|
37
|
+
type: :development
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rcov
|
40
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
requirement: *id003
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
description: A JDBC helper for JRuby/Database developers.
|
50
50
|
email: junegunn.c@gmail.com
|
51
51
|
executables: []
|
52
|
+
|
52
53
|
extensions: []
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
- lib/jdbc-helper
|
59
|
-
- lib/jdbc-helper/connection
|
60
|
-
- lib/jdbc-helper/connection/
|
61
|
-
- lib/jdbc-helper/connection/
|
62
|
-
- lib/jdbc-helper/connection/
|
63
|
-
- lib/jdbc-helper/
|
64
|
-
- lib/jdbc-helper/connector
|
65
|
-
- lib/jdbc-helper/connector/
|
66
|
-
- lib/jdbc-helper/
|
67
|
-
- lib/jdbc-helper/
|
68
|
-
- lib/jdbc-helper/
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
- test/
|
73
|
-
- test/
|
74
|
-
- test/
|
75
|
-
- test/
|
76
|
-
- test/
|
77
|
-
- test/
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.rdoc
|
58
|
+
files:
|
59
|
+
- lib/jdbc-helper.rb
|
60
|
+
- lib/jdbc-helper/connection.rb
|
61
|
+
- lib/jdbc-helper/connection/prepared_statement.rb
|
62
|
+
- lib/jdbc-helper/connection/result_set_enumerator.rb
|
63
|
+
- lib/jdbc-helper/connection/row.rb
|
64
|
+
- lib/jdbc-helper/connection/statement_pool.rb
|
65
|
+
- lib/jdbc-helper/connector.rb
|
66
|
+
- lib/jdbc-helper/connector/mysql_connector.rb
|
67
|
+
- lib/jdbc-helper/connector/oracle_connector.rb
|
68
|
+
- lib/jdbc-helper/constants.rb
|
69
|
+
- lib/jdbc-helper/object_wrapper.rb
|
70
|
+
- lib/jdbc-helper/sql.rb
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.rdoc
|
73
|
+
- test/database.yml
|
74
|
+
- test/helper.rb
|
75
|
+
- test/test_connection.rb
|
76
|
+
- test/test_connectors.rb
|
77
|
+
- test/test_object_wrapper.rb
|
78
|
+
- test/test_performance.rb
|
79
|
+
- test/test_sql.rb
|
80
|
+
has_rdoc: true
|
78
81
|
homepage: http://github.com/junegunn/jdbc-helper
|
79
|
-
licenses:
|
80
|
-
- MIT
|
82
|
+
licenses:
|
83
|
+
- MIT
|
81
84
|
post_install_message:
|
82
85
|
rdoc_options: []
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
90
|
none: false
|
87
|
-
requirements:
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 2
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
99
|
none: false
|
96
|
-
requirements:
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
100
104
|
requirements: []
|
105
|
+
|
101
106
|
rubyforge_project:
|
102
|
-
rubygems_version: 1.
|
107
|
+
rubygems_version: 1.5.1
|
103
108
|
signing_key:
|
104
109
|
specification_version: 3
|
105
|
-
summary: A JDBC helper for
|
106
|
-
test_files:
|
107
|
-
- test/database.yml
|
108
|
-
- test/helper.rb
|
109
|
-
- test/test_connection.rb
|
110
|
-
- test/test_connectors.rb
|
111
|
-
- test/test_object_wrapper.rb
|
112
|
-
- test/test_performance.rb
|
113
|
-
- test/test_sql.rb
|
110
|
+
summary: A JDBC helper for JRuby/Database developers.
|
111
|
+
test_files:
|
112
|
+
- test/database.yml
|
113
|
+
- test/helper.rb
|
114
|
+
- test/test_connection.rb
|
115
|
+
- test/test_connectors.rb
|
116
|
+
- test/test_object_wrapper.rb
|
117
|
+
- test/test_performance.rb
|
118
|
+
- test/test_sql.rb
|