# firebird.driver.types

## Exceptions

Next exceptions are required by Python DB API 2.0

`Error` is imported from `firebird.base.types`.

## `firebird.driver.types.Error`

Bases: `Exception`

Exception intended as a base for application-related errors.

Unlike the standard Exception, this class accepts arbitrary keyword arguments during initialization. These keyword arguments are stored as attributes on the exception instance.

Attribute lookup on instances of Error (or its subclasses) will return `None` for any attribute that was not explicitly set via keyword arguments during `__init__`, preventing AttributeError for common checks.

> [!IMPORTANT]
>
> Attribute lookup on this class never fails, as all attributes that are not actually set, have `None` value. The special attribute `__notes__` (used by `add_note` since Python 3.11) is explicitly excluded from this behavior to ensure compatibility.

> [!NOTE]
>
> **Example**
>
> ```python
> try:
>     if condition:
>         raise Error("Error message", err_code=1)
>     else:
>         raise Error("Unknown error")
> except Error as e:
>     if e.err_code is None:
>         ...
>     elif e.err_code == 1:
>         ...
> ```

> [!NOTE]
>
> Warnings are not errors and should typically derive from Warning, not this class.

## `firebird.driver.types.InterfaceError`

Bases: `Error`

Exception raised for errors that are reported by the driver rather than the Firebird itself.

## `firebird.driver.types.DatabaseError`

Bases: `Error`

Exception raised for all errors reported by Firebird.

### `gds_codes: tuple[int]`

Tuple with all returned GDS error codes

### `sqlcode: int`

Returned SQLCODE or None

### `sqlstate: str`

Returned SQLSTATE or None

## `firebird.driver.types.DataError`

Bases: `DatabaseError`

Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.

> [!NOTE]
>
> This exception class exists for DB-API 2.0 compatibility. The driver typically raises the base DatabaseError with specific Firebird codes, rather than this specialized subclass directly.

### `gds_codes: tuple[int]`

Tuple with all returned GDS error codes

### `sqlcode: int`

Returned SQLCODE or None

### `sqlstate: str`

Returned SQLSTATE or None

## `firebird.driver.types.OperationalError`

Bases: `DatabaseError`

Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.

> [!NOTE]
>
> This exception class exists for DB-API 2.0 compatibility. The driver typically raises the base DatabaseError with specific Firebird codes, rather than this specialized subclass directly.

### `gds_codes: tuple[int]`

Tuple with all returned GDS error codes

### `sqlcode: int`

Returned SQLCODE or None

### `sqlstate: str`

Returned SQLSTATE or None

## `firebird.driver.types.IntegrityError`

Bases: `DatabaseError`

Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.

> [!IMPORTANT]
>
> This exceptions is never directly thrown by Firebird driver.

### `gds_codes: tuple[int]`

Tuple with all returned GDS error codes

### `sqlcode: int`

Returned SQLCODE or None

### `sqlstate: str`

Returned SQLSTATE or None

## `firebird.driver.types.InternalError`

Bases: `DatabaseError`

Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.

> [!IMPORTANT]
>
> This exceptions is never directly thrown by Firebird driver.

### `gds_codes: tuple[int]`

Tuple with all returned GDS error codes

### `sqlcode: int`

Returned SQLCODE or None

### `sqlstate: str`

Returned SQLSTATE or None

## `firebird.driver.types.ProgrammingError`

Bases: `DatabaseError`

Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc.

> [!IMPORTANT]
>
> This exceptions is never directly thrown by Firebird driver.

### `gds_codes: tuple[int]`

Tuple with all returned GDS error codes

### `sqlcode: int`

Returned SQLCODE or None

### `sqlstate: str`

Returned SQLSTATE or None

## `firebird.driver.types.NotSupportedError`

Bases: `DatabaseError`

Exception raised in case a method or database API was used which is not supported by the database.

### `gds_codes: tuple[int]`

Tuple with all returned GDS error codes

### `sqlcode: int`

Returned SQLCODE or None

### `sqlstate: str`

Returned SQLSTATE or None

## `firebird.driver.types.FirebirdWarning`

Bases: `UserWarning`

Warning from Firebird engine.

The important difference from `Warning` class is that `FirebirdWarning` accepts keyword arguments, that are stored into instance attributes with the same name.

