ll.orasql

Utilities for working with cx_Oracle

Home › Python software › ll.orasqlText · XIST · Python

ll.orasql contains utilities for working with cx_Oracle:

class SQLObjectNotFoundError​(exceptions.Exception):

def __init__​(self, obj):

def __repr__​(self):

def __str__​(self):

class SQLNoSuchObjectError​(exceptions.Exception):

def __init__​(self, name, owner):

def __repr__​(self):

def __str__​(self):

class UnknownModeError​(exceptions.ValueError):

def __init__​(self, mode):

def __repr__​(self):

def __str__​(self):

class UnknownSchemaError​(exceptions.ValueError):

def __init__​(self, schema):

def __repr__​(self):

def __str__​(self):

class ConflictError​(exceptions.ValueError):

def __init__​(self, object, message):

def __repr__​(self):

def __str__​(self):

class Args​(dict):

An Args object is a subclass of dict that is used for passing arguments to procedures and functions. Both item and attribute access (i.e. __getitem__ and __getattr__) are available. Names are case insensitive.

def __init__​(self, arg=None, **kwargs):

def update​(self, arg=None, **kwargs):

def __getitem__​(self, name):

def __setitem__​(self, name, value):

def __delitem__​(self, name):

def __getattr__​(self, name):

def __setattr__​(self, name, value):

def __delattr__​(self, name):

def __xattrs__​(self, mode='default'):

def __xrepr__​(self, mode):

def __repr__​(self):

class RecordMaker​(object):

def __init__​(self, cursor):

def _decode​(self, value):

def __call__​(self, *row):

class Record​(tuple):

A Record is a subclass of tuple that is used for storing results of database fetches and procedure and function calls. Both item and attribute access (i.e. __getitem__ and __getattr__) are available. Field names are case insensitive.

def __getitem__​(self, arg):

def __getattr__​(self, name):

def get​(self, name, default=None):

Return the value for the field named name. If this field doesn't exist in self, return default instead.

def __contains__​(self, name):

def iterkeys​(self):

Return an iterator over field names

def keys​(self):

Return a list of field names

def items​(self):

Return a list of (field name, field value) tuples.

def iteritems​(self):

Return an iterator over (field name, field value) tuples.

def __xattrs__​(self, mode='default'):

def __xrepr__​(self, mode):

def __repr__​(self):

class _AllTypes​(object):

def __init__​(self, connection, class_, schema, count):

def __xattrs__​(self, mode='default'):

def __xrepr__​(self, mode):

def __iter__​(self):

class SessionPool​(OracleSessionPool):

SessionPool is a subclass of cx_Oracle.SessionPool.

def __init__​(self, user, password, database, min, max, increment, connectiontype=None, threaded=False, getmode=1, homogeneous=True):

def connectstring​(self):

def __repr__​(self):

class Connection​(cx_Oracle.Connection):

Connection is a subclass of cx_Oracle.Connection.

def __init__​(self, *args, **kwargs):

Create a new connection. In addition to the parameters supported by cx_Oracle.connect the following keyword argument is supported.

readlobs (bool or integer)

If readlobs is False all cursor fetch return LOB objects as usual. If readlobs is an int (or long) LOB`s with a maximum size of :var:`readlobs will be returned as strings. If readlobs is True all LOB values will be returned as strings.

def connectstring​(self):

def cursor​(self, readlobs=None):

Return a new cursor for this connection. For the meaning of readlobs see __init__.

def __repr__​(self):

def __xrepr__​(self, mode):

def iterschema​(self, schema='user'):

Generator that returns the number of different object types for this database. For the meaning of schema see iterobjects.

def itertables​(self, schema='user', mode='flat'):

Generator that yields all table definitions in the current users schema (or all users schemas). mode specifies the order in which tables will be yielded:

"drop"

Drop order, deleting records from the table in this order will not violate foreign key onstraints.

"flat"

Unordered.

schema specifies from which user tables should be yielded:

"user"

Only tables belonging to the current user (and those objects these depend on) will be yielded.

"all"

All tables from all users will be yielded.

Tables that are materialized view will be skipped in both casess.

def itersequences​(self, schema='user'):

