Class: DatabaseHelper::SQLQueryResult

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/utils/database_helpers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, results) ⇒ SQLQueryResult

Returns a new instance of SQLQueryResult.



34
35
36
37
# File 'lib/inspec/utils/database_helpers.rb', line 34

def initialize(cmd, results)
  @cmd = cmd
  @results = results
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



33
34
35
# File 'lib/inspec/utils/database_helpers.rb', line 33

def error
  @error
end

Instance Method Details

#column(column) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/inspec/utils/database_helpers.rb', line 55

def column(column)
  result = []
  @results.each do |row|
    result << row[column]
  end
  result
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/inspec/utils/database_helpers.rb', line 39

def empty?
  @results.empty?
end

#inspectObject



67
68
69
# File 'lib/inspec/utils/database_helpers.rb', line 67

def inspect
  to_s
end

#row(id) ⇒ Object



51
52
53
# File 'lib/inspec/utils/database_helpers.rb', line 51

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

#rowsObject



47
48
49
# File 'lib/inspec/utils/database_helpers.rb', line 47

def rows
  @results
end

#sizeObject



63
64
65
# File 'lib/inspec/utils/database_helpers.rb', line 63

def size
  @results.size
end

#successful?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/inspec/utils/database_helpers.rb', line 43

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

#to_sObject



71
72
73
# File 'lib/inspec/utils/database_helpers.rb', line 71

def to_s
  "SQL ResultSet"
end