pymssql文档

pymssql文档pymssqlmetho max connections number Setsmaximumn Defaultis25 get max connections Gets

pymssql methods

  • set_max_connections(number) — Sets maximum number of simultaneous database connections allowed to be open at any given time. Default is 25.
  • get_max_connections() — Gets current maximum number of simultaneous database connections allowed to be open at any given time.

Connection (pymssqlCnx) class

This class represents an MS SQL database connection. You can create an instance of this class by calling constructor
pymssql.connect(). It accepts the following arguments. Note that in most cases you will want to use keyword arguments, instead of positional arguments.

  • dsn — colon-delimited string of the form host:dbase:user:pass:opt:tty, primarily for compatibility with previous versions of pymssql. This argument is removed in pymssql 2.0.0.
  • user — database user to connect as.
  • password — user’s password.
  • trusted — bolean value signalling whether to use Windows Integrated Authentication to connect instead of SQL autentication with user and password (Windows only) This argument is removed in pymssql 2.0.0 however Windows authentication is still possible.
  • host — database host and instance you want to connect to. Valid examples are:
    • r'.\SQLEXPRESS' — SQLEXPRESS instance on local machine (Windows only)
    • r'(local)\SQLEXPRESS' — same as above (Windows only)
    • r'SQLHOST' — default instance at default port (Windows only)
    • r'SQLHOST' — specific instance at specific port set up in freetds.conf (Linux/*nix only)
    • r'SQLHOST,1433' — specified TCP port at specified host
    • r'SQLHOST:1433' — the same as above
    • r'SQLHOST,5000' — if you have set up an instance to listen on port 5000
    • r'SQLHOST:5000' — the same as above

‘.’ (the local host) is assumed if host is not provided.

  • database — the database you want initially to connect to, by default SQL Server selects the database which is set as default for specific user.
  • timeout — query timeout in seconds, default is 0 (wait indefinitely).
  • login_timeout — timeout for connection and login in seconds, default 60.
  • charset — character set with which to connect to the database.
  • as_dict — whether rows should be returned as dictionaries instead of tuples. You can access columns by 0-based index or by name. Please see examples. (Added in pymssql 1.0.2).
  • max_conn — how many simultaneous connections to allow; default is 25, maximum on Windows is ; trying to set it to higher value results in error ‘Attempt to set maximum number of DBPROCESSes lower than 1.’ (error 10073 severity 7). (Added in pymssql 1.0.2). This property is removed in pymssql 2.0.0.

Connection object properties

This class has no useful properties and data members.

Connection object methods

  • autocommit(status) — where status is a boolean value. This method turns autocommit mode on or off. By default, autocommit mode is off, what means every transaction must be explicitly committed if changed data is to be persisted in the database. You can turn autocommit mode on, what means every single operation commits itself as soon as it succeeds.
  • close() — Close the connection.
  • cursor() — Return a cursor object, that can be used to make queries and fetch results from the database.
  • commit() — Commit current transaction. You must call this method to persist your data if you leave autocommit at its default value, which is False. See also pymssql examples.
  • rollback() — Roll back current transaction.

Cusor (pymssqlCursor) class

This class represents a Cursor (in terms of Python DB-API specs) that is used to make queries against the database and obtaining results. You create 
pymssqlCursor instances by calling 
cursor() method on an open 
pymssqlCnx connection object.

Cusor object properties

  • rowcount — Returns number of rows affected by last operation. In case of SELECT statements it returns meaningful information only after all rows have been fetched.
  • connection — This is the extension of the DB-API specification. Returns a reference to the connection object on which the cursor was created.
  • lastrowid — This is the extension of the DB-API specification. Returns identity value of last inserted row. If previous operation did not involve inserting a row into a table with identity column, None is returned.
  • rownumber — This is the extension of the DB-API specification. Returns current 0-based index of the cursor in the result set.

Cusor object methods

  • close() — Close the cursor. The cursor is unusable from this point.
  • execute(operation),
  • execute(operation, params) — operation is a string and params, if specified, is a simple value, a tuple, or None. Performs the operation against the database, possibly replacing parameter placeholders with provided values. This should be preferred method of creating SQL commands, instead of concatenating strings manually, what makes a potential of SQL Injection attacks. This method accepts the same formatting as Python’s builtin string interpolation operator. If you call execute() with one argument, the % sign loses its special meaning, so you can use it as usual in your query string, for example in LIKE operator. See the examples. You must callconnection.commit() after execute() or your data will not be persisted in the database. You can also set connection.autocommit if you want it to be done automatically. This behaviour is required by DB-API, if you don’t like it, just use the _mssql module instead.
  • executemany(operation, params_seq) — operation is a string and params_seq is a sequence of tuples (e.g. a list). Execute a database operation repeatedly for each element in parameter sequence.
  • fetchone() — Fetch the next row of a query result, returning a tuple, or a dictionary if as_dict was passed to pymssql.connect(), orNone if no more data is available. Raises OperationalError if previous call to execute*() did not produce any result set or no call was issued yet.
  • fetchmany(size=None) — Fetch the next batch of rows of a query result, returning a list of tuples, or a list of dictionaries if as_dict was passed to pymssql.connect(), or an empty list if no more data is available. You can adjust the batch size using the size parameter, which is preserved across many calls to this method. Raises OperationalError if previous call to execute*() did not produce any result set or no call was issued yet.
  • fetchall() — Fetch all remaining rows of a query result, returning a list of tuples, or a list of dictionaries if as_dict was passed topymssql.connect(), or an empty list if no more data is available. Raises OperationalError if previous call to execute*() did not produce any result set or no call was issued yet.
  • fetchone_asdict() — (Warning: this method is not part of DB-API. This method is deprecated as of pymsssql 1.0.2. It was replaced byas_dict parameter to pymssql.connect()). Fetch the next row of a query result, returning a dictionary, or None if no more data is available. Data can be accessed by 0-based numeric column index, or by column name. Raises OperationalError if previous call to execute*() did not produce any result set or no call was issued yet. This method is removed in pymssql 2.0.0.
  • fetchmany_asdict(size=None) — (Warning: this method is not part of DB-API. This method is deprecated as of pymsssql 1.0.2. It was replaced by as_dict parameter to pymssql.connect()). Fetch the next batch of rows of a query result, returning a list of dictionaries. An empty list is returned if no more data is available. Data can be accessed by 0-based numeric column index, or by column name. You can adjust the batch size using the size parameter, which is preserved across many calls to this method. Raises OperationalError if previous call to execute*() did not produce any result set or no call was issued yet. This method is removed in pymssql 2.0.0.
  • fetchall_asdict() — (Warning: this method is not part of DB-API. This method is deprecated as of pymsssql 1.0.2. It was replaced byas_dict parameter to pymssql.connect()). Fetch all remaining rows of a query result, returning a list of dictionaries. An empty list is returned if no more data is available. Data can be accessed by 0-based numeric column index, or by column name. RaisesOperationalError if previous call to execute*() did not produce any result set or no call was issued yet. The idea and original implementation of this method by Sterling Michel <sterlingmichel_at_gmail_dot_com>. Thie method is removed in pymssql 2.0.0.
  • nextset() -- This method makes the cursor skip to the next available result set, discarding any remaining rows from the current set. Returns True value if next result is available, None if not.
  • __iter__()next() -- These methods faciliate Python iterator protocol. You most likely will not call them directly, but indirectly by using iterators.
  • setinputsizes()setoutputsize() -- These methods do nothing, as permitted by DB-API specs.

转载于:https://www.cnblogs.com/xcf007/archive/2012/12/24/2830934.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/227657.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月16日 下午8:50
下一篇 2026年3月16日 下午8:51


相关推荐

  • 腾讯混元翻译模型实测:Hunyuan-MT-7B开箱即用教程

    腾讯混元翻译模型实测:Hunyuan-MT-7B开箱即用教程

    2026年3月12日
    2
  • 教你如何激活成功教程无线网络密码(无线网络密码激活成功教程)

    教你如何激活成功教程无线网络密码(无线网络密码激活成功教程)面对电脑搜索到的无线网络信号 你是否怦然心动 但看到一个个 启用安全的无线网络 你是否又感到有一丝遗憾 本人作为一个心动 遗憾的代表 充分发挥主观能动性 总算学有所成 终于能成功无线密码 这份成功的喜悦不敢独享 写下该篇教程 nbsp nbsp nbsp 注 nbsp nbsp nbsp 1 本文针对的无线激活成功教程是指 wep 的激活成功教程 wpa 激活成功教程现在仍是技术难题 不在本文讨论之列 如果你家无线路由需要加密 为保障安全也请采用 wpa 模式 如果

    2026年2月22日
    1
  • 通过pycharm安装python_JAVA开发环境

    通过pycharm安装python_JAVA开发环境Python开发环境搭建与helloWorld测试1.去官网下载然后傻瓜式安装2.下载开发IDE:这里选用pychram下载地址:pychram官网新建一个工厂后写简单的helloworld然后:找到你工程的文件,Helloworld.py最后点击OK即可看运行结果:pycha…

    2022年8月27日
    5
  • C#生成Excel出现8000401a的错误的另一种解决办法。「建议收藏」

    C#生成Excel出现8000401a的错误的另一种解决办法。「建议收藏」网上能搜到的解决办法,常见的就是以下3种,比如参考这个博客https://www.cnblogs.com/gavindou/archive/2012/08/29/2661757.html1,增加虚拟权限:在web.config里面增加的键值;要求administrator具有管理员权限,这种方案使用后确实可行,可是不利于部署,因为有经验的人都知道把一个最高权限的服务器帐号密码公开显示在配置…

    2022年8月22日
    9
  • MQ消息队列详解、四大MQ的优缺点分析

    MQ消息队列详解、四大MQ的优缺点分析MQ消息队列详解近期有了想跳槽的打算,所以自己想巩固一下自己的技术,想了解一些面试比较容易加分的项,近期准备深入研究一下redis和mq这两样,这总体上都是为了解决服务器并发的原因,刚翻到了一篇有关于mq的,觉得写得特别好,特此记录一下,也算是为了加深自己的印象。首先从MQ容易面对的面试题切入一下为什么要使用MQ消息队列有什么优点和缺点kafka、ActiveMQ、RabbitMQ、R…

    2022年6月2日
    34
  • HTML CSS 鼠标样式效果[通俗易懂]

    HTML CSS 鼠标样式效果[通俗易懂]HTML/CSS/JS目录:https://blog.csdn.net/dkbnull/article/details/87934939 &lt;divstyle="cursor:hand"&gt;鼠标手型效果&lt;/div&gt;&lt;divstyle="cursor:pointer"&gt;鼠标手型效果&lt;/div&gt;&lt;!–pointer兼容性比较好

    2022年5月6日
    23

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号