Class: ActiveRecord::ConnectionAdapters::VerticaAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::VerticaAdapter
- Includes:
- Import::VerticaAdapter::InstanceMethods
- Defined in:
- lib/active_record/connection_adapters/vertica_adapter.rb,
lib/activerecord-import/active_record/adapters/vertica_adapter.rb
Constant Summary collapse
- ADAPTER_NAME =
'Vertica'.freeze
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#adapter_name ⇒ Object
:nodoc:.
-
#columns(table_name, name = nil) ⇒ Object
:nodoc:.
-
#disconnect! ⇒ Object
Close the connection.
-
#execute(sql, name = nil) ⇒ Object
return raw object.
-
#initialize(connection, connection_options, config) ⇒ VerticaAdapter
constructor
A new instance of VerticaAdapter.
- #primary_key(table) ⇒ Object
-
#quote_column_name(name) ⇒ Object
QUOTING.
-
#quote_table_name(name) ⇒ Object
:nodoc:.
-
#reconnect! ⇒ Object
Disconnects from the database if already connected, and establishes a new connection with the database.
- #reset ⇒ Object
- #schema_name ⇒ Object
- #select(sql, name = nil, binds = []) ⇒ Object
-
#tables(name = nil) ⇒ Object
:nodoc:.
Constructor Details
#initialize(connection, connection_options, config) ⇒ VerticaAdapter
Returns a new instance of VerticaAdapter.
86 87 88 89 90 91 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 86 def initialize(connection, , config) super(connection) @connection_options, @config = , config @quoted_column_names, @quoted_table_names = {}, {} # connect end |
Instance Method Details
#active? ⇒ Boolean
93 94 95 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 93 def active? @connection.opened? end |
#adapter_name ⇒ Object
:nodoc:
82 83 84 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 82 def adapter_name #:nodoc: ADAPTER_NAME end |
#columns(table_name, name = nil) ⇒ Object
:nodoc:
139 140 141 142 143 144 145 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 139 def columns(table_name, name = nil)#:nodoc: sql = "SELECT * FROM columns WHERE table_name = #{quote_column_name(table_name)}" columns = [] execute(sql, name){ |field| columns << VerticaColumn.new(field[:column_name],field[:column_default],field[:data_type],field[:is_nullable])} columns end |
#disconnect! ⇒ Object
Close the connection.
107 108 109 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 107 def disconnect! @connection.close rescue nil end |
#execute(sql, name = nil) ⇒ Object
return raw object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 112 def execute(sql, name=nil) log(sql,name) do if block_given? @connection = ::Vertica.connect(@connection.) @connection.query(sql) {|row| yield row } @connection.close else @connection = ::Vertica.connect(@connection.) results = @connection.query(sql) @connection.close results end end end |
#primary_key(table) ⇒ Object
155 156 157 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 155 def primary_key(table) '' end |
#quote_column_name(name) ⇒ Object
QUOTING
160 161 162 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 160 def quote_column_name(name) #:nodoc: "'#{name}'" end |
#quote_table_name(name) ⇒ Object
:nodoc:
164 165 166 167 168 169 170 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 164 def quote_table_name(name) #:nodoc: if schema_name.blank? name else "#{schema_name}.#{name}" end end |
#reconnect! ⇒ Object
Disconnects from the database if already connected, and establishes a new connection with the database.
99 100 101 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 99 def reconnect! @connection.reset_connection end |
#reset ⇒ Object
102 103 104 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 102 def reset reconnect! end |
#schema_name ⇒ Object
127 128 129 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 127 def schema_name @schema ||= @connection.[:schema] end |
#select(sql, name = nil, binds = []) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 147 def select(sql, name = nil, binds = []) rows = [] @connection = ::Vertica.connect(@connection.) @connection.query(sql) {|row| rows << row } @connection.close rows end |
#tables(name = nil) ⇒ Object
:nodoc:
131 132 133 134 135 136 137 |
# File 'lib/active_record/connection_adapters/vertica_adapter.rb', line 131 def tables(name = nil) #:nodoc: sql = "SELECT * FROM tables WHERE table_schema = #{quote_column_name(schema_name)}" tables = [] execute(sql, name) { |field| tables << field[:table_name] } tables end |