Generator that yields all sequence in the current users schema (or all users schemas). schema specifies from which user sequences should be yielded:

"user"

Only sequences belonging to the current user will be yielded.

"all"

All sequences from all users will be yielded.

def iterfks​(self, schema='user'):

Generator that yields all foreign key constraints in the current users schema (or all users schemas). schema specifies from which user foreign keys should be yielded:

"user"

Only tables belonging to the current user (and those objects these depend on) will be yielded.

"all"

All tables from all users will be yielded.

def iterobjects​(self, mode='create', schema='user'):

Generator that yields the sequences, tables, primary keys, foreign keys, comments, unique constraints, indexes, views, functions, procedures, packages and types in the current users schema (or all users schemas) in a specified order.

mode specifies the order in which objects will be yielded:

"create"

Create order, i.e. recreating the objects in this order will not lead to errors.

"drop"

Drop order, i.e. dropping the objects in this order will not lead to errors.

"flat"

Unordered.

schema specifies from which schema objects should be yielded:

"user"

Only objects belonging to the current user (and those objects these depend on) will be yielded.

"all"

All objects from all users will be yielded.

def _getobject​(self, name, owner=None):

def getobject​(self, name, owner=None):

Return the object named name from the schema. If owner is None the current schema is queried, else the specified one is used. name and owner are treated case insensitively.

def iterprivileges​(self, schema='user'):

Generator that yields object privileges for the current users (or all users) objects. schema specifies which privileges should be yielded:

"user"

Only object privileges for objects belonging to the current user will be yielded.

"all"

All object privileges will be yielded.

def connect​(*args, **kwargs):

Create a connection to the database and return a Connection object.

class Cursor​(OracleCursor):

A subclass of the cursor class in cx_Oracle. The "execute" methods support a unicode statement and unicode parameters (they will be encoded in the client encoding before being passed to the database). The "fetch" methods will return records as Record objects and string values and CLOB values, if the cursors readlobs attribute has the appropriate value) will be returned as unicode objects (except for BLOB values). (Note that strings in the national character set (and NCLOB values) are not supported).

def __init__​(self, connection, readlobs=None):

Return a new cursor for the connection connection. For the meaning of readlobs see Connection.__init__.

def _decode​(self, value, isblob):

def execute​(self, statement, parameters=None, **kwargs):

def executemany​(self, statement, parameters):

def __xrepr__​(self, mode):

def __repr__​(self):

def formatstring​(value, latin1=False):

class MixinNormalDates​(object):

Mixin class that provides methods for determining creation and modification dates for objects.

def cdate​(self, connection=None):

def udate​(self, connection=None):

class MixinCodeDDL​(object):

Mixin class that provides methods returning the create and drop statements for various objects.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def getfullname​(name, owner):

class Object​(object):

The base class for all Python classes modelling schema objects in the database.

Subclasses are: Sequence, Table, PrimaryKey, Comment, ForeignKey, Index, Unique, Synonym, View, MaterializedView, Library, Function, Package, Type, Trigger, JavaSource and Column.

class __metaclass__​(type):

def __init__​(self, name, owner=None, connection=None):

def __repr__​(self):

def __str__​(self):

def __eq__​(self, other):

def __ne__​(self, other):

def __hash__​(self):

def getfullname​(self):

def createddl​(self, *args, **kwargs):

Return SQL code to create this object.

def dropddl​(self, *args, **kwargs):

Return SQL code to drop this object

def cdate​(self, *args, **kwargs):

Return a datetime.datetime object with the creation date of self in the database specified by connection (or None if such information is not available).

def udate​(self, *args, **kwargs):

Return a datetime.datetime object with the last modification date of self in the database specified by connection (or None if such information is not available).

def iterreferences​(self, connection=None):

Objects directly used by self.

If connection is not None it will be used as the database connection from which to fetch data. If connection is None the connection from which self has been extracted will be used. If there is not such connection, you'll get an exception.

def iterreferencesall​(self, connection=None, done=None):

All objects used by self (recursively).

For the meaning of connection see iterreferences.

done is used internally and shouldn't be passed.

def iterreferencedby​(self, connection=None):

