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 ...
随机推荐
- 设计模式-代理模式(Proxy Model)
文 / vincentzh 原文连接:http://www.cnblogs.com/vincentzh/p/5988145.html 目录 1.写在前面 2.概述 3.目的 4.结构组成 5.实现 5 ...
- IIS7 应用程序池自动回收关闭的解决方案
在ASP.NET Application中加入某个定时任务,那想必一定是用一个线程在不停地做定时计算,在自己的ASP.NET应用程序中加入了Quartz.NET框架 夜间或者网站在经过无访问阶段后,后 ...
- CSS3_01之选择器、Hack
1.兄弟选择器:①相邻兄弟选择器:元素的后一个兄弟元素,选择器1+选择器2:②通用兄弟选择器:元素后的所有兄弟元素,选择器1~选择器2: 2.属性选择器:attr表示属性名称,elem表示元素名:①[ ...
- SharePoint 是哪些人设计、开发的?
闲下来的时候,我有时候会想:SharePoint 是哪些人设计.开发的? 毕竟,你说一个单选的字段,你从列表里面添加的时候,字段类型选的是 “Yes/No”:而如果你是通过编程把它加入列表的时候,字段 ...
- 苹果的MDM简介
MDM(Mobile Device Management)移动设备管理,一般会用于企业管理其移动设备,鉴于iOS是比较封闭的系统很多的功能都难以实现,所以利用苹果的MDM可以达到远程控制设备,像远程定 ...
- MongoDB学习笔记系列
回到占占推荐博客索引 该来的总会来的,Ef,Redis,MVC甚至Sqlserver都有了自己的系列,MongoDB没有理由不去整理一下,这个系列都是平时在项目开发时总结出来的,希望可以为各位一些帮助 ...
- Spark核心——RDD
Spark中最核心的概念为RDD(Resilient Distributed DataSets)中文为:弹性分布式数据集,RDD为对分布式内存对象的 抽象它表示一个被分区不可变且能并行操作的数据集:R ...
- WinXP/Win7/Win8本地用户配置文件迁移至域用户
一.概述 最近在进行加域的工作,PC大部分是Win7,使用过微软USMT 4.0和5.0工具进行迁移,但命令行报错,目前还没找到好的文章研究. 本文迁移方法很特殊,利用的是Windows默认配置文件. ...
- [jquery]if条件句
//写个网页用了多门语言,脑袋转不过来亚! //代码: if(){} else if(){} else {}
- [No0000A7]批处理经常用到的变量及批处理>NUL详细介绍
绝对路径是指调用绝对的程序位置的路径,例如: start C:\Windows\test.exe 相对路径是文件改变路径以后还会按照变量的路径所在位置去调用,例如: start %WINDIR%\te ...