2.1 Connection Objects

Implements the DB-API 2.0 Connection class.

Connection objects have the following interface:

close( )
Implements the DB-API 2.0 connection close() method.

Forces the database connection to be closed immediately. Any operation on the connection (including cursors) after calling this method will raise an exception.

This method is called by the __del__() method.

commit( [name = None])
Implements the DB-API 2.0 connection commit() method.

Calling this method commits any pending transaction to the database. By default Sybase transaction chaining is enabled. If you pass auto_commit = 1 to the connect() function when creating this Connection object then chained transaction mode will be turned off.

From the Sybase manual:

If you set chained transaction mode, Adaptive Server implicitly invokes a begin transaction before the following statements: delete, insert, open, fetch, select, and update. You must still explicitly close the transaction with a commit.

The optional name argument is an extension of the DB-API 2.0 specification. It allows you to make use of the Sybase ability to nest and name transactions.

rollback( [name = None])
Implements the DB-API 2.0 connection rollback() method.

Tells Sybase to roll back to the start of any pending transaction. Closing a connection without committing the changes first will cause an implicit rollback to be performed.

The optional name argument is an extension of the DB-API 2.0 specification. It allows you to make use of the Sybase ability to nest and name transactions.

cursor( )
Implements the DB-API 2.0 connection cursor() method.

Returns a new Cursor object using the connection.

begin( [name = None])
This is an extension of the DB-API 2.0 specification.

If you have turned off chained transaction mode via the auto_commit argument to the connection constructor then you can use this method to begin a transaction. It also allows you to use the nested transaction support in Sybase.

connect( )
This is an extension of the DB-API 2.0 specification.

If you pass a TRUE value to the delay_connect argument to the connect() function then you must call this method to complete the server connection process. This is useful if you wish to set connection properties which cannot be set after you have connected to the server.

get_property( prop)
This is an extension of the DB-API 2.0 specification.

Use this function to retrieve properties of the connection to the server.

import Sybase
db = Sybase.connect('SYBASE', 'sa', '', 'pubs2')
print db.get_property(Sybase.CS_TDS_VERSION)

set_property( prop, value)
This is an extension of the DB-API 2.0 specification.

Use this function to set properties of the connection to the server.

execute( sql)
This is an extension of the DB-API 2.0 specification.

This method executes the SQL passed in the sql argument via the ct_command(CS_LANG_CMD, ...) Sybase function. This is what programs such as sqsh use to send SQL to the server. The return value is a list of logical results. Each logical result is a list of row tuples.

The disadvantage to using this method is that you are not able to bind binary parameters to the command, you must format the parameters as part of the SQL string in the sql argument.

bulkcopy( table, direction = CS_BLK_IN, arraysize = 20)
This is an extension of the DB-API 2.0 specification.

Returns a new Bulkcopy object using the connection. The table argument identifies the table which you wish to perform bulkcopy operations upon. The arraysize argument specifies the number of rows stored in-memory for each DB request.

The direction argument controls the direction of the bulkcopy operation. Specify Sybase.CS_BLK_IN to copy data in, or Sybase.CS_BLK_OUT to copy data out.

bulkcopy( table, out=1,arraysize = 20)
A more convenient way of specifying BCP out.