Objects using self.

For the meaning of connection see iterreferences.

def iterreferencedbyall​(self, connection=None, done=None):

All objects depending on self (recursively).

For the meaning of connection see iterreferences.

done is used internally and shouldn't be passed.

def getconnection​(self, connection):

def getcursor​(self, connection):

property connectstring:

def __get__​(self):

def iterobjects​(cls, connection, schema='user'):

Generator that yields all objects of this type in the database schema of cursor.

def __iter__​(self):

def __xrepr__​(self, mode):

def __xattrs__​(self, mode='default'):

class Sequence​(MixinNormalDates, Object):

Models a sequence in the database.

def _createddl​(self, connection, term, copyvalue):

def createddl​(self, connection=None, term=True):

def createddlcopy​(self, connection=None, term=True):

Return SQL code to create an identical copy of this sequence.

def dropddl​(self, connection=None, term=True):

def iterreferences​(self, connection=None, schema='all'):

def __xattrs__​(self, mode='default'):

def _columntype​(rec, data_precision=None, data_scale=None, char_length=None):

def _columndefault​(rec):

class Table​(MixinNormalDates, Object):

Models a table in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def mview​(self, connection=None):

The materialized view this table belongs to (or None if it's a real table).

def ismview​(self, connection=None):

Is this table a materialized view?

def iterobjects​(cls, connection, schema='user'):

def itercolumns​(self, connection=None):

Generator that yields all column objects of the Table self.

def iterrecords​(self, connection=None):

Generator that yields all records of the table self.

def itercomments​(self, connection=None):

Generator that yields all column comments of the table self.

def iterconstraints​(self, connection=None):

Generator that yields all constraints for this table.

def iterreferences​(self, connection=None):

def iterreferencedby​(self, connection=None):

def __xattrs__​(self, mode='default'):

class Constraint​(Object):

Base class of all constraints (primary key constraints, foreign key constraints and unique constraints).

class PrimaryKey​(Constraint):

Models a primary key constraint in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def cdate​(self, connection=None):

def udate​(self, connection=None):

def iterreferencedby​(self, connection=None):

def iterreferences​(self, connection=None):

def table​(self, connection=None):

Return the Table self belongs to.

def __xattrs__​(self, mode='default'):

class Comment​(Object):

Models a column comment in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def cdate​(self, connection=None):

def udate​(self, connection=None):

def iterreferences​(self, connection=None):

def iterreferencedby​(self, connection=None):

class ForeignKey​(Constraint):

Models a foreign key constraint in the database.

def createddl​(self, connection=None, term=True):

def _ddl​(self, connection, cmd, term):

def dropddl​(self, connection=None, term=True):

def enableddl​(self, connection=None, term=True):

def disableddl​(self, connection=None, term=True):

def cdate​(self, connection=None):

def udate​(self, connection=None):

def iterreferencedby​(self, connection=None):

def iterreferences​(self, connection=None):

def table​(self, connection=None):

Return the Table self belongs to.

def pk​(self, connection=None):

Return the primary key referenced by self.

def isenabled​(self, connection=None):

Return whether this constraint is enabled.

def __xattrs__​(self, mode='default'):

class Index​(MixinNormalDates, Object):

Models an index in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def constraint​(self, connection=None):

If this index is generated by a constraint, return the constraint otherwise return None.

def isconstraint​(self, connection=None):

Is this index generated by a constraint?

def iterreferences​(self, connection=None):

def table​(self, connection=None):

Return the Table self belongs to.

def __xattrs__​(self, mode='default'):

class UniqueConstraint​(Constraint):

Models a unique constraint in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def cdate​(self, connection=None):

def udate​(self, connection=None):

def iterreferencedby​(self, connection=None):

def iterreferences​(self, connection=None):

def table​(self, connection=None):

Return the Table self belongs to.

def __xattrs__​(self, mode='default'):

class Synonym​(Object):

Models a synonym in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def cdate​(self, connection=None):

def udate​(self, connection=None):

def iterreferences​(self, connection=None, schema='all'):

def getobject​(self, connection=None):

Get the object for which self is a synonym.

class View​(MixinNormalDates, Object):

Models a view in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def iterrecords​(self, connection=None):

class MaterializedView​(View):

Models a meterialized view in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

def iterreferences​(self, connection=None):

def iterreferencedby​(self, connection=None):

class Library​(Object):

Models a library in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

class Argument​(object):

Argument objects hold information about the arguments of a stored procedure.

def __init__​(self, name, position, datatype, isin, isout):

def __repr__​(self):

def __xattrs__​(self, mode='default'):

class Callable​(MixinNormalDates, MixinCodeDDL, Object):

Models a callable object in the database, i.e. functions and procedures.

def __init__​(self, name, owner=None, connection=None):

def _calcargs​(self, cursor):

def _getargs​(self, cursor, *args, **kwargs):

def _wraparg​(self, cursor, arginfo, arg):

def _unwraparg​(self, cursor, arg):

def _makerecord​(self, cursor, args):

def iterarguments​(self, connection=None):

Generator that yields all arguments of the function/procedure self.

def __xattrs__​(self, mode='default'):

class Procedure​(Callable):

Models a procedure in the database. A Procedure object can be used as a wrapper for calling the procedure with keyword arguments.

def __call__​(self, cursor, *args, **kwargs):

Call the procedure with arguments args and keyword arguments kwargs. cursor must be a ll.orasql cursor. This will return a Record object containing the result of the call (i.e. this record will contain all specified and all out parameters).

class Function​(Callable):

Models a function in the database. A Function object can be used as a wrapper for calling the function with keyword arguments.

def __call__​(self, cursor, *args, **kwargs):

Call the function with arguments args and keyword arguments kwargs. cursor must be an ll.orasql cursor. This will return a tuple containing the result and a Record object containing the modified parameters (i.e. this record will contain all specified and out parameters).

class Package​(MixinNormalDates, MixinCodeDDL, Object):

Models a package in the database.

class PackageBody​(MixinNormalDates, MixinCodeDDL, Object):

Models a package body in the database.

class Type​(MixinNormalDates, MixinCodeDDL, Object):

Models a type definition in the database.

class Trigger​(MixinNormalDates, MixinCodeDDL, Object):

Models a trigger in the database.

class JavaSource​(MixinNormalDates, Object):

Models Java source code in the database.

def createddl​(self, connection=None, term=True):

def dropddl​(self, connection=None, term=True):

class Privilege​(object):

Models a database object privilege (i.e. a grant).

def __init__​(self, privilege, name, grantor, grantee, owner=None, connection=None):

def __repr__​(self):

def __str__​(self):

def getconnection​(self, connection):

def getcursor​(self, connection):

property connectstring:

def __get__​(self):

def iterobjects​(self, connection, schema='user'):

Generator that yields object privileges for the current users (or all users) objects.

schema specifies which privileges should be yielded:

"user"

Only object privileges for objects belonging to the current user will be yielded.

"all"

All object privileges will be yielded.

def grantddl​(self, connection=None, term=True, mapgrantee=True):

Return SQL code to grant this privilege. If mapgrantee is a list or a dictionary and self.grantee is not in this list (or dictionary) no command will returned. If it's a dictionary and self.grantee is in it, the privilege will be granted to the user specified as the value instead of the original one. If mapgrantee is true (the default) the privilege will be granted to the original grantee.

def __xattrs__​(self, mode='default'):

class Column​(Object):

Models a single column of a table in the database. This is used to output ALTER TABLE ... statements for adding, dropping and modifying columns.

def _getcolumnrecord​(self, cursor):

def addddl​(self, connection=None, term=True):

def modifyddl​(self, connection, cursorold, cursornew, term=True):

def dropddl​(self, connection=None, term=True):

def cdate​(self, connection=None):

def udate​(self, connection=None):

def iterreferences​(self, connection=None):

def iterreferencedby​(self, connection=None):

def datatype​(self, connection=None):

The SQL type of this column.

def default​(self, connection=None):

The SQL default value for this column.

def nullable​(self, connection=None):

Is this column nullable?

def comment​(self, connection=None):

The comment for this column.

def __xattrs__​(self, mode='default'):

def __iter__​(self):