Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsql_firebird_helpers.cpp File Reference

(508f587717ef550368a8ce7120c1ba8caeabce96)

#include "qsql_firebird_helpers_p.h"
#include <QtCore/qtimezone.h>
#include <firebird/impl/blr.h>
#include <algorithm>
#include <cstring>
#include <limits>
#include <iterator>
Include dependency graph for qsql_firebird_helpers.cpp:

Go to the source code of this file.

Functions

QString fbErrorString (IMaster *master, IStatus *status)
QSqlError fbError (IMaster *master, IStatus *status, QSqlError::ErrorType type)
QString fbErrorLog (const QSqlError &err)
void finishAndClear (Firebird::ThrowStatusWrapper &st, Firebird::ITransaction *&tr, TxnEnd end)
ITransaction * startDefaultTransaction (IAttachment *att, ThrowStatusWrapper &st, TxnWait wait)
QMetaType::Type blrTypeToQt (unsigned char blrType, bool hasScale)
qint64 pow10i (int n)
QMetaType::Type fbTypeToQt (int fbType, int scale)
QByteArray numericInputString (const QVariant &val)
bool decimalToScaledInt64 (const QByteArray &decimal, int scale, qint64 *out)
QString int128ToString (IUtil *util, ThrowStatusWrapper &st, const FB_I128 *value, int scale)
ISC_DATE encodeQDate (IUtil *util, const QDate &d)
ISC_TIME encodeQTime (IUtil *util, const QTime &t)
ISC_TIMESTAMP encodeQDateTime (IUtil *util, const QDateTime &dt)
static QByteArray toFirebirdZoneId (const QTimeZone &zone)
static QTimeZone fromFirebirdZoneId (const QByteArray &id)
ISC_TIMESTAMP_TZ encodeQDateTimeTz (IStatus *iStatus, IUtil *util, const QDateTime &dt)
ISC_TIME_TZ encodeQTimeTz (IStatus *iStatus, IUtil *util, const QDateTime &dt)
QDate decodeFirebirdDate (IUtil *util, ISC_DATE date)
QTime decodeFirebirdTime (IUtil *util, ISC_TIME time)
QDateTime decodeFirebirdTimestamp (IUtil *util, const ISC_TIMESTAMP &ts)
QDateTime decodeFirebirdTimestampTz (IStatus *iStatus, IUtil *util, const ISC_TIMESTAMP_TZ &tstz)
QDateTime decodeFirebirdTimeTz (IStatus *iStatus, IUtil *util, const ISC_TIME_TZ &ttz)
void encodeTextValue (char *data, int fbType, qsizetype length, const QByteArray &bytes)

Function Documentation

◆ blrTypeToQt()

QMetaType::Type blrTypeToQt ( unsigned char blrType,
bool hasScale )

Definition at line 107 of file qsql_firebird_helpers.cpp.

◆ decimalToScaledInt64()

bool decimalToScaledInt64 ( const QByteArray & decimal,
int scale,
qint64 * out )

Convert a plain decimal string (as produced by numericInputString) into the scaled integer Firebird stores for a NUMERIC/DECIMAL column: shift the decimal point by -scale digits (right for the usual negative scale), round half away from zero, and detect qint64 overflow. Works on the digit string, never through double — a double round-trip silently drops digits above 2^53 and an out-of-range double-to-integer cast is undefined behaviour. The read path (applyScale) avoids double for the same reason. Exponent notation is rejected, matching IInt128::fromString on the INT128 path.

Definition at line 218 of file qsql_firebird_helpers.cpp.

◆ decodeFirebirdDate()

QDate decodeFirebirdDate ( IUtil * util,
ISC_DATE date )

Definition at line 399 of file qsql_firebird_helpers.cpp.

◆ decodeFirebirdTime()

QTime decodeFirebirdTime ( IUtil * util,
ISC_TIME time )

Definition at line 408 of file qsql_firebird_helpers.cpp.

◆ decodeFirebirdTimestamp()

QDateTime decodeFirebirdTimestamp ( IUtil * util,
const ISC_TIMESTAMP & ts )

Definition at line 419 of file qsql_firebird_helpers.cpp.

◆ decodeFirebirdTimestampTz()

QDateTime decodeFirebirdTimestampTz ( IStatus * iStatus,
IUtil * util,
const ISC_TIMESTAMP_TZ & tstz )

Definition at line 429 of file qsql_firebird_helpers.cpp.

◆ decodeFirebirdTimeTz()

QDateTime decodeFirebirdTimeTz ( IStatus * iStatus,
IUtil * util,
const ISC_TIME_TZ & ttz )

Definition at line 450 of file qsql_firebird_helpers.cpp.

◆ encodeQDate()

ISC_DATE encodeQDate ( IUtil * util,
const QDate & d )

Definition at line 297 of file qsql_firebird_helpers.cpp.

◆ encodeQDateTime()

ISC_TIMESTAMP encodeQDateTime ( IUtil * util,
const QDateTime & dt )

