Class: Sqlite

Inherits:
Gloo::Core::Obj
  • Object
show all
Defined in:
lib/sqlite.rb

Constant Summary collapse

KEYWORD =
'sqlite'.freeze
KEYWORD_SHORT =
'sqlite'.freeze
DB =
'database'.freeze
DEFAULT_DB =
'test.db'.freeze
DB_REQUIRED_ERR =
'The database name is required!'.freeze
DB_NOT_FOUND_ERR =
'The database file was not found!'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.messagesObject

Get a list of message names that this object receives.



75
76
77
# File 'lib/sqlite.rb', line 75

def self.messages
  return super + [ 'verify' ]
end

.short_typenameObject

The short name of the object type.



41
42
43
# File 'lib/sqlite.rb', line 41

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



34
35
36
# File 'lib/sqlite.rb', line 34

def self.typename
  return KEYWORD
end

Instance Method Details

#add_children_on_create?Boolean

Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.

Returns:

  • (Boolean)


54
55
56
# File 'lib/sqlite.rb', line 54

def add_children_on_create?
  return true
end

#add_default_childrenObject

Add children to this object. This is used by containers to add children needed for default configurations.



63
64
65
66
# File 'lib/sqlite.rb', line 63

def add_default_children
  fac = @engine.factory
  fac.create_string DB, DEFAULT_DB, self
end

#get_query_result(result) ⇒ Object

Based on the result set, build a QueryResult object.



126
127
128
129
130
131
132
133
# File 'lib/sqlite.rb', line 126

def get_query_result( result )
  rows = []        
  while ( row = result.next ) do
    rows << row
  end

  return Gloo::Objs::QueryResult.new( result.columns, rows )
end

#msg_verifyObject

Verify access to the Sqlite database specified.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/sqlite.rb', line 82

def msg_verify
  name = db_value
  if name.empty?
    @engine.err DB_REQUIRED_ERR
    @engine.heap.it.set_to false
    return
  end

  unless File.exist? name
    @engine.err DB_NOT_FOUND_ERR
    @engine.heap.it.set_to false
    return
  end

  return unless connects?

  @engine.heap.it.set_to true
end

#query(sql, params = nil) ⇒ Object

Open a connection and execute the SQL statement. Return the resulting data.



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/sqlite.rb', line 109

def query( sql, params = nil )
  name = db_value
  unless name
    @engine.err DB_REQUIRED_ERR
    return
  end

  db = SQLite3::Database.open name
  # db.results_as_hash = true
  results = db.query( sql, params )

  return results
end