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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5621f7030c3292cb6df477676201211a0ccead25
4
- data.tar.gz: b6f8bc1ea53f2fcda33710348837aee5b529c759
3
+ metadata.gz: 1a6ffa844844713a37b94069b96c6826ebb4105e
4
+ data.tar.gz: 3ea2ee859b704e11d030f343b1d1e99926f3051a
5
5
  SHA512:
6
- metadata.gz: f74d77760ed9e90405c1c8d9f85246b65a137cfa1ff8e034e889139fe92158f4e501e531b34d8da164cbfc99222b2346a94a64a3171553ef0d87c5ff2832b90f
7
- data.tar.gz: 63dd22953040bf0add918624679f8ec1d99c24b1473f24b65583264647701574db2b303246e6343a594e6f9bdeec0057f967e4824510d7078e1de345ef985e98
6
+ metadata.gz: e7f12c1edb36ba819143feeca77c5cb137087c282076f667ea7583ba74a1fb7cf1324b979020c0744f7f3a7c1c40f4560d16e25b303a531138f878f40aa351ff
7
+ data.tar.gz: d348a5a11fbbfc5cc6f8aee07c27a2b851f141a02a456b7ed8fe469f1e0ba66532fd886cf1b24ae695d06ddd97785b10f4054ca3a520b212ab88d43b80bd25c1
@@ -1,3 +1,3 @@
1
1
  class Jvertica
2
- VERSION = "0.1.11"
2
+ VERSION = "0.2.0"
3
3
  end
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
- yield(o)
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))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jvertica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takahiro.nakayama