Class: DatalayerLight::MySQLDrv
- Inherits:
-
Object
- Object
- DatalayerLight::MySQLDrv
- Defined in:
- lib/thm/datalayerlight.rb
Overview
Fine for small capture projects
Instance Attribute Summary collapse
-
#autocommit ⇒ Object
writeonly
Sets the attribute autocommit.
-
#dbname ⇒ Object
Returns the value of attribute dbname.
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
-
#hostname ⇒ Object
writeonly
Sets the attribute hostname.
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#port ⇒ Object
writeonly
Sets the attribute port.
-
#username ⇒ Object
writeonly
Sets the attribute username.
Instance Method Summary collapse
- #close ⇒ Object
- #commit ⇒ Object
- #connect ⇒ Object
-
#initialize ⇒ MySQLDrv
constructor
A new instance of MySQLDrv.
- #query(sql) ⇒ Object
- #release ⇒ Object
-
#save ⇒ Object
Just a work around for functions that don’t exist in MySQL.
Constructor Details
#initialize ⇒ MySQLDrv
Returns a new instance of MySQLDrv.
93 94 95 96 97 98 99 100 101 |
# File 'lib/thm/datalayerlight.rb', line 93 def initialize @hostname = "127.0.0.1" @username = "guest" @password = "" @port = 3306 @dbname = "test" @debug = 1 @autocommit = true end |
Instance Attribute Details
#autocommit=(value) ⇒ Object (writeonly)
Sets the attribute autocommit
90 91 92 |
# File 'lib/thm/datalayerlight.rb', line 90 def autocommit=(value) @autocommit = value end |
#dbname ⇒ Object
Returns the value of attribute dbname.
91 92 93 |
# File 'lib/thm/datalayerlight.rb', line 91 def dbname @dbname end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
90 91 92 |
# File 'lib/thm/datalayerlight.rb', line 90 def debug=(value) @debug = value end |
#hostname=(value) ⇒ Object (writeonly)
Sets the attribute hostname
90 91 92 |
# File 'lib/thm/datalayerlight.rb', line 90 def hostname=(value) @hostname = value end |
#password=(value) ⇒ Object (writeonly)
Sets the attribute password
90 91 92 |
# File 'lib/thm/datalayerlight.rb', line 90 def password=(value) @password = value end |
#port=(value) ⇒ Object (writeonly)
Sets the attribute port
90 91 92 |
# File 'lib/thm/datalayerlight.rb', line 90 def port=(value) @port = value end |
#username=(value) ⇒ Object (writeonly)
Sets the attribute username
90 91 92 |
# File 'lib/thm/datalayerlight.rb', line 90 def username=(value) @username = value end |
Instance Method Details
#close ⇒ Object
138 139 140 |
# File 'lib/thm/datalayerlight.rb', line 138 def close @db.close end |
#commit ⇒ Object
134 135 136 |
# File 'lib/thm/datalayerlight.rb', line 134 def commit @db.commit end |
#connect ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/thm/datalayerlight.rb', line 103 def connect @db = Mysql.init if @debug == 0 puts "Hostname: #@hostname" puts "Username: #@username" puts "Password: #@password" puts "Port: #@port" puts "Dbname: #@dbname" end @db.connect("#@hostname", "#@username", "#@password", "#@dbname", @port) @db.autocommit(@autocommit) end |
#query(sql) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 120 def query(sql) begin @res = @db.query("#{sql;}") if @debug == true; puts "#{sql}"; end return @res rescue Mysql::Error => e puts e end end |
#release ⇒ Object
132 |
# File 'lib/thm/datalayerlight.rb', line 132 def release; end |
#save ⇒ Object
Just a work around for functions that don’t exist in MySQL
131 |
# File 'lib/thm/datalayerlight.rb', line 131 def save; end |