Module: ActiveRecord::ConnectionAdapters::MySQL::DatabaseStatements
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb |
Constant Summary
-
HIGH_PRECISION_CURRENT_TIMESTAMP =
private
Internal use only
Arel.sql("CURRENT_TIMESTAMP(6)", retryable: true).freeze
-
READ_QUERY =
private
Internal use only
# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 7AbstractAdapter.build_read_query_regexp( :desc, :describe, :set, :show, :use, :kill )
Instance Attribute Summary
- #analyze_without_explain? ⇒ Boolean readonly private
Instance Method Summary
- #build_explain_clause(options = [])
- #explain(arel, binds = [], options = [])
- #high_precision_current_timestamp
- #combine_multi_statements(total_sql) private
- #default_insert_value(column) private
- #max_allowed_packet private
- #max_allowed_packet_reached?(current_packet, previous_packet) ⇒ Boolean private
- #returning_column_values(result) private
- #write_query?(sql) ⇒ Boolean Internal use only
Instance Attribute Details
#analyze_without_explain? ⇒ Boolean
(readonly, private)
[ GitHub ]
# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 50
def analyze_without_explain? mariadb? && database_version >= "10.1.0" end
Instance Method Details
#build_explain_clause(options = [])
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 36
def build_explain_clause( = []) return "EXPLAIN" if .empty? explain_clause = "EXPLAIN #{ .join(" ").upcase}" if analyze_without_explain? && explain_clause.include?("ANALYZE") explain_clause.sub("EXPLAIN ", "") else explain_clause end end
#combine_multi_statements(total_sql) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 66
def combine_multi_statements(total_sql) total_sql.each_with_object([]) do |sql, total_sql_chunks| previous_packet = total_sql_chunks.last if max_allowed_packet_reached?(sql, previous_packet) total_sql_chunks << +sql else previous_packet << ";\n" previous_packet << sql end end end
#default_insert_value(column) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 54
def default_insert_value(column) super unless column.auto_increment? end
#explain(arel, binds = [], options = [])
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 27
def explain(arel, binds = [], = []) sql = build_explain_clause( ) + " " + to_sql(arel, binds) start = Process.clock_gettime(Process::CLOCK_MONOTONIC) result = internal_exec_query(sql, "EXPLAIN", binds) elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start MySQL::ExplainPrettyPrinter.new.pp(result, elapsed) end
#high_precision_current_timestamp
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 23
def HIGH_PRECISION_CURRENT_TIMESTAMP end
#max_allowed_packet (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 89
def max_allowed_packet @max_allowed_packet ||= show_variable("max_allowed_packet") end
#max_allowed_packet_reached?(current_packet, previous_packet) ⇒ Boolean
(private)
# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 78
def max_allowed_packet_reached?(current_packet, previous_packet) if current_packet.bytesize > max_allowed_packet raise ActiveRecordError, "Fixtures set is too large #{current_packet.bytesize}. Consider increasing the max_allowed_packet variable." elsif previous_packet.nil? true else (current_packet.bytesize + previous_packet.bytesize + 2) > max_allowed_packet end end
#returning_column_values(result) (private)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 58
def returning_column_values(result) if supports_insert_returning? result.rows.first else super end end
#write_query?(sql) ⇒ Boolean
This method is for internal use only.
# File 'activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb', line 17
def write_query?(sql) # :nodoc: !READ_QUERY.match?(sql) rescue ArgumentError # Invalid encoding !READ_QUERY.match?(sql.b) end