jvertica 0.1.11 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jvertica/version.rb +1 -1
- data/lib/jvertica.rb +39 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6ffa844844713a37b94069b96c6826ebb4105e
|
4
|
+
data.tar.gz: 3ea2ee859b704e11d030f343b1d1e99926f3051a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f12c1edb36ba819143feeca77c5cb137087c282076f667ea7583ba74a1fb7cf1324b979020c0744f7f3a7c1c40f4560d16e25b303a531138f878f40aa351ff
|
7
|
+
data.tar.gz: d348a5a11fbbfc5cc6f8aee07c27a2b851f141a02a456b7ed8fe469f1e0ba66532fd886cf1b24ae695d06ddd97785b10f4054ca3a520b212ab88d43b80bd25c1
|
data/lib/jvertica/version.rb
CHANGED
data/lib/jvertica.rb
CHANGED
@@ -26,6 +26,40 @@ class Jvertica
|
|
26
26
|
new(options)
|
27
27
|
end
|
28
28
|
|
29
|
+
# Properly quotes a value for safe usage in SQL queries.
|
30
|
+
#
|
31
|
+
# This method has quoting rules for common types. Any other object will be converted to
|
32
|
+
# a string using +:to_s+ and then quoted as a string.
|
33
|
+
#
|
34
|
+
# @param [Object] value The value to quote.
|
35
|
+
# @return [String] The quoted value that can be safely included in SQL queries.
|
36
|
+
def self.quote(value)
|
37
|
+
case value
|
38
|
+
when nil then 'NULL'
|
39
|
+
when false then 'FALSE'
|
40
|
+
when true then 'TRUE'
|
41
|
+
when DateTime then value.strftime("'%Y-%m-%d %H:%M:%S'::timestamp")
|
42
|
+
when Time then value.strftime("'%Y-%m-%d %H:%M:%S'::timestamp")
|
43
|
+
when Date then value.strftime("'%Y-%m-%d'::date")
|
44
|
+
when String then "'#{value.gsub(/'/, "''")}'"
|
45
|
+
when Numeric then value.to_s
|
46
|
+
when Array then value.map { |v| self.quote(v) }.join(', ')
|
47
|
+
else
|
48
|
+
if defined?(BigDecimal) and BigDecimal === value
|
49
|
+
value.to_s('F')
|
50
|
+
else
|
51
|
+
self.quote(value.to_s)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Quotes an identifier for safe use within SQL queries, using double quotes.
|
57
|
+
# @param [:to_s] identifier The identifier to quote.
|
58
|
+
# @return [String] The quoted identifier that can be safely included in SQL queries.
|
59
|
+
def self.quote_identifier(identifier)
|
60
|
+
"\"#{identifier.to_s.gsub(/"/, '""')}\""
|
61
|
+
end
|
62
|
+
|
29
63
|
attr_reader :host, :port, :database
|
30
64
|
|
31
65
|
def initialize(options)
|
@@ -148,7 +182,11 @@ class Jvertica
|
|
148
182
|
if block_given?
|
149
183
|
i, o = IO.pipe
|
150
184
|
thread = Thread.new do
|
151
|
-
|
185
|
+
begin
|
186
|
+
yield(o)
|
187
|
+
rescue => e
|
188
|
+
Thread.main.raise e
|
189
|
+
end
|
152
190
|
o.close
|
153
191
|
end
|
154
192
|
stream.addStream(org.jruby.util.IOInputStream.new(i))
|