Class: Rubyfb::Connection
- Inherits:
-
Object
- Object
- Rubyfb::Connection
- Defined in:
- lib/src.rb,
lib/connection.rb
Overview
This class represents a connection with a Firebird database.
Constant Summary collapse
- MARK_DATABASE_DAMAGED =
A definition for a connection option. This option should be given a setting of either true or false.
17
- WRITE_POLICY =
A definition for a connection option. This option should be given a setting of Connection::WRITE_ASYNCHRONOUS or Connection::WRITE_SYNCHRONOUS
24
- CHARACTER_SET =
A definition for a connection option. This option should be given a string setting which should be the name of the character set to be used by the connection.
48
- MESSAGE_FILE =
A definition for a connection option. This option should be given a string setting which should be the name of the message file to be used by the connection.
47
- NUMBER_OF_CACHE_BUFFERS =
A definition for a connection option. This option should be given a an integer setting. Values between 1 and 255 are valid, with 75 being the default.
5
- DBA_USER_NAME =
A definition for a connection option. This option should be given a string value which should be the database DBA user name.
19
- SQL_ROLE_NAME =
A definition for a connection option. This option should be given a string value which should be the ROLE to use when connecting.
60
- WRITE_ASYNCHONOUS =
A definition for a possible setting to accompany the WRITE_POLICY connection setting.
0
- WRITE_SYNCHONOUS =
A definition for a possible setting to accompany the WRITE_POLICY connection setting.
1
Instance Method Summary collapse
-
#close ⇒ Object
This method detaches a Connection object from a database.
-
#closed? ⇒ Boolean
This method is used to determine whether a Connection object represents an inactive database connection.
-
#create_statement(sql) ⇒ Object
This function creates a new statement object.
-
#database ⇒ Object
This is the accessor method for the database attribute.
-
#execute(sql, transaction) {|row| ... } ⇒ Object
This function executes a SQL statement against a connection.
-
#execute_immediate(sql) {|row| ... } ⇒ Object
This function executes a SQL statement against a connection.
- #force_encoding(fb_str, sqlsubtype) ⇒ Object
-
#initialize(database, user, password, options) ⇒ Connection
constructor
This is the constructor for the Connection class.
-
#open? ⇒ Boolean
This method is used to determine whether a Connection object represents an active database connection.
-
#prepare_call(procedure_name) ⇒ Object
Creates stored procedure call object.
-
#start_transaction {|transaction| ... } ⇒ Object
This method starts a new transaction against a connection.
-
#to_s ⇒ Object
This method generates a simple descriptive string for a Connection object.
-
#user ⇒ Object
This method retrieves the user name that was used in creating a Connection object.
Constructor Details
#initialize(database, user, password, options) ⇒ Connection
This is the constructor for the Connection class.
Parameters
- database
-
A reference to the Database object to be connected to.
- user
-
A reference to the user name to be used in making the database connection. Defaults to nil.
- password
-
A reference to the user password to be used in making the connection. Defaults to nil.
- options
-
A Hash containing the options to be applied to the new connection. The hash will contain key/setting values, with the keys being based on the option constants defined within the Connection class. Individual options have differing value requirements. See the option documentation entries for further details. Defaults to nil.
Exceptions
- Exception
-
Generated whenever an invalid database is specified to the method or an issue occurs establishing the database connection.
249 250 |
# File 'lib/src.rb', line 249 def initialize(database, user, password, ) end |
Instance Method Details
#close ⇒ Object
This method detaches a Connection object from a database. The object may not be used for database functionality following a successful call to this method. The close method will fail if there are outstanding transactions for a connection.
Exceptions
- Exception
-
Generated whenever the connection has at least one open transaction or an error occurs closing the connection.
279 280 |
# File 'lib/src.rb', line 279 def close end |
#closed? ⇒ Boolean
This method is used to determine whether a Connection object represents an inactive database connection.
265 266 |
# File 'lib/src.rb', line 265 def closed? end |
#create_statement(sql) ⇒ Object
This function creates a new statement object
Parameters
- sql
-
The SQL for the statement.
Exceptions
- Exception
-
Generated whenever a problem occurs creating the statement object.
374 375 |
# File 'lib/src.rb', line 374 def create_statement(sql) end |
#database ⇒ Object
This is the accessor method for the database attribute.
286 287 |
# File 'lib/src.rb', line 286 def database end |
#execute(sql, transaction) {|row| ... } ⇒ Object
This function executes a SQL statement against a connection. If the statement represented a SQL query then a ResultSet object is returned. If the statement was a non-query SQL statement then an Integer is returned indicating the number of rows affected by the statement. For all other types of statement the method returns nil. The method also accepts a block that takes a single parameter. This block will be executed once for each row in any result set generated.
Parameters
- sql
-
The SQL statement to be executed.
- transaction
-
The transaction to execute the SQL statement within.
Exceptions
- Exception
-
Generated if an error occurs executing the SQL statement.
340 341 342 |
# File 'lib/src.rb', line 340 def execute(sql, transaction) yield(row) end |
#execute_immediate(sql) {|row| ... } ⇒ Object
This function executes a SQL statement against a connection. This differs from the execute method in that an anonymous transaction is used in executing the statement. The output from this method is the same as for the execute method. The method also accepts a block that takes a single parameter. This block will be executed once for each row in any result set generated.
Parameters
- sql
-
The SQL statement to be executed.
Exceptions
- Exception
-
Generated whenever a problem occurs executing the SQL statement.
360 361 362 |
# File 'lib/src.rb', line 360 def execute_immediate(sql) yield(row) end |
#force_encoding(fb_str, sqlsubtype) ⇒ Object
8 9 10 |
# File 'lib/connection.rb', line 8 def force_encoding(fb_str, sqlsubtype) fb_str end |
#open? ⇒ Boolean
This method is used to determine whether a Connection object represents an active database connection.
257 258 |
# File 'lib/src.rb', line 257 def open? end |
#prepare_call(procedure_name) ⇒ Object
Creates stored procedure call object
4 5 6 |
# File 'lib/connection.rb', line 4 def prepare_call(procedure_name) Rubyfb::ProcedureCall.new(self, procedure_name) end |
#start_transaction {|transaction| ... } ⇒ Object
This method starts a new transaction against a connection. A successful call to this method returns a Transaction object. The transaction that is started relates to the Connection it was called upon only. To start a transaction that covers multiple connections use the Transaction class. This method accepts a block, taking a single parameter which will be the transaction created. This transaction is committed if the block completes normally or rolls back if an exception is thrown from the block.
Exceptions
- Exception
-
Thrown whenever a problem occurs starting the transaction.
319 320 321 |
# File 'lib/src.rb', line 319 def start_transaction yield transaction end |
#to_s ⇒ Object
This method generates a simple descriptive string for a Connection object.
302 303 |
# File 'lib/src.rb', line 302 def to_s end |
#user ⇒ Object
This method retrieves the user name that was used in creating a Connection object.
294 295 |
# File 'lib/src.rb', line 294 def user end |