12. API: DbObjectType Objects

Note

This object is an extension to the DB API. It is returned by the Connection.gettype() call and is available as the Variable.type for variables containing Oracle Database objects.

12.1. DbObjectType Methods

DbObjectType([sequence])

The object type may be called directly and serves as an alternative way of calling newobject().

DbObjectType.newobject([sequence])

Returns a new Oracle object of the given type. This object can then be modified by setting its attributes and then bound to a cursor for interaction with Oracle. If the object type refers to a collection, a sequence may be passed and the collection will be initialized with the items in that sequence.

12.2. DbObjectType Attributes

DbObjectType.attributes

This read-only attribute returns a list of the attributes that make up the object type.

DbObjectType.element_type

This read-only attribute returns the type of elements found in collections of this type, if iscollection is True; otherwise, it returns None. If the collection contains objects, this will be another object type; otherwise, it will be one of the database type constants.

DbObjectType.iscollection

This read-only attribute returns a boolean indicating if the object type refers to a collection or not.

DbObjectType.name

This read-only attribute returns the name of the type.

DbObjectType.package_name

This read-only attribute returns the name of the package, if the type refers to a PL/SQL type (otherwise, it returns the value None).

DbObjectType.schema

This read-only attribute returns the name of the schema that owns the type.

12.3. DbObject Objects

Note

This object is an extension to the DB API. It is returned by the DbObjectType.newobject() call and can be bound to variables of type OBJECT. Attributes can be retrieved and set directly.

12.3.1. DbObject Methods

DbObject.append(element)

Appends an element to the collection object. If no elements exist in the collection, this creates an element at index 0; otherwise, it creates an element immediately following the highest index available in the collection.

DbObject.asdict()

Returns a dictionary where the collection’s indexes are the keys and the elements are its values.

DbObject.aslist()

Returns a list of each of the collection’s elements in index order.

DbObject.copy()

Creates a copy of the object and returns it.

DbObject.delete(index)

Deletes the element at the specified index of the collection. If the element does not exist or is otherwise invalid, an error is raised. Note that the indices of the remaining elements in the collection are not changed. In other words, the delete operation creates holes in the collection.

DbObject.exists(index)

Returns True or False indicating if an element exists in the collection at the specified index.

DbObject.extend(sequence)

Appends all of the elements in the sequence to the collection. This is the equivalent of performing append() for each element found in the sequence.

DbObject.first()

Returns the index of the first element in the collection. If the collection is empty, None is returned.

DbObject.getelement(index)

Returns the element at the specified index of the collection. If no element exists at that index, an exception is raised.

DbObject.last()

Returns the index of the last element in the collection. If the collection is empty, None is returned.

DbObject.next(index)

Returns the index of the next element in the collection following the specified index. If there are no elements in the collection following the specified index, None is returned.

DbObject.prev(index)

Returns the index of the element in the collection preceding the specified index. If there are no elements in the collection preceding the specified index, None is returned.

DbObject.setelement(index, value)

Sets the value in the collection at the specified index to the given value.

DbObject.size()

Returns the number of elements in the collection.

DbObject.trim(num)

Removes the specified number of elements from the end of the collection.

12.3.2. DbObject Attributes

DbObject.Type

This read-only attribute returns an ObjectType corresponding to the type of object.

12.4. DbObjectAttribute Objects

Note

This object is an extension to the DB API. The elements of DbObjectType.attributes are instances of this type.

DbObjectAttribute.name

This read-only attribute returns the name of the attribute.

DbObjectAttribute.type

This read-only attribute returns the type of the attribute. This will be an Oracle Object Type if the variable binds Oracle objects; otherwise, it will be one of the database type constants.