Class: DBI::DBD::BaseAdonetDriver

Inherits:
BaseDriver
  • Object
show all
Includes:
System::Data::Common
Defined in:
lib/dbd/adonet.rb

Overview

Implements the basic functionality that constitutes a Driver

Drivers do not have a direct interface exposed to the user; these methods are mostly for DBD authors.

As with DBI::BaseDatabase, “DBD Required” and “DBD Optional” will be used to explain the same requirements.

Constant Summary collapse

DEFAULT_PROVIDER =
PROVIDERS[:mssql]

Instance Method Summary collapse

Constructor Details

#initialize(dbi_version, key) ⇒ BaseAdonetDriver

Returns a new instance of BaseAdonetDriver.



46
47
48
49
50
51
52
53
# File 'lib/dbd/adonet.rb', line 46

def initialize(dbi_version, key)
  major, minor = dbi_version.split(".").collect { |x| x.to_i }
  dbi_major, dbi_minor = DBI::VERSION.split(".").collect { |x| x.to_i }
  unless major == dbi_major and minor == dbi_minor
    raise InterfaceError, "Wrong DBD API version used"
  end
  @provider = PROVIDERS[key] || DEFAULT_PROVIDER
end

Instance Method Details

#connect(dbname, user, auth, attr) ⇒ Object

Connect to the database. DBD Required.



56
57
58
59
60
61
62
63
# File 'lib/dbd/adonet.rb', line 56

def connect(dbname, user, auth, attr)
  connection = factory.create_connection
  connection.connection_string = dbname
  connection.open
  return create_database(connection, attr);
rescue RuntimeError, System::Data::SqlClient::SqlException => err
  raise DBI::DatabaseError.new(err.message)
end

#create_database(connection, attr) ⇒ Object

Raises:

  • (NotImplementedError)


65
66
67
# File 'lib/dbd/adonet.rb', line 65

def create_database(connection, attr)
  raise NotImplementedError
end

#factoryObject



69
70
71
# File 'lib/dbd/adonet.rb', line 69

def factory
  @factory ||= DbProviderFactories.get_factory(@provider)
end