Top Level Namespace

Defined Under Namespace

Modules: DBI Classes: Mydbi

Instance Method Summary collapse

Instance Method Details

#ascii_query(sql, *values) ⇒ Object

see DBI::DatabaseHandle’s ascii_query



66
67
68
# File 'lib/mydbi.rb', line 66

def ascii_query(sql,*values)
  return $mydbi_db.ascii_query(sql,*values)
end

#dbconnect(db = nil, host = nil, username = nil, password = nil) ⇒ Object

make a connection, returns the dbh

the top level query and ascii_query commands will work with the most recent dbconnection. but if you save the DatabaseHandle returned you can still use those methods off of that object.

@db.query(“whatever”)



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mydbi.rb', line 39

def dbconnect(db=nil, host=nil, username=nil, password=nil)
  config = $mydbi_config[:default] 

  # optionally reset the config to a named datasource
  if db.instance_of?(Symbol)
    if $mydbi_config.key?(db)
      config = $mydbi_config[db] 
      db = nil
    else
      throw ArgumentError.new("No database connection named ':#{db}' is configured")
    end
  end

  db =   config[:db] if db.nil?
  host = config[:host] if host.nil?
  username = config[:username] if username.nil?
  password = config[:password] if password.nil?

  $mydbi_db = DBI.connect("DBI:Mysql:#{db}:#{host}", username, password)
end

#query(sql, *values) ⇒ Object

see DBI::DatabaseHandle’s query



61
62
63
# File 'lib/mydbi.rb', line 61

def query(sql,*values)
  return $mydbi_db.query(sql,*values) # TODO this is not passing the block along properly
end