Repository: rails/rails
File: activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb (Ruby)

Code before:
        def perform_query(raw_connection, sql, binds, type_casted_binds, prepare:, notification_payload:, batch:)
          raise NotImplementedError
        end

        def handle_warnings(raw_result, sql)
        end

        # Receive a native adapter result object and returns an ActiveRecord::Result object.
        def cast_result(raw_result)
          raise NotImplementedError
        end

        def affected_rows(raw_result)
          raise NotImplementedError
        end

        def preprocess_query(sql)
          if write_query?(sql)
            ensure_writes_are_allowed(sql)
            mark_transaction_written
          end

          # We call tranformers after the write checks so we don't add extra parsing work.
          # This means we assume no transformer whille change a read for a write
          # but it would be insane to do such a thing.
          ActiveRecord.query_transformers.each do |transformer|
            sql = transformer.call(sql, self)
          end

          sql
        end

        # Same as #internal_exec_query, but yields a native adapter result
        def internal_execute(sql, name = "SQL", binds = [], prepare: false, async: false, allow_retry: false, materialize_transactions: true, &block)
          sql = preprocess_query(sql)
          raw_execute(sql, name, binds, prepare: prepare, async: async, allow_retry: allow_retry, materialize_transactions: materialize_transactions, &block)
        end

        def execute_batch(statements, name = nil, **kwargs)
          statements.each do |statement|
            raw_execute(statement, name, **kwargs)
          end
        end

        def build_fixture_sql(fixtures, table_name)
          columns = schema_cache.columns_hash(table_name).reject { |_, column| supports_virtual_columns? && column.virtual? }

          values_list = fixtures.map do |fixture|
            fixture = fixture.stringify_keys

            unknown_columns = fixture.keys - columns.keys

Review comment (bug):
I may be wrong, but is this an unintended API change? I think that `#raw_execute` did not previously accept Arel, but only raw sql? And it looks like you changed all the internal code to compile Arel into sql before calling `#raw_execute`.

Code after:
      def high_precision_current_timestamp
        HIGH_PRECISION_CURRENT_TIMESTAMP
      end

      # Same as raw_execute but returns an ActiveRecord::Result object.
      def raw_exec_query(intent) # :nodoc:
        cast_result(raw_execute(intent))
      end

      # Execute a query and returns an ActiveRecord::Result
      def internal_exec_query(...) # :nodoc:
        cast_result(internal_execute(...))
      end

      def default_insert_value(column) # :nodoc:
        DEFAULT_INSERT_VALUE
      end

      private
        DEFAULT_INSERT_VALUE = Arel.sql("DEFAULT").freeze
        private_constant :DEFAULT_INSERT_VALUE

        # Lowest level way to execute a query. Doesn't check for illegal writes, doesn't annotate queries, yields a native result object.
        def raw_execute(intent)
          # Handle Arel compilation if needed
          compile_arel_in_intent(intent)

          # Handle SQL preprocessing if needed
          intent.processed_sql ||= preprocess_query(intent.raw_sql) if intent.raw_sql
          intent.type_casted_binds = type_casted_binds(intent.binds)
          log(intent) do |notification_payload|
            intent.notification_payload = notification_payload
            with_raw_connection(allow_retry: intent.allow_retry, materialize_transactions: intent.materialize_transactions) do |conn|
              result = perform_query(conn, intent)
              handle_warnings(result, intent.processed_sql)
              result
            end
          end
        end

        def perform_query(raw_connection, intent)
          raise NotImplementedError
        end

        def handle_warnings(raw_result, sql)
        end

        # Receive a native adapter result object and returns an ActiveRecord::Result object.
        def cast_result(raw_result)
          raise NotImplementedError
        end