hypersonic-plus 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/hdb/hdbi.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'dbi'
|
3
|
+
require 'hdb/hdb'
|
4
|
+
|
5
|
+
class HDBI < HDB
|
6
|
+
|
7
|
+
def initialize(host, port, dbname, user, password, timezone, connectionName, connector = "Pg")
|
8
|
+
|
9
|
+
super(host, port, dbname, user, password, timezone, connectionName, connector)
|
10
|
+
@connector = connector
|
11
|
+
@sth = nil
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def connect()
|
16
|
+
|
17
|
+
@connection = DBI.connect("dbi:#{@connector}:#{@dbname}:#{@host}", @user, @password)
|
18
|
+
hl << "Server version: #{self.execute("SHOW server_version").firstData.to_s}"
|
19
|
+
self.execute("SET TIME ZONE '#{@timezone}'") if @timezone
|
20
|
+
return @connection
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def disconnect()
|
25
|
+
|
26
|
+
@connection.disconnect()
|
27
|
+
@connection = nil
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def _execute(queryStr = self.queryStr)
|
32
|
+
|
33
|
+
@sth = @connection.execute(queryStr)
|
34
|
+
result = @sth.fetch_all
|
35
|
+
@resultTable = HFieldTable.new()
|
36
|
+
self.fieldNameList().each { |fieldName| @resultTable.addFieldName(fieldName) }
|
37
|
+
@resultTable.makeCaption()
|
38
|
+
result.each_with_index do |row, i|
|
39
|
+
row.each_with_name do |fieldValue, fieldName|
|
40
|
+
@resultTable.setDataByFieldName(i, fieldName, fieldValue)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
@sth.finish
|
44
|
+
@sth = nil
|
45
|
+
return self
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def fieldNameList()
|
50
|
+
|
51
|
+
fieldList = HList.new()
|
52
|
+
|
53
|
+
@sth.column_names.each { |fieldName| fieldList << fieldName }
|
54
|
+
|
55
|
+
return fieldList
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def rowsAffected
|
60
|
+
return @sth.rows # rows affected
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'hdb/hdbi.rb'
|
3
|
+
|
4
|
+
class HDBI
|
5
|
+
|
6
|
+
def self.testx
|
7
|
+
resultTable = hdb.select([:id, :name]).from(:recipe_types).where(["id > 0", "id < 20000"]).orderBy([:id, :name]).execute
|
8
|
+
resultTable.show
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.testxx
|
12
|
+
resultTable = hdb("quickorder_pg").select([:id, :name]).from(:recipe_types).where(["id > 0", "id < 20000"]).orderBy([:id, :name]).execute
|
13
|
+
resultTable.show
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.testmysql
|
17
|
+
id = hdb("quickorder").insert(:city_table, {name: "Wien"})
|
18
|
+
puts "id: #{id}"
|
19
|
+
resultTable = hdb("quickorder").select([:id, :name]).from(:city_table).where(["id > 0", "id < 20"]).orderBy([:id, :name]).execute
|
20
|
+
resultTable.show
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.test
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def self.test0
|
28
|
+
|
29
|
+
hdb = HDB.new('localhost', '5432', 'quickorder', 'quickorder', 'quickorder')
|
30
|
+
hdb.openConnection()
|
31
|
+
resultTable = hdb.select([:id, :name]).from(:cookbook).where(["id > 0", "id < 200"]).orderBy([:id, :name]).execute
|
32
|
+
resultTable = hdb.select("id, name").from("cookbook").where("id > 0 and id < 200").execute
|
33
|
+
hdb.show()
|
34
|
+
resultTable = hdb.select([:id, :name]).from(:cookbook).where(["id > 0", "id < 200"], "or").orderBy([:id, :name]).execute(pageSize: 10, page: 2)
|
35
|
+
hdb.toSqlTable().show()
|
36
|
+
id = hdb.insert(:recipe_types, {name: "'nome"})
|
37
|
+
p "delete: " + hdb.delete(:recipe_types, {id: id, name: '10'}).to_s
|
38
|
+
hdb.select(:name).from(:recipe_types).execute
|
39
|
+
hdb.show()
|
40
|
+
hdb.closeConnection
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def self.test1
|
46
|
+
|
47
|
+
dbh = DBI.connect("dbi:Pg:quickorder:localhost", "quickorder", "quickorder")
|
48
|
+
sth = dbh.execute("select * from cookbook")
|
49
|
+
p sth.column_names
|
50
|
+
sth.fetch do |row|
|
51
|
+
#p row['name'] # or row.by_field("name")
|
52
|
+
#p row[3] # or row.by_index(3)
|
53
|
+
row.each_with_name do |fieldValue, fieldName|
|
54
|
+
p " #{fieldName}: #{fieldValue}"
|
55
|
+
end
|
56
|
+
p "======================="
|
57
|
+
end
|
58
|
+
sth.finish
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.test2
|
63
|
+
|
64
|
+
dbh = DBI.connect("dbi:Pg:quickorder:localhost", "quickorder", "quickorder")
|
65
|
+
sth = dbh.prepare("select * from cookbook where id = ?")
|
66
|
+
sth.execute(1)
|
67
|
+
p sth.column_names
|
68
|
+
sth.fetch do |row|
|
69
|
+
#p row['name'] # or row.by_field("name")
|
70
|
+
#p row[3] # or row.by_index(3)
|
71
|
+
row.each_with_name do |fieldValue, fieldName|
|
72
|
+
p " #{fieldName}: #{fieldValue}"
|
73
|
+
end
|
74
|
+
p "======================="
|
75
|
+
end
|
76
|
+
sth.finish
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
# finish isn't required
|
82
|
+
def self.test3
|
83
|
+
|
84
|
+
dbh = DBI.connect("dbi:Pg:quickorder:localhost", "quickorder", "quickorder")
|
85
|
+
rows = dbh.select_all("select * from cookbook") # con select_all o select_one non e' necessario finish
|
86
|
+
rows.each do |row|
|
87
|
+
row.each_with_name do |fieldValue, fieldName|
|
88
|
+
p " #{fieldName}: #{fieldValue}"
|
89
|
+
end
|
90
|
+
p "======================="
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
def self.test4
|
97
|
+
|
98
|
+
dbh = DBI.connect("dbi:Pg:quickorder:localhost", "quickorder", "quickorder")
|
99
|
+
dbh.do("insert into recipe_types(name, position, department) values(?, ?, ?)", 'hypersonic', 1, nil)
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.test5
|
104
|
+
|
105
|
+
dbh = DBI.connect("dbi:Pg:quickorder:localhost", "quickorder", "quickorder")
|
106
|
+
sth = dbh.prepare("insert into recipe_types(name, position, department) values(?, ?, ?)")
|
107
|
+
sth.execute('hypersonic', 1, nil)
|
108
|
+
sth.finish
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.test6
|
113
|
+
|
114
|
+
dbh = DBI.connect("dbi:Pg:quickorder:localhost", "quickorder", "quickorder")
|
115
|
+
sth = dbh.execute("select * from cookbook")
|
116
|
+
rows = sth.fetch_all
|
117
|
+
|
118
|
+
printf "Number of rows affected: %d\n", sth.rows
|
119
|
+
printf "Number of columns: %d\n", sth.column_names.size
|
120
|
+
|
121
|
+
rows.each do |row|
|
122
|
+
row.each_with_name do |fieldValue, fieldName|
|
123
|
+
p " #{fieldName}: #{fieldValue}"
|
124
|
+
end
|
125
|
+
p "======================="
|
126
|
+
end
|
127
|
+
sth.finish
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
data/lib/hdb/hfield.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
=begin
|
4
|
+
FIELDS_TO_PGTYPES = {
|
5
|
+
fields.boolean: 'bool',
|
6
|
+
fields.integer: 'int4',
|
7
|
+
fields.text: 'text',
|
8
|
+
fields.html: 'text',
|
9
|
+
fields.date: 'date',
|
10
|
+
fields.datetime: 'timestamp',
|
11
|
+
fields.binary: 'bytea',
|
12
|
+
fields.many2one: 'int4',
|
13
|
+
fields.serialized: 'text',
|
14
|
+
}
|
15
|
+
=end
|
16
|
+
|
17
|
+
class HField < Hash
|
18
|
+
|
19
|
+
def initialize(args)
|
20
|
+
args.each { |key, value| self[key] = value }
|
21
|
+
end
|
22
|
+
|
23
|
+
def defaultValue()
|
24
|
+
|
25
|
+
case self[:type]
|
26
|
+
when "char"
|
27
|
+
return 'true'
|
28
|
+
when "text"
|
29
|
+
return ''
|
30
|
+
when "integer"
|
31
|
+
return 0
|
32
|
+
when "float"
|
33
|
+
return 0
|
34
|
+
when "date"
|
35
|
+
return ''
|
36
|
+
when "dateTime"
|
37
|
+
return ''
|
38
|
+
when "binary"
|
39
|
+
return ''
|
40
|
+
when "selection"
|
41
|
+
return ''
|
42
|
+
when "boolean"
|
43
|
+
return 'true'
|
44
|
+
else
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.autoComplete(modelName, fieldName, args = {})
|
51
|
+
|
52
|
+
return args if args[:type] != "automatic"
|
53
|
+
|
54
|
+
if fieldName =~ /^(\w+)_id$/
|
55
|
+
return self.manyToOne($1, args)
|
56
|
+
elsif fieldName =~ /^(\w+)_table$/
|
57
|
+
return self.oneToMany($1, "#{modelName}_id", args)
|
58
|
+
elsif fieldName =~ /^(\w+)_join$/
|
59
|
+
return self.manyToMany($1, "#{modelName}_#{fieldName}", "#{modelName}_id", "#{$1}_id", args)
|
60
|
+
elsif fieldName =~ /^(\w+)_virtual$/
|
61
|
+
return self.virtual($1, nil, args)
|
62
|
+
end
|
63
|
+
|
64
|
+
return HField.new(args)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.automatic(args = {})
|
69
|
+
args[:type] = "automatic"
|
70
|
+
return HField.new(args)
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.magic(args = {})
|
74
|
+
return self.automatic(args)
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.char(args = {})
|
78
|
+
args[:type] = "char"
|
79
|
+
args[:default] = '' unless args[:default]
|
80
|
+
return HField.new(args)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.text(args = {})
|
84
|
+
args[:type] = "text"
|
85
|
+
args[:default] = '' unless args[:default]
|
86
|
+
return HField.new(args)
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.integer(args = {})
|
90
|
+
args[:type] = "integer"
|
91
|
+
args[:default] = 0 unless args[:default]
|
92
|
+
return HField.new(args)
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.float(args = {})
|
96
|
+
args[:type] = "float"
|
97
|
+
args[:default] = 0 unless args[:default]
|
98
|
+
return HField.new(args)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.date(args = {})
|
102
|
+
args[:type] = "date"
|
103
|
+
args[:default] = '' unless args[:default]
|
104
|
+
return HField.new(args)
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.dateTime(args = {})
|
108
|
+
args[:type] = "datetime"
|
109
|
+
return HField.new(args)
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.binary(args = {})
|
113
|
+
args[:type] = "binary"
|
114
|
+
args[:default] = '' unless args[:default]
|
115
|
+
return HField.new(args)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.selection(args = {})
|
119
|
+
args[:type] = "selection"
|
120
|
+
return HField.new(args)
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.boolean(args = {})
|
124
|
+
args[:type] = "boolean"
|
125
|
+
args[:default] = false unless args[:default]
|
126
|
+
return HField.new(args)
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.oneToOne(modelName, args = {})
|
130
|
+
args[:modelNameReference] = modelName
|
131
|
+
#args[:constraint] = 'NOT NULL'
|
132
|
+
args[:onDelete] = 'CASCADE' # CASCADE or RESTRICT
|
133
|
+
args[:onUpdate] = 'CASCADE'
|
134
|
+
args[:type] = "oneToOne"
|
135
|
+
return HField.new(args)
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.oneToMany(modelName, referenceFieldName, args = {})
|
139
|
+
args[:modelNameReference] = modelName
|
140
|
+
args[:referenceFieldName] = referenceFieldName
|
141
|
+
args[:type] = "oneToMany"
|
142
|
+
return HField.new(args)
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.manyToOne(modelName, args = {})
|
146
|
+
args[:modelNameReference] = modelName
|
147
|
+
args[:onDelete] = 'CASCADE'
|
148
|
+
args[:onUpdate] = 'CASCADE'
|
149
|
+
#args[:constraint] = 'NOT NULL'
|
150
|
+
args[:type] = "manyToOne"
|
151
|
+
return HField.new(args)
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.manyToMany(modelName, joinTable, referenceFieldName, referenceFieldName2, args = {})
|
155
|
+
args[:modelNameReference] = modelName
|
156
|
+
args[:joinTable] = joinTable
|
157
|
+
args[:referenceFieldName] = referenceFieldName
|
158
|
+
args[:referenceFieldName2] = referenceFieldName2
|
159
|
+
#args[:constraint] = 'NOT NULL'
|
160
|
+
args[:type] = "manyToMany"
|
161
|
+
return HField.new(args)
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.virtual(functionName = nil, object = nil, args = {}, &block)
|
165
|
+
args[:object] = object
|
166
|
+
args[:functionName] = functionName
|
167
|
+
args[:type] = "virtual"
|
168
|
+
args[:block] = block
|
169
|
+
return HField.new(args)
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.primaryKey(args = {})
|
173
|
+
args[:type] = 'integer'
|
174
|
+
args[:system] = true
|
175
|
+
args[:constraint] = 'SERIAL PRIMARY KEY'
|
176
|
+
return HField.new(args)
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
data/lib/hdb/hmysql.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mysql'
|
4
|
+
require 'hdb/hdb'
|
5
|
+
|
6
|
+
class Hash
|
7
|
+
|
8
|
+
def join(separator)
|
9
|
+
|
10
|
+
arr = []
|
11
|
+
self.each do |key, value|
|
12
|
+
arr << "#{key} = #{value}"
|
13
|
+
end
|
14
|
+
return arr.join(separator)
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Array
|
20
|
+
|
21
|
+
def hjoin(separator, quoteChar = '"')
|
22
|
+
|
23
|
+
arr = []
|
24
|
+
self.each { |value| arr << "#{value}" }
|
25
|
+
return arr.join(separator)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
class HMySql < HDB
|
31
|
+
|
32
|
+
def initialize(host, port, dbname, user, password, timezone, connectionName)
|
33
|
+
|
34
|
+
super(host, port, dbname, user, password, timezone, connectionName, "hmysql")
|
35
|
+
@result = nil
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def connect()
|
40
|
+
|
41
|
+
@connection = Mysql.new(@host, @user, @password, @dbname, @port.to_i)
|
42
|
+
#hl << "Server version: #{self.execute("SHOW server_version").dataByFieldIndex(0,0).to_s}"
|
43
|
+
self.execute("SET time_zone = '#{@timezone}'") if @timezone
|
44
|
+
return @connection
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def disconnect()
|
49
|
+
|
50
|
+
@connection.close()
|
51
|
+
@connection = nil
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def _execute(queryStr = self.queryStr)
|
56
|
+
|
57
|
+
@result = @connection.query(queryStr)
|
58
|
+
|
59
|
+
return self unless @result
|
60
|
+
|
61
|
+
@resultTable = HFieldTable.new()
|
62
|
+
self.fieldNameList().each { |fieldName| @resultTable.addFieldName(fieldName) }
|
63
|
+
@resultTable.makeCaption()
|
64
|
+
r = 0
|
65
|
+
@result.each do |row|
|
66
|
+
row.each_with_index do |fieldValue, c|
|
67
|
+
@resultTable.setDataByFieldIndex(r, c, fieldValue.to_s)
|
68
|
+
end
|
69
|
+
r += 1
|
70
|
+
end
|
71
|
+
|
72
|
+
return self
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def fieldNameList()
|
77
|
+
|
78
|
+
fieldList = HList.new()
|
79
|
+
|
80
|
+
@result.fetch_fields.each { |field| fieldList << field.name }
|
81
|
+
|
82
|
+
return fieldList
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
def insert(tableName, values)
|
87
|
+
|
88
|
+
self.execute("INSERT INTO #{tableName} #{self.insertValues(values)}")
|
89
|
+
return @connection.insert_id
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
def rowsAffected
|
94
|
+
return @connection.affected_rows()
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
end
|
99
|
+
|