Definition at line 323 of file qsql_firebird_helpers.cpp.

◆ encodeQDateTimeTz()

ISC_TIMESTAMP_TZ encodeQDateTimeTz ( IStatus * iStatus,
IUtil * util,
const QDateTime & dt )

Definition at line 358 of file qsql_firebird_helpers.cpp.

◆ encodeQTime()

ISC_TIME encodeQTime ( IUtil * util,
const QTime & t )

Definition at line 313 of file qsql_firebird_helpers.cpp.

◆ encodeQTimeTz()

ISC_TIME_TZ encodeQTimeTz ( IStatus * iStatus,
IUtil * util,
const QDateTime & dt )

Definition at line 380 of file qsql_firebird_helpers.cpp.

◆ encodeTextValue()

void encodeTextValue ( char * data,
int fbType,
qsizetype length,
const QByteArray & bytes )

Encode a UTF-8 string into a CHAR/VARCHAR message slot: VARYING gets a 2-byte length prefix, TEXT is space-padded; data beyond the declared length is truncated. Shared by fillInputBuffer and lookupArrayDesc's bind loop so the Firebird text wire format lives in one place.

Definition at line 473 of file qsql_firebird_helpers.cpp.

◆ fbError()

QSqlError fbError ( IMaster * master,
IStatus * status,
QSqlError::ErrorType type )

Convert a Firebird status vector into a QSqlError. type is the context in which the error occurred, supplied by the caller (open() -> ConnectionError, prepare()/exec() -> StatementError, begin/commit/rollback -> TransactionError); QSqlError::ErrorType categorises errors by that context, not by the underlying Firebird cause. The SQLCODE is carried through as the native error code.

Definition at line 43 of file qsql_firebird_helpers.cpp.

◆ fbErrorLog()

QString fbErrorLog ( const QSqlError & err)

Definition at line 53 of file qsql_firebird_helpers.cpp.

◆ fbErrorString()

QString fbErrorString ( IMaster * master,
IStatus * status )

Definition at line 27 of file qsql_firebird_helpers.cpp.

◆ fbTypeToQt()

QMetaType::Type fbTypeToQt ( int fbType,
int scale )

Definition at line 150 of file qsql_firebird_helpers.cpp.

References fbBaseType().

Here is the call graph for this function:

◆ finishAndClear()

void finishAndClear ( Firebird::ThrowStatusWrapper & st,
Firebird::ITransaction *& tr,
TxnEnd end )

Commit (or roll back) a transaction whose handle must not outlive a failure: on a throw the interface is released and the member cleared before the rethrow, on success commit/rollback already released it, so the member is cleared too. Taking the handle by reference makes "released implies cleared" structural — every finish site shares this discipline instead of repeating it. (The bare-COMMIT path in exec() intentionally does NOT use this: a failed user COMMIT keeps the still-valid handle so it can be retried.)

Definition at line 74 of file qsql_firebird_helpers.cpp.

References Commit.

◆ fromFirebirdZoneId()

QTimeZone fromFirebirdZoneId ( const QByteArray & id)
static

Definition at line 349 of file qsql_firebird_helpers.cpp.

◆ int128ToString()

QString int128ToString ( IUtil * util,
ThrowStatusWrapper & st,
const FB_I128 * value,
int scale )

Definition at line 287 of file qsql_firebird_helpers.cpp.

◆ numericInputString()

QByteArray numericInputString ( const QVariant & val)

Canonical decimal string for binding a value to an INT128/DECFLOAT parameter via Firebird's fromString(). Integer and string variants are already plain C-locale decimals; floating-point variants are reformatted only when QVariant::toByteArray() yields exponential notation (e.g. a large double), which IInt128::fromString does not accept.

Definition at line 191 of file qsql_firebird_helpers.cpp.

◆ pow10i()

qint64 pow10i ( int n)

10^n as a 64-bit integer (n >= 0). Firebird numeric scale magnitudes are small (NUMERIC/DECIMAL precision <= 38, INT64 <= 18), so this never overflows for the integer-backed types it is used with.

Definition at line 142 of file qsql_firebird_helpers.cpp.

◆ startDefaultTransaction()

ITransaction * startDefaultTransaction ( IAttachment * att,
ThrowStatusWrapper & st,
TxnWait wait )

Start a transaction with the driver's default TPB: read-committed, record-version, read-write. wait selects isc_tpb_wait vs isc_tpb_nowait — the only axis on which the auto-started transaction (wait) and the explicit user transaction (nowait) differ.

Definition at line 96 of file qsql_firebird_helpers.cpp.

◆ toFirebirdZoneId()

QByteArray toFirebirdZoneId ( const QTimeZone & zone)
static

Firebird names fixed-offset zones by their bare displacement ("+05:30"), while Qt uses "UTC+05:30"-style ids for them. Map between the two so offset-tagged QDateTimes bind and read back cleanly.

Definition at line 341 of file qsql_firebird_helpers.cpp.