ctds¶
cTDS is a pure C implementation of the Python DB API 2.0 specification for Microsoft SQL Server.
-
ctds.
apilevel
¶
-
ctds.
paramstyle
¶
-
ctds.
threadsafety
¶
-
ctds.
version_info
¶ The cTDS version, as a (MAJOR, MINOR, PATCH) tuple.
-
exception
ctds.
Error
¶ -
Exception that is the base class of all other error exceptions. You can use this to catch all errors with one single except statement.
-
exception
ctds.
InterfaceError
¶ -
Exception raised for errors that are related to the database interface rather than the database itself.
-
exception
ctds.
DatabaseError
¶ -
Exception raised for errors that are related to the database.
The exception contains the following properties:
-
db_error
¶ A
dict
containing information relating to an error returned by the database.{ 'number': 123, 'description': 'An error description' }
-
os_error
¶ A
dict
containing information relating to an error caused by a database connection issue. This will beNone
if the error was not caused by a connection issue.{ 'number': 123, 'description': 'An error description' }
-
last_message
¶ A
dict
containing more detailed information about. the error returned from the database. This may beNone
if the error does not include more information from the database, e.g. a connection error.{ 'number': 123, 'state': 0, 'severity': 16, 'description': 'An error description' 'server': 'database-hostname' 'proc': 'procedure_name' 'line': 34 }
-
-
exception
ctds.
DataError
¶ -
Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.
-
exception
ctds.
OperationalError
¶ -
Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.
-
exception
ctds.
IntegrityError
¶ -
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.
-
exception
ctds.
InternalError
¶ -
Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.
-
exception
ctds.
ProgrammingError
¶ -
Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc.
-
exception
ctds.
NotSupportedError
¶ -
Exception raised in case a method or database API was used which is not supported by the database, e.g. calling
rollback()
on a connection that does not support transactions or has transactions turned off.
-
exception
ctds.
Warning
¶ -
Exception raised for important warnings like data truncations while inserting, etc.
-
ctds.
Binary
(string)¶ This function constructs an object capable of holding a binary (long) string value.
-
ctds.
Date
(year, month, day)¶ This function constructs an object holding a date value.
- Parameters
- Returns
A new date object.
- Return type
-
ctds.
DateFromTicks
(ticks)¶ This function constructs an object holding a date value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).
- Parameters
ticks (int) – The number of seconds since the epoch.
- Returns
A new date object.
- Return type
-
ctds.
Time
(hour, minute, second)¶ This function constructs an object holding a time value.
- Parameters
- Returns
A new time object.
- Return type
-
ctds.
TimeFromTicks
(ticks)¶ This function constructs an object holding a time value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).
- Parameters
ticks (int) – The number of seconds since the epoch.
- Returns
A new time object.
- Return type
-
ctds.
Timestamp
(year, month, day, hour, minute, second)¶ This function constructs an object holding a time stamp value.
-
ctds.
TimestampFromTicks
(ticks)¶ This function constructs an object holding a time stamp value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).
- Parameters
ticks (int) – The number of seconds since the epoch.
- Returns
A new datetime object.
- Return type
-
ctds.
connect
(server, port=1433, instance=None, user='', password='', database=None, appname='ctds', hostname=None, login_timeout=5, timeout=5, tds_version=None, autocommit=False, ansi_defaults=True, enable_bcp=True, paramstyle=None, read_only=False, ntlmv2=False)¶ Connect to a database.
Note
ctds.Connection.close()
should be called when the returned connection object is no longer required.New in version 1.6: paramstyle
New in version 1.6: read_only
New in version 1.8: hostname
New in version 1.8: ntlmv2
- Parameters
server (str) – The database server host.
port (int) – The database server port. This value is ignored if instance is provided.
instance (str) – An optional database instance to connect to.
user (str) – The database server username.
password (str) – The database server password.
database (str) – An optional database to initially connect to.
appname (str) – An optional application name to associate with the connection.
hostname (str) – An optional client host name to associate with the connection instead of the local device hostname.
login_timeout (int) – An optional login timeout, in seconds.
timeout (int) – An optional timeout for database requests, in seconds.
tds_version (str) – The TDS protocol version to use. If
None
is specified, the highest version supported by FreeTDS will be used.autocommit (bool) – Autocommit transactions on the connection.
ansi_defaults (bool) – Set ANSI_DEFAULTS and related settings to mimic ODBC drivers.
enable_bcp (bool) – Enable bulk copy support on the connection. This is required for
bulk_insert()
to function.paramstyle (str) – Override the default
ctds.paramstyle
value for this connection. Supported values: numeric, named.read_only (bool) – Indicate ‘read-only’ application intent.
ntlmv2 (bool) – Enable NTLMv2 authentication.
- Returns
A new Connection object connected to the database.
- Return type