Class: DatabaseHelper::SQLQueryResult

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, results) ⇒ SQLQueryResult

Returns a new instance of SQLQueryResult.



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

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

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



37
38
39
# File 'lib/utils/database_helpers.rb', line 37

def error
  @error
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @results.empty?
end

#inspectObject



69
70
71
# File 'lib/utils/database_helpers.rb', line 69

def inspect
  to_s
end

#row(id) ⇒ Object



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

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

#sizeObject



55
56
57
# File 'lib/utils/database_helpers.rb', line 55

def size
  @results.size
end

#stderrObject



64
65
66
67
# File 'lib/utils/database_helpers.rb', line 64

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

#stdoutObject



59
60
61
62
# File 'lib/utils/database_helpers.rb', line 59

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

#successful?Boolean

Returns:

  • (Boolean)


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

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

#to_sObject



73
74
75
# File 'lib/utils/database_helpers.rb', line 73

def to_s
  'SQL ResultSet'
end