您的位置:首页 > 数据库 > Oracle

Welcome to cx_Oracle’s documentation

2016-01-12 22:52 429 查看
由于想使用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.

  返回一个链接的用户名

  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: