Calling the ct_con_alloc() method of a CS_CONTEXT object will create a CS_CONNECTION object. When the CS_CONNECTION object is deallocated the Sybase ct_con_drop() function will be called for the connection.
CS_CONNECTION objects have the following interface:
char
columns. The default value is zero.
stderr
.
The default value is inherited from the CS_CONTEXT
object.
When operation is CS_INIT
a single argument is accepted
and the Sybase result code is returned.
When operation is CS_MSGLIMIT
two additional arguments
are expected; type and num. The Sybase result code is
returned.
When operation is CS_CLEAR
an additional type
argument is accepted and the Sybase result code is returned.
When operation is CS_GET
two additional arguments are
expected; type and index. A tuple is returned which
contains the Sybase result code and the requested CS_SERVERMSG
or CS_CLIENTMSG message. None
is returned as the
message object when the result code is not CS_SUCCEED
.
When operation is CS_STATUS
an additional type
argument is accepted. A tuple is returned which contains the Sybase
result code and the number of messages available for retrieval.
When operation is CS_EED_CMD
two additional arguments are
expected; type and index. A tuple is returned which
contains the Sybase result code and a CS_COMMAND object which
is used to retrieve extended error data.
def get_msgs(con, type): status, num_msgs = conn.ct_diag(CS_STATUS, type) if status != CS_SUCCEED: return [] err = [] for i in range(num_msgs): status, msg = conn.ct_diag(CS_GET, type, i + 1) if status != CS_SUCCEED: continue dict = {} for attr in dir(msg): dict[attr] = getattr(msg, attr) err.append(dict) return err def build_ct_exception(con, msg): err = [msg] err.extend(get_msgs(con, CS_SERVERMSG_TYPE)) err.extend(get_msgs(con, CS_CLIENTMSG_TYPE)) conn.ct_diag(CS_CLEAR, CS_ALLMSG_TYPE) return err
CS_CONNECTION
pointer, a NULL
CS_COOMAND
, and the
integer type argument and returns the Sybase result code.
= None
])
Not passing a server argument is the same as passing NULL
as the server to the Sybase ct_connect() function.
ctx = init_db() status, conn = ctx.ct_con_alloc() if status != CS_SUCCEED: raise CSError(ctx, 'ct_con_alloc') if conn.ct_con_props(CS_SET, CS_USERNAME, user_name) != CS_SUCCEED: raise CTError(conn, 'ct_con_props') if conn.ct_con_props(CS_SET, CS_PASSWORD, password) != CS_SUCCEED: raise CTError(conn, 'ct_con_props') status = conn.ct_connect()
The result is a tuple containing the Sybase result code and a new
instance of the CS_COMMAND class. None
is returned as
the CS_COMMAND object when the result code is not
CS_SUCCEED
.
ctx = init_db() conn = connect_db(ctx, 'SYBASE', 'guest', '') status, cmd = conn.ct_cmd_alloc() if status != CS_SUCCEED: raise CTError(conn, 'ct_cmd_alloc')
= BLK_VERSION_100
])
The result is a tuple containing the Sybase result code and a new
instance of the CS_BLKDESC class. None
is returned as
the CS_BLKDESC object when the result code is not
CS_SUCCEED
.
ctx = init_db() conn = connect_db(ctx, 'SYBASE', 'guest', '') status, blk = conn.blk_alloc() if status != CS_SUCCEED: raise CTError(conn, 'blk_alloc')
= CS_UNUSED
])
status = conn.ct_close(CS_FORCE_CLOSE)
This method will be automatically called when the CS_CONNECTION object is deleted. Applications do not need to call the method.
When action is CS_SET
a compatible value argument
must be supplied and the method returns the Sybase result code.
When action is CS_GET
the method returns a tuple
containing the Sybase result code and the property value.
When action is CS_CLEAR
the method returns the Sybase
result code.
The recognised properties are:
property | type |
CS_ANSI_BINDS |
bool |
CS_ASYNC_NOTIFS |
bool |
CS_BULK_LOGIN |
bool |
CS_CHARSETCNV |
bool |
CS_CONFIG_BY_SERVERNAME |
bool |
CS_DIAG_TIMEOUT |
bool |
CS_DISABLE_POLL |
bool |
CS_DS_COPY |
bool |
CS_DS_EXPANDALIAS |
bool |
CS_DS_FAILOVER |
bool |
CS_EXPOSE_FMTS |
bool |
CS_EXTERNAL_CONFIG |
bool |
CS_EXTRA_INF |
bool |
CS_HIDDEN_KEYS |
bool |
CS_LOGIN_STATUS |
bool |
CS_NOCHARSETCNV_REQD |
bool |
CS_SEC_APPDEFINED |
bool |
CS_SEC_CHALLENGE |
bool |
CS_SEC_CHANBIND |
bool |
CS_SEC_CONFIDENTIALITY |
bool |
CS_SEC_DATAORIGIN |
bool |
CS_SEC_DELEGATION |
bool |
CS_SEC_DETECTREPLAY |
bool |
CS_SEC_DETECTSEQ |
bool |
CS_SEC_ENCRYPTION |
bool |
CS_SEC_INTEGRITY |
bool |
CS_SEC_MUTUALAUTH |
bool |
CS_SEC_NEGOTIATE |
bool |
CS_SEC_NETWORKAUTH |
bool |
CS_CON_STATUS |
int |
CS_LOOP_DELAY |
int |
CS_RETRY_COUNT |
int |
CS_NETIO |
int |
CS_TEXTLIMIT |
int |
CS_DS_SEARCH |
int |
CS_DS_SIZELIMIT |
int |
CS_DS_TIMELIMIT |
int |
CS_ENDPOINT |
int |
CS_PACKETSIZE |
int |
CS_SEC_CREDTIMEOUT |
int |
CS_SEC_SESSTIMEOUT |
int |
CS_APPNAME |
string |
CS_HOSTNAME |
string |
CS_PASSWORD |
string |
CS_SERVERNAME |
string |
CS_USERNAME |
string |
CS_TDS_VERSION |
string |
CS_DS_DITBASE |
string |
CS_DS_PASSWORD |
string |
CS_DS_PRINCIPAL |
string |
CS_DS_PROVIDER |
string |
CS_SEC_KEYTAB |
string |
CS_SEC_MECHANISM |
string |
CS_SEC_SERVERPRINCIPAL |
string |
CS_TRANSACTION_NAME |
string |
CS_EED_CMD |
CS_COMMAND |
For an explanation of the property values and get/set/clear semantics please refer to the Sybase documentation.
def connect_db(ctx, server, user, passwd): status, conn = ctx.ct_con_alloc() if status != CS_SUCCEED: raise CSError(ctx, 'ct_con_alloc') if conn.ct_diag(CS_INIT) != CS_SUCCEED: raise CTError(conn, 'ct_diag') if conn.ct_con_props(CS_SET, CS_USERNAME, user) != CS_SUCCEED: raise CTError(conn, 'ct_con_props CS_USERNAME') if conn.ct_con_props(CS_SET, CS_PASSWORD, passwd) != CS_SUCCEED: raise CTError(conn, 'ct_con_props CS_PASSWORD') if conn.ct_connect(server) != CS_SUCCEED: raise CTError(conn, 'ct_connect') return conn ctx = init_db() conn = connect_db(ctx, 'SYBASE', 'guest', '')
When action is CS_SET
a compatible value argument
must be supplied and the method returns the Sybase result code.
When action is CS_GET
the method returns a tuple
containing the Sybase result code and the property value.
When action is CS_CLEAR
the method returns the Sybase
result code.
The recognised properties are:
property | type |
CS_OPT_ANSINULL |
bool |
CS_OPT_ANSIPERM |
bool |
CS_OPT_ARITHABORT |
bool |
CS_OPT_ARITHIGNORE |
bool |
CS_OPT_CHAINXACTS |
bool |
CS_OPT_CURCLOSEONXACT |
bool |
CS_OPT_FIPSFLAG |
bool |
CS_OPT_FORCEPLAN |
bool |
CS_OPT_FORMATONLY |
bool |
CS_OPT_GETDATA |
bool |
CS_OPT_NOCOUNT |
bool |
CS_OPT_NOEXEC |
bool |
CS_OPT_PARSEONLY |
bool |
CS_OPT_QUOTED_IDENT |
bool |
CS_OPT_RESTREES |
bool |
CS_OPT_SHOWPLAN |
bool |
CS_OPT_STATS_IO |
bool |
CS_OPT_STATS_TIME |
bool |
CS_OPT_STR_RTRUNC |
bool |
CS_OPT_TRUNCIGNORE |
bool |
CS_OPT_DATEFIRST |
int |
CS_OPT_DATEFORMAT |
int |
CS_OPT_ISOLATION |
int |
CS_OPT_ROWCOUNT |
int |
CS_OPT_TEXTSIZE |
int |
CS_OPT_AUTHOFF |
string |
CS_OPT_AUTHON |
string |
CS_OPT_CURREAD |
string |
CS_OPT_CURWRITE |
string |
CS_OPT_IDENTITYOFF |
string |
CS_OPT_IDENTITYON |
string |
For an explanation of the property values and get/set/clear semantics please refer to the Sybase documentation.
def connect_db(ctx, server, user, passwd): status, conn = ctx.ct_con_alloc() if status != CS_SUCCEED: raise CSError(ctx, 'ct_con_alloc') if conn.ct_diag(CS_INIT) != CS_SUCCEED: raise CTError(conn, 'ct_diag') if conn.ct_con_props(CS_SET, CS_USERNAME, user) != CS_SUCCEED: raise CTError(conn, 'ct_con_props CS_USERNAME') if conn.ct_con_props(CS_SET, CS_PASSWORD, passwd) != CS_SUCCEED: raise CTError(conn, 'ct_con_props CS_PASSWORD') if conn.ct_connect(server) != CS_SUCCEED: raise CTError(conn, 'ct_connect') if conn.ct_options(CS_SET, CS_OPT_CHAINXACTS, 1) != CS_SUCCEED: raise CTError(conn, 'ct_options') return conn ctx = init_db() conn = connect_db(ctx, 'SYBASE', 'guest', '')