Class DBI::BaseDatabase
In: lib/dbi/base_classes/database.rb
Parent: Base

Provides the core-level functionality for DatabaseHandles.

If the method description says "DBD Required", it‘s the DBD‘s responsibility to create this method.

Required methods unimplemented by the DBD will raise DBD::NotImplementedError.

"DBD Optional" methods are methods that do not have a default implementation but are optional due to the fact that many databases may not support these features (and emulating them would be prohibitive).

These methods raise DBI::NotSupportedError.

Otherwise, DBI will provide a general alternative which should meet the expectations of the documentation. However, DBDs can override every method in this class.

Methods

[]   []=   columns   commit   disconnect   do   execute   new   ping   prepare   rollback   tables  

Public Class methods

[Source]

    # File lib/dbi/base_classes/database.rb, line 21
21:         def initialize(handle, attr)
22:             @handle = handle
23:             @attr   = {}
24:             attr.each {|k,v| self[k] = v} 
25:         end

Public Instance methods

Get an attribute from the DatabaseHandle. These are DBD specific and embody things like Auto-Commit support for transactional databases.

DBD Authors:This messes with @attr directly.

[Source]

     # File lib/dbi/base_classes/database.rb, line 126
126:         def [](attr)
127:             @attr[attr]
128:         end

Set an attribute on the DatabaseHandle. DBD Optional.

[Source]

     # File lib/dbi/base_classes/database.rb, line 131
131:         def []=(attr, value)
132:             raise NotSupportedError
133:         end

Return a map of the columns that exist in the provided table name. DBD Required.

The result should be an array of DBI::ColumnInfo objects which have, at minimum, the following fields:

  • name:: the name of the column.
  • type:: This is not a field name in itself. You have two options:
    • type_name:: The name of the type as returned by the database
    • dbi_type:: A DBI::Type-conforming class that can be used to convert to a native type.
  • precision:: the precision (generally length) of the column
  • scale:: the scale (generally a secondary attribute to precision that helps indicate length) of the column

[Source]

    # File lib/dbi/base_classes/database.rb, line 59
59:         def columns(table)
60:             raise NotImplementedError
61:         end

Schedule a commit to the database immediately. DBD Optional.

[Source]

    # File lib/dbi/base_classes/database.rb, line 68
68:         def commit
69:             raise NotSupportedError
70:         end

Disconnect from the database. DBD Required.

[Source]

    # File lib/dbi/base_classes/database.rb, line 28
28:         def disconnect
29:             raise NotImplementedError
30:         end

Execute and complete the statement with the binds provided. Returns the row modified count (via BaseStatement#rows). Finishes the statement handle for you.

Roughly equivalent to:

  sth = dbh.prepare("my statement")
  sth.execute(my, bind, vars)
  result = sth.rows
  sth.finish

Returning the value stored in `result`.

[Source]

     # File lib/dbi/base_classes/database.rb, line 113
113:         def do(statement, *bindvars)
114:             stmt = execute(statement, *bindvars)
115:             res = stmt.rows
116:             stmt.finish
117:             return res
118:         end

Execute a statement with the binds provided. Returns the statement handle unfinished.

This is roughly equivalent to:

  sth = dbh.prepare("my statement")
  sth.execute(my, bind, vars)

[Source]

    # File lib/dbi/base_classes/database.rb, line 93
93:         def execute(statement, *bindvars)
94:             stmt = prepare(statement)
95:             stmt.bind_params(*bindvars)
96:             stmt.execute
97:             stmt
98:         end

Ping the database to ensure the connection is still alive. Boolean return, true for success. DBD Required.

[Source]

    # File lib/dbi/base_classes/database.rb, line 34
34:         def ping
35:             raise NotImplementedError
36:         end

Prepare a cached statement, returning a StatementHandle. DBD Required.

[Source]

    # File lib/dbi/base_classes/database.rb, line 40
40:         def prepare(statement)
41:             raise NotImplementedError
42:         end

Schedule a rollback to the database immediately. DBD Optional.

[Source]

    # File lib/dbi/base_classes/database.rb, line 73
73:         def rollback
74:             raise NotSupportedError
75:         end

Return the tables available to the database connection.

Note:the basic implementation returns an empty array.

[Source]

    # File lib/dbi/base_classes/database.rb, line 80
80:         def tables
81:             []
82:         end

[Validate]