cx_Oracle摘记
由于想使用python操作oracle所以查看了cx_Oracle的官方文档,同时也查看了twisted中cx_Oracle的使用。下面是摘自文档中一些我认为有用的内容
cx_Oracle is a module that enables access to Oracle databases and conforms to the Python database API specification. This module is currently built against Oracle 11.2 and 12.1 and works for both Python 2.x and 3.x.
Any outstanding changes will be rolled back when the connection object is destroyed or closed.
任何没有提交的事务将在链接被摧毁或者关闭前回滚
Connection.autocommit
This read-write attribute determines whether autocommit mode is on or off.
Connection.begin() Connection.begin([formatId, transactionId, branchId])
Explicitly begin a new transaction. Without parameters, this explicitly begins a local transaction; otherwise, this explicitly begins a distributed (global) transaction with the given parameters
显式的开启一个本地事务或分布式事务
Connection.cancel()
Cancel a long-running transaction.
Connection.changepassword(oldpassword, newpassword)
Change the password of the logon.
Connection.close()
Close the connection now, rather than whenever __del__ is called. The connection will be unusable from this point forward; an Error exception will be raised if any operation is attempted with the connection. The same applies to any cursor objects trying to use the connection.
立刻关闭一个链接,此刻之前的链接将不可用,任何操作或者游标对象想要连接都会抛异常
Connection.commit()
Commit any pending transactions to the database.
提交任何待定的事务到数据库
Connection.cursor()
Return a new Cursor object (Cursor Object) using the connection.
Connection.dsn
This read-only attribute returns the TNS entry of the database to which a connection has been established.
返回已经连接的TNS入口
Connection.encoding
This read-only attribute returns the IANA character set name of the character set in use by the Oracle client.
返回ORACLE客户端的IANA字符集设置
Connection.ping()
Ping the server which can be used to test if the connection is still active.
Connection.register(code, when, function)
Register the function as an OCI callback. The code is one of the function codes defined in the Oracle documentation of which the most common ones are defined as constants in this module. The when parameter is one of UCBTYPE_ENTRY, UCBTYPE_EXIT or UCBTYPE_REPLACE. The function is a Python function which will accept the parameters that the OCI function accepts, modified as needed to return Python objects that are of some use. Note that this is a highly experimental method and can cause cx_Oracle to crash if not used properly. In particular, the OCI does not provide sizing information to the callback so attempts to access a variable beyond the allocated size will crash cx_Oracle. Use with caution.
注册一个函数作为OCI的回调用
Connection.rollback()
Rollback any pending transactions.
Connection.shutdown([mode])
Shutdown the database.
Connection.startup(force=False, restrict=False)
Startup the database.
Connection.stmtcachesize
This read-write attribute specifies the size of the statement cache. This value can make a significant difference in performance (up to 100x) if you have a small number of statements that you execute repeatedly.
这个参数可以定义语句缓存的大小,如果你有少量的重复执行的语句,可以看显著调高性能
Connection.subscribe(namespace=cx_Oracle.SUBSCR_NAMESPACE_DBCHANGE, protocol=cx_Oracle.SUBSCR_PROTO_OCI, callback=None, timeout=0, operations=OPCODE_ALLOPS, rowids=False, port=0, qos=0, cqqos=0)
Return a new Subscription object (Subscription Object) using the connection.
返回一个订阅对象
Connection.tnsentry
This read-only attribute returns the TNS entry of the database to which a connection has been established.
Connection.unregister(code, when)
Unregister the function as an OCI callback
注销一个函数作为OCI的回调
Connection.username
This read-only attribute returns the name of the user which established the connection to the database.
= show name
Connection.version
This read-only attribute returns the version of the database to which a connection has been established.
Cursor Object
Cursor.arraysize
This read-write attribute specifies the number of rows to fetch at a time internally and is the default number of rows to fetch with the fetchmany() call. It defaults to 50 meaning to fetch 50 rows at a time
定义了一次得到的记录数量,也是fetchmany方法的默认值,就是50条记录
Cursor.bindarraysize¶
This read-write attribute specifies the number of rows to bind at a time and is used when creating variables via setinputsizes() or var(). It defaults to 1 meaning to bind a single row at a time.
绑定变量的数量,一行是一个
Cursor.arrayvar(dataType, value[, size])
Create an array variable associated with the cursor of the given type and size and return a variable object (Variable Objects). The value is either an integer specifying the number of elements to allocate or it is a list and the number of elements allocated is drawn from the size of the list. If the value is a list, the variable is also set with the contentsof the list. If the size is not specified and the type is a string or binary, 4000 bytes (maximum allowable by Oracle) is allocated. This is needed for passing arrays to PL/SQL (in cases where the list might be empty and the type cannot be determined automatically) or returning arrays from PL/SQL.
创建一个数组变量关联游标给出的类型和大小并且返回一个变量类型。value这个参数或者是一个整数指定分配元素的数量或者是一个列表。value是一个列表,变量也被设置成列表的内容。如果size么偶有被定义或者是一个字符串,4000个字节将被分配。
Cursor.bindnames()
Return the list of bind variable names bound to the statement. Note that the statement must have been prepared first.
返回一个绑定变量名字的列表
Cursor.callfunc(name, returnType, parameters=[], keywordParameters = {})¶
Call a function with the given name.
用给出的名字调用一个函数
Cursor.callproc(name, parameters=[], keyewordParameters = {})
Call a procedure with the given name.
调用一个过程
Cursor.close()
Close the cursor now,
关闭一个游标
Cursor.connection()
This read-only attribute returns a reference to the connection object on which the cursor was created.
返回一个游标被创建的连接引用
Cursor.description¶
This read-only attribute is a sequence of 7-item sequences
7项序列号
Cursor.execute(statement, [parameters, ]**keywordParameters)
Execute a statement against the database. Parameters may be passed as a dictionary or sequence or as keyword arguments. If the arguments are a dictionary, the values will be bound by name and if the arguments are a sequence the values will be bound by position.
A reference to the statement will be retained by the cursor. If None or the same string object is passed in again, the cursor will execute that statement again without performing a prepare or rebinding and redefining. This is most effective for algorithms where the same statement is used, but different parameters are bound to it (many times). Note that parameters that are not passed in during subsequent executions will retain the value passed in during the last execution that contained them.
For maximum efficiency when reusing an statement, it is best to use the setinputsizes() method to specify the parameter types and sizes ahead of time; in particular, None is assumed to be a string of length 1 so any values that are later bound as numbers or dates will raise a TypeError exception.
If the statement is a query, a list of variable objects (Variable Objects) will be returned corresponding to the list of variables into which data will be fetched with the fetchone(), fetchmany() and fetchall() methods; otherwise, None will be returned.
尽快执行数据库中的一句,参数可以通过字典或序列关键字,如果参数是一个字典,值将被名字绑定,如果是序列值将被绑定位置
Cursor.executemany(statement, parameters, batcherrors=False, arraydmlrowcounts=False)
Prepare a statement for execution against a database and then execute it against all parameter mappings or sequences found in the sequence parameters. The statement is managed in the same way as the execute() method manages it.
When true, the batcherrors parameter enables batch error support within Oracle and ensures that the call succeeds even if an exception takes place in one or more of the sequence of parameters. The errors can then be retrieved using getbatcherrors().
When true, the arraydmlrowcounts parameter enables DML row counts to be retrieved from Oracle after the method has completed. The row counts can then be retrieved using getarraydmlrowcounts().
准备对数据库执行的语句,然后执行它对所有参数映射或序列中发现序列参数。
Cursor.executemanyprepared(numIters)
Execute the previously prepared and bound statement the given number of times
执行之前准备的绑定的语句用给出的次数
Cursor.fetchall()
Fetch all (remaining) rows of a query result, returning
获取所有查询的记录,作为一个元组列表
Cursor.fetchmany([numRows=cursor.arraysize])
Fetch the next set of rows of a query result, returning a list of tuples
返回设置行数的结果,
Cursor.fetchone()¶
Fetch the next row of a query result set
从查询结果集中取得下一行
Cursor.fetchraw([numRows=cursor.arraysize])
Fetch the next set of rows of a query result into the internal buffers of the defined variables for the cursor
获取下一个设置行数的查询结果,放在缓存中
Cursor.fetchvars
This read-only attribute specifies the list of variables created for the last query that was executed on the cursor. Care should be taken when referencing this attribute. In particular, elements should not be removed.
这个参数指明了最后一次查询的变量列表
Cursor.getarraydmlrowcounts()
Retrieve the DML row counts after a call to executemany() with arraydmlrowcounts enabled. This will return a list of integers corresponding to the number of rows affected by the DML statement for each element of the array passed to executemany().
检索DML行的数量在调用executemany()
Cursor.getbatcherrors()
Retrieve the exceptions that took place after a call to executemany() with batcherors enabled.
检索异常
Cursor.numbersAsStrings
This integer attribute defines whether or not numbers should be returned as strings rather than integers or floating point numbers. This is useful to get around the fact that Oracle floating point numbers have considerably greater precision than C floating point numbers and not require a change to the SQL being executed.
这个整数属性定义了数字是否应该返回成字符串而不是整数或浮点数
Cursor.rowcount
This read-only attribute specifies the number of rows that have currently been fetched from the cursor (for select statements) or that have been affected by the operation (for insert, update and delete statementsCursor.setoutputsize(size[, column])
Cursor.rowfactory
This read-write attribute specifies a method to call for each row that is retrieved from the database. Ordinarily a tuple is returned for each row but if this attribute is set, the method is called with the argument tuple that would normally be returned and the result of the method is returned instead.
Cursor.setinputsizes(*args, **keywordArgs)
This can be used before a call to execute(), callfunc() or callproc() to predefine memory areas for the operation’s parameters.
可以在执行之前预先确定内存分配大小
Cursor.setoutputsize(size[, column])
This can be used before a call to execute() to predefine memory areas for the long columns that will be fetched. The column is specified as an index into the result sequence. Not specifying the column will set the default size for all large columns in the cursor.
Cursor.statement
This read-only attribute provides the string object that was previously prepared with prepare() or executed with execute().
Cursor.var(dataType[, size, arraysize, inconverter, outconverter, typename])
Create a variable associated with the cursor of the given type and characteristics and return a variable object (Variable Objects). If the size is not specified and the type is a string or binary, 4000 bytes (maximum allowable by Oracle) is allocated; if the size is not specified and the type is a long string or long binary, 128KB is allocated. If the arraysize is not specified, the bind array size (usually 1) is used. The inconverter and outconverter specify methods used for converting values to/from the database. More information can be found in the section on variable objects.
To create an empty SQL object variable, specify the typename. Additional support for editing the attributes of this object is not yet available but will be forthcoming in a future release.
This method was designed for use with PL/SQL in/out variables where the length or type cannot be determined automatically from the Python object passed in or for use in input and output type handlers defined on cursors or connections.
SessionPool Object
SessionPool.acquire()
Acquire a connection from the session pool and return a connection object (Connection Object).
从会话池中获得链接然后返回一个链接对象
SessionPool.busy¶
This read-only attribute returns the number of sessions currently acquired.
返回了当前获得会话的数量
SessionPool.drop(connection)
Drop the connection from the pool which is useful if the connection is no longer usable (such as when the session is killed).
从池子中删除一个不可用的连接
SessionPool.dsn
This read-only attribute returns the TNS entry of the database to which a connection has been established.
返回链接的TNS入口
SessionPool.homogeneous
This read-write boolean attribute indicates whether the pool is considered homogeneous or not. If the pool is not homogeneous different authentication can be used for each connection acquired from the pool.
这个读写布尔属性表明池是否均匀。
SessionPool.increment
This read-only attribute returns the number of sessions that will be established when additional sessions need to be created.
返回会话被创建时需要额外的会话数量
SessionPool.max
This read-only attribute returns the maximum number of sessions that the session pool can control.
返回会话池的上限
SessionPool.min
This read-only attribute returns the number of sessions with which the session pool was created and the minimum number of sessions that will be controlled by the session pool.
返回会话池的下线
SessionPool.name
返回会话池的名字
SessionPool.opened
This read-only attribute returns the number of sessions currently opened by the session pool.
返回当前打开会话的数量
SessionPool.release(connection)¶
Release the connection back to the pool. This will be done automatically as well if the connection object is garbage collected.
释放链接到进程池
SessionPool.timeout
This read-write attribute indicates the time (in seconds) after which idle sessions will be terminated in order to maintain an optimum number of open sessions.
空进程将被终止的时间
SessionPool.username
This read-only attribute returns the name of the user which established the connection to the database.
返回一个链接的用户名
cx_Oracle摘记的更多相关文章
- ubuntu 下安装 cx_Oracle库
1.下载3个zip包: 下载地址:http://www.oracle.com/technetwork/database/features/instant-client/index-097480.htm ...
- 使用pip安装 cx_Oracle 模块
1. 系统环境,linux, python3.5, pip以下命令的执行均使用root用户. 2. 执行 pip install cx_Oracle出错,提示不能定位Oracle的安装.出现该问题的原 ...
- python导入cx_Oracle报错的问题!
import cx_Oracle 总是报错:ImportError: DLL load failed: 找不到指定的模块. 或者:ImportError: DLL load failed: %1 不是 ...
- install cx_Oracle on Linux
step 1 : install oracle client library url: http://www.oracle.com/technetwork/topics/linuxsoft-08280 ...
- cx_Oracle 报错 Reason: image not found
(Study_env) ➜ DAL python -c "import cx_Oracle"Traceback (most recent call last): File &quo ...
- Python导入cx_Oracle报错
系统环境:RHEL5.4 python2.5(手动编译安装,系统带有2.4版本) 在使用python脚本访问数据库时,需要导入cx_Oracle模块 $>>>import cx_ ...
- Linux搭建python环境中cx_Oracle模块安装遇到的问题与解决方法
安装或使用cx_Oracle时,需要用到Oracel的链接库,如libclntsh.so.11.1,否则会有各种各样的错误信息. 安装Oracle Instant Client就可得到这个链接库,避免 ...
- Python中通过cx_oracle操作ORACLE数据库的封闭函数
哈哈,看来我的SQL自动化发布,马上就全面支持ORACLE,MYSQL,POSTGRESQL,MSSQL啦... http://blog.csdn.net/swiftshow/article/deta ...
- Python中通过cx_Oracle访问数据库遇到的问题总结
以下是Python中通过cx_Oracle操作数据库的过程中我所遇到的问题总结,感谢我们测试组的前辈朱勃给予的帮助最终解决了下列两个问题: 1)安装cx_Oracle会遇到的问题:在Windo ...
随机推荐
- SpringMVC + Spring + MyBatis 整合 + Spring shrio + easyUI + 权限管理框架,带shrio session和shrio cache集群实现方案
工作之余先来写了一个不算规范的简单架子 基于spring mvc + spring + mybatis + Spring shrio 基于redis的集群方案 系统权限部分,分成多个机构,其中每个机构 ...
- Centos7更改默认启动模式(转载)
今天心血来潮安装一个centos7的图形界面,但发现用之前的方式无法修改默认启动为命令行模式. 之前的方法:修改/etc/inittab文件中的 id:3:initdefault ...
- Linux2.6内核协议栈系列--TCP协议2.接收
1.排队机制 接收输入TCP报文时,有三个队列: ● 待处理队列 ● 预排队队列 ● 接收队列 接收队列包含了处理过的TCP数据段,也就是说,去除了全部的协议头,正准备将数据复制到用户应用程序.接收队 ...
- android MD5加密
public class MD5Uutils { //MD5加密,32位 public static String MD5(String str) { MessageDige ...
- freeswitch嵌入python脚本
操作系统:debian8.5_x64 freeswitch 版本 : 1.6.8 python版本:2.7.9 开启python模块 安装python lib库 apt-get install pyt ...
- python-socket模块
socket server #!/usr/bin/env python # -*- coding:utf-8 -*- import socket ip_port = ('127.0.0.1',9999 ...
- python-运算符
1.算数运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 本文转载自http://www.cnblogs.com/wupeiqi/articles/5444685.html
- idea fect
idea facet 昨天从svn检查一个项目后,部署至tomcat服务器,启动成功,但实际代码其实没有进去, 因为该项目不是maven项目, artifacats是自己配的, 应该是这里弄错的. 最 ...
- Referenced file contains errors (http://www.springframework.org/schema...错误
Referenced file contains errors (http://www.springframework.org/schema...错误 Referenced file contains ...
- NodeJS、NPM安装配置步骤(windows版本)
windows下的NodeJS安装是比较方便的(v0.6.0版本之后,支持windows native),只需要登陆官网(http://nodejs.org/),便可以看到首页的"INSTA ...