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 constructorpymssql.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 1474559; 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.

pymssql文档(转)的更多相关文章

  1. pymssql文档

    原文地址 http://pymssql.org/en/latest/ref/_mssql.html _mssql module reference pymssql模块类,方法和属性的完整文档. Com ...

  2. C#给PDF文档添加文本和图片页眉

    页眉常用于显示文档的附加信息,我们可以在页眉中插入文本或者图形,例如,页码.日期.公司徽标.文档标题.文件名或作者名等等.那么我们如何以编程的方式添加页眉呢?今天,这篇文章向大家分享如何使用了免费组件 ...

  3. dotNET跨平台相关文档整理

    一直在从事C#开发的相关技术工作,从C# 1.0一路用到现在的C# 6.0, 通常情况下被局限于Windows平台,Mono项目把我们C#程序带到了Windows之外的平台,在工作之余花了很多时间在M ...

  4. ABP文档 - Javascript Api - AJAX

    本节内容: AJAX操作相关问题 ABP的方式 AJAX 返回信息 处理错误 HTTP 状态码 WrapResult和DontWrapResult特性 Asp.net Mvc 控制器 Asp.net ...

  5. ABP文档 - EntityFramework 集成

    文档目录 本节内容: Nuget 包 DbContext 仓储 默认仓储 自定义仓储 特定的仓储基类 自定义仓储示例 仓储最佳实践 ABP可使用任何ORM框架,它已经内置了EntityFrame(以下 ...

  6. ABP文档 - SignalR 集成

    文档目录 本节内容: 简介 安装 服务端 客户端 连接确立 内置功能 通知 在线客户端 帕斯卡 vs 骆峰式 你的SignalR代码 简介 使用Abp.Web.SignalR nuget包,使基于应用 ...

  7. ABP文档 - 通知系统

    文档目录 本节内容: 简介 发送模式 通知类型 通知数据 通知重要性 关于通知持久化 订阅通知 发布通知 用户通知管理器 实时通知 客户端 通知存储 通知定义 简介 通知用来告知用户系统里特定的事件发 ...

  8. ABP文档 - Hangfire 集成

    文档目录 本节内容: 简介 集成 Hangfire 面板授权 简介 Hangfire是一个综合的后台作业管理器,可以在ABP里集成它替代默认的后台作业管理器,你可以为Hangfire使用相同的后台作业 ...

  9. ABP文档 - 后台作业和工作者

    文档目录 本节内容: 简介 后台作业 关于作业持久化 创建一个后台作业 在队列里添加一个新作业 默认的后台作业管理器 后台作业存储 配置 禁用作业执行 Hangfire 集成 后台工作者 创建一个后台 ...

随机推荐

  1. centos7 下安装和配置 mongodb (重点)

    1.下载安装包 wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.4.tgz 2.解压 tar -zxvf m ...

  2. Android 关于 CountDownTimer onTick() 倒计时不准确问题源码分析

    一.问题 CountDownTimer 使用比较简单,设置 5 秒的倒计时,间隔为 1 秒. final String TAG = "CountDownTimer"; * , ) ...

  3. 企业SOA架构案例分析

    面向服务的架构(SOA)是一个组件模型,它将应用程序的不同功能单元(称为服务)进行拆分,并通过这些服务之间定义良好的接口和契约联系起来.接口是采用中立的方式进行定义的,它应该独立于实现服务的硬件平台. ...

  4. LC 641. Design Circular Deque

    Design your implementation of the circular double-ended queue (deque). Your implementation should su ...

  5. 【分布式事务】使用atomikos+jta解决分布式事务问题

    一.前言 分布式事务,这个问题困惑了小编很久,在3个月之前,就间断性的研究分布式事务.从MQ方面,数据库事务方面,jta方面.近期终于成功了,使用JTA解决了分布式事务问题.先写一下心得,后面的二级提 ...

  6. Linux shell脚本重试机制

    重试机制在实际编程场景中应用比较场景,比如你的任务在请求一个正在写入数据但不确定什么时间会完成的文件,可能就需要通过尝试机制间隔一段时间重新执行任务. 以下 shell 脚本是实现重试机制的模板: # ...

  7. MVC自定义视图

    编写自定义模板,以单选按钮为例   1.在Shared新建模板视图(文件夹名必须为EditorTemplates)       2.编写模板代码   @model bool   <table&g ...

  8. Java数组(2):数组与泛型

    通常,数组与泛型不能很好的结合,你不能实例化具有参数化类型的数组.擦除会移除参数类型信息,而数组必须知道它们所持有的确切类型.但是我们可以参数化数组本身. import java.util.Array ...

  9. vue中自定义指令的使用

    原文地址 vue中除了内置的指令(v-show,v-model)还允许我们自定义指令 想要创建自定义指令,就要注册指令(以输入框获取焦点为例) 一.注册全局指令: // 注册一个全局自定义指令 `v- ...

  10. Spring boot Gradle项目搭建

    Spring boot Gradle项目搭建 使用IDEA创建Gradle工程     操作大致为:File->new->Project->Gradle(在左侧选项栏中)     创 ...