Créer  Editer  FrontPage  Index  Chercher  Changements  History  RSS  Login

Gda::Connection

class Gda::Connection

The Gda::Connection class offers access to all operations involving an opened connection to a database. Gda::Connection objects are obtained via the Gda::Client class.

Once obtained, applications can use GdaConnection to execute commands, run transactions, and get information about all objects stored in the underlying database.

Instance Methods

add_errors(*errors)
Adds one or more errors to the connection. This method is usually called by providers, to inform clients of errors that happened during some operation. As soon as this method is called, the connection object (and the associated Gda::Client object) emits the "error" signal, to which clients can connect to be informed of errors.
  • errors: one or several Gda::Error objects.
  • Returns: self.
begin_transaction(xaction)
Starts a transaction on the data source, identified by the xaction parameter. Before starting a transaction, you can check whether the underlying provider does support transactions or not by using the Gda::Connection#supports? method.
  • xaction: a Gda::Transaction object.
  • Returns: true if the transaction was started successfully, false otherwise.
change_database(name)
Changes the current database for the given connection. This operation is not available in all providers.
  • name: name of the database to switch to.
  • Returns: true if successful, false otherwise.
clear_errors
This method lets you clear the list of Gda::Error's of the current connection. This is useful to reuse a Gda::Connection because next uses of Gda::Connection#errors will return an empty list.
  • Returns: self.
client
Gets the Gda::Client object associated with a connection. This is always the client that created the connection, as returned by Gda::Client#open_connection.
  • Returns: the Gda::Client to which the connection belongs to.
client=(client)
Associates a Gda::Client with this connection. This method is not intended to be called by applications.
  • client: a Gda::Client object.
  • Returns: the given parameter 'client'.
close
Closes the connection to the underlying data source. After calling this method, you should not use anymore the Gda::Connection object, since it may have been destroyed.
  • Returns: nil.
cnc_string
Gets the connection string used to open this connection. The connection string is the string sent over to the underlying database provider, which describes the parameters to be used to open a connection on the underlying data source.
  • Returns: the connection string used when opening this connection.
commit_transaction(xaction)
Commits the given transaction to the backend database. You need to do Gda::Connection#begin_transaction first.
  • xaction: a Gda::Transaction object.
  • Returns: true if the transaction was finished successfully, false otherwise.
create_database(name)
Creates a new database on the connection.
  • name: database name.
  • Returns: true if successful, false otherwise.
create_table(name, attributes)
Creates a table on the current connection from the given set of fields.
  • name: the name of the table to create.
  • attributes: an array of Gda::FieldAttributes objects.
  • Returns: true if successful, false otherwise.
database
This method returns the name of the currently active database in the connection.
  • Returns: the name of the currently active database in the connection.
drop_database(name)
Drops a database from the connection.
  • name: database name.
  • Returns: true if successful, false otherwise.
drop_table(name)
Drops a table from the database.
  • name: the name of the table to drop.
  • Returns: true if successful, false otherwise.
dsn
This method returns the data source name the connection object is connected to.
  • Returns: the data source name the connection object is connected to.
errors
Retrieves a list of the last errors ocurred in the connection.
execute(cmd, params=nil)
Synonym for Gda::Connection#execute_single_command.
execute_command(cmd, params=nil)
Executes a command on the underlying data source. This method provides the way to send several commands at once to the data source being accessed by the Gda::Connection. The Gda::Command specified can contain a list of commands in its "text" property (usually a set of SQL commands separated by ';').
execute_non_query(cmd, params=nil)
Executes a single command on the underlying database, and gets the number of rows affected.
  • cmd: a Gda::Command object.
  • params: parameters, as a Gda::ParameterList object.
  • Returns: the number of affected rows by the executed command, or -1 on error.
execute_single_command(cmd, params=nil)
Executes a single command on the given connection. This method lets you retrieve a simple data model from the underlying difference, instead of having to retrieve a list of them, as is the case with Gda::Connection#execute_command.
get_schema(schema, params=nil)
Asks the underlying data source for a list of database objects. This is the method that lets applications ask the different providers about all their database objects (tables, views, procedures, etc). The set of database objects that are retrieved are given by the 2 parameters of this method: 'schema' (which specifies the specific schema required) and 'params' (which is a list of Gda::Parameter objects that can be used to give more detail about the objects to be returned). The list of parameters is specific to each schema type.
opened?
Checks whether a connection is open or not.
  • Returns: true if the connection is open, false if it is not.
options
This method returns the GdaConnectionOptions used to open this connection.
password
This method returns the pass word used to open this connection.
  • Returns: the pass word used to open this connection.
provider
This method returns the provider ID used to open this connection.
  • Returns: the provider ID used to open this connection.
reset!
Resets the connection.
  • Returns: true if successful, false otherwise.
rollback_transaction(xaction)
Rollbacks the given transaction. This means that all changes made to the underlying data source since the last call to Gda:Connection#begin_transaction or Gda::Connection#commit_transaction will be discarded.
  • xaction: a Gda::Transaction object.
  • Returns: true if the operation was successful, false otherwise.
server_version
This method returns the version string of the underlying database server.
  • Returns: the version string of the underlying database server.
set_client(client)
Associates a Gda::Client with this connection. This method is not intended to be called by applications.
supports?(feature)
Asks the underlying provider for if a specific feature is supported.
  • feature: feature to ask for (see GdaConnectionFeature).
  • Returns: true if the provider supports it, false if not.
username
This method returns the user name used to open this connection.
  • Returns: the user name used to open this connection.
Dernière modification:2011/06/09 07:40:13
Mots clef:
Références:[Gda::Client] [Gda::Export] [Gda::Transaction] [Gda::Connection] [Gda::Command]