Class: HMySql
Instance Attribute Summary
Attributes inherited from HDB
#connection, #resultTable, #sth, #table
Instance Method Summary
collapse
Methods inherited from HDB
HDB, #closeConnection, #columnCount, #data, #delete, destroy, #direction, #execute, #from, #insertValues, #limit, #method_missing, newHDB, #normalizeWhereFormat, #offset, #openConnection, #orderBy, #primitiveType?, #queryStr, #quote, #quoteValue, #rowCount, #select, #show, #toClassName, #update, #updateValues, #where
Constructor Details
#initialize(host, port, dbname, user, password, timezone, connectionName) ⇒ HMySql
Returns a new instance of HMySql.
32
33
34
35
36
37
|
# File 'lib/hdb/hmysql.rb', line 32
def initialize(host, port, dbname, user, password, timezone, connectionName)
super(host, port, dbname, user, password, timezone, connectionName, "hmysql")
@result = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class HDB
Instance Method Details
#_execute(queryStr = self.queryStr) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/hdb/hmysql.rb', line 55
def _execute(queryStr = self.queryStr)
@result = @connection.query(queryStr)
return self unless @result
@resultTable = HFieldTable.new()
self.fieldNameList().each { |fieldName| @resultTable.addFieldName(fieldName) }
@resultTable.makeCaption()
r = 0
@result.each do |row|
row.each_with_index do |fieldValue, c|
@resultTable.setDataByFieldIndex(r, c, fieldValue.to_s)
end
r += 1
end
return self
end
|
#connect ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/hdb/hmysql.rb', line 39
def connect()
@connection = Mysql.new(@host, @user, @password, @dbname, @port.to_i)
self.execute("SET time_zone = '#{@timezone}'") if @timezone
return @connection
end
|
#disconnect ⇒ Object
48
49
50
51
52
53
|
# File 'lib/hdb/hmysql.rb', line 48
def disconnect()
@connection.close()
@connection = nil
end
|
#fieldNameList ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/hdb/hmysql.rb', line 76
def fieldNameList()
fieldList = HList.new()
@result.fetch_fields.each { |field| fieldList << field.name }
return fieldList
end
|
#insert(tableName, values) ⇒ Object
86
87
88
89
90
91
|
# File 'lib/hdb/hmysql.rb', line 86
def insert(tableName, values)
self.execute("INSERT INTO #{tableName} #{self.insertValues(values)}")
return @connection.insert_id
end
|
#rowsAffected ⇒ Object
93
94
95
|
# File 'lib/hdb/hmysql.rb', line 93
def rowsAffected
return @connection.affected_rows()
end
|