<commit_before>module PLSQL

  module ProcedureClassMethods #:nodoc:
    def find(schema, procedure, package = nil, override_schema_name = nil)
      if package.nil?
        if (row = schema.select_first(
            "SELECT #{procedure_object_id_src(schema)}.object_id
            FROM all_procedures p, all_objects o
            WHERE p.owner = :owner
              AND p.object_name = :object_name
              AND o.owner = p.owner
              AND o.object_name = p.object_name
              AND o.object_type = p.object_type
              AND o.object_type in ('PROCEDURE', 'FUNCTION')",
            schema.schema_name, procedure.to_s.upcase))
          new(schema, procedure, nil, nil, row[0])
        # search for synonym
        elsif (row = schema.select_first(
            "SELECT o.owner, o.object_name, #{procedure_object_id_src(schema)}.object_id
            FROM all_synonyms s, all_objects o, all_procedures p
            WHERE s.owner IN (:owner, 'PUBLIC')
              AND s.synonym_name = :synonym_name
              AND o.owner = s.table_owner
              AND o.object_name = s.table_name
              AND o.object_type IN ('PROCEDURE','FUNCTION')
              AND o.owner = p.owner
              AND o.object_name = p.object_name
              AND o.object_type = p.object_type
              ORDER BY DECODE(s.owner, 'PUBLIC', 1, 0)",
            schema.schema_name, procedure.to_s.upcase))
          new(schema, row[1], nil, row[0], row[2])
        else
          nil
        end
      elsif package && (row = schema.select_first(
            # older Oracle versions do not have object_id column in all_procedures
            "SELECT #{procedure_object_id_src(schema)}.object_id
            FROM all_procedures p, all_objects o
            WHERE p.owner = :owner
              AND p.object_name = :object_name
              AND p.procedure_name = :procedure_name
              AND o.owner = p.owner
              AND o.object_name = p.object_name
              AND o.object_type = p.object_type
              AND o.object_type = 'PACKAGE'",
            override_schema_name || schema.schema_name, package, procedure.to_s.upcase))
        new(schema, procedure, package, override_schema_name, row[0])
      else
        nil
      end
    end

    private

    def procedure_object_id_src(schema)
      (schema.connection.database_version <=> [11, 1, 0, 0]) >= 0 ? "p" : "o"
    end
  end

  module ProcedureCommon #:nodoc:
    attr_reader :arguments, :argument_list, :out_list, :return
    attr_reader :schema, :schema_name, :package, :procedure

    # return type string from metadata that can be used in DECLARE block or table definition
    def self.type_to_sql(metadata) #:nodoc:
      case metadata[:data_type]
      when 'NUMBER'
        precision, scale = metadata[:data_precision], metadata[:data_scale]
        "NUMBER#{precision ? "(#{precision}#{scale ? ",#{scale}": ""})" : ""}"<commit_msg>rm all_procedures.object_type calls if < 11g<commit_after>module PLSQL

  module ProcedureClassMethods #:nodoc:
    def find(schema, procedure, package = nil, override_schema_name = nil)
      if package.nil?
        if (row = schema.select_first(
            "SELECT #{procedure_object_id_src(schema)}.object_id
            FROM all_procedures p, all_objects o
            WHERE p.owner = :owner
              AND p.object_name = :object_name
              AND o.owner = p.owner
              AND o.object_name = p.object_name
              AND o.object_type in ('PROCEDURE', 'FUNCTION')",
            schema.schema_name, procedure.to_s.upcase))
          new(schema, procedure, nil, nil, row[0])
        # search for synonym
        elsif (row = schema.select_first(
            "SELECT o.owner, o.object_name, #{procedure_object_id_src(schema)}.object_id
            FROM all_synonyms s, all_objects o, all_procedures p
            WHERE s.owner IN (:owner, 'PUBLIC')
              AND s.synonym_name = :synonym_name
              AND o.owner = s.table_owner
              AND o.object_name = s.table_name
              AND o.object_type IN ('PROCEDURE','FUNCTION')
              AND o.owner = p.owner
              AND o.object_name = p.object_name
              ORDER BY DECODE(s.owner, 'PUBLIC', 1, 0)",
            schema.schema_name, procedure.to_s.upcase))
          new(schema, row[1], nil, row[0], row[2])
        else
          nil
        end
      elsif package && (row = schema.select_first(
            # older Oracle versions do not have object_id column in all_procedures
            "SELECT #{procedure_object_id_src(schema)}.object_id
            FROM all_procedures p, all_objects o
            WHERE p.owner = :owner
              AND p.object_name = :object_name
              AND p.procedure_name = :procedure_name
              AND o.owner = p.owner
              AND o.object_name = p.object_name
              AND o.object_type = 'PACKAGE'",
            override_schema_name || schema.schema_name, package, procedure.to_s.upcase))
        new(schema, procedure, package, override_schema_name, row[0])
      else
        nil
      end
    end

    private

    def procedure_object_id_src(schema)
      (schema.connection.database_version <=> [11, 1, 0, 0]) >= 0 ? "p" : "o"
    end
  end

  module ProcedureCommon #:nodoc:
    attr_reader :arguments, :argument_list, :out_list, :return
    attr_reader :schema, :schema_name, :package, :procedure

    # return type string from metadata that can be used in DECLARE block or table definition
    def self.type_to_sql(metadata) #:nodoc:
      case metadata[:data_type]
      when 'NUMBER'
        precision, scale = metadata[:data_precision], metadata[:data_scale]
        "NUMBER#{precision ? "(#{precision}#{scale ? ",#{scale}": ""})" : ""}"
{'fraction_non_alphanumeric': 0.09970419349225683, 'fraction_numerical': 0.0048721071863581, 'mean_word_length': 2.1986644407345577, 'pattern_counts': {'":': 2, '<': 6, '<?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': '2812246', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1702, 'n_words': 437}