> [!IMPORTANT]
>
> Attribute lookup on this class never fails, as all attributes that are not actually set, have `None` value.

Example:

```text
try:
    if condition:
        raise FirebirdWarning("Error message", err_code=1)
    else:
        raise FirebirdWarning("Unknown error")
except FirebirdWarning as e:
    if e.err_code is None:
        ...
    elif e.err_code == 1:
        ...
```

This is the exception inheritance layout:

```text
Exception
|__Error
    |__InterfaceError
    |__DatabaseError
        |__DataError
        |__OperationalError
        |__IntegrityError
        |__InternalError
        |__ProgrammingError
        |__NotSupportedError

UserWarning
|__FirebirdWarning
```

## Sentinels

## `firebird.driver.types.TIMEOUT`

Bases: `Sentinel`

Sentinel to signal that operation timed out

## Other constants and types required by Python DB API 2.0 specification

### Globals

## `firebird.driver.types.apilevel: str`

String constant stating the supported DB API level.

## `firebird.driver.types.threadsafety: int`

Integer constant stating the level of thread safety the interface supports. Curretly `1` = Threads may share the module, but not connections.

## `firebird.driver.types.paramstyle: str`

String constant stating the type of parameter marker formatting expected by the interface. `'qmark'` = Question mark style, e.g. '...WHERE name=?'

### Helper constants for work with [`Cursor.description`](<https://firebird-driver.readthedocs.io/ref-core/#firebird.driver.core.Cursor.description>) content

- DESCRIPTION\_NAME
- DESCRIPTION\_TYPE\_CODE
- DESCRIPTION\_DISPLAY\_SIZE
- DESCRIPTION\_INTERNAL\_SIZE
- DESCRIPTION\_PRECISION
- DESCRIPTION\_SCALE
- DESCRIPTION\_NULL\_OK

### Types

## `firebird.driver.types.STRING`

This type object is used to describe columns in a database that are string-based (e.g. CHAR).

## `firebird.driver.types.BINARY`

This type object is used to describe (long) binary columns in a database (e.g. LONG, RAW, BLOBs).

## `firebird.driver.types.NUMBER`

This type object is used to describe numeric columns in a database.

## `firebird.driver.types.DATETIME`

This type object is used to describe date/time columns in a database.

## `firebird.driver.types.ROWID`

This type object is used to describe the "Row ID" column in a database.

### Constructors for data types

## `firebird.driver.types.Date`

This callable constructs an object holding a date value.

## `firebird.driver.types.Time`

This callable constructs an object holding a time value.

## `firebird.driver.types.Timestamp`

This callable constructs an object holding a time stamp value.

## `firebird.driver.types.DateFromTicks(ticks: float) -> Date`

Constructs an object holding a date value from the given ticks value (number of seconds since the epoch).

## `firebird.driver.types.TimeFromTicks(ticks: float) -> Time`

Constructs an object holding a time value from the given ticks value (number of seconds since the epoch).

## `firebird.driver.types.TimestampFromTicks(ticks: float) -> Timestamp`

Constructs an object holding a time stamp value from the given ticks value (number of seconds since the epoch).

## `firebird.driver.types.Binary`

This callable constructs an object capable of holding a binary (long) string value.

## Types for type hints

## `firebird.driver.types.DESCRIPTION`

DB API 2.0 Cursor DESCRIPTION

## `firebird.driver.types.CB_OUTPUT_LINE`

Callback that accepts line of text output

## `firebird.driver.types.Transactional`

Bases: `Protocol`

Protocol type for object that supports transactional processing.

### `begin(tpb: bytes | None = None) -> None`

Begin transaction.

### `commit(*, retaining: bool = False) -> None`

Commit transaction.

### `is_active() -> bool`

Returns True if transaction is active.

### `rollback(*, retaining: bool = False, savepoint: str | None = None) -> None`

Rollback transaction.

## Enums

## `firebird.driver.types.NetProtocol`

Bases: `IntEnum`

Network protocol options available for connection.

## `firebird.driver.types.DirectoryCode`

Bases: `IntEnum`

IConfigManager directory codes.

## `firebird.driver.types.XpbKind`

Bases: `IntEnum`

