Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

DBI connection string is mising DBI driver #111

Closed
jeremyevans opened this Issue · 4 comments

1 participant

@jeremyevans
Owner

What steps will reproduce the problem?
1. Sequel("dbi:///memory")
2.
3.

What is the expected output? What do you see instead?
dbi.rb:connect constructs
'DBI:' + dbname
I believe this should be
'DBI:' + dbd ':' + + '=' + + ';' + ...
The dbd driver can be case sensitive - I've included the Og dbd map below.
Some (mysql only?) params are:
host, database, port, socket, flag

What version of the product are you using? On what operating system?
Sequel 0.3.1

Please provide any additional information below.

def dbd_map
{
:ado=>"ADO",
:db2=>"DB2",
:frontbase=>"FrontBase",
:interbase=>"InterBase",
:msql=>"Msql",
:mysql=>"Mysql",
:odbc=>"ODBC",
:oracle=>"Oracle",
:pg=>"Pg",
:proxy=>"Proxy",
:sqlite=>"SQLite",
:sqlrelay=>"SQLRelay"
}
end

Google Code Info:
Issue #: 86
Author: mvy...@gmail.com
Created On: 2007-11-03T00:27:42.000Z
Closed On: 2007-11-24T08:58:40.000Z

@jeremyevans jeremyevans was assigned
@jeremyevans jeremyevans closed this
@jeremyevans
Owner

In Og we've adapter the following convention for the shceme name when using the dbi
driver in a uri/url:
"dbi-://etc."
I'll post some of the utility code when it's done and tested.

Google Code Info:
Author: mvy...@gmail.com
Created On: 2007-11-06T06:05:33.000Z

@jeremyevans
Owner

The following might be useful to add to the generic Database class in Database.rb?

  DBI_DBD_REGEXP = /dbi-(.*)/i.freeze
  # Accepts a string in the format dbi-<vendor> and returns the an array of
  # symbols <tt>[<adapter>, <dbd>]</tt>
  # Where 'dbi' is not in the uri scheme, then _both_ the adapter and dbd  
  # values are the uri scheme given: mysql, postgresql, etc.
  # Valid vendor names (case insensitive in the uri) are the keys of +dbd_map+.
  # Specifically:
  #  * ado 
  #  * db2       
  #  * frontbase
  #  * interbase
  #  * msql 
  #  * mysql
  #  * odbc
  #  * oracle
  #  * pg
  #  * proxy
  #  * sqlite
  #  * sqlrelay  
  #    
  def self.parse_dbd(dbi_scheme)
    scheme = dbi_scheme.downcase
    adapter = (scheme =~ DBI_DBD_REGEXP ? "dbi" : scheme)
    dbd = (scheme =~ DBI_DBD_REGEXP ? $1 : scheme)
    [adapter.intern, dbd.intern]
  end

  # Converts a uri to an options hash. These options are then passed
  # to a newly created database object.

  def self.uri_to_options(uri)
    split_scheme = parse_dbd(uri.scheme)
    {
    :adapter => split_scheme[0],
    :dbd => split_scheme[1],
    :dbd_options => uri.fragment,
    :user => uri.user,
    :password => uri.password,
    :host => uri.host,
    :port => uri.port,
    :database => (uri.path =~ /\/(.*)/) && ($1)
    }
  end

def uri
  scheme = "#{@opts[:adapter]}"
  scheme << "-#{@opts[:dbd]}" if !(@opts[:adapter] == @opts[:dbd])
  uri = URI::Generic.new(
    scheme,
    nil,
    @opts[:host],
    @opts[:port],
    nil,
    "/#{@opts[:database]}",
    nil,
    nil,
    nil
  )
  uri.user = @opts[:user]
  uri.password = @opts[:password] if uri.user
  uri.to_s
end
alias url uri # Because I don't care much for the semantic difference.

Google Code Info:
Author: mvy...@gmail.com
Created On: 2007-11-06T06:29:58.000Z

@jeremyevans
Owner

Finally, the following can be added to dbi.rb, and will construct a valid dsn

  SEMICOLON_SEPARATOR=";".freeze
  COLON_SEPARATOR=":".freeze
  def construct_dbi_dsn
    dsn = "#{@opts[:adapter]}"
    dsn << COLON_SEPARATOR 
    dsn << dbd_map[@opts[:dbd]] 
    dsn << COLON_SEPARATOR
    dsn << (("hostname=" << @opts[:host]) << SEMICOLON_SEPARATOR) if @opts[:host]
    dsn << (("database=" << @opts[:database]) << SEMICOLON_SEPARATOR) if

@opts[:database]
dsn << (("port=" << @opts[:port].to_s) << SEMICOLON_SEPARATOR) if @opts[:port]
dsn << ((@opts[:flags].map{|f|"flag=#{f}"}.join(SEMICOLON_SEPARATOR)) <<
SEMI_COLON_SEPARATOR) if @opts[:flags]
dsn << @opts[:dbd_options] if @opts[:dbd_options]
return dsn
end

  def connect
    dsn = construct_dbi_dsn
    ::DBI.connect(dsn, @opts[:user], @opts[:password])
  end

Google Code Info:
Author: mvy...@gmail.com
Created On: 2007-11-06T06:35:21.000Z

@jeremyevans
Owner

Fixed in the trunk.

Google Code Info:
Author: cico...@gmail.com
Created On: 2007-11-24T08:58:41.000Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.