fluent-query-dbi 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +20 -0
- data/README.md +32 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/fluent-query-dbi.gemspec +64 -0
- data/lib/fluent-query/drivers/dbi/prepared.rb +106 -0
- data/lib/fluent-query/drivers/dbi.rb +195 -0
- data/lib/fluent-query/drivers/shared/results/dbi.rb +163 -0
- metadata +133 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
gem "fluent-query-sql", ">= 0.9.0"
|
5
|
+
gem "fluent-query", ">= 0.9.0"
|
6
|
+
gem "abstract", ">= 1.0.0"
|
7
|
+
gem "hash-utils", ">= 0.18.0"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "bundler", ">= 1.0.13"
|
13
|
+
gem "jeweler", ">= 1.6.0"
|
14
|
+
end
|
15
|
+
|
16
|
+
# fluent-query-sql
|
17
|
+
# fluent-query-dbh
|
18
|
+
# fluent-query-mysql
|
19
|
+
# fluent-query-sqlite
|
20
|
+
# fluent-query-postgresql
|
21
|
+
# native-query
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
fluent-query (0.9.0)
|
6
|
+
abstract (>= 1.0.0)
|
7
|
+
hash-utils (>= 0.18.0)
|
8
|
+
hashie (>= 1.0.0)
|
9
|
+
fluent-query-sql (0.9.0)
|
10
|
+
abstract (>= 1.0.0)
|
11
|
+
fluent-query (>= 0.9.0)
|
12
|
+
hash-utils (>= 0.18.0)
|
13
|
+
git (1.2.5)
|
14
|
+
hash-utils (0.18.0)
|
15
|
+
hashie (1.0.0)
|
16
|
+
jeweler (1.6.3)
|
17
|
+
bundler (~> 1.0)
|
18
|
+
git (>= 1.2.5)
|
19
|
+
rake
|
20
|
+
rake (0.9.2)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
abstract (>= 1.0.0)
|
27
|
+
bundler (>= 1.0.13)
|
28
|
+
fluent-query (>= 0.9.0)
|
29
|
+
fluent-query-sql (>= 0.9.0)
|
30
|
+
hash-utils (>= 0.18.0)
|
31
|
+
jeweler (>= 1.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 - 2011 Martin Kozák (martinkozak@martinkozak.net)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
Fluent Query DBI Driver
|
2
|
+
=======================
|
3
|
+
|
4
|
+
**Fluent Query** is cool way how to write SQL queries and general way
|
5
|
+
how to convert series of method calls to string query in an universal
|
6
|
+
and system independent manner.
|
7
|
+
|
8
|
+
This is **DBI** driver for *Fluent Query*. It can be used with
|
9
|
+
[Fluent Query][4] or [Native Query][5] only, and some specific database
|
10
|
+
driver, not standalone.
|
11
|
+
|
12
|
+
|
13
|
+
Contributing
|
14
|
+
------------
|
15
|
+
|
16
|
+
1. Fork it.
|
17
|
+
2. Create a branch (`git checkout -b 20101220-my-change`).
|
18
|
+
3. Commit your changes (`git commit -am "Added something"`).
|
19
|
+
4. Push to the branch (`git push origin 20101220-my-change`).
|
20
|
+
5. Create an [Issue][2] with a link to your branch.
|
21
|
+
6. Enjoy a refreshing Diet Coke and wait.
|
22
|
+
|
23
|
+
Copyright
|
24
|
+
---------
|
25
|
+
|
26
|
+
Copyright © 2009-2011 [Martin Kozák][3]. See `LICENSE.txt` for
|
27
|
+
further details.
|
28
|
+
|
29
|
+
[2]: http://github.com/martinkozak/fluent-query-dbi/issues
|
30
|
+
[3]: http://www.martinkozak.net/
|
31
|
+
[4]: http://github.com/martinkozak/fluent-query
|
32
|
+
[5]: http://github.com/martinkozak/native-query
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rake'
|
14
|
+
require 'jeweler'
|
15
|
+
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "fluent-query-dbi"
|
19
|
+
gem.homepage = "http://github.com/martinkozak/fluent-query-dbi"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = 'Generic DBI support for the Fluent Query. Fluent Query is cool way how to write SQL queries in Ruby. Contains base libraries used by specific SQL driver.'
|
22
|
+
gem.email = "martinkozak@martinkozak.net"
|
23
|
+
gem.authors = ["Martin Kozák"]
|
24
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
25
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
26
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
27
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.0
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{fluent-query-dbi}
|
8
|
+
s.version = "0.9.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Martin Kozák}]
|
12
|
+
s.date = %q{2011-07-14}
|
13
|
+
s.email = %q{martinkozak@martinkozak.net}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE.txt",
|
16
|
+
"README.md"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"fluent-query-dbi.gemspec",
|
27
|
+
"lib/fluent-query/drivers/dbi.rb",
|
28
|
+
"lib/fluent-query/drivers/dbi/prepared.rb",
|
29
|
+
"lib/fluent-query/drivers/shared/results/dbi.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/martinkozak/fluent-query-dbi}
|
32
|
+
s.licenses = [%q{MIT}]
|
33
|
+
s.require_paths = [%q{lib}]
|
34
|
+
s.rubygems_version = %q{1.8.5}
|
35
|
+
s.summary = %q{Generic DBI support for the Fluent Query. Fluent Query is cool way how to write SQL queries in Ruby. Contains base libraries used by specific SQL driver.}
|
36
|
+
|
37
|
+
if s.respond_to? :specification_version then
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
41
|
+
s.add_runtime_dependency(%q<fluent-query-sql>, [">= 0.9.0"])
|
42
|
+
s.add_runtime_dependency(%q<fluent-query>, [">= 0.9.0"])
|
43
|
+
s.add_runtime_dependency(%q<abstract>, [">= 1.0.0"])
|
44
|
+
s.add_runtime_dependency(%q<hash-utils>, [">= 0.18.0"])
|
45
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.13"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.6.0"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<fluent-query-sql>, [">= 0.9.0"])
|
49
|
+
s.add_dependency(%q<fluent-query>, [">= 0.9.0"])
|
50
|
+
s.add_dependency(%q<abstract>, [">= 1.0.0"])
|
51
|
+
s.add_dependency(%q<hash-utils>, [">= 0.18.0"])
|
52
|
+
s.add_dependency(%q<bundler>, [">= 1.0.13"])
|
53
|
+
s.add_dependency(%q<jeweler>, [">= 1.6.0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<fluent-query-sql>, [">= 0.9.0"])
|
57
|
+
s.add_dependency(%q<fluent-query>, [">= 0.9.0"])
|
58
|
+
s.add_dependency(%q<abstract>, [">= 1.0.0"])
|
59
|
+
s.add_dependency(%q<hash-utils>, [">= 0.18.0"])
|
60
|
+
s.add_dependency(%q<bundler>, [">= 1.0.13"])
|
61
|
+
s.add_dependency(%q<jeweler>, [">= 1.6.0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module FluentQuery
|
4
|
+
module Drivers
|
5
|
+
class DBI < FluentQuery::Drivers::SQL
|
6
|
+
|
7
|
+
##
|
8
|
+
# DBI prepared query.
|
9
|
+
#
|
10
|
+
|
11
|
+
class Prepared
|
12
|
+
|
13
|
+
##
|
14
|
+
# Holds associated driver instance.
|
15
|
+
#
|
16
|
+
|
17
|
+
@driver
|
18
|
+
|
19
|
+
##
|
20
|
+
# Holds appropriate query.
|
21
|
+
#
|
22
|
+
|
23
|
+
@query
|
24
|
+
|
25
|
+
##
|
26
|
+
# Holds prepared query in native form.
|
27
|
+
#
|
28
|
+
|
29
|
+
@native
|
30
|
+
|
31
|
+
##
|
32
|
+
# Holds prepared query form.
|
33
|
+
#
|
34
|
+
|
35
|
+
@prepared
|
36
|
+
|
37
|
+
##
|
38
|
+
# Holds directives matcher.
|
39
|
+
#
|
40
|
+
|
41
|
+
@@matcher = nil
|
42
|
+
|
43
|
+
##
|
44
|
+
# Constructor.
|
45
|
+
#
|
46
|
+
|
47
|
+
def initialize(driver, query)
|
48
|
+
@driver = driver
|
49
|
+
@query = query
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Returns directives matcher.
|
54
|
+
#
|
55
|
+
|
56
|
+
def matcher
|
57
|
+
if @@matcher.nil?
|
58
|
+
directives = FluentQuery::Compiler::FORMATTING_DIRECTIVES.map { |s| s.to_s }
|
59
|
+
@@matcher = Regexp::new("%%(?:" << directives.join("|") << ")(?:([^\w])|$)")
|
60
|
+
end
|
61
|
+
|
62
|
+
@@matcher
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Returns prepared query form.
|
67
|
+
#
|
68
|
+
|
69
|
+
def prepared
|
70
|
+
if @prepared.nil?
|
71
|
+
string = @driver.build_query(@query, :compile)
|
72
|
+
string.gsub!(self.matcher, '?\1')
|
73
|
+
@prepared = string
|
74
|
+
end
|
75
|
+
|
76
|
+
@prepared
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Returns prepared query in the native form.
|
81
|
+
#
|
82
|
+
|
83
|
+
def native
|
84
|
+
if @native.nil?
|
85
|
+
@native = @driver.native_connection.prepare(self.prepared)
|
86
|
+
end
|
87
|
+
|
88
|
+
@native
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
##
|
93
|
+
# Executes the query.
|
94
|
+
#
|
95
|
+
|
96
|
+
def execute(*args)
|
97
|
+
self.native.execute(*args)
|
98
|
+
self.native
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
@@ -0,0 +1,195 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "abstract"
|
3
|
+
require "hash-utils/object" # >= 0.17.0
|
4
|
+
require "hash-utils/array"
|
5
|
+
require "hash-utils/hash"
|
6
|
+
|
7
|
+
require "fluent-query/drivers/sql"
|
8
|
+
require "fluent-query/drivers/exception"
|
9
|
+
require "fluent-query/drivers/shared/results/dbi"
|
10
|
+
require "fluent-query/drivers/dbi/prepared"
|
11
|
+
|
12
|
+
module FluentQuery
|
13
|
+
module Drivers
|
14
|
+
|
15
|
+
##
|
16
|
+
# Generic DBI database driver.
|
17
|
+
# @abstract
|
18
|
+
#
|
19
|
+
|
20
|
+
class DBI < FluentQuery::Drivers::SQL
|
21
|
+
|
22
|
+
##
|
23
|
+
# Constructor.
|
24
|
+
#
|
25
|
+
|
26
|
+
public
|
27
|
+
def initialize(connection)
|
28
|
+
if self.instance_of? DBI
|
29
|
+
not_implemented
|
30
|
+
end
|
31
|
+
|
32
|
+
super(connection)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Returns preparation placeholder.
|
37
|
+
#
|
38
|
+
|
39
|
+
public
|
40
|
+
def quote_placeholder
|
41
|
+
"?"
|
42
|
+
end
|
43
|
+
|
44
|
+
##### EXECUTING
|
45
|
+
|
46
|
+
##
|
47
|
+
# Builds connection string according to settings.
|
48
|
+
# @return [String] connection string
|
49
|
+
#
|
50
|
+
|
51
|
+
public
|
52
|
+
def connection_string
|
53
|
+
|
54
|
+
if @_nconnection_settings.nil?
|
55
|
+
raise FluentQuery::Drivers::Exception::new('Connection settings hasn\'t been assigned yet.')
|
56
|
+
end
|
57
|
+
|
58
|
+
# Gets settings
|
59
|
+
|
60
|
+
server = @_nconnection_settings[:server]
|
61
|
+
port = @_nconnection_settings[:port]
|
62
|
+
socket = @_nconnection_settings[:socket]
|
63
|
+
database = @_nconnection_settings[:database]
|
64
|
+
|
65
|
+
# Builds connection string and other parameters
|
66
|
+
|
67
|
+
if server.nil?
|
68
|
+
server = "localhost"
|
69
|
+
end
|
70
|
+
|
71
|
+
connection_string = "DBI:%s:database=%s;host=%s" % [self.driver_name, database, server]
|
72
|
+
|
73
|
+
if not port.nil?
|
74
|
+
connection_string << ";port=" << port.to_s
|
75
|
+
end
|
76
|
+
if not socket.nil?
|
77
|
+
connection_string << ";socket=" << socket
|
78
|
+
end
|
79
|
+
|
80
|
+
# Returns
|
81
|
+
return connection_string
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Returns DBI driver name.
|
87
|
+
#
|
88
|
+
# @return [String] driver name
|
89
|
+
# @abstract
|
90
|
+
#
|
91
|
+
|
92
|
+
public
|
93
|
+
def driver_name
|
94
|
+
not_implemented
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Returns authentification settings.
|
99
|
+
# @return [Array] with username and password
|
100
|
+
#
|
101
|
+
|
102
|
+
public
|
103
|
+
def authentification
|
104
|
+
@_nconnection_settings.take_values(:username, :password)
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Opens the connection.
|
109
|
+
#
|
110
|
+
# It's lazy, so it will open connection before first request through
|
111
|
+
# {@link native_connection()} method.
|
112
|
+
#
|
113
|
+
|
114
|
+
public
|
115
|
+
def open_connection(settings)
|
116
|
+
@_nconnection_settings = settings
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Returns native connection.
|
121
|
+
#
|
122
|
+
|
123
|
+
public
|
124
|
+
def native_connection
|
125
|
+
|
126
|
+
if not @_nconnection_settings
|
127
|
+
raise FluentQuery::Drivers::Exception::new("Connection is closed.")
|
128
|
+
end
|
129
|
+
|
130
|
+
if @_nconnection.nil?
|
131
|
+
require "dbi"
|
132
|
+
|
133
|
+
# Gets authentification
|
134
|
+
username, password = self.authentification
|
135
|
+
|
136
|
+
# Connects
|
137
|
+
@_nconnection = ::DBI::connect(self.connection_string, username, password)
|
138
|
+
end
|
139
|
+
|
140
|
+
return @_nconnection
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Closes the connection.
|
145
|
+
#
|
146
|
+
|
147
|
+
public
|
148
|
+
def close_connection!
|
149
|
+
if not @_nconnection.nil?
|
150
|
+
@_nconnection.disconnect
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# Executes the query and returns data result.
|
156
|
+
#
|
157
|
+
|
158
|
+
public
|
159
|
+
def execute(query)
|
160
|
+
connection = self.native_connection
|
161
|
+
|
162
|
+
if query.array? and query.first.kind_of? FluentQuery::Drivers::DBI::Prepared
|
163
|
+
data = query.first.execute(*query.second)
|
164
|
+
else
|
165
|
+
data = connection.execute(query.to_s)
|
166
|
+
end
|
167
|
+
|
168
|
+
return FluentQuery::Drivers::Shared::Results::DBI::new(data)
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# Executes the query and returns count of the changed/inserted rows.
|
173
|
+
#
|
174
|
+
|
175
|
+
public
|
176
|
+
def do(query)
|
177
|
+
connection = self.native_connection
|
178
|
+
count = connection.do(query)
|
179
|
+
|
180
|
+
return count
|
181
|
+
end
|
182
|
+
|
183
|
+
##
|
184
|
+
# Generates prepared query.
|
185
|
+
#
|
186
|
+
|
187
|
+
public
|
188
|
+
def prepare(query)
|
189
|
+
DBI::Prepared::new(self, query)
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
@@ -0,0 +1,163 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "fluent-query/drivers/result"
|
3
|
+
require "fluent-query/data"
|
4
|
+
|
5
|
+
module FluentQuery
|
6
|
+
module Drivers
|
7
|
+
module Shared
|
8
|
+
module Results
|
9
|
+
|
10
|
+
##
|
11
|
+
# PostgreSQL query native token.
|
12
|
+
#
|
13
|
+
|
14
|
+
class DBI < FluentQuery::Drivers::Result
|
15
|
+
|
16
|
+
##
|
17
|
+
# Brings resultset datasource.
|
18
|
+
# @var DBI::StatementHandle result source
|
19
|
+
#
|
20
|
+
|
21
|
+
protected
|
22
|
+
@_source
|
23
|
+
|
24
|
+
##
|
25
|
+
# Brings sources directory.
|
26
|
+
# @var Hash
|
27
|
+
#
|
28
|
+
|
29
|
+
protected
|
30
|
+
@@_sources = { }
|
31
|
+
|
32
|
+
##
|
33
|
+
# Initializes result.
|
34
|
+
#
|
35
|
+
|
36
|
+
public
|
37
|
+
def initialize(source)
|
38
|
+
super()
|
39
|
+
|
40
|
+
@_source = source
|
41
|
+
@_columns = nil
|
42
|
+
|
43
|
+
ObjectSpace::define_finalizer(self, self.class.method(:finalize).to_proc)
|
44
|
+
@@_sources[self.object_id] = @_source
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Dispatches object destroying.
|
49
|
+
#
|
50
|
+
|
51
|
+
public
|
52
|
+
def self.finalize(id)
|
53
|
+
if @@_sources[id]
|
54
|
+
@@_sources[id].finish
|
55
|
+
@@_sources.delete(id)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Returns all selected rows.
|
61
|
+
#
|
62
|
+
|
63
|
+
public
|
64
|
+
def all
|
65
|
+
self.to_enum.map { |i| i }
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Returns one row.
|
70
|
+
#
|
71
|
+
|
72
|
+
public
|
73
|
+
def one
|
74
|
+
row = @_source.fetch_hash
|
75
|
+
|
76
|
+
if row
|
77
|
+
result = FluentQuery::Data[row]
|
78
|
+
else
|
79
|
+
result = nil
|
80
|
+
end
|
81
|
+
|
82
|
+
return result
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# Returns first value of first row.
|
87
|
+
#
|
88
|
+
|
89
|
+
public
|
90
|
+
def single
|
91
|
+
result = @_source.fetch
|
92
|
+
|
93
|
+
if not result.nil?
|
94
|
+
result = result.first
|
95
|
+
else
|
96
|
+
result = nil
|
97
|
+
end
|
98
|
+
|
99
|
+
return result
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Yields all rows as hashes.
|
104
|
+
#
|
105
|
+
|
106
|
+
public
|
107
|
+
def hash
|
108
|
+
result = nil
|
109
|
+
first = true
|
110
|
+
|
111
|
+
while result or first
|
112
|
+
first = false
|
113
|
+
result = self.one
|
114
|
+
|
115
|
+
if result
|
116
|
+
yield result
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Handles iterating.
|
123
|
+
#
|
124
|
+
|
125
|
+
public
|
126
|
+
def each(&block)
|
127
|
+
self.hash &block
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Repeats the query leaded to the result.
|
132
|
+
#
|
133
|
+
|
134
|
+
public
|
135
|
+
def repeat!
|
136
|
+
@_source.execute
|
137
|
+
return self
|
138
|
+
end
|
139
|
+
|
140
|
+
##
|
141
|
+
# Returns rows count.
|
142
|
+
#
|
143
|
+
|
144
|
+
public
|
145
|
+
def count
|
146
|
+
@_source.all.count
|
147
|
+
end
|
148
|
+
|
149
|
+
##
|
150
|
+
# Frees result resources.
|
151
|
+
#
|
152
|
+
|
153
|
+
public
|
154
|
+
def free!
|
155
|
+
@_source.finish
|
156
|
+
@@_sources.delete(self.object_id)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-query-dbi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.9.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Martin Koz\xC3\xA1k"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-14 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fluent-query-sql
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.9.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: fluent-query
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: abstract
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.0.0
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: hash-utils
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.18.0
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.0.13
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: jeweler
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.6.0
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
description:
|
82
|
+
email: martinkozak@martinkozak.net
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
87
|
+
extra_rdoc_files:
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
files:
|
91
|
+
- .document
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- fluent-query-dbi.gemspec
|
99
|
+
- lib/fluent-query/drivers/dbi.rb
|
100
|
+
- lib/fluent-query/drivers/dbi/prepared.rb
|
101
|
+
- lib/fluent-query/drivers/shared/results/dbi.rb
|
102
|
+
homepage: http://github.com/martinkozak/fluent-query-dbi
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: -2491359393769812598
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: "0"
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 1.8.5
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: Generic DBI support for the Fluent Query. Fluent Query is cool way how to write SQL queries in Ruby. Contains base libraries used by specific SQL driver.
|
132
|
+
test_files: []
|
133
|
+
|