Xpb builder kinds.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.StateResult`

Bases: `IntEnum`

IState result codes.

## `firebird.driver.types.PageSize`

Bases: `IntEnum`

Supported database page sizes.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.DBKeyScope`

Bases: `IntEnum`

Scope of DBKey context.

## `firebird.driver.types.InfoItemType`

Bases: `IntEnum`

Data type of information item.

## `firebird.driver.types.SrvInfoCode`

Bases: `IntEnum`

Service information (isc\_info\_svc\_\*) codes.

## `firebird.driver.types.BlobInfoCode`

Bases: `IntEnum`

BLOB information (isc\_info\_blob\_\*) codes.

## `firebird.driver.types.DbInfoCode`

Bases: `IntEnum`

Database information codes, corresponding to the isc\_info\_\* constants used for database-level information requests.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.ResultSetInfoCode`

Bases: `IntEnum`

Result set information codes.

## `firebird.driver.types.Features`

Bases: `IntEnum`

Firebird features (Response to DbInfoCode.FEATURES).

## `firebird.driver.types.ReplicaMode`

Bases: `IntEnum`

Replica modes. Response to DbInfoCode.REPLICA\_MODE or as value for DPBItem.SET\_DB\_REPLICA.

## `firebird.driver.types.StmtInfoCode`

Bases: `IntEnum`

Statement information (isc\_info\_sql\_\*) codes.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.ReqInfoCode`

Bases: `IntEnum`

Request information (isc\_info\_\*) codes.

## `firebird.driver.types.ReqState`

Bases: `IntEnum`

Request states(isc\_info\_req\_\*) codes.

## `firebird.driver.types.TraInfoCode`

Bases: `IntEnum`

Transaction information (isc\_info\_tra\_\*) codes.

## `firebird.driver.types.TraInfoIsolation`

Bases: `IntEnum`

Transaction isolation response.

## `firebird.driver.types.TraInfoReadCommitted`

Bases: `IntEnum`

Transaction isolation Read Committed response.

## `firebird.driver.types.TraInfoAccess`

Bases: `IntEnum`

Transaction isolation access mode response.

## `firebird.driver.types.TraAccessMode`

Bases: `IntEnum`

Transaction Access Mode TPB parameters.

## `firebird.driver.types.TraIsolation`

Bases: `IntEnum`

Transaction Isolation TPB paremeters.

## `firebird.driver.types.TraReadCommitted`

Bases: `IntEnum`

Read Committed Isolation TPB paremeters.

## `firebird.driver.types.Isolation`

Bases: `IntEnum`

Transaction Isolation TPB parameters.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.TraLockResolution`

Bases: `IntEnum`

Transaction Lock resolution TPB parameters.

## `firebird.driver.types.TableShareMode`

Bases: `IntEnum`

Transaction table share mode TPB parameters.

## `firebird.driver.types.TableAccessMode`

Bases: `IntEnum`

Transaction Access Mode TPB parameters.

## `firebird.driver.types.DefaultAction`

Bases: `IntEnum`

Default action when transaction is ended automatically.

## `firebird.driver.types.StatementType`

Bases: `IntEnum`

Statement type.

## `firebird.driver.types.SQLDataType`

Bases: `IntEnum`

SQL data type.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.DPBItem`

Bases: `IntEnum`

Database Parameter Buffer (DPB) items, corresponding to isc\_dpb\_\* constants (using VERSION2 codes).

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.TPBItem`

Bases: `IntEnum`

Transaction Parameter Buffer (DPB) items, corresponding to isc\_tpb\_\* constants.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SPBItem`

Bases: `IntEnum`

isc\_spb\_\* items.

## `firebird.driver.types.BPBItem`

Bases: `IntEnum`

isc\_bpb\_\* items.

## `firebird.driver.types.BlobType`

Bases: `IntEnum`

Blob type.

## `firebird.driver.types.BlobStorage`

Bases: `IntEnum`

Blob storage.

## `firebird.driver.types.ServerAction`

Bases: `IntEnum`

isc\_action\_svc\_\* items.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvDbInfoOption`

Bases: `IntEnum`

Parameters for SvcInfoCode.SRV\_DB\_INFO.

## `firebird.driver.types.SrvRepairOption`

Bases: `IntEnum`

Parameters for ServerAction.REPAIR.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvBackupOption`

