# firebird.driver.fbapi

This module contains low-level [ctypes](<https://docs.python.org/3/library/ctypes.html>) interface to Firebird client library (`fbclient.so/dll`).

## Constants

### Type codes

```text
- SQL_TEXT
- SQL_VARYING
- SQL_SHORT
- SQL_LONG
- SQL_FLOAT
- SQL_DOUBLE
- SQL_D_FLOAT
- SQL_TIMESTAMP
- SQL_BLOB
- SQL_ARRAY
- SQL_QUAD
- SQL_TYPE_TIME
- SQL_TYPE_DATE
- SQL_INT64
- SQL_BOOLEAN
- SQL_NULL
- SUBTYPE_NUMERIC
- SUBTYPE_DECIMAL
```

### Internal type codes (for example used by ARRAY descriptor)

```text
- blr_text
- blr_text2
- blr_short
- blr_long
- blr_quad
- blr_float
- blr_double
- blr_d_float
- blr_timestamp
- blr_varying
- blr_varying2
- blr_blob
- blr_cstring
- blr_cstring2
- blr_blob_id
- blr_sql_date
- blr_sql_time
- blr_int64
- blr_blob2
- blr_domain_name
- blr_domain_name2
- blr_not_nullable
- blr_column_name
- blr_column_name2
- blr_bool
- blr_dec64
- blr_dec128
- blr_dec_fixed
- blr_sql_time_tz
- blr_timestamp_tz
- blr_ex_time_tz
- blr_ex_timestamp_tz
```

## Types

## `firebird.driver.fbapi.Int`

## `firebird.driver.fbapi.IntPtr`

## `firebird.driver.fbapi.Int64`

## `firebird.driver.fbapi.Int64Ptr`

## `firebird.driver.fbapi.QWord`

## `firebird.driver.fbapi.STRING`

## `firebird.driver.fbapi.ISC_LONG`

## `firebird.driver.fbapi.ISC_LONG_PTR`

## `firebird.driver.fbapi.ISC_ULONG`

## `firebird.driver.fbapi.ISC_SHORT`

## `firebird.driver.fbapi.ISC_USHORT`

## `firebird.driver.fbapi.ISC_UCHAR`

## `firebird.driver.fbapi.ISC_INT64`

## `firebird.driver.fbapi.ISC_UINT64`

## `firebird.driver.fbapi.ISC_DATE`

## `firebird.driver.fbapi.ISC_TIME`

## `firebird.driver.fbapi.FB_DEC16`

## `firebird.driver.fbapi.FB_DEC16Ptr`

## `firebird.driver.fbapi.FB_DEC34`

## `firebird.driver.fbapi.FB_DEC34Ptr`

## `firebird.driver.fbapi.FB_I128`

## `firebird.driver.fbapi.FB_I128Ptr`

## `firebird.driver.fbapi.ISC_QUAD`

ISC\_QUAD

## `firebird.driver.fbapi.ISC_QUAD_PTR`

## `firebird.driver.fbapi.FB_API_HANDLE`

## `firebird.driver.fbapi.FB_API_HANDLE_PTR`

## `firebird.driver.fbapi.ISC_STATUS`

## `firebird.driver.fbapi.ISC_STATUS_PTR`

## `firebird.driver.fbapi.ISC_STATUS_ARRAY`

## `firebird.driver.fbapi.ISC_STATUS_ARRAY_PTR`

## `firebird.driver.fbapi.ISC_ARRAY_BOUND`

ISC\_ARRAY\_BOUND

## `firebird.driver.fbapi.ISC_ARRAY_DESC`

ISC\_ARRAY\_DESC

## `firebird.driver.fbapi.ISC_ARRAY_DESC_PTR`

## `firebird.driver.fbapi.RESULT_VECTOR`

## `firebird.driver.fbapi.ISC_TIME_TZ`

ISC\_TIME\_TZ

## `firebird.driver.fbapi.ISC_TIME_TZ_EX`

ISC\_TIME\_TZ\_EX

## `firebird.driver.fbapi.ISC_TIMESTAMP`

ISC\_TIMESTAMP

## `firebird.driver.fbapi.ISC_TIMESTAMP_TZ`

ISC\_TIMESTAMP\_TZ

## `firebird.driver.fbapi.ISC_TIMESTAMP_TZ_EX`

ISC\_TIMESTAMP\_TZ\_EX

## `firebird.driver.fbapi.TraceCounts`

Trace counters for table

## `firebird.driver.fbapi.PerformanceInfo`

Performance info

## Variables

## `firebird.driver.fbapi.err_encoding`

Encoding used to decode error messages from Firebird.

## Functions

## `firebird.driver.fbapi.has_api() -> bool`

Reaturns True if Firebird API is already loaded.

## `firebird.driver.fbapi.load_api(filename: str | Path | FirebirdProvider | None = None) -> None`

Initializes bindings to Firebird Client Library unless they are already initialized. Called automatically by `get_api()`.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `filename` | `str \| Path \| FirebirdProvider \| None` | Client library filename or runtime provider. When omitted, the configured filename is used, or the driver locates a system client library. | `None` |

A supplied provider sets `FIREBIRD` to its root before loading the client library if the variable is unset or resolves to a different directory.

**Hooks**

Event `HookType.HOOK_API_LOADED`: Executed after api is initialized. Hook routine must have signature: `hook_func(api)`. Any value returned by hook is ignored.

## `firebird.driver.fbapi.get_api() -> FirebirdAPI`

Returns Firebird API. Loads the API if needed.

## Classes

## `firebird.driver.fbapi.FirebirdAPI`

Firebird Client API interface object. Loads Firebird Client Library and exposes `fb_get_master_interface()`. Uses [`ctypes`](<https://docs.python.org/3/library/ctypes.html>) for bindings.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `filename` | `FirebirdProvider \| str \| Path \| None` | Client library filename or runtime provider. When omitted, the driver locates a system client library. | `None` |
| `provider` | `FirebirdProvider \| None` | Runtime provider supplied by keyword, as an alternative to `filename`. | `None` |

When a runtime provider is supplied, `FIREBIRD` is set to its root before loading the client library if the variable is unset or resolves to a different directory.

Attributes:

| Name | Type | Description |
| --- | --- | --- |
| `provider` | `` `.FirebirdProvider` `` | Runtime provider used to load this API |
| `client_library` | `` `ctypes.CDLL` `` | Loaded Firebird client library `ctypes` handler |
| `client_library_name` | `` `~pathlib.Path` `` | Path to loaded Firebird client library |
| `master` | `iMaster` | Firebird API IMaster interface |
| `util` | `iUtil` | Firebird API IUtil interface |

Methods:

| Name | Description |
| --- | --- |
| `fb_get_master_interface` | This function is used to obtain primary Firebird interface, required to access all the rest of interfaces. Has no parameters and always succeeds.<br><br>Returns: `.iMaster` |
| `fb_get_database_handle` | Helper function that returns database handle for specified IAttachment interface.<br><br>Arguments: status (`ISC_STATUS_PTR`): :ISC status db\_handle (`FB_API_HANDLE_PTR`): database handle att (iAttachment): attachment<br><br>Returns: `ISC_STATUS` |
| `fb_get_transaction_handle` | Helper function that returns database handle for specified ITransaction interface.<br><br>Arguments: status (`ISC_STATUS_PTR`): ISC status tra\_handle (`FB_API_HANDLE_PTR`): Transaction handle att (iTransaction): Transaction<br><br>Returns: `ISC_STATUS` |
| `fb_interpret` | Helper function that fills buffer with text for errors noted in ISC status.<br><br>Arguments: buffer (`STRING`): Buffer for message buf\_size (int): Buffer size status\_ptr: Pointer to `ISC_STATUS_PTR`<br><br>Returns: `ISC_LONG` |
| `fb_sqlstate` | Helper function that returns SQLSTATE for ISC\_STATUS.<br><br>Arguments: status (`ISC_STATUS_PTR`): ISC status<br><br>Returns: `STRING` - 5 characters of SQLSTATE |
| `isc_sqlcode` | Helper function that returns SQLCODE for ISC\_STATUS.<br><br>Arguments: status (`ISC_STATUS_PTR`): ISC status<br><br>Returns: `ISC_LONG` |
| `isc_array_lookup_bounds` | Old API function. |
| `isc_array_put_slice` | Old API function. |
| `isc_array_get_slice` | Old API function. |
| `isc_que_events` | Old API function. |
| `isc_event_counts` | Old API function. |
| `isc_cancel_events` | Old API function. |
| `isc_compile_request` | Old API function. |
| `isc_start_request` | Old API function. |
| `isc_release_request` | Old API function. |
| `isc_receive` | Old API function. |
| `isc_start_and_send` | Old API function. |
| `isc_send` | Old API function. |
| `isc_open_blob2` | Old API function. |
| `isc_blob_info` | Old API function. |
| `isc_create_blob2` | Old API function. |
| `isc_get_segment` | Old API function. |
| `isc_put_segment` | Old API function. |
| `isc_close_blob` | Old API function. |

### `client_library: ctypes.CDLL`

Firebird client library

### `client_library_name: Path`

Firebird client library name

### `fb_get_database_handle`

Firebird API

### `fb_get_master_interface`

Firebird API

### `fb_get_transaction_handle`

Firebird API

### `fb_interpret`

Firebird API

### `fb_shutdown_callback`

Firebird API

### `fb_sqlstate`

Firebird API

### `isc_array_get_slice`

Firebird API

### `isc_array_lookup_bounds`

Firebird API

### `isc_array_put_slice`

Firebird API

### `isc_blob_info`

Firebird API

### `isc_cancel_events`

Firebird API

### `isc_close_blob`

Firebird API

### `isc_compile_request`

Firebird API

### `isc_create_blob2`

Firebird API

### `isc_event_counts`

Firebird API

### `isc_get_segment`

Firebird API

### `isc_open_blob2`

Firebird API

### `isc_put_segment`

Firebird API

### `isc_que_events`

Firebird API

### `isc_receive`

Firebird API

### `isc_release_request`

Firebird API

### `isc_send`

Firebird API

### `isc_sqlcode`

Firebird API

### `isc_start_and_send`

Firebird API

### `isc_start_request`

Firebird API

### `provider: FirebirdProvider`

Runtime provider used by this API, available after initialization.

### `isc_event_block(event_buffer: bytes, result_buffer: bytes, *args) -> int`

Convenience wrapper for isc\_event\_block() API function. Injects variable number of parameters into `C_isc_event_block` call.

## Firebird API Interface definitions

## `firebird.driver.fbapi.IVersioned_VTable`

Interface virtual method table

## `firebird.driver.fbapi.IVersioned_struct`

Fiebird Interface data structure

## `firebird.driver.fbapi.IReferenceCounted_VTable`

IReferenceCounted virtual method table

## `firebird.driver.fbapi.IReferenceCounted_struct`

IReferenceCounted data structure

## `firebird.driver.fbapi.IDisposable_VTable`

IDisposable virtual method table

## `firebird.driver.fbapi.IDisposable_struct`

IDisposable data structure

## `firebird.driver.fbapi.IStatus_VTable`

IStatus VTable

## `firebird.driver.fbapi.IStatus_struct`

IStatus interface

## `firebird.driver.fbapi.IMaster_VTable`

IMaster virtual method table

## `firebird.driver.fbapi.IMaster_struct`

IMaster interface

## `firebird.driver.fbapi.IPluginBase_VTable`

IPluginBase virtual method table

## `firebird.driver.fbapi.IPluginBase_struct`

IPluginBase interface

## `firebird.driver.fbapi.IPluginSet_VTable`

IPluginSet virtual method table

## `firebird.driver.fbapi.IPluginSet_struct`

IPluginSet interface

## `firebird.driver.fbapi.IConfigEntry_VTable`

IConfigEntry virtual method table

## `firebird.driver.fbapi.IConfigEntry_struct`

IConfigEntry interface

## `firebird.driver.fbapi.IConfig_VTable`

IConfig virtual method table

## `firebird.driver.fbapi.IConfig_struct`

IConfig interface

## `firebird.driver.fbapi.IFirebirdConf_VTable`

IFirebirdConf virtual method table

## `firebird.driver.fbapi.IFirebirdConf_struct`

IFirebirdConf interface

## `firebird.driver.fbapi.IPluginManager_VTable`

IPluginManager virtual method table

## `firebird.driver.fbapi.IPluginManager_struct`

IPluginManager interface

## `firebird.driver.fbapi.IConfigManager_VTable`

IConfigManager virtual method table

## `firebird.driver.fbapi.IConfigManager_struct`

IConfigManager interface

## `firebird.driver.fbapi.IEventCallback_VTable`

IEventCallback virtual method table

## `firebird.driver.fbapi.IEventCallback_struct`

IEventCallback interface

## `firebird.driver.fbapi.IBlob_VTable`

IBlob virtual method table

## `firebird.driver.fbapi.IBlob_struct`

IBlob interface

## `firebird.driver.fbapi.ITransaction_VTable`

ITransaction virtual method table

## `firebird.driver.fbapi.ITransaction_struct`

ITransaction interface

## `firebird.driver.fbapi.IMessageMetadata_VTable`

IMessageMetadata virtual method table

## `firebird.driver.fbapi.IMessageMetadata_struct`

IMessageMetadata interface

## `firebird.driver.fbapi.IMetadataBuilder_VTable`

IMetadataBuilder virtual method table

## `firebird.driver.fbapi.IMetadataBuilder_struct`

IMetadataBuilder interface

## `firebird.driver.fbapi.IResultSet_VTable`

IResultSet virtual method table

## `firebird.driver.fbapi.IResultSet_struct`

IResultSet interface

## `firebird.driver.fbapi.IStatement_VTable`

IStatement virtual method table

## `firebird.driver.fbapi.IStatement_struct`

IStatement interface

## `firebird.driver.fbapi.IBatch_VTable`

IBatch virtual method table

## `firebird.driver.fbapi.IBatch_struct`

IBatch interface

## `firebird.driver.fbapi.IBatchCompletionState_VTable`

IBatchCompletionState virtual method table

## `firebird.driver.fbapi.IBatchCompletionState_struct`

IBatchCompletionState interface

## `firebird.driver.fbapi.IRequest_VTable`

IRequest virtual method table

## `firebird.driver.fbapi.IRequest_struct`

IRequest interface

## `firebird.driver.fbapi.IEvents_VTable`

IEvents virtual method table

## `firebird.driver.fbapi.IEvents_struct`

IEvents interface

## `firebird.driver.fbapi.IAttachment_VTable`

IAttachment virtual method table

## `firebird.driver.fbapi.IAttachment_struct`

IAttachment interface

## `firebird.driver.fbapi.IService_VTable`

IService virtual method table

## `firebird.driver.fbapi.IService_struct`

IService interface

## `firebird.driver.fbapi.IProvider_VTable`

IProvider virtual method table

## `firebird.driver.fbapi.IProvider_struct`

IProvider interface

## `firebird.driver.fbapi.IDtcStart_VTable`

IDtcStart virtual method table

## `firebird.driver.fbapi.IDtcStart_struct`

IDtcStart interface

## `firebird.driver.fbapi.IDtc_VTable`

IDtc virtual method table

## `firebird.driver.fbapi.IDtc_struct`

IDtc interface

## `firebird.driver.fbapi.ICryptKeyCallback_VTable`

ICryptKeyCallback virtual method table

## `firebird.driver.fbapi.ICryptKeyCallback_struct`

ICryptKeyCallback interface

## `firebird.driver.fbapi.ITimer_VTable`

ITimer virtual method table

## `firebird.driver.fbapi.ITimer_struct`

ITimer interface

## `firebird.driver.fbapi.ITimerControl_VTable`

ITimerControl virtual method table

## `firebird.driver.fbapi.ITimerControl_struct`

ITimerControl interface

## `firebird.driver.fbapi.IVersionCallback_VTable`

IVersionCallback virtual method table

## `firebird.driver.fbapi.IVersionCallback_struct`

IVersionCallback interface

## `firebird.driver.fbapi.IUtil_VTable`

IUtil virtual method table

## `firebird.driver.fbapi.IUtil_struct`

IUtil interface

## `firebird.driver.fbapi.IOffsetsCallback_VTable`

IOffsetsCallback virtual method table

## `firebird.driver.fbapi.IOffsetsCallback_struct`

IOffsetsCallback interface

## `firebird.driver.fbapi.IXpbBuilder_VTable`

IXpbBuilder virtual method table

## `firebird.driver.fbapi.IXpbBuilder_struct`

IXpbBuilder interface

## `firebird.driver.fbapi.IDecFloat16_VTable`

IDecFloat16 virtual method table

## `firebird.driver.fbapi.IDecFloat16_struct`

IDecFloat16 interface

## `firebird.driver.fbapi.IDecFloat34_VTable`

IDecFloat34 virtual method table

## `firebird.driver.fbapi.IDecFloat34_struct`

IDecFloat34 interface

## `firebird.driver.fbapi.IInt128_VTable`

IInt128 virtual method table

## `firebird.driver.fbapi.IInt128_struct`

IInt128 interface
