Sha256: 8d8b4c66fb8a3a730042ffb3db9b3320a40b9ca62eb4399639380c286426318b

Contents?: true

Size: 1.17 KB

Versions: 31

Compression:

Stored size: 1.17 KB

Contents

# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter

module DatabaseHelper
  class SQLColumn
    def initialize(row, name)
      @row = row
      @name = name
    end

    def value
      @row.nil? ? '' : @row[@name.downcase]
    end

    def to_s
      'SQL Column'
    end
  end

  class SQLRow
    def initialize(query, row)
      @query = query
      @row = row
    end

    def column(column)
      SQLColumn.new(@row, column)
    end

    def to_s
      'SQL Row'
    end
  end

  class SQLQueryResult
    attr_reader :error
    def initialize(cmd, results)
      @cmd = cmd
      @results = results
    end

    def empty?
      @results.empty?
    end

    def successful?
      @cmd.exit_status == 0 && @error.nil?
    end

    def row(id)
      SQLRow.new(self, @results[id])
    end

    def size
      @results.size
    end

    def stdout
      warn '[DEPRECATION] The `stdout` method is deprecated. Use `row` instead.'
      @cmd.stdout
    end

    def stderr
      warn '[DEPRECATION] The `stderr` method is deprecated. Use `successful?` instead.'
      @cmd.stderr
    end

    def inspect
      to_s
    end

    def to_s
      'SQL ResultSet'
    end
  end
end

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
inspec-core-2.2.34 lib/utils/database_helpers.rb
inspec-2.2.34 lib/utils/database_helpers.rb
inspec-core-2.2.27 lib/utils/database_helpers.rb
inspec-2.2.27 lib/utils/database_helpers.rb
inspec-core-2.2.20 lib/utils/database_helpers.rb
inspec-2.2.20 lib/utils/database_helpers.rb
inspec-core-2.2.16 lib/utils/database_helpers.rb
inspec-2.2.16 lib/utils/database_helpers.rb
inspec-core-2.2.10 lib/utils/database_helpers.rb
inspec-2.2.10 lib/utils/database_helpers.rb
inspec-core-2.1.84 lib/utils/database_helpers.rb
inspec-2.1.84 lib/utils/database_helpers.rb
inspec-core-2.1.83 lib/utils/database_helpers.rb
inspec-2.1.83 lib/utils/database_helpers.rb
inspec-core-2.1.81 lib/utils/database_helpers.rb
inspec-core-2.1.80 lib/utils/database_helpers.rb
inspec-2.1.80 lib/utils/database_helpers.rb
inspec-core-2.1.78 lib/utils/database_helpers.rb
inspec-2.1.78 lib/utils/database_helpers.rb
inspec-core-2.1.72 lib/utils/database_helpers.rb