Bases: `IntEnum`

Parameters for ServerAction.BACKUP.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvRestoreOption`

Bases: `IntEnum`

Parameters for ServerAction.RESTORE.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvNBackupOption`

Bases: `IntEnum`

Parameters for ServerAction.NBAK.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvTraceOption`

Bases: `IntEnum`

Parameters for ServerAction.TRACE\_\*.

## `firebird.driver.types.SrvPropertiesOption`

Bases: `IntEnum`

Parameters for ServerAction.PROPERTIES.

## `firebird.driver.types.SrvValidateOption`

Bases: `IntEnum`

Parameters for ServerAction.VALIDATE.

## `firebird.driver.types.SrvUserOption`

Bases: `IntEnum`

Parameters for ServerAction.ADD\_USER|DELETE\_USER|MODIFY\_USER|DISPLAY\_USER.

## `firebird.driver.types.DbAccessMode`

Bases: `IntEnum`

Values for isc\_spb\_prp\_access\_mode.

## `firebird.driver.types.DbSpaceReservation`

Bases: `IntEnum`

Values for isc\_spb\_prp\_reserve\_space.

## `firebird.driver.types.DbWriteMode`

Bases: `IntEnum`

Values for isc\_spb\_prp\_write\_mode.

## `firebird.driver.types.ShutdownMode`

Bases: `IntEnum`

Values for isc\_spb\_prp\_shutdown\_mode.

## `firebird.driver.types.OnlineMode`

Bases: `IntEnum`

Values for isc\_spb\_prp\_online\_mode.

## `firebird.driver.types.ShutdownMethod`

Bases: `IntEnum`

Database shutdown method options.

## `firebird.driver.types.TransactionState`

Bases: `IntEnum`

Transaction state.

## `firebird.driver.types.DbProvider`

Bases: `IntEnum`

Database Providers.

## `firebird.driver.types.DbClass`

Bases: `IntEnum`

Database Classes.

## `firebird.driver.types.Implementation`

Bases: `IntEnum`

Implementation - Legacy format.

## `firebird.driver.types.ImpCPU`

Bases: `IntEnum`

Implementation - CPU.

## `firebird.driver.types.ImpOS`

Bases: `IntEnum`

Implementation - CPU.

## `firebird.driver.types.ImpCompiler`

Bases: `IntEnum`

Implementation - Compiler.

## `firebird.driver.types.CancelType`

Bases: `IntEnum`

Cancel types for `Connection.cancel_operation()`

## `firebird.driver.types.DecfloatRound`

Bases: `Enum`

DECFLOAT ROUND options.

## `firebird.driver.types.DecfloatTraps`

Bases: `Enum`

DECFLOAT TRAPS options.

## Flags

## `firebird.driver.types.StateFlag`

Bases: `IntFlag`

IState flags.

## `firebird.driver.types.PreparePrefetchFlag`

Bases: `IntFlag`

Flags for Statement Prefetch.

## `firebird.driver.types.StatementFlag`

Bases: `IntFlag`

Statement flags.

## `firebird.driver.types.CursorFlag`

Bases: `IntFlag`

Cursor flags.

## `firebird.driver.types.ConnectionFlag`

Bases: `IntFlag`

Flags returned for DbInfoCode.CONN\_FLAGS.

## `firebird.driver.types.EncryptionFlag`

Bases: `IntFlag`

Crypto status (Response to DbInfoCode.CRYPT\_STATE).

## `firebird.driver.types.ServerCapability`

Bases: `IntFlag`

Server capabilities (returned by isc\_info\_svc\_capabilities).

## `firebird.driver.types.SrvRepairFlag`

Bases: `IntFlag`

isc\_spb\_rpr\_\* flags used as options for the ServerAction.REPAIR service action.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvStatFlag`

Bases: `IntFlag`

isc\_spb\_sts\_\* flags for ServerAction.DB\_STATS.

## `firebird.driver.types.SrvBackupFlag`

Bases: `IntFlag`

isc\_spb\_bkp\_\* flags for ServerAction.BACKUP.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvRestoreFlag`

Bases: `IntFlag`

isc\_spb\_res\_\* flags for ServerAction.RESTORE.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvNBackupFlag`

