Class: DBI::BaseDriver
- Includes:
- System::Data::Common
- Defined in:
- lib/dbi/base_classes/driver.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.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_PROVIDER =
"System.Data.SqlServer"
Instance Method Summary collapse
-
#connect(dbname, user, auth, attr) ⇒ Object
Connect to the database.
- #create_database(connection, attr) ⇒ Object
-
#data_sources ⇒ Object
Return the data sources available to this driver.
-
#default_attributes ⇒ Object
Default attributes to set on the DatabaseHandle.
-
#default_user ⇒ Object
Default u/p information in an array.
-
#disconnect_all ⇒ Object
Disconnect all DatabaseHandles.
- #factory ⇒ Object
-
#initialize(dbi_version, key) ⇒ BaseDriver
constructor
A new instance of BaseDriver.
- #load_factory(provider_name) ⇒ Object
Constructor Details
#initialize(dbi_version, key) ⇒ BaseDriver
Returns a new instance of BaseDriver.
30 31 32 33 34 35 36 37 38 |
# File 'lib/dbi/base_classes/driver.rb', line 30 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] load_factory @provider end |
Instance Method Details
#connect(dbname, user, auth, attr) ⇒ Object
Connect to the database. DBD Required.
41 42 43 44 45 46 47 48 |
# File 'lib/dbi/base_classes/driver.rb', line 41 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.) end |
#create_database(connection, attr) ⇒ Object
50 51 52 |
# File 'lib/dbi/base_classes/driver.rb', line 50 def create_database(connection, attr) raise NotImplementedError end |
#data_sources ⇒ Object
Return the data sources available to this driver. Returns an empty array per default.
71 72 73 |
# File 'lib/dbi/base_classes/driver.rb', line 71 def data_sources [] end |
#default_attributes ⇒ Object
Default attributes to set on the DatabaseHandle.
65 66 67 |
# File 'lib/dbi/base_classes/driver.rb', line 65 def default_attributes {} end |
#default_user ⇒ Object
Default u/p information in an array.
60 61 62 |
# File 'lib/dbi/base_classes/driver.rb', line 60 def default_user ['', ''] end |
#disconnect_all ⇒ Object
Disconnect all DatabaseHandles. DBD Required.
76 77 78 |
# File 'lib/dbi/base_classes/driver.rb', line 76 def disconnect_all raise NotImplementedError end |
#factory ⇒ Object
54 55 56 57 |
# File 'lib/dbi/base_classes/driver.rb', line 54 def factory load_factory(@provider) unless defined? @factory and not @factory.nil? @factory end |
#load_factory(provider_name) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/dbi/base_classes/driver.rb', line 80 def load_factory(provider_name) return nil if defined? @factory provider = (provider_name.nil? || provider_name.empty?) ? DEFAULT_PROVIDER : provider_name @factory = DbProviderFactories.get_factory provider end |