def object_exists?(object_name)
      safe_name = "'#{object_name.gsub('\'','\'\'')}'"
      klass = self.class.name

      sql =
          if klass == 'ActiveRecord::ConnectionAdapters::SQLServerAdapter'
            # use sysobjects table.
            "SELECT COUNT(*) AS \"one\" FROM \"sysobjects\" WHERE \"name\"=#{safe_name}"
          elsif klass == 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
            # use sqlite_master table.
            "SELECT COUNT(*) AS \"one\" FROM \"sqlite_master\" WHERE (\"type\"='table' OR \"type\"='view') AND (\"name\"=#{safe_name})"
          else
            # query the information_schema TABLES and ROUTINES views.
            "SELECT SUM(Z.\"one\") AS \"one\" FROM (SELECT COUNT(*) AS \"one\" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=#{safe_name} UNION SELECT COUNT(*) AS \"one\" FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=#{safe_name}) AS Z"
          end

      result = exec_query(sql).first

      result && result['one'] >= 1
    end
def object_exists?(object_name)
      safe_name = "'#{object_name.gsub('\'','\'\'')}'"
      klass = self.class.name

      sql =
          if klass == 'ActiveRecord::ConnectionAdapters::SQLServerAdapter'
            # use sysobjects table.
            "SELECT COUNT(*) AS \"one\" FROM \"sysobjects\" WHERE \"name\"=#{safe_name}"
          elsif klass == 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
            # use sqlite_master table.
            "SELECT COUNT(*) AS \"one\" FROM \"sqlite_master\" WHERE (\"type\"='table' OR \"type\"='view') AND (\"name\"=#{safe_name})"
          else
            # query the information_schema TABLES and ROUTINES views.
            "SELECT SUM(Z.\"one\") AS \"one\" FROM (SELECT COUNT(*) AS \"one\" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME=#{safe_name} UNION SELECT COUNT(*) AS \"one\" FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME=#{safe_name}) AS Z"
          end

      result = exec_query(sql).first

      result && result['one'] >= 1
    end
Searches the database to determine if an object with the specified name exists.