Bases: `IntFlag`

isc\_spb\_nbk\_\* flags for ServerAction.NBAK.

> [!NOTE]
>
> Some members are specific to certain Firebird versions, indicated by comments.

## `firebird.driver.types.SrvPropertiesFlag`

Bases: `IntFlag`

isc\_spb\_prp\_\* flags for ServerAction.PROPERTIES.

## `firebird.driver.types.ImpFlags`

Bases: `IntFlag`

Implementation - Endianness.

## Dataclasses

## `firebird.driver.types.ItemMetadata`

Information for single item from `iMessageMetadata`.

This `dataclass` is used internally, and it's not intended for general use.

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `field` | `str` | Field name |
| `relation` | `str` | Relation name |
| `owner` | `str` | Owner name |
| `alias` | `str` | Field alias |
| `datatype` | `SQLDataType` | Data type |
| `nullable` | `bool` | Whether NULLs are allowed |
| `subtype` | `int` | Data sub-type |
| `length` | `int` | Size of raw field data in message buffer |
| `scale` | `int` | Field scale |
| `charset` | `int` | Character set |
| `offset` | `int` | Offset of raw field data in message buffer |
| `null_offset` | `int` | Offset of null flag in message buffer |

## `firebird.driver.types.TableAccessStats`

Table access statistics.

Data structure returned by `.Connection.get_table_access_stats()`.

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `table_id` | `int` | Relation ID |
| `sequential` | `int` | Number of sequential table scans (row reads) |
| `indexed` | `int` | Number of reads done via an index |
| `inserts` | `int` | Number of inserts |
| `updates` | `int` | Number of updates |
| `deletes` | `int` | Number of deleted |
| `backouts` | `int` | Number of removals of a version of a record |
| `purges` | `int` | Number of removals of old versions of fully mature records (records that are committed, so that older ancestor versions are no longer needed) |
| `expunges` | `int` | Number of removals of a record and all of its ancestors, for records whose deletions have been committed |

## `firebird.driver.types.UserInfo`

Information about Firebird user.

Data structure returned by `.Service.get_user()` and `.Service.get_users()`.

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `user_name` | `str` | User (login) name |
| `password` | `str` | User password |
| `first_name` | `str` | First name |
| `middle_name` | `str` | Middle name |
| `last_name` | `str` | Last name |
| `user_id` | `int` | User ID |
| `group_id` | `int` | User Group ID |
| `group_name` | `str` | Group name |
| `admin` | `bool` | True is user has admin priviledges |

## `firebird.driver.types.BCD`

BCD number.

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `sign` | `int` | Sign |
| `number` | `bytes` | Number |
| `exp` | `int` | Exponent |

## `firebird.driver.types.TraceSession`

Information about active trace session.

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `id` | `int` | Session ID number |
| `user` | `str` | User name |
| `timestamp` | `datetime` | Session start timestamp |
| `name` | `str` | Session name (if defined) |
| `flags` | `list` | List with session flag names |
| `plugins` | `list` | List with trace plugins for this session |

## `firebird.driver.types.ImpData`

Information about Firebird implementation (new format).

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `cpu` | `ImpCPU` | CPU identification |
| `os` | `ImpOS` | Operating system |
| `compiler` | `ImpCompiler` | Compiler indentification |
| `flags` | `ImpFlags` | Implementation flags |
| `db_class` | `DbClass` | Provider class |
| `depth` | `int` | Depth of info stack |

## `firebird.driver.types.ImpDataOld`

Information about Firebird implementation (new format).

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `implementation` | `Implementation` | CPU and OS identification |
| `db_class` | `DbClass` | Provider class |

## Helper functions

## `firebird.driver.types.get_timezone(timezone: str | None = None) -> datetime.tzinfo`

Returns `datetime.tzinfo` for specified time zone.

This is preferred method to obtain timezone information for construction of timezone-aware `datetime.datetime` and `datetime.time` objects. Current implementation uses `dateutil.tz` for timezone tzinfo objects, but adds metadata neccessary to store timezone regions into database instead zoned time, and to handle offset-based timezones in format required by Firebird.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `timezone` | `str \| None` | Timezone region specification or UTC offset. | `None` |
