Class: MySQL
- Inherits:
-
Mysql
show all
- Includes:
- Eprint
- Defined in:
- lib/DrbDB/MyMultiSQL/jdbc.rb,
lib/DrbDB/MyMultiSQL/mysql-ruby.rb
Constant Summary
collapse
- MYSQL_FIELD_TYPE =
{
Mysql::Field::TYPE_BIT => "BIT",
Mysql::Field::TYPE_BLOB => "BLOB",
Mysql::Field::TYPE_CHAR => "CHAR",
Mysql::Field::TYPE_DATE => "DATE",
Mysql::Field::TYPE_DATETIME => "DATETIME",
Mysql::Field::TYPE_DECIMAL => "DECIMAL",
Mysql::Field::TYPE_DOUBLE => "DOUBLE",
Mysql::Field::TYPE_ENUM => "ENUM",
Mysql::Field::TYPE_FLOAT => "FLOAT",
Mysql::Field::TYPE_INT24 => "INT24",
Mysql::Field::TYPE_LONG => "LONG",
Mysql::Field::TYPE_LONGLONG => "LONGLONG",
Mysql::Field::TYPE_NEWDECIMAL=> "NEWDECIMAL",
Mysql::Field::TYPE_NULL => "NULL",
Mysql::Field::TYPE_SET => "SET",
Mysql::Field::TYPE_SHORT => "SHORT",
Mysql::Field::TYPE_STRING => "CHAR",
Mysql::Field::TYPE_TIME => "TIME",
Mysql::Field::TYPE_TIMESTAMP=> "TIMESTAMP",
Mysql::Field::TYPE_TINY => "TINY",
Mysql::Field::TYPE_VAR_STRING=> "VARCHAR",
Mysql::Field::TYPE_YEAR => "YEAR"
}
Constants included
from Eprint
Eprint::TERM_COLOUR
Instance Method Summary
collapse
Methods included from Eprint
#ecode, #edebug, #eerror, #eeval, #eexception, #efatal, #einfo, #eprint, #ewarn, #getBinding, #report_mail
Constructor Details
#initialize(host, user, password, dbase) ⇒ MySQL
Returns a new instance of MySQL.
16
17
18
19
20
21
22
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 16
def initialize(host,user,password,dbase)
@host=host
@user=user
@password=password
@dbase=dbase
@conn = Jdbc::DriverManager.getConnection("jdbc:mysql://#{@host}/#{@dbase}?user=#{@user}&password=#{@password}&zeroDateTimeBehavior=convertToNull&jdbcCompliantTruncation=false");
end
|
Instance Method Details
#escape_string(string) ⇒ Object
96
97
98
99
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 96
def escape_string(string)
string
end
|
#fetch_hash(res, with_table = false) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 54
def fetch_hash(res,with_table=false)
begin
data=Array.new
unless res.nil?
while res.next do
md=res.meta_data
row=Hash.new
i=1
while i<=md.column_count do
=if with_table then
md.table_name(i)+"."+md.column_label(i)
else
md.column_label(i)
end
row[]=res.getString(md.column_label(i))
i+=1
end
data.push(row)
end
end
return data
rescue =>e
eerror("metadata:#{md.inspect}\nrow:#{row.inspect}\nheader:#{.inspect},colnum:#{i}")
eerror("error preparing the result:#{e}\n #{e.backtrace.join("\n\t")}")
end
end
|
#fields(sql) {|nil| ... } ⇒ Object
81
82
83
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 81
def fields(sql)
yield nil
end
|
#inspect ⇒ Object
101
102
103
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 101
def inspect
"jmysql(#{@dbase})"
end
|
#qrow(sql, with_table = false) ⇒ Object
85
86
87
88
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 85
def qrow(sql,with_table=false)
row=fetch_hash(query(sql),with_table).first
return row
end
|
#query(sql) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 25
def query(sql)
return nil if sql.nil? or sql.length ==0
begin
stmt = @conn.createStatement
res = stmt.executeQuery(sql)
rescue SQLException => err
eerror("#{err} in\n#{sql}")
raise "#{err}\n#{sql}\n"
rescue CommunicationsException => e
edebug("comm error")
eerror("#{e} in\n#{sql}")
raise "#{e}\n#{sql}\n"
rescue =>e
edebug("other error: #{e.class.name}")
eerror("#{err} in\n#{sql}")
end
return res
end
|
#reconnect ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/DrbDB/MyMultiSQL/mysql-ruby.rb', line 54
def reconnect
begin
real_connect(@host,@user,@password,@dbase)
rescue MysqlError => err
ewarn("reconnecting: #{err.error}")
end
end
|
#rows(sql, with_table = false) ⇒ Object
90
91
92
93
94
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 90
def rows(sql,with_table=false)
if ret=query(sql)
fetch_hash(ret,with_table)
end
end
|
#to_s ⇒ Object
104
105
106
|
# File 'lib/DrbDB/MyMultiSQL/jdbc.rb', line 104
def to_s
inspect
end
|