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.



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

Parameters:

  • value

    the value to set the attribute autocommit to.



90
91
92
# File 'lib/thm/datalayerlight.rb', line 90

def autocommit=(value)
  @autocommit = value
end

#dbnameObject

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

Parameters:

  • value

    the value to set the attribute debug to.



90
91
92
# File 'lib/thm/datalayerlight.rb', line 90

def debug=(value)
  @debug = value
end

#hostname=(value) ⇒ Object (writeonly)

Sets the attribute hostname

Parameters:

  • value

    the value to set the attribute hostname to.



90
91
92
# File 'lib/thm/datalayerlight.rb', line 90

def hostname=(value)
  @hostname = value
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



90
91
92
# File 'lib/thm/datalayerlight.rb', line 90

def password=(value)
  @password = value
end

#port=(value) ⇒ Object (writeonly)

Sets the attribute port

Parameters:

  • value

    the value to set the attribute port to.



90
91
92
# File 'lib/thm/datalayerlight.rb', line 90

def port=(value)
  @port = value
end

#username=(value) ⇒ Object (writeonly)

Sets the attribute username

Parameters:

  • value

    the value to set the attribute username to.



90
91
92
# File 'lib/thm/datalayerlight.rb', line 90

def username=(value)
  @username = value
end

Instance Method Details

#closeObject



138
139
140
# File 'lib/thm/datalayerlight.rb', line 138

def close
  @db.close
end

#commitObject



134
135
136
# File 'lib/thm/datalayerlight.rb', line 134

def commit
  @db.commit
end

#connectObject



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

#releaseObject



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

def release; end

#saveObject

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



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

def save; end