pymssql module reference

python > pymssql module reference
27.04.2018 15:25:43


Наиболее часто встречающиеся слова в статье:

[connect] [database] [pymssql] [windows] [connection] [timeout] [default] [FreeTDS] [seconds] [version]


Статья:

Module-level symbols

Constants, required by the DB-API 2.0 (PEP 249) specification.

pymssql.apilevel

''2.0''  pymssql strives for compliance with DB-API 2.0.

pymssql.paramstyle

''pyformat''  pymssql uses extended python format codes.

pymssql.threadsafety

1 – Module may be shared, but not connections.

Functions

pymssql.connect(server=''.'', user='''', password='''', database='''', timeout=0, login_timeout=60, charset=''UTF-8'', as_dict=False, host='''', appname=None, port=''1433'', conn_properties, autocommit=False, tds_version=''7.1'')

Constructor for creating a connection to the database. Returns a Connection object.

Parameters:
  • server (str) – database host
  • user (str) – database user to connect as
  • password (str) – user’s password
  • database (str) – the database to initially connect to
  • timeout (int) – query timeout in seconds, default 0 (no timeout)
  • login_timeout (int) – timeout for connection and login in seconds, default 60
  • charset (str) – character set with which to connect to the database
  • conn_properties – SQL queries to send to the server upon connection establishment. Can be a string or another kind of iterable of strings. Default value: See _mssql.connect()
  • as_dict (bool) – whether rows should be returned as dictionaries instead of tuples
  • appname (str) – Set the application name to use for the connection
  • port (str) – the TCP port to use to connect to the server
  • autocommit (bool) – Whether to use default autocommiting mode or not
  • tds_version (str) – TDS protocol version to use.

Warning

Currently, setting timeout or login_timeout has a process-wide effect because the FreeTDS db-lib API functions used to implement such timeouts have a global effect.

Note

If you need to connect to Azure:

  • Use FreeTDS 0.91 or newer
  • Use TDS 7.1 or newer
  • Make sure FreeTDS is built with SSL support
  • Specify the database name you are connecting to in the connect() call
  • Specify the username in username@servername form in the connect() call

Example:

pymssql.connect("xxx.database.windows.net", "username@xxx.database.windows.net", "password", "db_name")

or:

pymssql.connect("myalias", "username@xxx.database.windows.net", "password", "db_name")

if you’ve defined myalias in the freetds.conf FreeTDS config file:

[myalias]
host = xxx.database.windows.net
tds version = 7.1
...