25#ifndef FBCPP_STATEMENT_H
26#define FBCPP_STATEMENT_H
29#include "fb-cpp-export.h"
36#include "StatementOptions.h"
37#include "NumericConverter.h"
38#include "CalendarConverter.h"
39#include "Descriptor.h"
40#include "impl/ParameterSetter.h"
43#include "StructBinding.h"
44#include "VariantTypeTraits.h"
62#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
63#include <boost/multiprecision/cpp_int.hpp>
64#include <boost/multiprecision/cpp_dec_float.hpp>
67#if FB_CPP_USE_BOOST_DECIMAL != 0
68#include <boost/decimal.hpp>
87 SELECT = isc_info_sql_stmt_select,
91 INSERT = isc_info_sql_stmt_insert,
95 UPDATE = isc_info_sql_stmt_update,
99 DELETE = isc_info_sql_stmt_delete,
103 DDL = isc_info_sql_stmt_ddl,
123 COMMIT = isc_info_sql_stmt_commit,
127 ROLLBACK = isc_info_sql_stmt_rollback,
145 class FB_CPP_EXPORT
Statement final :
private impl::ParameterSetter<Statement, false>
148 friend class impl::ParameterSetter<
Statement, false>;
215 return statementHandle !=
nullptr;
235 return statementHandle;
244 return resultSetHandle;
302 return inDescriptors;
310 return outDescriptors;
325 std::string getLegacyPlan();
330 std::string getPlan();
366 bool fetchAbsolute(
unsigned position);
371 bool fetchRelative(
int offset);
380 using impl::ParameterSetter<
Statement,
false>::clearParameters;
381 using impl::ParameterSetter<
Statement,
false>::set;
382 using impl::ParameterSetter<
Statement,
false>::setBlobId;
383 using impl::ParameterSetter<
Statement,
false>::setArrayId;
384 using impl::ParameterSetter<
Statement,
false>::setBool;
385 using impl::ParameterSetter<
Statement,
false>::setBytes;
386 using impl::ParameterSetter<
Statement,
false>::setDate;
387 using impl::ParameterSetter<
Statement,
false>::setDouble;
388 using impl::ParameterSetter<
Statement,
false>::setFloat;
389 using impl::ParameterSetter<
Statement,
false>::setInt16;
390 using impl::ParameterSetter<
Statement,
false>::setInt32;
391 using impl::ParameterSetter<
Statement,
false>::setInt64;
392 using impl::ParameterSetter<
Statement,
false>::setNull;
393 using impl::ParameterSetter<
Statement,
false>::setOpaqueDate;
394 using impl::ParameterSetter<
Statement,
false>::setOpaqueDecFloat16;
395 using impl::ParameterSetter<
Statement,
false>::setOpaqueDecFloat34;
396 using impl::ParameterSetter<
Statement,
false>::setOpaqueInt128;
397 using impl::ParameterSetter<
Statement,
false>::setOpaqueTime;
398 using impl::ParameterSetter<
Statement,
false>::setOpaqueTimeTz;
399 using impl::ParameterSetter<
Statement,
false>::setOpaqueTimestamp;
400 using impl::ParameterSetter<
Statement,
false>::setOpaqueTimestampTz;
401 using impl::ParameterSetter<
Statement,
false>::setScaledInt16;
402 using impl::ParameterSetter<
Statement,
false>::setScaledInt32;
403 using impl::ParameterSetter<
Statement,
false>::setScaledInt64;
404 using impl::ParameterSetter<
Statement,
false>::setScaledOpaqueInt128;
405 using impl::ParameterSetter<
Statement,
false>::setString;
406 using impl::ParameterSetter<
Statement,
false>::setTime;
407 using impl::ParameterSetter<
Statement,
false>::setTimeTz;
408 using impl::ParameterSetter<
Statement,
false>::setTimestamp;
409 using impl::ParameterSetter<
Statement,
false>::setTimestampTz;
411#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
412 using impl::ParameterSetter<
Statement,
false>::setBoostDecFloat16;
413 using impl::ParameterSetter<
Statement,
false>::setBoostDecFloat34;
414 using impl::ParameterSetter<
Statement,
false>::setBoostInt128;
415 using impl::ParameterSetter<
Statement,
false>::setScaledBoostInt128;
418#if FB_CPP_USE_BOOST_DECIMAL != 0
419 using impl::ParameterSetter<
Statement,
false>::setBoostDecimal128;
420 using impl::ParameterSetter<
Statement,
false>::setBoostDecimal32;
421 using impl::ParameterSetter<
Statement,
false>::setBoostDecimal64;
438 return outRow->isNull(index);
447 return outRow->getBool(index);
453 std::optional<std::int16_t>
getInt16(
unsigned index)
456 return outRow->getInt16(index);
465 return outRow->getScaledInt16(index);
471 std::optional<std::int32_t>
getInt32(
unsigned index)
474 return outRow->getInt32(index);
483 return outRow->getScaledInt32(index);
489 std::optional<std::int64_t>
getInt64(
unsigned index)
492 return outRow->getInt64(index);
501 return outRow->getScaledInt64(index);
510 return outRow->getScaledOpaqueInt128(index);
513#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
520 return outRow->getBoostInt128(index);
529 return outRow->getScaledBoostInt128(index);
539 return outRow->getFloat(index);
548 return outRow->getDouble(index);
557 return outRow->getOpaqueDecFloat16(index);
560#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
567 return outRow->getBoostDecFloat16(index);
571#if FB_CPP_USE_BOOST_DECIMAL != 0
578 return outRow->getBoostDecimal32(index);
587 return outRow->getBoostDecimal64(index);
597 return outRow->getOpaqueDecFloat34(index);
600#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
607 return outRow->getBoostDecFloat34(index);
611#if FB_CPP_USE_BOOST_DECIMAL != 0
618 return outRow->getBoostDecimal128(index);
628 return outRow->getDate(index);
637 return outRow->getOpaqueDate(index);
646 return outRow->getTime(index);
655 return outRow->getOpaqueTime(index);
664 return outRow->getTimestamp(index);
673 return outRow->getOpaqueTimestamp(index);
682 return outRow->getTimeTz(index);
691 return outRow->getOpaqueTimeTz(index);
700 return outRow->getTimestampTz(index);
709 return outRow->getOpaqueTimestampTz(index);
718 return outRow->getBlobId(index);
727 return outRow->getArrayId(index);
736 return outRow->getString(index);
742 std::optional<std::vector<std::byte>>
getBytes(
unsigned index)
745 return outRow->getBytes(index);
755 template <
typename T>
759 return outRow->get<T>(index);
769 template <Aggregate T>
773 return outRow->get<T>();
783 template <TupleLike T>
787 return outRow->get<T>();
798 template <VariantLike V>
802 return outRow->get<V>(index);
806 const std::vector<Descriptor>& getSetterDescriptors() const noexcept
808 return inDescriptors;
811 std::vector<std::byte>& getSetterMessage() noexcept
816 Client& getSetterClient() noexcept
821 void validateSetter() const noexcept
823 assert(statementHandle !=
nullptr);
826 Client& getClient() noexcept;
828 void clearCurrentRow() noexcept
834 Attachment* attachment;
835 impl::StatusWrapper statusWrapper;
836 impl::CalendarConverter calendarConverter;
837 impl::NumericConverter numericConverter;
838 FbRef<fb::IStatement> statementHandle;
839 FbRef<fb::IResultSet> resultSetHandle;
840 FbRef<fb::IMessageMetadata> inMetadata;
841 std::vector<Descriptor> inDescriptors;
842 std::vector<std::byte> inMessage;
843 FbRef<fb::IMessageMetadata> outMetadata;
844 std::vector<Descriptor> outDescriptors;
845 std::vector<std::byte> outMessage;
846 std::unique_ptr<Row> outRow;
848 unsigned cursorFlags = 0;
849 bool currentRow =
false;
858 inline std::optional<bool> Statement::get<std::optional<bool>>(
unsigned index)
860 return getBool(index);
864 inline std::optional<BlobId> Statement::get<std::optional<BlobId>>(
unsigned index)
866 return getBlobId(index);
870 inline std::optional<ArrayId> Statement::get<std::optional<ArrayId>>(
unsigned index)
872 return getArrayId(index);
876 inline std::optional<std::int16_t> Statement::get<std::optional<std::int16_t>>(
unsigned index)
878 return getInt16(index);
882 inline std::optional<ScaledInt16> Statement::get<std::optional<ScaledInt16>>(
unsigned index)
884 return getScaledInt16(index);
888 inline std::optional<std::int32_t> Statement::get<std::optional<std::int32_t>>(
unsigned index)
890 return getInt32(index);
894 inline std::optional<ScaledInt32> Statement::get<std::optional<ScaledInt32>>(
unsigned index)
896 return getScaledInt32(index);
900 inline std::optional<std::int64_t> Statement::get<std::optional<std::int64_t>>(
unsigned index)
902 return getInt64(index);
906 inline std::optional<ScaledInt64> Statement::get<std::optional<ScaledInt64>>(
unsigned index)
908 return getScaledInt64(index);
912 inline std::optional<ScaledOpaqueInt128> Statement::get<std::optional<ScaledOpaqueInt128>>(
unsigned index)
914 return getScaledOpaqueInt128(index);
917#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
919 inline std::optional<BoostInt128> Statement::get<std::optional<BoostInt128>>(
unsigned index)
921 return getBoostInt128(index);
925 inline std::optional<ScaledBoostInt128> Statement::get<std::optional<ScaledBoostInt128>>(
unsigned index)
927 return getScaledBoostInt128(index);
932 inline std::optional<float> Statement::get<std::optional<float>>(
unsigned index)
934 return getFloat(index);
938 inline std::optional<double> Statement::get<std::optional<double>>(
unsigned index)
940 return getDouble(index);
944 inline std::optional<OpaqueDecFloat16> Statement::get<std::optional<OpaqueDecFloat16>>(
unsigned index)
946 return getOpaqueDecFloat16(index);
949#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
951 inline std::optional<BoostDecFloat16> Statement::get<std::optional<BoostDecFloat16>>(
unsigned index)
953 return getBoostDecFloat16(index);
957#if FB_CPP_USE_BOOST_DECIMAL != 0
959 inline std::optional<BoostDecimal32> Statement::get<std::optional<BoostDecimal32>>(
unsigned index)
961 return getBoostDecimal32(index);
965 inline std::optional<BoostDecimal64> Statement::get<std::optional<BoostDecimal64>>(
unsigned index)
967 return getBoostDecimal64(index);
972 inline std::optional<OpaqueDecFloat34> Statement::get<std::optional<OpaqueDecFloat34>>(
unsigned index)
974 return getOpaqueDecFloat34(index);
977#if FB_CPP_USE_BOOST_MULTIPRECISION != 0
979 inline std::optional<BoostDecFloat34> Statement::get<std::optional<BoostDecFloat34>>(
unsigned index)
981 return getBoostDecFloat34(index);
985#if FB_CPP_USE_BOOST_DECIMAL != 0
987 inline std::optional<BoostDecimal128> Statement::get<std::optional<BoostDecimal128>>(
unsigned index)
989 return getBoostDecimal128(index);
994 inline std::optional<Date> Statement::get<std::optional<Date>>(
unsigned index)
996 return getDate(index);
1000 inline std::optional<OpaqueDate> Statement::get<std::optional<OpaqueDate>>(
unsigned index)
1002 return getOpaqueDate(index);
1006 inline std::optional<Time> Statement::get<std::optional<Time>>(
unsigned index)
1008 return getTime(index);
1012 inline std::optional<OpaqueTime> Statement::get<std::optional<OpaqueTime>>(
unsigned index)
1014 return getOpaqueTime(index);
1018 inline std::optional<OpaqueTimestamp> Statement::get<std::optional<OpaqueTimestamp>>(
unsigned index)
1020 return getOpaqueTimestamp(index);
1024 inline std::optional<Timestamp> Statement::get<std::optional<Timestamp>>(
unsigned index)
1026 return getTimestamp(index);
1030 inline std::optional<TimeTz> Statement::get<std::optional<TimeTz>>(
unsigned index)
1032 return getTimeTz(index);
1036 inline std::optional<OpaqueTimeTz> Statement::get<std::optional<OpaqueTimeTz>>(
unsigned index)
1038 return getOpaqueTimeTz(index);
1042 inline std::optional<TimestampTz> Statement::get<std::optional<TimestampTz>>(
unsigned index)
1044 return getTimestampTz(index);
1048 inline std::optional<OpaqueTimestampTz> Statement::get<std::optional<OpaqueTimestampTz>>(
unsigned index)
1050 return getOpaqueTimestampTz(index);
1054 inline std::optional<std::string> Statement::get<std::optional<std::string>>(
unsigned index)
1056 return getString(index);
1060 inline std::optional<std::vector<std::byte>> Statement::get<std::optional<std::vector<std::byte>>>(
unsigned index)
1062 return getBytes(index);
Represents a connection to a Firebird database.
Reference-counted smart pointer for Firebird objects using addRef/release semantics.
A disconnected buffer of rows fetched from a Statement's result set.
Represents options used when preparing a Statement.
Prepares, executes, and fetches SQL statements against a Firebird attachment.
std::optional< std::vector< std::byte > > getBytes(unsigned index)
Reads a text or varying column as its raw bytes.
V get(unsigned index)
Retrieves a column value as a user-defined variant type.
bool hasCurrentRow() const noexcept
Returns whether the statement is positioned on a current output row.
std::optional< ArrayId > getArrayId(unsigned index)
Reads an array identifier column.
std::optional< OpaqueTime > getOpaqueTime(unsigned index)
Reads a raw time-of-day column in Firebird's representation.
std::optional< OpaqueDecFloat34 > getOpaqueDecFloat34(unsigned index)
Reads a Firebird 34-digit decimal floating-point column.
std::vector< std::byte > & getOutputMessage() noexcept
Provides direct access to the raw output message buffer.
const std::vector< Descriptor > & getInputDescriptors() noexcept
Provides cached descriptors for each input column.
const std::vector< Descriptor > & getOutputDescriptors() noexcept
Provides cached descriptors for each output column.
bool isValid() noexcept
Returns whether the Statement object is valid.
StatementType getType() noexcept
Returns the type classification reported by the server.
std::optional< TimeTz > getTimeTz(unsigned index)
Reads a time-of-day column with timezone.
std::optional< BoostDecFloat34 > getBoostDecFloat34(unsigned index)
Reads a Boost-based 34-digit decimal floating-point column.
std::optional< Time > getTime(unsigned index)
Reads a time-of-day column without timezone.
std::optional< Date > getDate(unsigned index)
Reads a date column.
FbRef< fb::IResultSet > getResultSetHandle() noexcept
Provides access to the underlying Firebird currently open result set handle, if any.
bool isNull(unsigned index)
Reports whether the most recently fetched row has a null at the given column.
std::optional< OpaqueDate > getOpaqueDate(unsigned index)
Reads a raw date column in Firebird's representation.
T get()
Retrieves all output columns into a user-defined aggregate struct.
std::optional< std::int64_t > getInt64(unsigned index)
Reads a 64-bit signed integer column.
FbRef< fb::IStatement > getStatementHandle() noexcept
Provides direct access to the underlying Firebird statement handle.
std::optional< ScaledInt32 > getScaledInt32(unsigned index)
Reads a scaled 32-bit signed integer column.
std::optional< float > getFloat(unsigned index)
Reads a single precision floating-point column.
std::optional< double > getDouble(unsigned index)
Reads a double precision floating-point column.
std::optional< OpaqueTimestampTz > getOpaqueTimestampTz(unsigned index)
Reads a raw timestamp-with-time-zone column in Firebird's representation.
std::optional< ScaledInt16 > getScaledInt16(unsigned index)
Reads a scaled 16-bit signed integer column.
std::optional< BlobId > getBlobId(unsigned index)
Reads a blob identifier column.
std::optional< ScaledOpaqueInt128 > getScaledOpaqueInt128(unsigned index)
Reads a Firebird scaled 128-bit integer column.
FbRef< fb::IMessageMetadata > getOutputMetadata() noexcept
Returns the metadata describing columns produced by the statement.
std::optional< OpaqueTimeTz > getOpaqueTimeTz(unsigned index)
Reads a raw time-of-day column with timezone in Firebird's representation.
std::optional< std::string > getString(unsigned index)
Reads a textual column, applying number-to-string conversions when needed.
std::optional< std::int32_t > getInt32(unsigned index)
Reads a 32-bit signed integer column.
FbRef< fb::IMessageMetadata > getInputMetadata() noexcept
Returns the metadata describing prepared input parameters.
~Statement() noexcept
Releases resources; ignores failures to keep destructor noexcept.
std::optional< ScaledBoostInt128 > getScaledBoostInt128(unsigned index)
Reads a scaled Boost 128-bit integer column.
T get(unsigned index)
Retrieves a column using the most appropriate typed accessor specialization.
std::optional< BoostInt128 > getBoostInt128(unsigned index)
Reads a Boost 128-bit integer column.
std::optional< bool > getBool(unsigned index)
Reads a boolean column from the current row.
std::optional< BoostDecimal32 > getBoostDecimal32(unsigned index)
Reads a Boost.Decimal 7-digit decimal floating-point column.
std::optional< OpaqueTimestamp > getOpaqueTimestamp(unsigned index)
Reads a raw timestamp column in Firebird's representation.
Attachment & getAttachment() noexcept
Returns the Attachment object reference used to create this Statement.
std::optional< BoostDecimal64 > getBoostDecimal64(unsigned index)
Reads a Boost.Decimal 16-digit decimal floating-point column.
std::optional< std::int16_t > getInt16(unsigned index)
Reads a 16-bit signed integer column.
std::optional< TimestampTz > getTimestampTz(unsigned index)
Reads a timestamp-with-time-zone column.
std::vector< std::byte > & getInputMessage() noexcept
Provides direct access to the raw input message buffer.
std::optional< OpaqueDecFloat16 > getOpaqueDecFloat16(unsigned index)
Reads a Firebird 16-digit decimal floating-point column.
std::optional< Timestamp > getTimestamp(unsigned index)
Reads a timestamp column without timezone.
std::optional< BoostDecFloat16 > getBoostDecFloat16(unsigned index)
Reads a Boost-based 16-digit decimal floating-point column.
std::optional< ScaledInt64 > getScaledInt64(unsigned index)
Reads a scaled 64-bit signed integer column.
std::optional< BoostDecimal128 > getBoostDecimal128(unsigned index)
Reads a Boost.Decimal 34-digit decimal floating-point column.
Represents a transaction in one or more Firebird databases.
StatementType
Distinguishes the semantic category of the prepared SQL statement.
@ SAVEPOINT
Statement manages a savepoint.
@ PUT_SEGMENT
Statement writes a blob segment - legacy feature.
@ UPDATE
Server classified the statement as an UPDATE.
@ COMMIT
Statement commits a transaction.
@ ROLLBACK
Statement rolls back a transaction.
@ EXEC_PROCEDURE
Statement executes a stored procedure.
@ DELETE
Server classified the statement as a DELETE.
@ DDL
Statement performs data definition operations.
@ GET_SEGMENT
Statement reads a blob segment - legacy feature.
@ INSERT
Server classified the statement as an INSERT.
@ SELECT
Server classified the statement as a SELECT.
@ SET_GENERATOR
Statement sets a generator (sequence) value.
@ START_TRANSACTION
Statement starts a new transaction.
@ SELECT_FOR_UPDATE
Cursor-based SELECT that allows updates.