Module: Vertica
- Defined in:
- lib/vertica.rb,
lib/vertica/version.rb,
lib/vertica/protocol/message.rb,
lib/vertica/protocol/frontend/bind.rb,
lib/vertica/protocol/frontend/sync.rb,
lib/vertica/protocol/frontend/close.rb,
lib/vertica/protocol/frontend/flush.rb,
lib/vertica/protocol/frontend/parse.rb,
lib/vertica/protocol/frontend/query.rb,
lib/vertica/protocol/backend/no_data.rb,
lib/vertica/protocol/backend/unknown.rb,
lib/vertica/protocol/backend/data_row.rb,
lib/vertica/protocol/frontend/execute.rb,
lib/vertica/protocol/frontend/startup.rb,
lib/vertica/protocol/frontend/describe.rb,
lib/vertica/protocol/frontend/password.rb,
lib/vertica/protocol/frontend/copy_data.rb,
lib/vertica/protocol/frontend/copy_done.rb,
lib/vertica/protocol/frontend/copy_fail.rb,
lib/vertica/protocol/frontend/terminate.rb,
lib/vertica/protocol/frontend/ssl_request.rb,
lib/vertica/protocol/backend/bind_complete.rb,
lib/vertica/protocol/backend/authentication.rb,
lib/vertica/protocol/backend/close_complete.rb,
lib/vertica/protocol/backend/error_response.rb,
lib/vertica/protocol/backend/parse_complete.rb,
lib/vertica/protocol/backend/notice_response.rb,
lib/vertica/protocol/backend/ready_for_query.rb,
lib/vertica/protocol/backend/row_description.rb,
lib/vertica/protocol/frontend/cancel_request.rb,
lib/vertica/protocol/backend/backend_key_data.rb,
lib/vertica/protocol/backend/command_complete.rb,
lib/vertica/protocol/backend/copy_in_response.rb,
lib/vertica/protocol/backend/parameter_status.rb,
lib/vertica/protocol/backend/portal_suspended.rb,
lib/vertica/protocol/backend/empty_query_response.rb,
lib/vertica/protocol/backend/parameter_description.rb
Overview
Main module for this library. It contains the Vertica.connect method to return a Connection instance, and methods to quote values (Vertica.quote) and identifiers (Vertica.quote_identifier) to safely include those in SQL strings to prevent SQL injection.
Defined Under Namespace
Modules: Protocol Classes: Column, Connection, DataType, Error, Query, Result, Row, RowDescription
Constant Summary collapse
- PROTOCOL_VERSION =
The protocol version (3.0.0) implemented in this library.
3 << 16
- 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
"1.0.3"
Class Method Summary collapse
-
.connect(**kwargs) ⇒ Vertica::Connection
Opens a new connection to a Vertica database.
-
.quote(value) ⇒ String
Properly quotes a value for safe usage in SQL queries.
-
.quote_identifier(identifier) ⇒ String
Quotes an identifier for safe use within SQL queries, using double quotes.
Class Method Details
.connect(**kwargs) ⇒ Vertica::Connection
Opens a new connection to a Vertica database.
18 19 20 |
# File 'lib/vertica.rb', line 18 def self.connect(**kwargs) Vertica::Connection.new(**kwargs) end |
.quote(value) ⇒ String
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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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 |
.quote_identifier(identifier) ⇒ String
Quotes an identifier for safe use within SQL queries, using double quotes.
48 49 50 |
# File 'lib/vertica.rb', line 48 def self.quote_identifier(identifier) "\"#{identifier.to_s.gsub(/"/, '""')}\"" end |