Class: ActiveRecord::ConnectionAdapters::HanaclientAdapter
Defined Under Namespace
Classes: StatementPool
Constant Summary
collapse
- ADAPTER_NAME =
"Hanaclient".freeze
- NATIVE_DATABASE_TYPES =
Supports all standard activerecord types and unicode
{
primary_key: "BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY",
string: { name: "VARCHAR", limit: 3000 },
integer: { name: "INTEGER", limit: 8 },
float: { name: "FLOAT", limit: 53 },
decimal: { name: "DECIMAL" },
time: { name: "TIME" },
date: { name: "DATE" },
seconddate: { name: "SECONDDATE" },
timestamp: { name: "TIMESTAMP" },
binary: { name: "VARBINARY", limit: 3000 },
unicode: { name: "NVARCHAR", limit: 3000 },
text: { name: "CLOB" },
boolean: { name: "BOOLEAN" }
}
Instance Method Summary
collapse
#fetch_type_metadata, #quote_column_name, #quote_table_name, #quote_table_name_for_assignment, #quoted_false, #quoted_time, #quoted_true, #unquoted_false, #unquoted_true
#change_column, #change_column_comment, #change_column_default, #change_column_null, #change_table_comment, #create_table, #drop_table, #extract_foreign_key_action, #foreign_keys, #indexes, #remove_index, #rename_column, #rename_index, #rename_table, #type_to_sql
#commit_db_transaction, #default_sequence_name, #empty_insert_statement_value, #exec_delete, #exec_insert, #exec_query, #exec_rollback_db_transaction, #execute, #insert_fixtures, #insert_fixtures_set, #reset_transaction, #truncate
Constructor Details
#initialize(connection, logger, connection_string, config) ⇒ HanaclientAdapter
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 105
def initialize( connection, logger, connection_string, config)
super(connection, logger, config)
@statements = StatementPool.new(self.class.type_cast_config_to_integer(config[:statement_limit]))
@connection_string = connection_string
@affected_rows = 0
connect!
end
|
Instance Method Details
#active? ⇒ Boolean
120
121
122
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 120
def active?
result = HA.instance.api.hanaclient_execute_immediate(@connection, "SELECT 1 FROM DUMMY") == 1
end
|
#arel_visitor ⇒ Object
101
102
103
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 101
def arel_visitor
Arel::Visitors::Hanaclient.new(self)
end
|
#clear_cache! ⇒ Object
143
144
145
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 143
def clear_cache!
@statements.clear
end
|
#connect! ⇒ Object
124
125
126
127
128
129
130
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 124
def connect!
result = HA.instance.api.hanaclient_connect(@connection, @connection_string)
unless result == 1
result, error = HA.instance.api.hanaclient_error(@connection)
raise ActiveRecord::StatementInvalid.new(error)
end
end
|
#disconnect! ⇒ Object
138
139
140
141
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 138
def disconnect!
super
HA.instance.api.hanaclient_disconnect( @connection )
end
|
#native_database_types ⇒ Object
147
148
149
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 147
def native_database_types
NATIVE_DATABASE_TYPES
end
|
#new_column_from_field(table_name, field) ⇒ Object
Creates a new column object given a hanaclient response statement (field)
152
153
154
155
156
157
158
159
160
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 152
def new_column_from_field(table_name, field)
name = field[3]
default = field[11]
sql_type_metadata = fetch_type_metadata(field[6])
nullable = field[10] == "TRUE"
table_name = field[1]
collation = field[12]
Hanaclient::Column.new(name, default, sql_type_metadata, nullable, table_name, nil, collation, comment: nil)
end
|
#primary_keys(table_name) ⇒ Object
Returns the primary keys of a given table
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 163
def primary_keys(table_name)
raise ArgumentError unless table_name.present?
scope = quoted_scope(table_name)
column_names = query_values(" SELECT COLUMN_NAME\n FROM SYS.INDEX_COLUMNS\n WHERE CONSTRAINT = 'PRIMARY KEY'\n AND SCHEMA_NAME = \#{scope[:schema]}\n AND TABLE_NAME = \#{scope[:name]}\n ORDER BY POSITION\n SQL\n\n column_names.map{|name| name}\nend\n".strip_heredoc, "SCHEMA")
|
#reconnect! ⇒ Object
132
133
134
135
136
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 132
def reconnect!
super
disconnect!
connect!
end
|
#schema_creation ⇒ Object
97
98
99
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 97
def schema_creation
Hanaclient::SchemaCreation.new self
end
|
#supports_foreign_keys? ⇒ Boolean
116
117
118
|
# File 'lib/active_record/connection_adapters/hanaclient_adapter.rb', line 116
def supports_foreign_keys?
true
end
|