Connection Object

Note

Any outstanding changes will be rolled back when the connection object is destroyed or closed.

Connection.__enter__()

The entry point for the connection as a context manager, a feature available in Python 2.5 and higher. It returns itself.

Note

This method is an extension to the DB API definition.

Connection.__exit__()

The exit point for the connection as a context manager, a feature available in Python 2.5 and higher. In the event of an exception, the transaction is rolled back; otherwise, the transaction is committed.

Note

This method is an extension to the DB API definition.

Connection.action

This write-only attribute sets the action column in the v$session table and is only available in Oracle 10g.

Note

This attribute is an extension to the DB API definition.

Connection.autocommit

This read-write attribute determines whether autocommit mode is on or off.

Note

This attribute is an extension to the DB API definition.

Connection.begin()
Connection.begin([formatId, transactionId, branchId])

Explicitly begin a new transaction. Without parameters, this explicitly begins a local transaction; otherwise, this explicitly begins a distributed (global) transaction with the given parameters. See the Oracle documentation for more details.

Note that in order to make use of global (distributed) transactions, the twophase argument to the Connection constructor must be a true value. See the comments on the Connection constructor for more information (Module Interface).

Note

This method is an extension to the DB API definition.

Connection.cancel()
Cancel a long-running transaction. This is only effective on non-Windows platforms.
Connection.clientinfo

This write-only attribute sets the client_info column in the v$session table and is only available in Oracle 10g.

Note

This attribute is an extension to the DB API definition.

Connection.close()
Close the connection now, rather than whenever __del__ is called. The connection will be unusable from this point forward; an Error exception will be raised if any operation is attempted with the connection. The same applies to any cursor objects trying to use the connection.
Connection.commit()
Commit any pending transactions to the database.
Connection.cursor()
Return a new Cursor object (Cursor Object) using the connection.
Connection.dsn

This read-only attribute returns the TNS entry of the database to which a connection has been established.

Note

This attribute is an extension to the DB API definition.

Connection.encoding

This read-only attribute returns the IANA character set name of the character set in use by the Oracle client.

Note

This attribute is an extension to the DB API definition.

Connection.maxBytesPerCharacter

This read-only attribute returns the maximum number of bytes each character can use for the client character set.

Note

This attribute is an extension to the DB API definition.

Connection.module

This write-only attribute sets the module column in the v$session table and is only available in Oracle 10g.

Connection.nencoding

This read-only attribute returns the IANA character set name of the national character set in use by the Oracle client.

Note

This attribute is an extension to the DB API definition.

Connection.password

This read-write attribute initially contains the password of the user which established the connection to the database.

Note

This attribute is an extension to the DB API definition.

Connection.ping()

Ping the server which can be used to test if the connection is still active.

Note

This method is an extension to the DB API definition and is only available in Oracle 10g R2 and higher.

Connection.prepare()

Prepare the distributed (global) transaction for commit.

Note

This method is an extension to the DB API definition.

Connection.register(code, when, function)

Register the function as an OCI callback. The code is one of the function codes defined in the Oracle documentation of which the most common ones are defined as constants in this module. The when parameter is one of UCBTYPE_ENTRY, UCBTYPE_EXIT or UCBTYPE_REPLACE. The function is a Python function which will accept the parameters that the OCI function accepts, modified as needed to return Python objects that are of some use. Note that this is a highly experimental method and can cause cx_Oracle to crash if not used properly. In particular, the OCI does not provide sizing information to the callback so attempts to access a variable beyond the allocated size will crash cx_Oracle. Use with caution.

Note

This method is an extension to the DB API definition.

Connection.rollback()
Rollback any pending transactions.
Connection.shutdown([mode])

Shutdown the database. In order to do this the connection must connected as SYSDBA or SYSOPER. First shutdown using one of the DBSHUTDOWN constants defined in the constants (Constants) section. Next issue the SQL statements required to close the database (“alter database close normal”) and dismount the database (“alter database dismount”) followed by a second call to this method with the DBSHUTDOWN_FINAL mode.

Note

This method is an extension to the DB API definition and is only available in Oracle 10g R2 and higher.

Connection.startup(force=False, restrict=False)

Startup the database. This is equivalent to the SQL*Plus command “startup nomount”. The connection must be connected as SYSDBA or SYSOPER with the PRELIM_AUTH option specified for this to work. Once this method has completed, connect again without the PRELIM_AUTH option and issue the statements required to mount (“alter database mount”) and open (“alter database open”) the database.

Note

This method is an extension to the DB API definition and is only available in Oracle 10g R2 and higher.

Connection.stmtcachesize

This read-write attribute specifies the size of the statement cache. This value can make a significant difference in performance (up to 100x) if you have a small number of statements that you execute repeatedly.

Note

This attribute is an extension to the DB API definition.

Connection.tnsentry

This read-only attribute returns the TNS entry of the database to which a connection has been established.

Note

This attribute is an extension to the DB API definition.

Connection.unregister(code, when)

Unregister the function as an OCI callback. The code is one of the function codes defined in the Oracle documentation of which the most common ones are defined as constants in this module. The when parameter is one of UCBTYPE_ENTRY, UCBTYPE_EXIT or UCBTYPE_REPLACE.

Note

This method is an extension to the DB API definition.

Connection.username

This read-only attribute returns the name of the user which established the connection to the database.

Note

This attribute is an extension to the DB API definition.

Connection.version

This read-only attribute returns the version of the database to which a connection has been established.

Note

This attribute is an extension to the DB API definition.