module Vertica
Main module for this library. It contains the {.connect} method to return a {Vertica::Connection} instance, and methods to quote values ({.quote}) and identifiers ({.quote_identifier}) to safely include those in SQL strings to prevent SQL injection.
Constants
- PROTOCOL_VERSION
The protocol version (3.0.0) implemented in this library.
- VERSION
The version of the package. We adhere to semantic versioning. To release a new version, update this constant, commit to master, and run `rake release`
Public Class Methods
Properly quotes a value for safe usage in SQL queries.
This method has quoting rules for common types. Any other object will be converted to a string using :to_s
and then quoted as a string.
@param value [Object] The value to quote. @return [String] The quoted value that can be safely included in SQL queries.
# File lib/vertica.rb, line 29 def self.quote(value) case value when nil then 'NULL' when false then 'FALSE' when true then 'TRUE' when DateTime then value.strftime("'%Y-%m-%dT%H:%M:%S.%6N%z'::timestamptz") when Time then value.strftime("'%Y-%m-%dT%H:%M:%S.%6N%z'::timestamptz") when Date then value.strftime("'%Y-%m-%d'::date") when String then "'#{value.gsub(/'/, "''")}'" when BigDecimal then value.to_s('F') when Numeric then value.to_s when Array then value.map { |v| self.quote(v) }.join(', ') else self.quote(value.to_s) end end
Quotes an identifier for safe use within SQL queries, using double quotes. @param identifier [:to_s] The identifier to quote. @return [String] The quoted identifier that can be safely included in SQL queries.
# File lib/vertica.rb, line 48 def self.quote_identifier(identifier) "\"#{identifier.to_s.gsub(/"/, '""')}\"" end