Class: DatalayerLight::MySQLDrv

Inherits:
Object
  • Object
show all
Defined in:
lib/thm/datalayerlight.rb

Overview

Fine for small capture projects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMySQLDrv

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

Parameters:

  • value

    the value to set the attribute autocommit to.



126
127
128
# File 'lib/thm/datalayerlight.rb', line 126

def autocommit=(value)
  @autocommit = value
end

#autocommitvalue=(value) ⇒ Object (writeonly)

Sets the attribute autocommitvalue

Parameters:

  • value

    the value to set the attribute autocommitvalue to.



126
127
128
# File 'lib/thm/datalayerlight.rb', line 126

def autocommitvalue=(value)
  @autocommitvalue = value
end

#dbnameObject

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

Parameters:

  • value

    the value to set the attribute debug to.



126
127
128
# File 'lib/thm/datalayerlight.rb', line 126

def debug=(value)
  @debug = value
end

#hostname=(value) ⇒ Object (writeonly)

Sets the attribute hostname

Parameters:

  • value

    the value to set the attribute hostname to.



126
127
128
# File 'lib/thm/datalayerlight.rb', line 126

def hostname=(value)
  @hostname = value
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



126
127
128
# File 'lib/thm/datalayerlight.rb', line 126

def password=(value)
  @password = value
end

#port=(value) ⇒ Object (writeonly)

Sets the attribute port

Parameters:

  • value

    the value to set the attribute port to.



126
127
128
# File 'lib/thm/datalayerlight.rb', line 126

def port=(value)
  @port = value
end

#username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



126
127
128
# File 'lib/thm/datalayerlight.rb', line 126

def username=(value)
  @username = value
end

Instance Method Details

#closeObject



182
183
184
# File 'lib/thm/datalayerlight.rb', line 182

def close
  @db.close
end

#commitObject



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

#connectObject



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

#releaseObject



174
# File 'lib/thm/datalayerlight.rb', line 174

def release; end

#saveObject

Just a work around for functions that don’t exist in MySQL



173
# File 'lib/thm/datalayerlight.rb', line 173

def save; end