Sha256: c54359a2008baa47b0cc5524707c7fcd67d6170632a8ad4099faa3547f0d5095

Contents?: true

Size: 974 Bytes

Versions: 22

Compression:

Stored size: 974 Bytes

Contents

require 'upsert/merge_function/mysql'

class Upsert
  class MergeFunction
    # @private
    class Mysql2_Client < MergeFunction
      include Mysql

      def sql(row)
        quoted_params = (row.selector.values + row.setter.values).map { |v| connection.quote_value v }
        %{CALL #{name}(#{quoted_params.join(', ')})}
      end

      def execute(row)
        first_try = true
        begin
          connection.execute sql(row)
        rescue Mysql2::Error => e
          if e.message =~ /PROCEDURE.*does not exist/i
            if first_try
              Upsert.logger.info %{[upsert] Function #{name.inspect} went missing, trying to recreate}
              first_try = false
              create!
              retry
            else
              Upsert.logger.info %{[upsert] Failed to create function #{name.inspect} for some reason}
              raise e
            end
          else
            raise e
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
upsert-2.9.10-java lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.9.10 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.9.9-universal-java-11 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.9.9 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.2.1 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.2.0 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.1.2 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.1.1 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.1.0 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.0.4 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.0.3 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.0.2 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.0.1 lib/upsert/merge_function/Mysql2_Client.rb
upsert-2.0.0 lib/upsert/merge_function/Mysql2_Client.rb
upsert-1.2.0 lib/upsert/merge_function/Mysql2_Client.rb
upsert-1.1.7 lib/upsert/merge_function/Mysql2_Client.rb
upsert-1.1.6 lib/upsert/merge_function/Mysql2_Client.rb
upsert-1.1.5 lib/upsert/merge_function/Mysql2_Client.rb
upsert-1.1.4 lib/upsert/merge_function/Mysql2_Client.rb
upsert-1.1.3 lib/upsert/merge_function/Mysql2_Client.rb