Class: Rimportor::ActiveRecord::Adapter::Mysql2
- Inherits:
-
Object
- Object
- Rimportor::ActiveRecord::Adapter::Mysql2
- Defined in:
- lib/rimportor/active_record/adapter/mysql2.rb
Instance Method Summary collapse
- #exec_in_pool ⇒ Object
- #exec_insert(import_statement) ⇒ Object
- #exec_statement(statement) ⇒ Object
- #max_allowed_packet ⇒ Object
- #statement_too_big?(statement) ⇒ Boolean
Instance Method Details
#exec_in_pool ⇒ Object
14 15 16 17 18 |
# File 'lib/rimportor/active_record/adapter/mysql2.rb', line 14 def exec_in_pool ::Rimportor::Util::Connection.in_pool do |connection| yield(connection) end end |
#exec_insert(import_statement) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rimportor/active_record/adapter/mysql2.rb', line 24 def exec_insert(import_statement) insert_statement, value_statements = import_statement if statement_too_big? ("#{insert_statement}, #{value_statements.join(',')}") puts 'Statement too big' else exec_statement "#{insert_statement},#{value_statements.join(',')}" end end |
#exec_statement(statement) ⇒ Object
33 34 35 |
# File 'lib/rimportor/active_record/adapter/mysql2.rb', line 33 def exec_statement(statement) exec_in_pool { |connection| connection.execute statement } end |
#max_allowed_packet ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/rimportor/active_record/adapter/mysql2.rb', line 6 def max_allowed_packet exec_in_pool do |connection| result = connection.execute("SHOW VARIABLES like 'max_allowed_packet';") val = result.respond_to?(:fetch_row) ? result.fetch_row[1] : result.first[1] val.to_i end end |
#statement_too_big?(statement) ⇒ Boolean
20 21 22 |
# File 'lib/rimportor/active_record/adapter/mysql2.rb', line 20 def statement_too_big?(statement) statement.size > max_allowed_packet end |