hypersonicplus 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/hdatastructures/hfieldtable.rb +285 -0
- data/lib/hdatastructures/hhash.rb +9 -0
- data/lib/hdatastructures/hlist.rb +100 -0
- data/lib/hdatastructures/hrecord.rb +75 -0
- data/lib/hdatastructures/hspreadfieldtable.rb +129 -0
- data/lib/hdb/hdataloader.rb +75 -0
- data/lib/hdb/hdb.rb +357 -0
- data/lib/hdb/hdb_test.rb +248 -0
- data/lib/hdb/hdbgenerator.rb +211 -0
- data/lib/hdb/hdbi.rb +63 -0
- data/lib/hdb/hdbi_test.rb +133 -0
- data/lib/hdb/hfield.rb +180 -0
- data/lib/hdb/hmysql.rb +99 -0
- data/lib/hdb/hmysql2.rb +96 -0
- data/lib/hdb/hodb.rb +948 -0
- data/lib/hdb/hpgsql.rb +54 -0
- data/lib/hengine/application_controller.rb +204 -0
- data/lib/hengine/hconfiguration.rb +40 -0
- data/lib/hengine/hhotlogger.rb +13 -0
- data/lib/hengine/hlogger.rb +119 -0
- data/lib/hengine/hmalloc.rb +275 -0
- data/lib/hengine/hmoduleloader.rb +15 -0
- data/lib/hengine/hsessiondata.rb +79 -0
- data/lib/hengine/hshareddata.rb +60 -0
- data/lib/hengine/htranslate.rb +40 -0
- data/lib/hengine/hviewloader.rb +99 -0
- data/lib/hinit/hinit.rb +3 -0
- data/lib/hmisc/hcolorize.rb +100 -0
- data/lib/hmisc/hdecoratorfunctions.rb +15 -0
- data/lib/hmisc/hdir.rb +19 -0
- data/lib/hmisc/hhtmlnode.rb +27 -0
- data/lib/hmisc/hinputvalidator.rb +95 -0
- data/lib/hmisc/hio.rb +142 -0
- data/lib/hmisc/hjson.rb +16 -0
- data/lib/hsqlmanager/hpgsqldatabasemanager.rb +76 -0
- data/lib/hsqlmanager/hsqldatabasemanager.rb +349 -0
- data/lib/hsqlmanager/hsqltable.rb +16 -0
- data/lib/husermanager/husermanager.rb +122 -0
- data/lib/hwidgets/haccordionmenu.rb +117 -0
- data/lib/hwidgets/hcheckboxtag.rb +33 -0
- data/lib/hwidgets/hdbactionbuttons.rb +26 -0
- data/lib/hwidgets/hdbcombobox.rb +71 -0
- data/lib/hwidgets/hdbdialogview.rb +190 -0
- data/lib/hwidgets/hdbfilterview.rb +28 -0
- data/lib/hwidgets/hdbtableview.rb +213 -0
- data/lib/hwidgets/hdbview.rb +63 -0
- data/lib/hwidgets/hdivtag.rb +9 -0
- data/lib/hwidgets/hdropdown.rb +44 -0
- data/lib/hwidgets/hformfield.rb +91 -0
- data/lib/hwidgets/hgrouptag.rb +65 -0
- data/lib/hwidgets/hhiddeninputtag.rb +12 -0
- data/lib/hwidgets/hinputtag.rb +55 -0
- data/lib/hwidgets/hlabeltag.rb +30 -0
- data/lib/hwidgets/hmainview.rb +37 -0
- data/lib/hwidgets/hpagination.rb +65 -0
- data/lib/hwidgets/hradiobuttontag.rb +30 -0
- data/lib/hwidgets/hselecttag.rb +32 -0
- data/lib/hwidgets/htableview.rb +262 -0
- data/lib/hwidgets/htabview.rb +84 -0
- data/lib/hwidgets/htextareatag.rb +20 -0
- data/lib/hwidgets/htopnav.rb +85 -0
- data/lib/hwidgets/hwidget.rb +423 -0
- data/lib/hypersonic.rb +9 -0
- metadata +276 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Go to http://rubular.com to try the regex strings
|
4
|
+
|
5
|
+
class HInputValidator
|
6
|
+
|
7
|
+
def self.isValid?(input) # General Validation
|
8
|
+
|
9
|
+
return self.isLengthValid?(input)
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.isLengthValid?(input)
|
14
|
+
|
15
|
+
regex = /\A.{0,40}\z/
|
16
|
+
return !(input !~ regex)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.isMandatory?(input)
|
21
|
+
|
22
|
+
regex = /\A.{1,500}\z/
|
23
|
+
return !(input !~ regex) && self.isValid?(input)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.isPassword?(input)
|
28
|
+
|
29
|
+
regex = /^[\w.@!$\-]{5,}$/ # at least 5 character, are allow the follows special chars: . @ ! $ -
|
30
|
+
return !(input !~ regex) && self.isValid?(input)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.isReal?(input)
|
35
|
+
|
36
|
+
regex = /^-?[0-9]\d*(\.\d+)?$/
|
37
|
+
return !(input !~ regex) && self.isValid?(input)
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.isInteger?(input)
|
42
|
+
|
43
|
+
regex = /\A-?[0-9]+\z/
|
44
|
+
return !(input !~ regex) && self.isValid?(input)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.isNatural?(input)
|
49
|
+
|
50
|
+
regex = /\A[0-9]+\z/
|
51
|
+
return !(input !~ regex) && self.isValid?(input)
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.isEmail?(input)
|
56
|
+
|
57
|
+
regex = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
|
58
|
+
return !(input !~ regex) && self.isValid?(input)
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.isUnique?(fieldValue, fieldName, modelName)
|
63
|
+
|
64
|
+
result = HSqlTable.new().loadFromQuery("select count(*) from #{modelName} where #{fieldName} = '#{fieldValue}'")[0][0]
|
65
|
+
return (result == "1") && self.isValid?(fieldValue)
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
# isValid("hb@gmail.com", "email,unique", "email", "users")
|
70
|
+
def self.isValid(fieldValue, fieldType, fieldName, modelName)
|
71
|
+
|
72
|
+
result = true
|
73
|
+
types = fieldType.split(",")
|
74
|
+
types.each do |type|
|
75
|
+
type = type.strip()
|
76
|
+
result &&= self.isLengthValid?(fieldValue) if (type == "length")
|
77
|
+
result &&= self.isMandatory?(fieldValue) if (type == "mandatory")
|
78
|
+
result &&= self.isPassword?(fieldValue) if (type == "password")
|
79
|
+
result &&= self.isReal?(fieldValue) if (type == "real")
|
80
|
+
result &&= self.isInteger?(fieldValue) if (type == "integer")
|
81
|
+
result &&= self.isNatural?(fieldValue) if (type == "natural")
|
82
|
+
result &&= self.isEmail?(fieldValue) if (type == "email")
|
83
|
+
result &&= self.isUnique?(fieldValue, fieldName, modelName) if (type == "unique")
|
84
|
+
end
|
85
|
+
|
86
|
+
return (result) ? "true": "false"
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.valid?(fieldValue: nil, fieldType: nil, fieldName: nil, modelName: nil)
|
91
|
+
return self.isValid(fieldValue, fieldType, fieldName, modelName)
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
end
|
data/lib/hmisc/hio.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'net/smtp'
|
4
|
+
require 'mail'
|
5
|
+
|
6
|
+
def puta(array, margin: 0)
|
7
|
+
array.each do |value|
|
8
|
+
puts " " * margin + "#{value}".green if value.class != Hash and value.class != Array
|
9
|
+
puth(value, margin: margin + 3) if value.class == Hash
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def puth(hash, margin: 0)
|
14
|
+
hash.each do |key, value|
|
15
|
+
puts " " * margin + "#{key}:".hight_cyan
|
16
|
+
puts " " * (margin + 3) + "#{value}".hight_cyan if value.class != Hash and value.class != Array
|
17
|
+
puta(value, margin: margin + 3) if value.class == Array
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class HIO
|
22
|
+
|
23
|
+
@@indentSpace = 0
|
24
|
+
|
25
|
+
def self.htmlEcholn(str)
|
26
|
+
return "" if (str == "")
|
27
|
+
#return str.to_s
|
28
|
+
return str.to_s + "\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.htmlEcholnOpenBlock(str)
|
32
|
+
|
33
|
+
result = self.htmlEcholn(str)
|
34
|
+
@@indentSpace += 1
|
35
|
+
return result
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.htmlEcholnCloseBlock(str)
|
40
|
+
|
41
|
+
@@indentSpace -= 1
|
42
|
+
return self.htmlEcholn(str);
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.quote(str)
|
47
|
+
return "'#{str}'";
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.isQuoted(str)
|
51
|
+
|
52
|
+
return (str[0] == "'" && str[-1] == "'")
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.unQuote(str)
|
57
|
+
|
58
|
+
return isQuoted(str) ? str[1..-2] : str
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.gmailOptions(username, password)
|
63
|
+
|
64
|
+
return options = {
|
65
|
+
:address => "smtp.gmail.com",
|
66
|
+
:port => 587,
|
67
|
+
:user_name => username,
|
68
|
+
:password => password,
|
69
|
+
:authentication => 'plain',
|
70
|
+
:enable_starttls_auto => true
|
71
|
+
}
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def self.gmxOptions(username, password)
|
77
|
+
|
78
|
+
return options = {
|
79
|
+
:address => "mail.gmx.com",
|
80
|
+
:port => 587,
|
81
|
+
:user_name => username,
|
82
|
+
:password => password,
|
83
|
+
:authentication => 'plain',
|
84
|
+
:enable_starttls_auto => true
|
85
|
+
}
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.options(emailFrom, emailPassword)
|
90
|
+
|
91
|
+
provider = emailFrom[emailFrom.index('@') + 1, emailFrom.size - 1]
|
92
|
+
return self.gmxOptions(emailFrom, emailPassword) if(provider == "gmx.com")
|
93
|
+
return self.gmailOptions(emailFrom, emailPassword) if(provider == "gmail.com")
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def self.sendEmail(emailFrom, emailTo, emailSubject, emailBody, emailPassword = "quickorder", emailFromName = "")
|
99
|
+
|
100
|
+
Mail.defaults do
|
101
|
+
delivery_method :smtp, self.options(emailFrom, emailPassword)
|
102
|
+
end
|
103
|
+
|
104
|
+
Mail.deliver do
|
105
|
+
to emailTo
|
106
|
+
from emailFrom
|
107
|
+
subject emailSubject
|
108
|
+
body emailBody
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
=begin
|
114
|
+
message = <<MESSAGE_END
|
115
|
+
From: Private Person <herbert.bonaffini@gmx.com>
|
116
|
+
To: A Test User <herbert.bonaffini@gmail.com>
|
117
|
+
Subject: SMTP e-mail test
|
118
|
+
|
119
|
+
This is a test e-mail message.
|
120
|
+
MESSAGE_END
|
121
|
+
|
122
|
+
Net::SMTP.start('smtp.gmx.com', 465, 'localhost', 'herbert.bonaffini@gmx.com', 'quickorder', :plain) do |smtp|
|
123
|
+
smtp.send_message message, 'herbert.bonaffini@gmx.com',
|
124
|
+
'herbert.bonaffini@gmail.com'
|
125
|
+
end
|
126
|
+
|
127
|
+
|
128
|
+
provider = substr($emailFrom, strpos($emailFrom, '@') + 1);
|
129
|
+
|
130
|
+
if(provider == "gmx.com")
|
131
|
+
phpMailer = HIO::gmxPHPmailer();
|
132
|
+
else
|
133
|
+
phpMailer = HIO::gmailPHPmailer();
|
134
|
+
|
135
|
+
phpMailer->Username = emailFrom;
|
136
|
+
phpMailer->Password = password;
|
137
|
+
=end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
data/lib/hmisc/hjson.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
ESCAPED_CHARS = {
|
2
|
+
'>' => '\u003e',
|
3
|
+
'<' => '\u003c',
|
4
|
+
'&' => '\u0026',
|
5
|
+
"\u2028" => '\u2028',
|
6
|
+
"\u2029" => '\u2029',
|
7
|
+
}
|
8
|
+
|
9
|
+
ESCAPE_REGEX_WITH_HTML_ENTITIES = /[\u2028\u2029><&]/u
|
10
|
+
|
11
|
+
class String
|
12
|
+
def to_json
|
13
|
+
super.gsub ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "hsqlmanager/hsqldatabasemanager"
|
4
|
+
|
5
|
+
class HPgSqlDatabaseManager < HSqlDatabaseManager
|
6
|
+
|
7
|
+
def connect()
|
8
|
+
|
9
|
+
timezone = hc.value("timezone")
|
10
|
+
|
11
|
+
return @connection if(@connection != nil)
|
12
|
+
|
13
|
+
connectionPtr = HSharedData.instance().value("pg-#{@dbname}")
|
14
|
+
return connectionPtr.connection if (connectionPtr != nil)
|
15
|
+
|
16
|
+
connection = PGconn.new(@host, @port, "", "", @dbname, @user, @password)
|
17
|
+
HSharedData.instance().setValue(self, "pg-#{@dbname}")
|
18
|
+
puts "Server version: #{connection.query("SHOW server_version").to_s}"
|
19
|
+
connection.query("SET TIME ZONE '#{timezone}'");
|
20
|
+
return connection
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def close()
|
25
|
+
|
26
|
+
HSharedData.instance().setValue(nil, "pg-#{@dbname}")
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.setPgSqlConnection()
|
31
|
+
|
32
|
+
host = hc.value("host")
|
33
|
+
port = hc.value("port")
|
34
|
+
dbname = hc.value("dbname")
|
35
|
+
user = hc.value("user")
|
36
|
+
password = hc.value("password")
|
37
|
+
|
38
|
+
pgSqlDatabaseManager = HPgSqlDatabaseManager.new(host, port, dbname, user, password)
|
39
|
+
pgSqlDatabaseManager.openConnection()
|
40
|
+
return pgSqlDatabaseManager
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def self.defaultPgSqlDatabaseManager()
|
46
|
+
|
47
|
+
pgDbName = hc.value("pg_dbname")
|
48
|
+
pgSqlDatabaseManager = HSharedData.instance().value("pg-#{pgDbName}")
|
49
|
+
return (pgSqlDatabaseManager == nil) ? self.setPgSqlConnection() : pgSqlDatabaseManager
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def self.test1()
|
55
|
+
|
56
|
+
pgSqlDatabaseManager = HPgSqlDatabaseManager.new("127.0.0.1", "5432", "quickorder", "quickorder", "quickorder")
|
57
|
+
pgSqlDatabaseManager.openConnection()
|
58
|
+
# la seguente query genera 3 colonne invece di 4
|
59
|
+
# si tratta di un bug
|
60
|
+
result = pgSqlDatabaseManager.run("select id, name, price, name from cookbook")
|
61
|
+
# come toppa si puo' usare la seguente query
|
62
|
+
#result = pgSqlDatabaseManager.run("select id, name, price, name as ciao from cookbook")
|
63
|
+
pgSqlDatabaseManager.show()
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def hpgsql()
|
70
|
+
|
71
|
+
return HPgSqlDatabaseManager.defaultPgSqlDatabaseManager()
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
#hpgsql.test1
|
76
|
+
|
@@ -0,0 +1,349 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# databaseManager.select("id, name").from("cookbook").where("id > 10").orderBy("id").limit(5).offset(5).run().show()
|
4
|
+
|
5
|
+
|
6
|
+
class HSqlDatabaseManager
|
7
|
+
|
8
|
+
attr_reader :resultTable, :connection
|
9
|
+
|
10
|
+
def initialize(host, port, dbname, user, password)
|
11
|
+
|
12
|
+
@host = host
|
13
|
+
@port = port
|
14
|
+
@dbname = dbname
|
15
|
+
@user = user
|
16
|
+
@password = password
|
17
|
+
|
18
|
+
@connection = nil
|
19
|
+
|
20
|
+
@select = nil
|
21
|
+
@from = nil
|
22
|
+
@where = nil
|
23
|
+
@orderBy = nil
|
24
|
+
@limit = nil
|
25
|
+
@offset = nil
|
26
|
+
|
27
|
+
@resultTable = nil
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# posso passare anche un array di campi
|
32
|
+
def select(select)
|
33
|
+
select = select.join(',') if(select.class == Array)
|
34
|
+
@select = select
|
35
|
+
return self
|
36
|
+
end
|
37
|
+
def from(from)
|
38
|
+
@from = from
|
39
|
+
return self
|
40
|
+
end
|
41
|
+
def where(where)
|
42
|
+
@where = where
|
43
|
+
return self
|
44
|
+
end
|
45
|
+
def orderBy(orderBy)
|
46
|
+
@orderBy = orderBy
|
47
|
+
return self
|
48
|
+
end
|
49
|
+
def limit(limit)
|
50
|
+
@limit = limit
|
51
|
+
return self
|
52
|
+
end
|
53
|
+
def offset(offset)
|
54
|
+
@offset = offset
|
55
|
+
return self
|
56
|
+
end
|
57
|
+
|
58
|
+
def queryStr()
|
59
|
+
|
60
|
+
where = "where #{@where}" if(@where)
|
61
|
+
orderBy = "order by #{@orderBy}" if(@orderBy)
|
62
|
+
limit = "limit #{@limit}" if(@limit)
|
63
|
+
offset = "offset #{@offset}" if(@offset)
|
64
|
+
return "select #{@select} from #{@from} #{where} #{orderBy} #{limit} #{offset}"
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def openConnection()
|
70
|
+
|
71
|
+
@connection = self.connect() if(@connection == nil)
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def closeConnection()
|
77
|
+
|
78
|
+
@connection.close() if(@connection != nil)
|
79
|
+
@connection = nil
|
80
|
+
self.close()
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def fieldNameList()
|
86
|
+
|
87
|
+
fieldList = HList.new()
|
88
|
+
|
89
|
+
for i in (0..@resultTable.nfields() - 1)
|
90
|
+
fieldList.insertTail(HRecord.new(@resultTable.fname(i)))
|
91
|
+
end
|
92
|
+
|
93
|
+
return fieldList
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
def run(queryStr = self.queryStr)
|
98
|
+
|
99
|
+
@resultTable = @connection.query(queryStr)
|
100
|
+
return self
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
# def setQuery(queryStr)
|
105
|
+
# return self.run(queryStr)
|
106
|
+
# end
|
107
|
+
|
108
|
+
def runWithPaging(pageSize = "all", page = 0, queryStr = self.queryStr)
|
109
|
+
|
110
|
+
limit = "limit #{pageSize}"
|
111
|
+
offset = "offset #{page} * #{pageSize}"
|
112
|
+
if(pageSize == "all")
|
113
|
+
limit = offset = ""
|
114
|
+
end
|
115
|
+
|
116
|
+
queryStr += " #{limit} #{offset}"
|
117
|
+
|
118
|
+
return self.run(queryStr)
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
def dataByFieldName(row, fieldName)
|
123
|
+
|
124
|
+
return nil if(@resultTable.count() == 0)
|
125
|
+
return @resultTable[row][fieldName]
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
def dataByFieldIndex(row, fieldIndex)
|
130
|
+
|
131
|
+
return self.dataByFieldName(row, @resultTable.keys[fieldIndex])
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
# Se si vuole efficienza conviene non usare la seguente funzione
|
136
|
+
# ma le precedenti
|
137
|
+
def toSqlTable()
|
138
|
+
|
139
|
+
sqlTable = HSqlTable.new()
|
140
|
+
|
141
|
+
fieldNameList = self.fieldNameList()
|
142
|
+
|
143
|
+
fieldNameList.eachWithIndex do |fieldName, i|
|
144
|
+
sqlTable.setFieldName(i, fieldName.value(), "true");
|
145
|
+
end
|
146
|
+
|
147
|
+
@resultTable.each_with_index do |row, i|
|
148
|
+
j = 0
|
149
|
+
row.each do |key, value|
|
150
|
+
sqlTable.setDataByFieldIndex(i, j, HRecord.new(value))
|
151
|
+
j += 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
return sqlTable
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
def rowCount()
|
160
|
+
|
161
|
+
return @resultTable.count()
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
def columnCount()
|
166
|
+
|
167
|
+
return 0 if(self.rowCount() == 0)
|
168
|
+
return @resultTable[0].count()
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
def quoteValue(value)
|
174
|
+
|
175
|
+
return nil unless(value)
|
176
|
+
return (value[0] != '#') ? "'#{value}'" : value[1, value.size - 1]
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
# quota tutti i valori tranne quelli che iniziano con #
|
182
|
+
# quindi se nella mia query devo richiamare una funzione basta farla precedere dal cancelletto
|
183
|
+
def quote(args)
|
184
|
+
|
185
|
+
return nil unless(args)
|
186
|
+
|
187
|
+
result = Hash.new()
|
188
|
+
|
189
|
+
args.each do |key, value|
|
190
|
+
result[key] = self.quoteValue(args[key])
|
191
|
+
end
|
192
|
+
return result
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
def insertValues(args)
|
198
|
+
|
199
|
+
return "(id) values(default)" unless(args)
|
200
|
+
|
201
|
+
args = self.quote(args)
|
202
|
+
|
203
|
+
keys = args.keys
|
204
|
+
|
205
|
+
result = "("
|
206
|
+
i = -1
|
207
|
+
for i in (0..args.count - 2) do
|
208
|
+
result += "#{keys[i]}, "
|
209
|
+
end
|
210
|
+
result += "#{keys[i + 1]}) values("
|
211
|
+
i = -1
|
212
|
+
for i in (0..args.count - 2) do
|
213
|
+
result += "#{args[keys[i]]}, "
|
214
|
+
end
|
215
|
+
result += "#{args[keys[i + 1]]})"
|
216
|
+
return result
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
def updateValues(args)
|
221
|
+
|
222
|
+
return "" unless(args)
|
223
|
+
|
224
|
+
args = self.quote(args)
|
225
|
+
|
226
|
+
keys = args.keys
|
227
|
+
|
228
|
+
result = ""
|
229
|
+
i = -1
|
230
|
+
for i in (0..args.count - 2) do
|
231
|
+
result += "#{keys[i]} = #{args[keys[i]]}, "
|
232
|
+
end
|
233
|
+
result += "#{keys[i + 1]} = #{args[keys[i + 1]]}"
|
234
|
+
|
235
|
+
return result
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
def insertOrUpdateIfExist(tableName, where, values = nil)
|
240
|
+
|
241
|
+
resultTable = self.run("select id from #{tableName} where #{where} ").resultTable
|
242
|
+
if(resultTable.count == 0)
|
243
|
+
insertQuery = "insert into #{tableName} #{self.insertValues(values)} returning id"
|
244
|
+
p "================= insertOrUpdateIfExist ================== ", insertQuery
|
245
|
+
newId = self.run(insertQuery).resultTable[0]["id"]
|
246
|
+
return newId
|
247
|
+
else
|
248
|
+
p values
|
249
|
+
updateQuery = "update #{tableName} set #{self.updateValues(values)} where #{where}"
|
250
|
+
p updateQuery
|
251
|
+
self.run(updateQuery) if(values)
|
252
|
+
return resultTable[0]["id"]
|
253
|
+
end
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
def insertOrUpdateIfExistCached(tableName, dialogViewLevel, id, values)
|
258
|
+
|
259
|
+
value = {}
|
260
|
+
value[:view_level] = dialogViewLevel
|
261
|
+
value[:table_name] = tableName
|
262
|
+
value[:field_id] = id
|
263
|
+
value[:field_value] = values
|
264
|
+
value[:state] = "none"
|
265
|
+
|
266
|
+
return self.insertOrUpdateIfExist("cache_table", "table_name = '#{tableName}' and field_id = #{id}", value)
|
267
|
+
|
268
|
+
end
|
269
|
+
|
270
|
+
def unloadCache(tableName, dialogViewLevel, id)
|
271
|
+
|
272
|
+
p "unloadCache"
|
273
|
+
resultTable = self.run("select field_id, field_value from cache_table where table_name = '#{tableName}'").resultTable
|
274
|
+
resultTable.each do |row|
|
275
|
+
self.insertOrUpdateIfExist(tableName, "id = #{row['field_id']}", eval(row['field_value']))
|
276
|
+
end
|
277
|
+
self.run("delete from cache_table where table_name = '#{tableName}'").resultTable
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
def deleteCacheBranch(tableName, dialogViewLevel)
|
282
|
+
|
283
|
+
self.run("delete from cache_table where table_name = '#{tableName}' and view_level >= #{dialogViewLevel}").resultTable
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
def setParentChildTableValues(parentTableName, childTableName, where, parentValues, childValues)
|
288
|
+
|
289
|
+
parentTableId = self.insertOrUpdateIfExist("#{parentTableName}_table", where, parentValues)
|
290
|
+
|
291
|
+
i = 0
|
292
|
+
record = Hash.new()
|
293
|
+
childValues.each do |key, value|
|
294
|
+
childRecord = {"#{parentTableName}_id" => parentTableId,
|
295
|
+
:field_name => key,
|
296
|
+
:field_value => value,
|
297
|
+
:ordering => i}
|
298
|
+
recordWhere = "#{parentTableName}_id = #{parentTableId} and field_name = '#{key}'"
|
299
|
+
self.insertOrUpdateIfExist("#{childTableName}_table", recordWhere, childRecord)
|
300
|
+
i += 1
|
301
|
+
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
def extractFromHash(value, key = nil)
|
306
|
+
|
307
|
+
return nil unless(value)
|
308
|
+
value = eval(value) if(value[0] == '{' && value[-1] == '}') # E' un hash table
|
309
|
+
return value[key] if(value && key)
|
310
|
+
return value
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
def parentChildValueOf(parentTableName, childTableName, parentTableId, fieldName, key = nil)
|
315
|
+
|
316
|
+
return nil if(parentTableId == -1)
|
317
|
+
|
318
|
+
selectQuery = "select field_value from #{childTableName}_table where field_name = '#{fieldName}' and #{parentTableName}_id = #{parentTableId}"
|
319
|
+
value = self.run(selectQuery).dataByFieldName(0, "field_value")
|
320
|
+
return extractFromHash(value, key)
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
def parentChildValueOfByUsername(parentTableName, childTableName, username, fieldName, key = nil)
|
325
|
+
|
326
|
+
selectQuery = "select id from #{parentTableName}_table where username = '#{username}'"
|
327
|
+
parentTableId = self.run(selectQuery).dataByFieldName(0, "id")
|
328
|
+
return self.parentChildValueOf(parentTableName, childTableName, parentTableId, fieldName, key)
|
329
|
+
|
330
|
+
end
|
331
|
+
|
332
|
+
def show()
|
333
|
+
|
334
|
+
self.fieldNameList().show()
|
335
|
+
puts
|
336
|
+
@resultTable.each do |row|
|
337
|
+
row.each do |key, value|
|
338
|
+
print "%-15s" % row[key]
|
339
|
+
end
|
340
|
+
puts
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|