<commit_before>require 'rubygems'
require 'data_objects'
if RUBY_PLATFORM =~ /java/
  require 'do_jdbc'
  require 'java'
  # gem 'jdbc-mysql'
  # require 'jdbc/mysql' # the JDBC driver, packaged as a gem

else # MRI and Ruby 1.9
  gem 'ruby-oci8', '>=2.0.2'
  require 'oci8'
  require File.expand_path(File.join(File.dirname(__FILE__), 'oci8_patch'))
end

require 'do_oracle_ext'
require File.expand_path(File.join(File.dirname(__FILE__), 'do_oracle', 'version'))
# require File.expand_path(File.join(File.dirname(__FILE__), 'do_oracle', 'transaction'))

if RUBY_PLATFORM !~ /java/
  module DataObjects
    module Oracle
      class Command
        private
        
        def execute(*args)
          oci8_conn = @connection.instance_variable_get("@connection")
          raise OracleError, "This connection has already been closed." unless oci8_conn
          
          sql, bind_variables = replace_argument_placeholders(@text, args)
          execute_internal(oci8_conn, sql, bind_variables)
        end
        
        # Replace ? placeholders with :n argument placeholders in string of SQL
        # as required by OCI8#exec method
        # Compare number of ? placeholders with number of passed arguments
        # and raise exception if different
        def replace_argument_placeholders(sql_string, args)
          sql = sql_string.dup
          args_count = args.length
          bind_variables = []
          
          replacements = 0
          mismatch     = false
          
          sql.gsub!(/(IS |IS NOT )?\?/) do |x|
            arg = args[replacements]
            replacements += 1
            case arg
            when Array
              i = 0
              "(" << arg.map do |a|
                bind_variables << a
                i += 1
                ":a#{replacements}_#{i}"
              end.join(", ") << ")"
            when Range
              bind_variables << arg.first << arg.last
              ":r#{replacements}_1 AND :r#{replacements}_2"
            when nil
              # if "IS ?" or "IS NOT ?" then replace with NULL
              if $1
                "#{$1}NULL"
              # otherwise pass as bind variable
              else
                bind_variables << arg
                ":#{replacements}"
              end
            else
              bind_variables << arg
              ":#{replacements}"
            end
          end
          
          if sql =~ /^\s*INSERT.+RETURNING.+INTO :insert_id\s*$/i
            @insert_id_present = true
          end
          
          if args_count != replacements
            raise ArgumentError, "Binding mismatch: #{args_count} for #{replacements}"<commit_msg>implementation of Regexp parameters support<commit_after>require 'rubygems'
require 'data_objects'
if RUBY_PLATFORM =~ /java/
  require 'do_jdbc'
  require 'java'
  # gem 'jdbc-mysql'
  # require 'jdbc/mysql' # the JDBC driver, packaged as a gem

else # MRI and Ruby 1.9
  gem 'ruby-oci8', '>=2.0.2'
  require 'oci8'
  require File.expand_path(File.join(File.dirname(__FILE__), 'oci8_patch'))
end

require 'do_oracle_ext'
require File.expand_path(File.join(File.dirname(__FILE__), 'do_oracle', 'version'))
# require File.expand_path(File.join(File.dirname(__FILE__), 'do_oracle', 'transaction'))

if RUBY_PLATFORM !~ /java/
  module DataObjects
    module Oracle
      class Command
        private
        
        def execute(*args)
          oci8_conn = @connection.instance_variable_get("@connection")
          raise OracleError, "This connection has already been closed." unless oci8_conn
          
          sql, bind_variables = replace_argument_placeholders(@text, args)
          execute_internal(oci8_conn, sql, bind_variables)
        end
        
        # Replace ? placeholders with :n argument placeholders in string of SQL
        # as required by OCI8#exec method
        # Compare number of ? placeholders with number of passed arguments
        # and raise exception if different
        def replace_argument_placeholders(sql_string, args)
          sql = sql_string.dup
          args_count = args.length
          bind_variables = []
          
          replacements = 0
          mismatch     = false
          
          sql.gsub!(/(IS |IS NOT )?\?/) do |x|
            arg = args[replacements]
            replacements += 1
            case arg
            when Array
              i = 0
              "(" << arg.map do |a|
                bind_variables << a
                i += 1
                ":a#{replacements}_#{i}"
              end.join(", ") << ")"
            when Range
              bind_variables << arg.first << arg.last
              ":r#{replacements}_1 AND :r#{replacements}_2"
            when Regexp
              regexp_options = arg.options & Regexp::IGNORECASE > 0 ? "i" : ""
              regexp_options << "m" if arg.options & Regexp::MULTILINE > 0
              bind_variables << arg.source << regexp_options
              ":re#{replacements}_1, :re#{replacements}_2"
            when NilClass
              # if "IS ?" or "IS NOT ?" then replace with NULL
              if $1
                "#{$1}NULL"
              # otherwise pass as bind variable
              else
                bind_variables << arg
                ":#{replacements}"
              end
            else
              bind_variables << arg
              ":#{replacements}"
            end
          end
          
          if sql =~ /^\s*INSERT.+RETURNING.+INTO :insert_id\s*$/i
            @insert_id_present = true
          end
          
          if args_count != replacements
            raise ArgumentError, "Binding mismatch: #{args_count} for #{replacements}"
{'fraction_non_alphanumeric': 0.09867608120035304, 'fraction_numerical': 0.007766990291262136, 'mean_word_length': 1.7679531021006352, 'pattern_counts': {'":': 9, '<': 37, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1521890', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1568, 'n_words': 417}