gloo-lang 0.9.6 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/lib/VERSION +1 -1
- data/lib/gloo_lang/app/args.rb +3 -2
- data/lib/gloo_lang/app/engine.rb +25 -26
- data/lib/gloo_lang/app/help.rb +10 -9
- data/lib/gloo_lang/app/log.rb +5 -3
- data/lib/gloo_lang/app/settings.rb +10 -9
- data/lib/gloo_lang/convert/converter.rb +9 -2
- data/lib/gloo_lang/core/baseo.rb +2 -1
- data/lib/gloo_lang/core/dictionary.rb +16 -6
- data/lib/gloo_lang/core/event_manager.rb +9 -8
- data/lib/gloo_lang/core/factory.rb +11 -10
- data/lib/gloo_lang/core/gloo_system.rb +9 -8
- data/lib/gloo_lang/core/heap.rb +5 -4
- data/lib/gloo_lang/core/here.rb +2 -2
- data/lib/gloo_lang/core/obj.rb +9 -8
- data/lib/gloo_lang/core/obj_finder.rb +3 -3
- data/lib/gloo_lang/core/parser.rb +6 -5
- data/lib/gloo_lang/core/pn.rb +20 -16
- data/lib/gloo_lang/core/verb.rb +2 -1
- data/lib/gloo_lang/exec/dispatch.rb +8 -8
- data/lib/gloo_lang/exec/exec_env.rb +7 -6
- data/lib/gloo_lang/exec/runner.rb +10 -10
- data/lib/gloo_lang/exec/script.rb +6 -5
- data/lib/gloo_lang/exec/stack.rb +8 -7
- data/lib/gloo_lang/expr/expression.rb +3 -2
- data/lib/gloo_lang/objs/basic/alias.rb +4 -4
- data/lib/gloo_lang/objs/basic/boolean.rb +3 -3
- data/lib/gloo_lang/objs/basic/container.rb +2 -2
- data/lib/gloo_lang/objs/basic/decimal.rb +3 -3
- data/lib/gloo_lang/objs/basic/integer.rb +3 -3
- data/lib/gloo_lang/objs/basic/script.rb +1 -1
- data/lib/gloo_lang/objs/basic/string.rb +3 -3
- data/lib/gloo_lang/objs/basic/text.rb +2 -2
- data/lib/gloo_lang/objs/ctrl/each.rb +3 -3
- data/lib/gloo_lang/objs/ctrl/repeat.rb +2 -2
- data/lib/gloo_lang/objs/data/markdown.rb +2 -2
- data/lib/gloo_lang/objs/data/query.rb +4 -4
- data/lib/gloo_lang/objs/data/table.rb +3 -3
- data/lib/gloo_lang/objs/dt/date.rb +1 -1
- data/lib/gloo_lang/objs/dt/datetime.rb +2 -2
- data/lib/gloo_lang/objs/dt/time.rb +1 -1
- data/lib/gloo_lang/objs/ror/erb.rb +2 -2
- data/lib/gloo_lang/objs/ror/eval.rb +3 -3
- data/lib/gloo_lang/objs/web/http_get.rb +3 -3
- data/lib/gloo_lang/objs/web/http_post.rb +8 -8
- data/lib/gloo_lang/objs/web/json.rb +5 -5
- data/lib/gloo_lang/objs/web/slack.rb +1 -1
- data/lib/gloo_lang/objs/web/teams.rb +1 -1
- data/lib/gloo_lang/objs/web/uri.rb +6 -6
- data/lib/gloo_lang/persist/file_loader.rb +6 -5
- data/lib/gloo_lang/persist/file_saver.rb +2 -1
- data/lib/gloo_lang/persist/file_storage.rb +6 -5
- data/lib/gloo_lang/persist/persist_man.rb +9 -8
- data/lib/gloo_lang/utils/stats.rb +5 -4
- data/lib/gloo_lang/verbs/context.rb +4 -4
- data/lib/gloo_lang/verbs/create.rb +3 -3
- data/lib/gloo_lang/verbs/execute.rb +4 -4
- data/lib/gloo_lang/verbs/help.rb +23 -23
- data/lib/gloo_lang/verbs/if.rb +3 -3
- data/lib/gloo_lang/verbs/list.rb +7 -7
- data/lib/gloo_lang/verbs/load.rb +3 -3
- data/lib/gloo_lang/verbs/move.rb +6 -6
- data/lib/gloo_lang/verbs/put.rb +6 -6
- data/lib/gloo_lang/verbs/quit.rb +1 -1
- data/lib/gloo_lang/verbs/run.rb +5 -5
- data/lib/gloo_lang/verbs/save.rb +1 -1
- data/lib/gloo_lang/verbs/show.rb +5 -5
- data/lib/gloo_lang/verbs/tell.rb +5 -4
- data/lib/gloo_lang/verbs/unless.rb +3 -3
- data/lib/gloo_lang/verbs/version.rb +1 -1
- data/lib/gloo_lang/verbs/wait.rb +1 -1
- metadata +2 -4
- data/lib/gloo_lang/objs/data/mysql.rb +0 -192
- data/lib/gloo_lang/objs/data/sqlite.rb +0 -159
data/lib/gloo_lang/verbs/load.rb
CHANGED
@@ -19,10 +19,10 @@ module GlooLang
|
|
19
19
|
fn = @tokens.second
|
20
20
|
|
21
21
|
if fn
|
22
|
-
|
23
|
-
|
22
|
+
@engine.log.debug "Getting ready to load file: #{fn}"
|
23
|
+
@engine.persist_man.load fn
|
24
24
|
else
|
25
|
-
|
25
|
+
@engine.err MISSING_EXPR_ERR
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
data/lib/gloo_lang/verbs/move.rb
CHANGED
@@ -56,15 +56,15 @@ module GlooLang
|
|
56
56
|
def lookup_obj
|
57
57
|
arr = @tokens.before_token( TO )
|
58
58
|
if arr.count == 1
|
59
|
-
|
59
|
+
@engine.err MISSING_SRC_ERR
|
60
60
|
return
|
61
61
|
end
|
62
62
|
|
63
63
|
name = arr[ 1 ]
|
64
|
-
pn = GlooLang::Core::Pn.new name
|
64
|
+
pn = GlooLang::Core::Pn.new( @engine, name )
|
65
65
|
o = pn.resolve
|
66
66
|
|
67
|
-
|
67
|
+
@engine.err( "#{MISSING_SRC_OBJ_ERR} #{name}" ) unless o
|
68
68
|
return o
|
69
69
|
end
|
70
70
|
|
@@ -74,13 +74,13 @@ module GlooLang
|
|
74
74
|
def lookup_dst
|
75
75
|
dst = @tokens.after_token( TO )
|
76
76
|
unless dst
|
77
|
-
|
77
|
+
@engine.err MISSING_DST_ERR
|
78
78
|
return nil
|
79
79
|
end
|
80
80
|
|
81
|
-
pn = GlooLang::Core::Pn.new dst
|
81
|
+
pn = GlooLang::Core::Pn.new( @engine, dst )
|
82
82
|
o = pn.resolve
|
83
|
-
|
83
|
+
@engine.err( "#{MISSING_DST_OBJ_ERR} '#{dst}'" ) unless o
|
84
84
|
return o
|
85
85
|
end
|
86
86
|
|
data/lib/gloo_lang/verbs/put.rb
CHANGED
@@ -54,7 +54,7 @@ module GlooLang
|
|
54
54
|
def fetch_value_tokens
|
55
55
|
value = @tokens.before_token( INTO )
|
56
56
|
if value.nil? || ( value.count <= 1 )
|
57
|
-
|
57
|
+
@engine.err MISSING_EXPR_ERR
|
58
58
|
return nil
|
59
59
|
end
|
60
60
|
|
@@ -69,7 +69,7 @@ module GlooLang
|
|
69
69
|
target = @tokens.after_token( INTO )
|
70
70
|
return target if target
|
71
71
|
|
72
|
-
|
72
|
+
@engine.err INTO_MISSING_ERR
|
73
73
|
return nil
|
74
74
|
end
|
75
75
|
|
@@ -77,15 +77,15 @@ module GlooLang
|
|
77
77
|
# Update the target with the new value.
|
78
78
|
#
|
79
79
|
def update_target( target, value )
|
80
|
-
pn = GlooLang::Core::Pn.new target
|
80
|
+
pn = GlooLang::Core::Pn.new( @engine, target )
|
81
81
|
o = pn.resolve
|
82
82
|
if o.nil?
|
83
|
-
|
83
|
+
@engine.err "#{TARGET_ERR} #{target}"
|
84
84
|
elsif value.count.positive?
|
85
|
-
expr = GlooLang::Expr::Expression.new( value )
|
85
|
+
expr = GlooLang::Expr::Expression.new( @engine, value )
|
86
86
|
result = expr.evaluate
|
87
87
|
o.set_value result
|
88
|
-
|
88
|
+
@engine.heap.it.set_to result
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
data/lib/gloo_lang/verbs/quit.rb
CHANGED
data/lib/gloo_lang/verbs/run.rb
CHANGED
@@ -19,7 +19,7 @@ module GlooLang
|
|
19
19
|
#
|
20
20
|
def run
|
21
21
|
if @tokens.token_count < 2
|
22
|
-
|
22
|
+
@engine.err MISSING_EXPR_ERR
|
23
23
|
return
|
24
24
|
end
|
25
25
|
|
@@ -54,7 +54,7 @@ module GlooLang
|
|
54
54
|
# Run a script specified by pathname
|
55
55
|
#
|
56
56
|
def run_script
|
57
|
-
GlooLang::Exec::Runner.run @tokens.second
|
57
|
+
GlooLang::Exec::Runner.run( @engine, @tokens.second )
|
58
58
|
end
|
59
59
|
|
60
60
|
#
|
@@ -62,12 +62,12 @@ module GlooLang
|
|
62
62
|
#
|
63
63
|
def run_expression
|
64
64
|
unless @tokens.token_count > 2
|
65
|
-
|
65
|
+
@engine.err MISSING_EXPR_ERR
|
66
66
|
return
|
67
67
|
end
|
68
68
|
|
69
|
-
expr = GlooLang::Expr::Expression.new( @tokens.params[ 1..-1 ] )
|
70
|
-
|
69
|
+
expr = GlooLang::Expr::Expression.new( @engine, @tokens.params[ 1..-1 ] )
|
70
|
+
@engine.parser.run expr.evaluate
|
71
71
|
end
|
72
72
|
|
73
73
|
end
|
data/lib/gloo_lang/verbs/save.rb
CHANGED
data/lib/gloo_lang/verbs/show.rb
CHANGED
@@ -17,12 +17,12 @@ module GlooLang
|
|
17
17
|
#
|
18
18
|
def run
|
19
19
|
if @tokens.token_count > 1
|
20
|
-
expr = GlooLang::Expr::Expression.new( @tokens.params )
|
20
|
+
expr = GlooLang::Expr::Expression.new( @engine, @tokens.params )
|
21
21
|
result = expr.evaluate
|
22
|
-
|
23
|
-
|
22
|
+
@engine.log.show get_formatted_string( result )
|
23
|
+
@engine.heap.it.set_to result
|
24
24
|
else
|
25
|
-
|
25
|
+
@engine.log.show ''
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -51,7 +51,7 @@ module GlooLang
|
|
51
51
|
#
|
52
52
|
def get_formatted_string( str )
|
53
53
|
if @params&.token_count&.positive?
|
54
|
-
expr = GlooLang::Expr::Expression.new( @params.tokens )
|
54
|
+
expr = GlooLang::Expr::Expression.new( @engine, @params.tokens )
|
55
55
|
val = expr.evaluate
|
56
56
|
color = val.to_sym
|
57
57
|
# return ColorizedString[ str.to_s ].colorize( color )
|
data/lib/gloo_lang/verbs/tell.rb
CHANGED
@@ -51,7 +51,7 @@ module GlooLang
|
|
51
51
|
def setup_msg
|
52
52
|
@msg = @tokens.after_token( TO )
|
53
53
|
|
54
|
-
|
54
|
+
@engine.err( UNKNOWN_MSG_ERR ) unless @msg
|
55
55
|
end
|
56
56
|
|
57
57
|
#
|
@@ -59,7 +59,7 @@ module GlooLang
|
|
59
59
|
#
|
60
60
|
def setup_target
|
61
61
|
@obj_name = @tokens.second
|
62
|
-
pn = GlooLang::Core::Pn.new @obj_name
|
62
|
+
pn = GlooLang::Core::Pn.new( @engine, @obj_name )
|
63
63
|
@target_obj = pn.resolve
|
64
64
|
end
|
65
65
|
|
@@ -68,9 +68,10 @@ module GlooLang
|
|
68
68
|
#
|
69
69
|
def dispatch_msg
|
70
70
|
if @target_obj
|
71
|
-
GlooLang::Exec::Dispatch.message
|
71
|
+
GlooLang::Exec::Dispatch.message(
|
72
|
+
@engine, @msg, @target_obj, @params )
|
72
73
|
else
|
73
|
-
|
74
|
+
@engine.err "#{OBJ_NOT_FOUND_ERR} #{@obj_name}"
|
74
75
|
end
|
75
76
|
end
|
76
77
|
|
@@ -55,7 +55,7 @@ module GlooLang
|
|
55
55
|
# The first token is the verb, so we drop it.
|
56
56
|
value = value[ 1..-1 ]
|
57
57
|
else
|
58
|
-
|
58
|
+
@engine.err MISSING_EXPR_ERR
|
59
59
|
end
|
60
60
|
|
61
61
|
return value
|
@@ -67,7 +67,7 @@ module GlooLang
|
|
67
67
|
def evals_false( value )
|
68
68
|
eval_result = false
|
69
69
|
if value.count.positive?
|
70
|
-
expr = GlooLang::Expr::Expression.new( value )
|
70
|
+
expr = GlooLang::Expr::Expression.new( @engine, value )
|
71
71
|
result = expr.evaluate
|
72
72
|
eval_result = true if result == false
|
73
73
|
eval_result = true if result.is_a?( Numeric ) && result.zero?
|
@@ -81,7 +81,7 @@ module GlooLang
|
|
81
81
|
#
|
82
82
|
def run_do
|
83
83
|
cmd = @tokens.expr_after( DO )
|
84
|
-
i =
|
84
|
+
i = @engine.parser.parse_immediate cmd
|
85
85
|
return unless i
|
86
86
|
|
87
87
|
i.run
|
data/lib/gloo_lang/verbs/wait.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gloo-lang
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Crane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -309,9 +309,7 @@ files:
|
|
309
309
|
- lib/gloo_lang/objs/ctrl/each.rb
|
310
310
|
- lib/gloo_lang/objs/ctrl/repeat.rb
|
311
311
|
- lib/gloo_lang/objs/data/markdown.rb
|
312
|
-
- lib/gloo_lang/objs/data/mysql.rb
|
313
312
|
- lib/gloo_lang/objs/data/query.rb
|
314
|
-
- lib/gloo_lang/objs/data/sqlite.rb
|
315
313
|
- lib/gloo_lang/objs/data/table.rb
|
316
314
|
- lib/gloo_lang/objs/dt/date.rb
|
317
315
|
- lib/gloo_lang/objs/dt/datetime.rb
|
@@ -1,192 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# A MySQL database connection.
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# https://github.com/brianmario/mysql2
|
8
|
-
# https://www.rubydoc.info/gems/mysql2/0.2.3/Mysql2/Client
|
9
|
-
#
|
10
|
-
# Connection Parameters
|
11
|
-
# user = opts[:username]
|
12
|
-
# pass = opts[:password]
|
13
|
-
# host = opts[:host] || 'localhost'
|
14
|
-
# port = opts[:port] || 3306
|
15
|
-
# database = opts[:database]
|
16
|
-
# socket = opts[:socket]
|
17
|
-
# flags = opts[:flags] || 0
|
18
|
-
#
|
19
|
-
require 'mysql2'
|
20
|
-
|
21
|
-
module GlooLang
|
22
|
-
module Objs
|
23
|
-
class Mysql < GlooLang::Core::Obj
|
24
|
-
|
25
|
-
KEYWORD = 'mysql'.freeze
|
26
|
-
KEYWORD_SHORT = 'mysql'.freeze
|
27
|
-
|
28
|
-
HOST = 'host'.freeze
|
29
|
-
DB = 'database'.freeze
|
30
|
-
USER = 'username'.freeze
|
31
|
-
PASSWD = 'password'.freeze
|
32
|
-
|
33
|
-
#
|
34
|
-
# The name of the object type.
|
35
|
-
#
|
36
|
-
def self.typename
|
37
|
-
return KEYWORD
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# The short name of the object type.
|
42
|
-
#
|
43
|
-
def self.short_typename
|
44
|
-
return KEYWORD_SHORT
|
45
|
-
end
|
46
|
-
|
47
|
-
# ---------------------------------------------------------------------
|
48
|
-
# Children
|
49
|
-
# ---------------------------------------------------------------------
|
50
|
-
|
51
|
-
#
|
52
|
-
# Does this object have children to add when an object
|
53
|
-
# is created in interactive mode?
|
54
|
-
# This does not apply during obj load, etc.
|
55
|
-
#
|
56
|
-
def add_children_on_create?
|
57
|
-
return true
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# Add children to this object.
|
62
|
-
# This is used by containers to add children needed
|
63
|
-
# for default configurations.
|
64
|
-
#
|
65
|
-
def add_default_children
|
66
|
-
fac = $engine.factory
|
67
|
-
fac.create_string HOST, nil, self
|
68
|
-
fac.create_string DB, nil, self
|
69
|
-
fac.create_string USER, nil, self
|
70
|
-
fac.create_string PASSWD, nil, self
|
71
|
-
end
|
72
|
-
|
73
|
-
# ---------------------------------------------------------------------
|
74
|
-
# Messages
|
75
|
-
# ---------------------------------------------------------------------
|
76
|
-
|
77
|
-
#
|
78
|
-
# Get a list of message names that this object receives.
|
79
|
-
#
|
80
|
-
def self.messages
|
81
|
-
return super + [ 'verify' ]
|
82
|
-
end
|
83
|
-
|
84
|
-
#
|
85
|
-
# SSH to the host and execute the command, then update result.
|
86
|
-
#
|
87
|
-
def msg_verify
|
88
|
-
return unless connects?
|
89
|
-
|
90
|
-
$engine.heap.it.set_to true
|
91
|
-
end
|
92
|
-
|
93
|
-
# ---------------------------------------------------------------------
|
94
|
-
# DB functions (all database connections)
|
95
|
-
# ---------------------------------------------------------------------
|
96
|
-
|
97
|
-
#
|
98
|
-
# Open a connection and execute the SQL statement.
|
99
|
-
# Return the resulting data.
|
100
|
-
#
|
101
|
-
def query( sql, params = nil )
|
102
|
-
h = {
|
103
|
-
host: host_value,
|
104
|
-
database: db_value,
|
105
|
-
username: user_value,
|
106
|
-
password: passwd_value
|
107
|
-
}
|
108
|
-
client = Mysql2::Client.new( h )
|
109
|
-
return client.query( sql ) unless params
|
110
|
-
|
111
|
-
pst = client.prepare( sql )
|
112
|
-
return pst.execute( *params )
|
113
|
-
end
|
114
|
-
|
115
|
-
# ---------------------------------------------------------------------
|
116
|
-
# Private functions
|
117
|
-
# ---------------------------------------------------------------------
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
#
|
122
|
-
# Get the host from the child object.
|
123
|
-
# Returns nil if there is none.
|
124
|
-
#
|
125
|
-
def host_value
|
126
|
-
o = find_child HOST
|
127
|
-
return nil unless o
|
128
|
-
|
129
|
-
o = GlooLang::Objs::Alias.resolve_alias( o )
|
130
|
-
return o.value
|
131
|
-
end
|
132
|
-
|
133
|
-
#
|
134
|
-
# Get the Database name from the child object.
|
135
|
-
# Returns nil if there is none.
|
136
|
-
#
|
137
|
-
def db_value
|
138
|
-
o = find_child DB
|
139
|
-
return nil unless o
|
140
|
-
|
141
|
-
o = GlooLang::Objs::Alias.resolve_alias( o )
|
142
|
-
return o.value
|
143
|
-
end
|
144
|
-
|
145
|
-
#
|
146
|
-
# Get the Username from the child object.
|
147
|
-
# Returns nil if there is none.
|
148
|
-
#
|
149
|
-
def user_value
|
150
|
-
o = find_child USER
|
151
|
-
return nil unless o
|
152
|
-
|
153
|
-
o = GlooLang::Objs::Alias.resolve_alias( o )
|
154
|
-
return o.value
|
155
|
-
end
|
156
|
-
|
157
|
-
#
|
158
|
-
# Get the Password name from the child object.
|
159
|
-
# Returns nil if there is none.
|
160
|
-
#
|
161
|
-
def passwd_value
|
162
|
-
o = find_child PASSWD
|
163
|
-
return nil unless o
|
164
|
-
|
165
|
-
o = GlooLang::Objs::Alias.resolve_alias( o )
|
166
|
-
return o.value
|
167
|
-
end
|
168
|
-
|
169
|
-
#
|
170
|
-
# Try the connection and make sure it works.
|
171
|
-
# Returns true if we can establish a connection.
|
172
|
-
#
|
173
|
-
def connects?
|
174
|
-
begin
|
175
|
-
h = {
|
176
|
-
host: host_value,
|
177
|
-
database: db_value,
|
178
|
-
username: user_value,
|
179
|
-
password: passwd_value
|
180
|
-
}
|
181
|
-
Mysql2::Client.new( h )
|
182
|
-
rescue => e
|
183
|
-
$engine.err e.message
|
184
|
-
$engine.heap.it.set_to false
|
185
|
-
return false
|
186
|
-
end
|
187
|
-
return true
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
@@ -1,159 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# A Sqlite3 database connection.
|
5
|
-
#
|
6
|
-
# https://www.rubydoc.info/gems/sqlite3/1.3.11
|
7
|
-
# https://www.devdungeon.com/content/ruby-sqlite-tutorial
|
8
|
-
#
|
9
|
-
# db.results_as_hash = true
|
10
|
-
# Set results to return as Hash object.
|
11
|
-
# This is slower but offers a huge convenience.
|
12
|
-
# Consider turning it off for high performance situations.
|
13
|
-
# Each row will have the column name as the hash key.
|
14
|
-
#
|
15
|
-
# # Alternatively, to only get one row and discard the rest,
|
16
|
-
# replace `db.query()` with `db.get_first_value()`.
|
17
|
-
#
|
18
|
-
require 'sqlite3'
|
19
|
-
|
20
|
-
module GlooLang
|
21
|
-
module Objs
|
22
|
-
class Sqlite < GlooLang::Core::Obj
|
23
|
-
|
24
|
-
KEYWORD = 'sqlite'.freeze
|
25
|
-
KEYWORD_SHORT = 'sqlite'.freeze
|
26
|
-
|
27
|
-
DB = 'database'.freeze
|
28
|
-
DEFAULT_DB = 'test.db'.freeze
|
29
|
-
|
30
|
-
DB_REQUIRED_ERR = 'The database name is required!'.freeze
|
31
|
-
DB_NOT_FOUND_ERR = 'The database file was not found!'.freeze
|
32
|
-
|
33
|
-
#
|
34
|
-
# The name of the object type.
|
35
|
-
#
|
36
|
-
def self.typename
|
37
|
-
return KEYWORD
|
38
|
-
end
|
39
|
-
|
40
|
-
#
|
41
|
-
# The short name of the object type.
|
42
|
-
#
|
43
|
-
def self.short_typename
|
44
|
-
return KEYWORD_SHORT
|
45
|
-
end
|
46
|
-
|
47
|
-
# ---------------------------------------------------------------------
|
48
|
-
# Children
|
49
|
-
# ---------------------------------------------------------------------
|
50
|
-
|
51
|
-
#
|
52
|
-
# Does this object have children to add when an object
|
53
|
-
# is created in interactive mode?
|
54
|
-
# This does not apply during obj load, etc.
|
55
|
-
#
|
56
|
-
def add_children_on_create?
|
57
|
-
return true
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# Add children to this object.
|
62
|
-
# This is used by containers to add children needed
|
63
|
-
# for default configurations.
|
64
|
-
#
|
65
|
-
def add_default_children
|
66
|
-
fac = $engine.factory
|
67
|
-
fac.create_string DB, DEFAULT_DB, self
|
68
|
-
end
|
69
|
-
|
70
|
-
# ---------------------------------------------------------------------
|
71
|
-
# Messages
|
72
|
-
# ---------------------------------------------------------------------
|
73
|
-
|
74
|
-
#
|
75
|
-
# Get a list of message names that this object receives.
|
76
|
-
#
|
77
|
-
def self.messages
|
78
|
-
return super + [ 'verify' ]
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# Verify access to the Sqlite database specified.
|
83
|
-
#
|
84
|
-
def msg_verify
|
85
|
-
name = db_value
|
86
|
-
if name.empty?
|
87
|
-
$engine.err DB_REQUIRED_ERR
|
88
|
-
$engine.heap.it.set_to false
|
89
|
-
return
|
90
|
-
end
|
91
|
-
|
92
|
-
unless File.exist? name
|
93
|
-
$engine.err DB_NOT_FOUND_ERR
|
94
|
-
$engine.heap.it.set_to false
|
95
|
-
return
|
96
|
-
end
|
97
|
-
|
98
|
-
return unless connects?
|
99
|
-
|
100
|
-
$engine.heap.it.set_to true
|
101
|
-
end
|
102
|
-
|
103
|
-
# ---------------------------------------------------------------------
|
104
|
-
# DB functions (all database connections)
|
105
|
-
# ---------------------------------------------------------------------
|
106
|
-
|
107
|
-
#
|
108
|
-
# Open a connection and execute the SQL statement.
|
109
|
-
# Return the resulting data.
|
110
|
-
#
|
111
|
-
def query( sql, params = nil )
|
112
|
-
name = db_value
|
113
|
-
unless name
|
114
|
-
$engine.err DB_REQUIRED_ERR
|
115
|
-
return
|
116
|
-
end
|
117
|
-
|
118
|
-
db = SQLite3::Database.open name
|
119
|
-
db.results_as_hash = true
|
120
|
-
return db.query( sql, params )
|
121
|
-
end
|
122
|
-
|
123
|
-
# ---------------------------------------------------------------------
|
124
|
-
# Private functions
|
125
|
-
# ---------------------------------------------------------------------
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
#
|
130
|
-
# Get the Database file from the child object.
|
131
|
-
# Returns nil if there is none.
|
132
|
-
#
|
133
|
-
def db_value
|
134
|
-
o = find_child DB
|
135
|
-
return nil unless o
|
136
|
-
|
137
|
-
return o.value
|
138
|
-
end
|
139
|
-
|
140
|
-
#
|
141
|
-
# Try the connection and make sure it works.
|
142
|
-
# Returns true if we can connect and do a query.
|
143
|
-
#
|
144
|
-
def connects?
|
145
|
-
begin
|
146
|
-
db = SQLite3::Database.open db_value
|
147
|
-
sql = "SELECT COUNT(name) FROM sqlite_master WHERE type='table'"
|
148
|
-
db.get_first_value sql
|
149
|
-
rescue => e
|
150
|
-
$engine.err e.message
|
151
|
-
$engine.heap.it.set_to false
|
152
|
-
return false
|
153
|
-
end
|
154
|
-
return true
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|