Class: Gloo::Objs::Sqlite

Inherits:
GlooLang::Core::Obj
  • Object
show all
Defined in:
lib/gloo/objs/data/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.



77
78
79
# File 'lib/gloo/objs/data/sqlite.rb', line 77

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

.short_typenameObject

The short name of the object type.



43
44
45
# File 'lib/gloo/objs/data/sqlite.rb', line 43

def self.short_typename
  return KEYWORD_SHORT
end

.typenameObject

The name of the object type.



36
37
38
# File 'lib/gloo/objs/data/sqlite.rb', line 36

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)


56
57
58
# File 'lib/gloo/objs/data/sqlite.rb', line 56

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.



65
66
67
68
# File 'lib/gloo/objs/data/sqlite.rb', line 65

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

#msg_verifyObject

Verify access to the Sqlite database specified.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/gloo/objs/data/sqlite.rb', line 84

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.



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

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
  return db.query( sql, params )
end