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.
-
#autocommitvalue ⇒ Object
writeonly
Sets the attribute autocommitvalue.
-
#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.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/thm/datalayerlight.rb', line 129 def initialize @hostname = "127.0.0.1" @username = "guest" @password = "" @port = 3306 @dbname = "test" @debug = 0 @autocommit = false @autocommitvalue = 100 @k = Keycounter.new end |
Instance Attribute Details
#autocommit=(value) ⇒ Object (writeonly)
Sets the attribute autocommit
126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 126 def autocommit=(value) @autocommit = value end |
#autocommitvalue=(value) ⇒ Object (writeonly)
Sets the attribute autocommitvalue
126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 126 def autocommitvalue=(value) @autocommitvalue = value end |
#dbname ⇒ Object
Returns the value of attribute dbname.
127 128 129 |
# File 'lib/thm/datalayerlight.rb', line 127 def dbname @dbname end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 126 def debug=(value) @debug = value end |
#hostname=(value) ⇒ Object (writeonly)
Sets the attribute hostname
126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 126 def hostname=(value) @hostname = value end |
#password=(value) ⇒ Object (writeonly)
Sets the attribute password
126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 126 def password=(value) @password = value end |
#port=(value) ⇒ Object (writeonly)
Sets the attribute port
126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 126 def port=(value) @port = value end |
#username=(value) ⇒ Object (writeonly)
Sets the attribute username
126 127 128 |
# File 'lib/thm/datalayerlight.rb', line 126 def username=(value) @username = value end |
Instance Method Details
#close ⇒ Object
182 183 184 |
# File 'lib/thm/datalayerlight.rb', line 182 def close @db.close end |
#commit ⇒ Object
176 177 178 179 180 |
# File 'lib/thm/datalayerlight.rb', line 176 def commit @db.commit @k.keycount_reset("COMMITCOUNTER") puts "Syncing data to disk..." end |
#connect ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/thm/datalayerlight.rb', line 141 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
158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/thm/datalayerlight.rb', line 158 def query(sql) begin @res = @db.query("#{sql;}") print "COMMIT COUNTER: " if @debug == 1 @k.keycount("COMMITCOUNTER") pp @k.keycount_reader("COMMITCOUNTER") if @debug == 1 commit if @k.keycount_reader("COMMITCOUNTER") == @autocommitvalue if @debug == true; puts "#{sql}"; end return @res rescue Mysql::Error => e puts e end end |
#release ⇒ Object
174 |
# File 'lib/thm/datalayerlight.rb', line 174 def release; end |
#save ⇒ Object
Just a work around for functions that don’t exist in MySQL
173 |
# File 'lib/thm/datalayerlight.rb', line 173 def save; end |