rhodes-framework 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/Manifest.txt +8 -2
- data/README.txt +1 -0
- data/Rakefile +6 -30
- data/lib/builtinME.rb +67 -5
- data/lib/date.rb +121 -80
- data/lib/date/format.rb +44 -42
- data/lib/dateME.rb +2 -1
- data/lib/erb.rb +278 -238
- data/lib/rational.rb +2 -2
- data/lib/rho/rho.rb +59 -24
- data/lib/rho/rhoapplication.rb +13 -4
- data/lib/rho/rhocontroller.rb +7 -3
- data/lib/rho/rhoerror.rb +33 -0
- data/lib/rho/rhoutils.rb +5 -2
- data/lib/rhodes.rb +2 -2
- data/lib/rhom/rhom.rb +24 -11
- data/lib/rhom/rhom_db_adapter.rb +56 -23
- data/lib/rhom/rhom_object.rb +3 -32
- data/lib/rhom/rhom_object_factory.rb +154 -154
- data/lib/rhom/rhom_source.rb +9 -9
- data/lib/singleton.rb +3 -3
- data/lib/time.rb +20 -2
- data/lib/version.rb +2 -2
- data/spec/app/mspec/matchers/raise_error.rb +2 -1
- data/spec/app/spec/fixtures/object_values.txt +2 -2
- data/spec/app/spec/pagination/fixtures/object_values.txt +91 -0
- data/spec/app/spec/rho_controller_spec.rb +2 -2
- data/spec/app/spec/rho_spec.rb +8 -3
- data/spec/app/spec/rhom_db_adapter_spec.rb +27 -0
- data/spec/app/spec/{rhom_object_factory_spec.rb → rhom_object_spec.rb} +125 -10
- data/spec/app/spec/rhom_spec.rb +19 -8
- data/spec/app/spec/rhoruby_spec.rb +31 -0
- data/spec/app/spec/spec_helper.rb +2 -1
- data/spec/app/spec/syncengine_spec.rb +30 -0
- data/spec/app/spec_runner.rb +9 -5
- data/spec/build.yml +3 -2
- data/spec/rhoconfig.txt +2 -0
- metadata +19 -83
- data/lib/rhom/rhom_db_adapterME.rb +0 -92
data/lib/rational.rb
CHANGED
@@ -3,7 +3,7 @@ class Fixnum
|
|
3
3
|
alias quof fdiv
|
4
4
|
alias rdiv quo
|
5
5
|
|
6
|
-
alias power! **
|
6
|
+
alias power! ** unless defined?(0.power!)
|
7
7
|
alias rpower **
|
8
8
|
|
9
9
|
end
|
@@ -13,7 +13,7 @@ class Bignum
|
|
13
13
|
alias quof fdiv
|
14
14
|
alias rdiv quo
|
15
15
|
|
16
|
-
alias power! **
|
16
|
+
alias power! ** unless defined?(0.power!)
|
17
17
|
alias rpower **
|
18
18
|
|
19
19
|
end
|
data/lib/rho/rho.rb
CHANGED
@@ -3,10 +3,12 @@ require 'rho/render'
|
|
3
3
|
require 'rho/rhoapplication'
|
4
4
|
require 'rhom'
|
5
5
|
require 'rhofsconnector'
|
6
|
+
require 'rho/rhoerror'
|
6
7
|
|
7
8
|
module Rho
|
8
9
|
class RHO
|
9
10
|
APPLICATIONS = {}
|
11
|
+
APPNAME = 'app'
|
10
12
|
|
11
13
|
def initialize(app_manifest_filename=nil)
|
12
14
|
puts "Calling RHO.initialize"
|
@@ -25,10 +27,25 @@ module Rho
|
|
25
27
|
Rhom::RhomDbAdapter::close
|
26
28
|
end
|
27
29
|
|
30
|
+
def raise_rhoerror(errCode)
|
31
|
+
raise Rho::RhoError.new(errCode)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_app(appname)
|
35
|
+
if (APPLICATIONS[appname].nil?)
|
36
|
+
require RhoApplication::get_app_path(appname)+'application'
|
37
|
+
APPLICATIONS[appname] = Object.const_get('AppApplication').new
|
38
|
+
end
|
39
|
+
APPLICATIONS[appname]
|
40
|
+
end
|
41
|
+
|
28
42
|
# Return the directories where we need to load configuration files
|
29
43
|
def process_model_dirs(app_manifest_filename=nil)
|
30
44
|
File.open(app_manifest_filename).each do |line|
|
31
|
-
|
45
|
+
str = line.chomp
|
46
|
+
if str != nil and str.length > 0
|
47
|
+
require File.join(File.dirname(app_manifest_filename), str )
|
48
|
+
end
|
32
49
|
end
|
33
50
|
end
|
34
51
|
|
@@ -38,10 +55,19 @@ module Rho
|
|
38
55
|
File.open(Rho::RhoFSConnector.get_rhoconfig_filename).each do |line|
|
39
56
|
parts = line.chop.split('=')
|
40
57
|
key = parts[0]
|
41
|
-
value =
|
58
|
+
value = nil
|
59
|
+
if key and defined? RHO_ME
|
60
|
+
value = rho_get_app_property(key.strip)
|
61
|
+
end
|
62
|
+
|
63
|
+
if !value
|
64
|
+
value = parts[1] if parts[1]
|
65
|
+
end
|
66
|
+
|
42
67
|
if key and value
|
43
|
-
|
44
|
-
|
68
|
+
val = value.strip.gsub(/\'|\"/,'')
|
69
|
+
val = val == 'nil' ? nil : val
|
70
|
+
Rho::RhoConfig.add_config(key.strip,val)
|
45
71
|
end
|
46
72
|
end
|
47
73
|
rescue Exception => e
|
@@ -63,9 +89,10 @@ module Rho
|
|
63
89
|
|
64
90
|
src_id = source['source_id']
|
65
91
|
url = source['url']
|
92
|
+
name = source['name']
|
66
93
|
if !self.source_initialized?(src_id)
|
67
94
|
Rhom::RhomDbAdapter::insert_into_table('sources',
|
68
|
-
{"source_id"=>src_id,"source_url"=>url})
|
95
|
+
{"source_id"=>src_id,"source_url"=>url,"name"=>name})
|
69
96
|
end
|
70
97
|
end
|
71
98
|
end
|
@@ -74,15 +101,6 @@ module Rho
|
|
74
101
|
def source_initialized?(source_id)
|
75
102
|
Rhom::RhomDbAdapter::select_from_table('sources','*', 'source_id'=>source_id).size > 0 ? true : false
|
76
103
|
end
|
77
|
-
|
78
|
-
def get_app(appname)
|
79
|
-
if (APPLICATIONS[appname].nil?)
|
80
|
-
require RhoApplication::get_app_path(appname)+'application'
|
81
|
-
#APPLICATIONS[appname] = Object.const_get(appname+'Application').new
|
82
|
-
APPLICATIONS[appname] = Object.const_get('AppApplication').new
|
83
|
-
end
|
84
|
-
APPLICATIONS[appname]
|
85
|
-
end
|
86
104
|
|
87
105
|
def serve(req)
|
88
106
|
begin
|
@@ -107,6 +125,8 @@ module Rho
|
|
107
125
|
end
|
108
126
|
|
109
127
|
def serve_index(index_name)
|
128
|
+
# TODO: Removed hardcoded appname
|
129
|
+
get_app(APPNAME).set_menu
|
110
130
|
begin
|
111
131
|
puts 'inside RHO.serve_index: ' + index_name
|
112
132
|
res = init_response
|
@@ -118,6 +138,8 @@ module Rho
|
|
118
138
|
end
|
119
139
|
|
120
140
|
def serve_index_hash(index_name)
|
141
|
+
# TODO: Removed hardcoded appname
|
142
|
+
get_app(APPNAME).set_menu
|
121
143
|
begin
|
122
144
|
puts 'inside RHO.serve_index: ' + index_name
|
123
145
|
res = init_response
|
@@ -161,10 +183,10 @@ module Rho
|
|
161
183
|
data << "Expires: 0" << CRLF
|
162
184
|
|
163
185
|
data << CRLF
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
186
|
+
if ( !res['request-body'].nil? )
|
187
|
+
data << res['request-body']
|
188
|
+
end
|
189
|
+
|
168
190
|
data
|
169
191
|
end
|
170
192
|
|
@@ -187,10 +209,10 @@ module Rho
|
|
187
209
|
body << <<-_HTML_STRING_
|
188
210
|
<html>
|
189
211
|
<head>
|
190
|
-
<title>Server Error</title>
|
191
212
|
<meta name="viewport" content="width=320"/>
|
192
213
|
</head>
|
193
214
|
<body>
|
215
|
+
<h2>Server Error</h2>
|
194
216
|
<p>
|
195
217
|
_HTML_STRING_
|
196
218
|
body << 'Error: ' << exception.message << "<br/>" if exception
|
@@ -213,13 +235,21 @@ module Rho
|
|
213
235
|
class RhoConfig
|
214
236
|
|
215
237
|
@@sources = {}
|
216
|
-
@@config = {'start_path' => '/app',
|
217
|
-
'options_path' => '/app/Settings'}
|
238
|
+
@@config = {'start_path' => '/app', 'options_path' => '/app/Settings'}
|
218
239
|
|
219
240
|
class << self
|
220
241
|
def method_missing(name, *args)
|
221
|
-
|
222
|
-
|
242
|
+
unless name == Fixnum
|
243
|
+
varname = name.to_s.gsub(/\=/,"")
|
244
|
+
setting = (name.to_s =~ /=/)
|
245
|
+
if setting
|
246
|
+
@@config[varname] = args[0]
|
247
|
+
# save changes to file
|
248
|
+
RhoConf.set_property_by_name(varname,args[0])
|
249
|
+
else
|
250
|
+
@@config[varname]
|
251
|
+
end
|
252
|
+
end
|
223
253
|
end
|
224
254
|
|
225
255
|
def sources
|
@@ -230,13 +260,18 @@ module Rho
|
|
230
260
|
@@config
|
231
261
|
end
|
232
262
|
|
263
|
+
def add_config(key,value)
|
264
|
+
@@config[key] = value if key # allow nil value
|
265
|
+
end
|
266
|
+
|
233
267
|
def add_source(modelname, new_source=nil)
|
234
268
|
if new_source
|
235
269
|
unless @@sources[new_source]
|
236
270
|
@@sources[modelname] = new_source
|
271
|
+
@@sources[modelname]['name'] ||= modelname
|
237
272
|
end
|
238
273
|
end
|
239
274
|
end
|
240
275
|
end
|
241
276
|
end # RhoConfig
|
242
|
-
end # Rho
|
277
|
+
end # Rho
|
data/lib/rho/rhoapplication.rb
CHANGED
@@ -3,15 +3,25 @@ require 'rhofsconnector'
|
|
3
3
|
|
4
4
|
module Rho
|
5
5
|
class RhoApplication
|
6
|
+
attr_accessor :default_menu
|
6
7
|
|
7
8
|
def initialize
|
8
|
-
|
9
|
+
unless @rhom
|
9
10
|
@rhom = Rhom::Rhom.new
|
10
11
|
end
|
12
|
+
unless @default_menu
|
13
|
+
@default_menu = { "Home" => :home, "Refresh" => :refresh,
|
14
|
+
"Sync" => :sync, "Options" => :options, "Log" => :log, :separator => nil, "Close" => :close }
|
15
|
+
end
|
11
16
|
end
|
17
|
+
|
18
|
+
def set_menu(menu=nil)
|
19
|
+
disp_menu = menu ? menu : @default_menu
|
20
|
+
puts "RhoApplication: Using menu - #{disp_menu.inspect}"
|
21
|
+
WebView.set_menu_items(disp_menu)
|
22
|
+
end
|
12
23
|
|
13
24
|
class << self
|
14
|
-
|
15
25
|
def get_app_path(appname)
|
16
26
|
Rho::RhoFSConnector::get_app_path(appname)
|
17
27
|
end
|
@@ -23,13 +33,12 @@ module Rho
|
|
23
33
|
def get_model_path(appname, modelname)
|
24
34
|
Rho::RhoFSConnector::get_model_path(appname, modelname)
|
25
35
|
end
|
26
|
-
|
27
36
|
end
|
28
37
|
|
29
38
|
def serve(req,res)
|
30
39
|
req[:modelpath] = self.class.get_model_path req['application'], req['model']
|
31
40
|
require req[:modelpath]+'controller'
|
32
|
-
res['request-body'] = (Object.const_get(req['model']+'Controller').new).send :serve, @rhom, req, res
|
41
|
+
res['request-body'] = (Object.const_get(req['model']+'Controller').new).send :serve, self, @rhom, req, res
|
33
42
|
end
|
34
43
|
|
35
44
|
end # RhoApplication
|
data/lib/rho/rhocontroller.rb
CHANGED
@@ -4,6 +4,7 @@ require 'rho/rhoviewhelpers'
|
|
4
4
|
|
5
5
|
module Rho
|
6
6
|
class RhoController
|
7
|
+
attr_accessor :menu
|
7
8
|
|
8
9
|
def default_action
|
9
10
|
return Hash['GET','show','PUT','update','POST','update',
|
@@ -11,11 +12,14 @@ module Rho
|
|
11
12
|
return Hash['GET','index','POST','create'][@request['request-method']]
|
12
13
|
end
|
13
14
|
|
14
|
-
def serve(object_mapping,req,res)
|
15
|
-
@request, @response = req, res
|
15
|
+
def serve(application,object_mapping,req,res)
|
16
|
+
@request, @response = req, res
|
16
17
|
@object_mapping = object_mapping
|
17
18
|
@params = RhoSupport::query_params req
|
18
|
-
send req['action'].nil? ? default_action : req['action']
|
19
|
+
res = send req['action'].nil? ? default_action : req['action']
|
20
|
+
application.set_menu(@menu)
|
21
|
+
@menu = nil
|
22
|
+
res
|
19
23
|
end
|
20
24
|
|
21
25
|
# Returns true if the request's header contains "XMLHttpRequest".
|
data/lib/rho/rhoerror.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Rho
|
2
|
+
class RhoError < Exception
|
3
|
+
ERR_NONE = 0
|
4
|
+
ERR_NETWORK = 1
|
5
|
+
ERR_REMOTESERVER = 2
|
6
|
+
ERR_RUNTIME = 3
|
7
|
+
ERR_UNEXPECTEDSERVERRESPONSE = 4
|
8
|
+
ERR_DIFFDOMAINSINSYNCSRC = 5
|
9
|
+
|
10
|
+
attr_reader :code
|
11
|
+
|
12
|
+
def initialize(err_code)
|
13
|
+
@code = err_code
|
14
|
+
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
if code == ERR_NETWORK
|
18
|
+
return "Could not establish network connection"
|
19
|
+
elsif code == ERR_REMOTESERVER
|
20
|
+
return "Server returned an error"
|
21
|
+
elsif code == ERR_RUNTIME
|
22
|
+
return "Internal error"
|
23
|
+
elsif code == ERR_UNEXPECTEDSERVERRESPONSE
|
24
|
+
return "Unexpected server response"
|
25
|
+
elsif code == ERR_DIFFDOMAINSINSYNCSRC
|
26
|
+
return "All sync sources should be from one domain"
|
27
|
+
end
|
28
|
+
|
29
|
+
return "Unknown error"
|
30
|
+
end
|
31
|
+
|
32
|
+
end # RhoError
|
33
|
+
end # Rho
|
data/lib/rho/rhoutils.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Rho
|
2
2
|
class RhoUtils
|
3
3
|
def self.load_offline_data(tables=[], dir_prefix=nil)
|
4
|
-
first_row=true
|
5
4
|
columns = []
|
6
5
|
tables.each do |filename|
|
7
6
|
Rhom::RhomDbAdapter.delete_all_from_table(filename)
|
7
|
+
Rhom::RhomDbAdapter.start_transaction
|
8
|
+
|
9
|
+
first_row=true
|
8
10
|
prefix = dir_prefix.nil? ? "" : dir_prefix
|
9
11
|
File.open(File.join(Rho::RhoFSConnector.get_base_app_path,'app',prefix,'fixtures',filename+'.txt')).each do |line|
|
10
12
|
if first_row
|
@@ -18,8 +20,9 @@ module Rho
|
|
18
20
|
end
|
19
21
|
Rhom::RhomDbAdapter.insert_into_table(filename,row)
|
20
22
|
end
|
23
|
+
|
24
|
+
Rhom::RhomDbAdapter.commit
|
21
25
|
columns = []
|
22
|
-
first_row = true
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
data/lib/rhodes.rb
CHANGED
data/lib/rhom/rhom.rb
CHANGED
@@ -21,17 +21,15 @@
|
|
21
21
|
|
22
22
|
require 'rhom/rhom_object_factory'
|
23
23
|
require 'rhom/rhom_object'
|
24
|
-
|
25
|
-
require 'rhom/rhom_db_adapterME'
|
26
|
-
else
|
27
|
-
require 'rhom/rhom_db_adapter'
|
28
|
-
end
|
24
|
+
require 'rhom/rhom_db_adapter'
|
29
25
|
|
30
26
|
module Rhom
|
31
|
-
|
27
|
+
UPDATE_TYPES = ["'create'","'query'","'ask'"]
|
28
|
+
|
29
|
+
class RecordNotFound < StandardError
|
30
|
+
end
|
32
31
|
|
33
32
|
class Rhom
|
34
|
-
include RhomObject
|
35
33
|
attr_accessor :factory
|
36
34
|
|
37
35
|
def initialize
|
@@ -40,18 +38,33 @@ module Rhom
|
|
40
38
|
|
41
39
|
class << Rhom
|
42
40
|
def client_id
|
43
|
-
c_id = ::Rhom::RhomDbAdapter
|
41
|
+
c_id = ::Rhom::RhomDbAdapter.select_from_table('client_info','client_id')[0]
|
44
42
|
c_id.nil? ? nil : c_id['client_id']
|
45
43
|
end
|
46
44
|
|
47
45
|
def database_full_reset
|
48
|
-
|
49
|
-
|
46
|
+
SyncEngine.stop_sync
|
47
|
+
|
48
|
+
::Rhom::RhomDbAdapter.execute_sql("UPDATE client_info SET reset=1")
|
49
|
+
|
50
|
+
if defined? RHO_ME
|
51
|
+
::Rhom::RhomDbAdapter.execute_sql("UPDATE sources SET token=NULL")
|
52
|
+
else
|
53
|
+
::Rhom::RhomDbAdapter.execute_sql("UPDATE sources SET token=0")
|
54
|
+
end
|
55
|
+
|
56
|
+
if defined? RHO_DBME
|
57
|
+
::Rhom::RhomDbAdapter.destroy_table('object_values')
|
58
|
+
#::Rhom::RhomDbAdapter.delete_all_from_table('object_values')
|
59
|
+
else
|
60
|
+
::Rhom::RhomDbAdapter.delete_all_from_table('object_values')
|
61
|
+
::Rhom::RhomDbAdapter.execute_sql("VACUUM")
|
62
|
+
end
|
50
63
|
end
|
51
64
|
|
52
65
|
def database_full_reset_and_logout
|
53
66
|
database_full_reset
|
54
|
-
SyncEngine
|
67
|
+
SyncEngine.logout
|
55
68
|
end
|
56
69
|
end #class methods
|
57
70
|
end # Rhom
|
data/lib/rhom/rhom_db_adapter.rb
CHANGED
@@ -17,20 +17,18 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
#
|
20
|
-
#$:.unshift(File.join(File.dirname(__FILE__), '../../'))
|
21
|
-
# require 'sqlite3/database'
|
22
20
|
require 'rhodes'
|
23
21
|
|
24
22
|
module Rhom
|
25
23
|
class RhomDbAdapter
|
26
24
|
|
27
25
|
@@database = nil
|
26
|
+
@@inside_transaction = false
|
28
27
|
|
29
28
|
class << self
|
30
29
|
|
31
30
|
# maintains a single database connection
|
32
31
|
def open(dbfile=nil)
|
33
|
-
#puts "DB name = " + dbfile.inspect
|
34
32
|
unless @@database or dbfile.nil?
|
35
33
|
@@database = SQLite3::Database.new(dbfile)
|
36
34
|
end
|
@@ -38,7 +36,7 @@ module Rhom
|
|
38
36
|
|
39
37
|
# closes the database if and only if it is open
|
40
38
|
def close
|
41
|
-
if @@database
|
39
|
+
if @@database
|
42
40
|
@@database.close
|
43
41
|
@@database = nil
|
44
42
|
else
|
@@ -47,32 +45,58 @@ module Rhom
|
|
47
45
|
return true
|
48
46
|
end
|
49
47
|
|
48
|
+
def start_transaction
|
49
|
+
begin
|
50
|
+
@@inside_transaction = true
|
51
|
+
@@database.start_transaction
|
52
|
+
rescue Exception => e
|
53
|
+
puts "exception when start_transaction"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def commit
|
58
|
+
begin
|
59
|
+
@@inside_transaction = false
|
60
|
+
@@database.commit
|
61
|
+
rescue Exception => e
|
62
|
+
puts "exception when commit transaction"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def rollback
|
67
|
+
begin
|
68
|
+
@@inside_transaction = false
|
69
|
+
@@database.rollback
|
70
|
+
rescue Exception => e
|
71
|
+
puts "exception when rollback transaction"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
50
75
|
# execute a sql statement
|
51
76
|
# optionally, disable the factory processing
|
52
77
|
# which returns the result array directly
|
53
78
|
def execute_sql(sql=nil)
|
54
79
|
result = []
|
55
80
|
if sql
|
56
|
-
#puts
|
81
|
+
#puts "RhomDbAdapter: Executing query - #{sql}"
|
57
82
|
# Make sure we lock the sync engine's mutex
|
58
83
|
# before we perform a database transaction.
|
59
84
|
# This prevents concurrency issues.
|
60
85
|
begin
|
61
|
-
SyncEngine
|
62
|
-
# execute sql statement inside of transaction
|
63
|
-
# result is returned as an array of hashes
|
64
|
-
# @@database.transaction unless @@database.transaction_active?
|
65
|
-
# @@database.results_as_hash = true
|
86
|
+
SyncEngine.lock_sync_mutex unless @@inside_transaction
|
66
87
|
result = @@database.execute sql
|
67
|
-
|
68
|
-
SyncEngine::unlock_sync_mutex
|
88
|
+
SyncEngine.unlock_sync_mutex unless @@inside_transaction
|
69
89
|
rescue Exception => e
|
70
|
-
puts "exception when running query: #{e}"
|
90
|
+
#puts "exception when running query: #{e}"
|
71
91
|
# make sure we unlock even if there's an error!
|
72
|
-
|
92
|
+
if @@inside_transaction
|
93
|
+
raise
|
94
|
+
else
|
95
|
+
SyncEngine.unlock_sync_mutex
|
96
|
+
end
|
73
97
|
end
|
74
98
|
end
|
75
|
-
#puts "
|
99
|
+
#puts "result is: #{result.inspect}"
|
76
100
|
result
|
77
101
|
end
|
78
102
|
|
@@ -87,7 +111,6 @@ module Rhom
|
|
87
111
|
if select_arr and select_arr.length > 0
|
88
112
|
where_str += " and attrib in (#{select_str(select_arr)})"
|
89
113
|
end
|
90
|
-
#puts "where_str: #{where_str}" if where_str
|
91
114
|
where_str
|
92
115
|
end
|
93
116
|
|
@@ -109,19 +132,20 @@ module Rhom
|
|
109
132
|
def string_from_key_vals(values, delim)
|
110
133
|
vals = ""
|
111
134
|
values.each do |key,value|
|
112
|
-
|
135
|
+
op = value.nil? ? 'is ' : '= '
|
136
|
+
vals << " \"#{key}\" #{op} #{get_value_for_sql_stmt(value)} #{delim}"
|
113
137
|
end
|
114
138
|
vals
|
115
139
|
end
|
116
140
|
|
117
141
|
# generates a value for sql statement
|
118
142
|
def get_value_for_sql_stmt(value)
|
119
|
-
if value.
|
120
|
-
"'#{value}'"
|
121
|
-
elsif value.nil?
|
143
|
+
if value.nil? or value == 'NULL'
|
122
144
|
"NULL"
|
145
|
+
elsif value.is_a?(String)
|
146
|
+
"'#{value}'"
|
123
147
|
else
|
124
|
-
"#{value}"
|
148
|
+
"'#{value.to_s}'"
|
125
149
|
end
|
126
150
|
end
|
127
151
|
|
@@ -193,7 +217,16 @@ module Rhom
|
|
193
217
|
end
|
194
218
|
execute_sql query
|
195
219
|
end
|
196
|
-
|
220
|
+
|
221
|
+
# deletes all rows from a given table by recreating db-file and save all other tables
|
222
|
+
def destroy_table(table)
|
223
|
+
query = nil
|
224
|
+
if table
|
225
|
+
query = "destroy #{table}"
|
226
|
+
end
|
227
|
+
execute_sql query
|
228
|
+
end
|
229
|
+
|
197
230
|
# updates values (hash) in a given table which satisfy condition (hash)
|
198
231
|
# example usage is the following:
|
199
232
|
# update_into_table('object_values',{"value"=>"Electronics"},{"object"=>"some-object", "attrib"=>"industry"})
|
@@ -212,5 +245,5 @@ module Rhom
|
|
212
245
|
end # Rhom
|
213
246
|
|
214
247
|
at_exit do
|
215
|
-
Rhom::RhomDbAdapter
|
248
|
+
::Rhom::RhomDbAdapter.close
|
216
249
|
end
|