def replace_nil_binds(sql, args)
      nils = []
      args.each_with_index { |value, i| nils << i if value.nil? }
      unless nils.empty? then
        logger.debug { "SQL executor working around RDBI bug by eliminating the nil arguments #{nils.to_series} for the SQL:\n#{sql}..." }
        # Quoted ? is too much of a pain for this hack; bail out.
        raise ArgumentError.new("RDBI work-around does not support quoted ? in transactional SQL: #{sql}") if sql =~ /'[^,]*[?][^,]*'/
        prefix, binds_s, suffix = /(.+\s*values\s*\()([^)]*)(\).*)/i.match(sql).captures
        sql = prefix
        binds = binds_s.split('?')
        last = binds_s[-1, 1]
        del_cnt = 0
        binds.each_with_index do |s, i|
          sql << s
          if nils.include?(i) then
            args.delete_at(i - del_cnt)
            del_cnt += 1
            sql << 'NULL'
          elsif i < binds.size - 1 or last == '?'
            sql << '?'
          end
        end
        sql << suffix
      end
      logger.debug { "SQL executor converted the SQL to:\n#{sql}\nwith arguments #{args.qp}" }
      return args.unshift(sql)
    end
def replace_nil_binds(sql, args)
      nils = []
      args.each_with_index { |value, i| nils << i if value.nil? }
      unless nils.empty? then
        logger.debug { "SQL executor working around RDBI bug by eliminating the nil arguments #{nils.to_series} for the SQL:\n#{sql}..." }
        # Quoted ? is too much of a pain for this hack; bail out.
        raise ArgumentError.new("RDBI work-around does not support quoted ? in transactional SQL: #{sql}") if sql =~ /'[^,]*[?][^,]*'/
        prefix, binds_s, suffix = /(.+\s*values\s*\()([^)]*)(\).*)/i.match(sql).captures
        sql = prefix
        binds = binds_s.split('?')
        last = binds_s[-1, 1]
        del_cnt = 0
        binds.each_with_index do |s, i|
          sql << s
          if nils.include?(i) then
            args.delete_at(i - del_cnt)
            del_cnt += 1
            sql << 'NULL'
          elsif i < binds.size - 1 or last == '?'
            sql << '?'
          end
        end
        sql << suffix
      end
      logger.debug { "SQL executor converted the SQL to:\n#{sql}\nwith arguments #{args.qp}" }
      return args.unshift(sql)
    end
Replaces nil arguments with a +NULL+ literal in the given SQL.

 @param (see #transact)
 @return [Array] the (possibly modified) SQL followed by the non-nil arguments