# frozen_string_literal: truemoduleActiveRecordmoduleConnectionAdaptersmoduleMySQLmoduleDatabaseStatements# Returns an ActiveRecord::Result instance.defselect_all(*,**)# :nodoc:result=ifExplainRegistry.collect?&&prepared_statementsunprepared_statement{super}elsesuperend@connection.abandon_results!resultenddefquery(sql,name=nil)# :nodoc:execute(sql,name).to_aendREAD_QUERY=ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(:begin,:commit,:explain,:select,:set,:show,:release,:savepoint,:rollback,:describe,:desc,:with)# :nodoc:private_constant:READ_QUERYdefwrite_query?(sql)# :nodoc:!READ_QUERY.match?(sql)end# Executes the SQL statement in the context of this connection.defexecute(sql,name=nil)ifpreventing_writes?&&write_query?(sql)raiseActiveRecord::ReadOnlyError,"Write query attempted while in readonly mode: #{sql}"end# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been# made since we established the connection@connection.query_options[:database_timezone]=ActiveRecord::Base.default_timezonesuperenddefexec_query(sql,name="SQL",binds=[],prepare: false)ifwithout_prepared_statement?(binds)execute_and_free(sql,name)do|result|ifresultActiveRecord::Result.new(result.fields,result.to_a)elseActiveRecord::Result.new([],[])endendelseexec_stmt_and_free(sql,name,binds,cache_stmt: prepare)do|_,result|ifresultActiveRecord::Result.new(result.fields,result.to_a)elseActiveRecord::Result.new([],[])endendendenddefexec_delete(sql,name=nil,binds=[])ifwithout_prepared_statement?(binds)@lock.synchronizedoexecute_and_free(sql,name){@connection.affected_rows}endelseexec_stmt_and_free(sql,name,binds){|stmt|stmt.affected_rows}endendalias:exec_update:exec_deleteprivatedefexecute_batch(statements,name=nil)combine_multi_statements(statements).eachdo|statement|execute(statement,name)end@connection.abandon_results!enddefdefault_insert_value(column)superunlesscolumn.auto_increment?enddeflast_inserted_id(result)@connection.last_idenddefsupports_set_server_option?@connection.respond_to?(:set_server_option)enddefmulti_statements_enabled?(flags)ifflags.is_a?(Array)flags.include?("MULTI_STATEMENTS")else(flags&Mysql2::Client::MULTI_STATEMENTS)!=0endenddefwith_multi_statementsprevious_flags=@config[:flags]unlessmulti_statements_enabled?(previous_flags)ifsupports_set_server_option?@connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_ON)else@config[:flags]=Mysql2::Client::MULTI_STATEMENTSreconnect!endendyieldensureunlessmulti_statements_enabled?(previous_flags)ifsupports_set_server_option?@connection.set_server_option(Mysql2::Client::OPTION_MULTI_STATEMENTS_OFF)else@config[:flags]=previous_flagsreconnect!endendenddefcombine_multi_statements(total_sql)total_sql.each_with_object([])do|sql,total_sql_chunks|previous_packet=total_sql_chunks.lastifmax_allowed_packet_reached?(sql,previous_packet)total_sql_chunks<<+sqlelseprevious_packet<<";\n"previous_packet<<sqlendendenddefmax_allowed_packet_reached?(current_packet,previous_packet)ifcurrent_packet.bytesize>max_allowed_packetraiseActiveRecordError,"Fixtures set is too large #{current_packet.bytesize}. Consider increasing the max_allowed_packet variable."elsifprevious_packet.nil?trueelse(current_packet.bytesize+previous_packet.bytesize+2)>max_allowed_packetendenddefmax_allowed_packet@max_allowed_packet||=show_variable("max_allowed_packet")enddefexec_stmt_and_free(sql,name,binds,cache_stmt: false)ifpreventing_writes?&&write_query?(sql)raiseActiveRecord::ReadOnlyError,"Write query attempted while in readonly mode: #{sql}"endmaterialize_transactions# make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been# made since we established the connection@connection.query_options[:database_timezone]=ActiveRecord::Base.default_timezonetype_casted_binds=type_casted_binds(binds)log(sql,name,binds,type_casted_binds)doifcache_stmtstmt=@statements[sql]||=@connection.prepare(sql)elsestmt=@connection.prepare(sql)endbeginresult=ActiveSupport::Dependencies.interlock.permit_concurrent_loadsdostmt.execute(*type_casted_binds)endrescueMysql2::Error=>eifcache_stmt@statements.delete(sql)elsestmt.closeendraiseeendret=yieldstmt,resultresult.freeifresultstmt.closeunlesscache_stmtretendendendendendend