### Firebird SQL Profiler Setup and Session Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.profiler.md This snippet demonstrates the preparation of tables and routines, starting a profiler session, executing procedures, and finishing the session. It includes creating a table, functions, and procedures, then using the profiler's start and finish commands. ```sql -- Preparation - create table and routines that will be analyzed create table tab ( id integer not null, val integer not null ); set term !; create or alter function mult(p1 integer, p2 integer) returns integer as begin return p1 * p2; end! create or alter procedure ins as declare n integer = 1; begin while (n <= 1000) do begin if (mod(n, 2) = 1) then insert into tab values (:n, mult(:n, 2)); n = n + 1; end end! set term ; -- Start profiling select rdb$profiler.start_session('Profile Session 1', null, null, null, 'DETAILED_REQUESTS') from rdb$database; set term !; execute block as begin execute procedure ins; delete from tab; end! set term ; execute procedure ins; select rdb$profiler.start_session('Profile Session 2') from rdb$database; select mod(id, 5), sum(val) from tab where id <= 50 group by mod(id, 5) order by sum(val); execute procedure rdb$profiler.finish_session(true); ``` -------------------------------- ### Inno Setup: Load Installation Settings from File Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Innosetup-command-line-reference.md Use the /LOADINF parameter to load installation settings from a previously saved file. This allows for automated or pre-configured installations. Ensure filenames with spaces are enclosed in quotes. ```bash /LOADINF="filename" ``` -------------------------------- ### Inno Setup: Save Installation Settings to File Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Innosetup-command-line-reference.md Use the /SAVEINF parameter to save the current installation settings to a specified file. This is useful for creating configuration files for future installations. Ensure filenames with spaces are enclosed in quotes. ```bash /SAVEINF="filename" ``` -------------------------------- ### Inno Setup: Specify Installation Language Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Innosetup-command-line-reference.md Use the /LANG parameter to specify the language for the installer. This suppresses the language selection dialog if a valid language code is provided. ```bash /LANG=language ``` -------------------------------- ### Install Static Library Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/README.md Use this command to install the static library to the default installation paths. ```makefile make install ``` -------------------------------- ### Run Scripted Installer Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Readme.md Execute the installer in a fully scripted mode, automating the installation process without user interaction. ```batch fbit.bat SCRIPTED ``` -------------------------------- ### Inno Setup: Specify Password Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Innosetup-command-line-reference.md Use the /PASSWORD parameter to specify the password for password-protected installations. This parameter is ignored if the password is not set in the [Setup] section or if an invalid password is provided. ```bash /PASSWORD=password ``` -------------------------------- ### Prepare SPB for Starting a Service Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md Create an SPB for starting a service and add parameters such as the action and database name. ```cpp IXpbBuilder* spb2 = utl->getXpbBuilder(&status, IXpbBuilder::SPB_START, NULL, 0); spb2->insertTag(&status, isc_action_svc_db_stats); spb2->insertString(&status, isc_spb_dbname, "employee"); spb2->insertInt(&status, isc_spb_options, isc_spb_sts_encryption); ``` -------------------------------- ### Install Firebird SuperClassic as Application with No Auto Start Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Readme.md Configure Firebird to install as a SuperClassic service, running as an application and not starting automatically. ```batch fbit.bat SCRIPTED SUPERCLASSIC APPTASK NOAUTOSTART ``` -------------------------------- ### Starting a Transaction with TPB Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md Start a transaction using a pre-configured TPB for non-default transaction parameters. ```cpp ITransaction* tra = att->startTransaction(&status, tpb->getBufferLength(&status), tpb->getBuffer(&status)); ``` -------------------------------- ### Open Firebird Install Script in InnoSetup Source: https://github.com/firebirdsql/firebird/blob/master/doc/README.build.mingw.html This describes the manual step of opening the InnoSetup script file to create an executable installer for the Firebird build. ```text firebird/builds/install/arch-specific/mingw/super/FirebirdInstall_15.iss ``` -------------------------------- ### Start a Service Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md Initiate a service using the start() method of the IService interface with the prepared SPB. ```cpp svc->start(&status, spb2->getBufferLength(&status), spb2->getBuffer(&status)); ``` -------------------------------- ### Firebird Install with Specific Tasks Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/installation_scripted.txt Use the /TASKS parameter with caution, as it can override default tasks. This example explicitly selects the CopyFbClientAsGds32Task. ```bash /TASKS="CopyFbClientAsGds32Task" ``` -------------------------------- ### Install Version File Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtommath/CMakeLists.txt Installs the generated version file to a specified configuration directory. Ensure the CONFIG_INSTALL_DIR is correctly defined. ```cmake install(FILES ${PROJECT_VERSION_FILE} DESTINATION ${CONFIG_INSTALL_DIR} ) ``` -------------------------------- ### Integer Configuration Value Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/Firebird_conf.txt Provides examples of valid integer values for configuration settings. ```firebird.conf 1 42 4711 ``` -------------------------------- ### Inno Setup: Override Destination Directory Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Innosetup-command-line-reference.md Use the /DIR parameter to override the default installation directory. A fully qualified path must be provided. The 'expand:' prefix can be used to expand constants. ```bash /DIR="x:\dirname" ``` ```bash /DIR=expand:{autopf}\My Program ``` -------------------------------- ### Firebird Server Install with Customizations Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/installation_scripted.txt Use this to perform a full server installation, change the default SYSDBA password, and deploy gds32. ```bash /MERGETASKS="CopyFbClientAsGds32Task" /SYSDBAPASSWORD="mypassword" ``` -------------------------------- ### Compile decNumber Example 1 Source: https://github.com/firebirdsql/firebird/blob/master/extern/decNumber/readme.txt Compile example1.c along with decNumber.c and decContext.c. Compiler optimization is recommended. Ensure your compiler supports stdint.h and line comments, or consult the User's Guide for alternatives. ```bash gcc -o example1 example1.c decNumber.c decContext.c ``` -------------------------------- ### Install Library Target with CMake Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtommath/CMakeLists.txt Installs the main library target, including its export configuration, and specifies installation directories for different file types. ```cmake install(TARGETS ${PROJECT_NAME} EXPORT ${TARGETS_EXPORT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) ``` -------------------------------- ### Install Homebrew Dependencies Source: https://github.com/firebirdsql/firebird/blob/master/doc/README.build.macosx.md Installs essential build tools and libraries using Homebrew. ```bash brew install automake autoconf-archive cmake libtool ninja ``` -------------------------------- ### Install Headers Source: https://github.com/firebirdsql/firebird/blob/master/extern/libcds/CMakeLists.txt Installs the 'cds' directory from the source to the 'include' destination, assigning it to the HEADERS_COMPONENT. ```cmake install(DIRECTORY ${PROJECT_SOURCE_DIR}/cds DESTINATION include COMPONENT ${HEADERS_COMPONENT}) ``` -------------------------------- ### Install Library Targets Source: https://github.com/firebirdsql/firebird/blob/master/extern/libcds/CMakeLists.txt Defines installation rules for shared and static library targets, including component assignments and destination paths. Also installs an export file for CMake. ```cmake install(TARGETS ${CDS_SHARED_LIBRARY} EXPORT LibCDSConfig LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT ${LIBRARIES_COMPONENT} NAMELINK_SKIP RUNTIME DESTINATION lib${LIB_SUFFIX}) install(TARGETS ${CDS_SHARED_LIBRARY} EXPORT LibCDSConfig LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT ${HEADERS_COMPONENT} NAMELINK_ONLY) install(TARGETS ${CDS_STATIC_LIBRARY} EXPORT LibCDSConfig DESTINATION lib${LIB_SUFFIX} COMPONENT ${LIBRARIES_COMPONENT}) install(EXPORT LibCDSConfig FILE LibCDSConfig.cmake NAMESPACE LibCDS:: DESTINATION lib/cmake/LibCDS) ``` -------------------------------- ### Install ib_udf2 for Firebird 2 Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.ddl.txt Execute this script to install the ib_udf library for Firebird 2, which includes support for NULL signaling. Note the '2' in the filename. ```sql udf/ib_udf2.sql ``` -------------------------------- ### Install RE2 headers and library Source: https://github.com/firebirdsql/firebird/blob/master/extern/re2/CMakeLists.txt Installs the RE2 header files, library, and CMake configuration files. ```cmake install(FILES ${RE2_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/re2) install(TARGETS re2 EXPORT re2Config ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(EXPORT re2Config DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/re2 NAMESPACE re2::) ``` -------------------------------- ### Configure and Install pkg-config File Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtommath/CMakeLists.txt Configures a pkg-config file (.pc) for shared libraries and installs it to the specified directory. This allows other projects to easily find and link against the library. ```cmake set(CMAKE_INSTALL_PKGCONFIGDIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig" CACHE PATH "Folder where to install .pc files") configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc @ONLY ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${CMAKE_INSTALL_PKGCONFIGDIR} ) ``` -------------------------------- ### Run Regular Interactive Installer Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Readme.md Execute the standard interactive installer for Firebird. This is the default behavior when running fbit.bat without arguments. ```batch fbit.bat ``` -------------------------------- ### BIN_AND Function Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.builtin_functions.txt Performs a binary AND operation on all provided numeric arguments. ```sql select bin_and(flags, 1) from x; ``` -------------------------------- ### ASC Index Node Example (3 Segments) Source: https://github.com/firebirdsql/firebird/blob/master/doc/ods11-index-structure.html Shows 'stored data' and 'real value/state' for a 3-segment ascending index. Examples include NULLs and the string 'FIREBIRD', demonstrating prefix compression where parts of the string are omitted. ```text prefix length stored data real value/state 0 0 NULL, NULL, NULL 0 10 x01(1) x70(F) x73(I) x82(R) x69(E) x01(1) x66(B) x73(I) x82(R) x68(D) NULL, NULL, FIREBIRD 0 10 x02(2) x70(F) x73(I) x82(R) x69(E) x02(2) x66(B) x73(I) x82(R) x68(D) NULL, FIREBIRD, NULL 0 10 x03(3) x70(F) x73(I) x82(R) x69(E) x03(3) x66(B) x73(I) x82(R) x68(D) FIREBIRD, NULL, NULL 3 9 x00(0) x00(0) x02(2) x65(A) x00(0) x00(0) x00(0) x01(1) x66(B) FI, A, B ``` -------------------------------- ### PKCS#1 v1.5 Encryption Example 12.1 Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/notes/rsa-testvectors/pkcs1v15crypt-vectors.txt This example shows a PKCS#1 v1.5 encryption operation. It includes the plaintext message, the random seed used for padding, and the resulting ciphertext. This is useful for testing encryption functions. ```text Message: 7d e6 9c d9 22 8b bc fb 9a 8c a8 c6 c3 ef af 05 6f e4 a7 f4 Seed: 33 d6 2c d6 67 82 3f bf 13 d5 92 ae 4d 02 a2 37 0d 1d 99 db 06 c7 25 42 5e 0d 12 fc b4 83 4e f9 e5 49 9d 60 7e 8a ae fe ba 81 96 49 fb 3d 61 c7 05 f5 e9 a3 a2 f8 96 27 61 89 a3 20 0d 2f af f7 76 79 e0 56 34 9a 5b 9b 7b 44 49 b6 75 cd 48 b6 98 09 32 c2 cf c4 6b f8 9a 77 34 f6 8d d9 f4 fe 77 e1 d9 cf 1f 31 b2 1c 4c 61 Encryption: 04 ca ef fc d5 1c 3f c9 23 63 46 77 4d a0 cf a7 7e 9e 64 65 f6 43 7f f4 6d 9f a4 58 b3 62 34 12 c3 10 30 09 fb fe 20 31 96 df 72 96 26 e0 ee 3a fb 6b 10 a5 ac d7 2e 84 28 1d 9d 9b cb a3 e0 ef 77 dd 84 f3 db 19 2d 31 b5 b6 66 f7 6c 93 81 06 81 37 3b aa 58 e6 da db 01 fa 5c 65 ec 89 fa 51 cc 24 74 61 1b 9a 7c b0 0e 86 2f d3 d4 9b 1c d3 1a fc 2d b4 49 e0 9d ae 2d 0a 7d 4d f0 bc 32 0b 5a ``` -------------------------------- ### Create Local Temporary Table for Indexing Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.created_local_temporary_tables.md Sets up a local temporary table with columns suitable for demonstrating index creation. ```sql create local temporary table temp_orders ( order_id integer not null, customer_id integer, order_date date ); ``` -------------------------------- ### Create a Mapping Using Any Plugin Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.mapping.html This example demonstrates creating a mapping that applies to any authentication plugin. It maps any user authenticated through any plugin to the 'GUEST' user within the current database. ```sql CREATE MAPPING "ANY_PLUGIN_TO_GUEST" USING ANY PLUGIN FROM ANY TYPE ANY TO USER "GUEST" ``` -------------------------------- ### PKCS#1 v1.5 Encryption Example 12.2 Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/notes/rsa-testvectors/pkcs1v15crypt-vectors.txt This is another PKCS#1 v1.5 encryption test case. It provides a different message and seed, along with the corresponding ciphertext, useful for comprehensive testing of encryption algorithms. ```text Message: 97 ee a8 56 a9 bd bc 71 4e b3 ac 22 f6 eb 32 71 96 69 c4 2f 94 30 c5 89 50 c6 4c 0d ab ff 3a 9e 20 43 41 6c 67 ca aa ab 7c 68 cc b3 ca 99 a3 Seed: 9f 14 12 61 ce c4 f2 c5 2f 96 91 25 a3 6f 14 10 27 08 82 50 d3 6b 17 42 1c d0 96 14 76 19 06 46 8a fa b7 62 2c 0d 02 19 36 91 74 47 91 e0 d3 5b 6b c9 f3 37 7e 10 b2 85 6c 8e d9 19 9c 89 f4 a4 16 13 d3 c4 0c ca 37 3a 7c c6 3c 52 60 fe 5a ``` -------------------------------- ### RSA Public Key Modulus Example Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/notes/rsa-testvectors/pkcs1v15crypt-vectors.txt This snippet shows the modulus of a 1024-bit RSA public key used in PKCS#1 v1.5 encryption test vectors. ```plaintext a8 b3 b2 84 af 8e b5 0b 38 70 34 a8 60 f1 46 c4 91 9f 31 87 63 cd 6c 55 98 c8 ae 48 11 a1 e0 ab c4 c7 e0 b0 82 d6 93 a5 e7 fc ed 67 5c f4 66 85 12 77 2c 0c bc 64 a7 42 c6 c6 30 f5 33 c8 cc 72 f6 2a e8 33 c4 0b f2 58 42 e9 84 bb 78 bd bf 97 c0 10 7d 55 bd b6 62 f5 c4 e0 fa b9 84 5c b5 14 8e f7 39 2d d3 aa ff 93 ae 1e 6b 66 7b b3 d4 24 76 16 d4 f5 ba 10 d4 cf d2 26 de 88 d3 9f 16 fb ``` -------------------------------- ### MOD Function Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.builtin_functions.txt Use MOD to get the remainder of a division. X is the dividend and Y is the divisor. ```sql select mod(x, 10) from y; ``` -------------------------------- ### POSITION Function Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.builtin_functions.txt Find the starting position of a substring within another string. Returns 0 if not found. ```sql select rdb$relation_name from rdb$relations where position('RDB$' IN rdb$relation_name) = 1; ``` -------------------------------- ### Inno Setup: Override Start Menu Folder Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Innosetup-command-line-reference.md Use the /GROUP parameter to override the default Start Menu folder name. The 'expand:' prefix can be used to expand constants. This parameter is ignored if program group page is disabled. ```bash /GROUP="folder name" ``` -------------------------------- ### Firebird Replication Configuration Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/README.replication.md Sample configuration for the replica side of Firebird replication. Specifies the journal source directory and the accepted source database GUID. ```ini database = /data/mydb.fdb { journal_source_directory = /incoming/ source_guid = "{6F9619FF-8B86-D011-B42D-00CF4FC964FF}" } ``` -------------------------------- ### Build Static Library with libtommath and Test Binary Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/README.md Builds a static library and the `test` binary, enabling libtommath support. Ensure libtommath is installed. ```makefile make CFLAGS="-DUSE_LTM -DLTM_DESC" EXTRALIBS="-ltommath" test ``` -------------------------------- ### Get System Context for Search Path Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.schemas.md Retrieves the current session's search path, including any invalid schemas listed. The example shows how to parse this string into individual schema names. ```sql RDB$GET_CONTEXT('SYSTEM', 'SEARCH_PATH') ``` ```sql select NAME from SYSTEM.RDB$SQL.PARSE_UNQUALIFIED_NAMES(RDB$GET_CONTEXT('SYSTEM', 'SEARCH_PATH')) ``` -------------------------------- ### Show Grants Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.ddl.txt Demonstrates how to view granted permissions in isql, showing the grantor information. ```SQL show grant; /* Grant permissions for this database */ GRANT R1 TO PUBLIC GRANTED BY USER1 GRANT R1 TO USER1 WITH ADMIN OPTION ``` -------------------------------- ### Create Metadata for Stack Trace Examples Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.PSQL_stack_trace.txt This SQL code sets up the necessary tables, exceptions, and stored procedures/triggers to demonstrate PSQL stack trace behavior. ```sql CREATE TABLE ERR (ID INT NOT NULL PRIMARY KEY, NAME VARCHAR(16)); CREATE EXCEPTION EX '!'; CREATE OR ALTER PROCEDURE ERR_1 AS BEGIN EXCEPTION EX 'ID = 3'; END; CREATE OR ALTER TRIGGER ERR_BI FOR ERR BEFORE INSERT AS BEGIN IF (NEW.ID = 2) THEN EXCEPTION EX 'ID = 2'; IF (NEW.ID = 3) THEN EXECUTE PROCEDURE ERR_1; IF (NEW.ID = 4) THEN NEW.ID = 1 / 0; END; CREATE OR ALTER PROCEDURE ERR_2 AS BEGIN INSERT INTO ERR VALUES (3, '333'); END; ``` -------------------------------- ### DESC Index Node Example (1 Segment) Source: https://github.com/firebirdsql/firebird/blob/master/doc/ods11-index-structure.html Demonstrates the 'stored data' and 'real value/state' for a descending index with one segment. Highlights the special byte representations for NULL (0xFE) and values starting with 0xFF. ```text prefix length stored data real value/state 0 2 xFE xFE () x4A (J) 0xFE 0x4A 1 1 xFF () 0xFF 0 1 xFF NULL 1 0 xFF NULL ``` -------------------------------- ### Get Time Zone Transitions Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.time_zone.md Retrieves the set of time zone transition rules between specified start and end timestamps for a given time zone name. This procedure is part of the RDB$TIME_ZONE_UTIL package and returns details about zone and DST offsets. ```sql select * from rdb$time_zone_util.transitions( 'America/Sao_Paulo', timestamp '2017-01-01', timestamp '2019-01-01'); ``` -------------------------------- ### Cost-Based JOIN Order Calculation with Enhanced Index Considerations Source: https://github.com/firebirdsql/firebird/blob/master/doc/README.Optimizer.txt This example shows the cost-based JOIN order calculation in Firebird, which now considers selectivity, cardinality, and the number of indexes, including those matched with IS NULL and STARTING WITH. This leads to fewer JOIN order combinations being calculated. ```sql SELECT * FROM Relations r JOIN RelationCategories rc ON (rc.RelationID = r.RelationID and rc.CATEGORYID = 1) WHERE r.FIRSTNAME LIKE 'J%' ``` -------------------------------- ### Build Static Library with GMP, libtommath, tomsfastmath and Timing Binary Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/README.md Builds a static library and the `timing` binary, enabling support for GMP, libtommath, and tomsfastmath. This is useful for performance comparisons. ```makefile make CFLAGS="-DUSE_GMP -DGMP_DESC -DLTM_DESC -DTFM_DESC" EXTRALIBS="-lgmp" timing ``` -------------------------------- ### Run decNumber Example 1 Source: https://github.com/firebirdsql/firebird/blob/master/extern/decNumber/readme.txt Execute example1 with two numeric arguments to observe their addition. The output format shows the operands and the result. ```bash example1 1.23 1.27 ``` -------------------------------- ### Build Static Library Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/README.md Use this command to build the library as a static library. GNU Make is required. ```makefile make ``` -------------------------------- ### Install Package Configuration Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtommath/CMakeLists.txt Installs the exported package configuration file to the destination directory. This is used for installed packages. ```cmake install(EXPORT ${TARGETS_EXPORT_NAME} DESTINATION ${CONFIG_INSTALL_DIR} FILE ${PROJECT_CONFIG_FILE} ) ``` -------------------------------- ### String Configuration Value Example Source: https://github.com/firebirdsql/firebird/blob/master/doc/Firebird_conf.txt Demonstrates the format for string values in configuration settings. ```firebird.conf RootDirectory = /opt/firebird ``` -------------------------------- ### Example of Named Windows in SQL Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.window_functions.md Demonstrates the use of the `WINDOW` clause to define and reference named windows. This helps in avoiding repetitive expressions and improving query readability. ```sql select id, department, salary, count(*) over w1, first_value(salary) over w2, last_value(salary) over w2 from employee window w1 as (partition by department), w2 as (w1 order by salary) order by department, salary; ``` -------------------------------- ### Grant Schema and Object Permissions Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.schemas.md This example demonstrates creating a schema, creating a table within it, and then granting USAGE permission on the schema and SELECT permission on the table to another user. ```sql -- Connected as USER1 create schema SCHEMA1; create table SCHEMA1.TABLE1 (ID integer); grant usage on schema SCHEMA1 to user USER2; grant select on table SCHEMA1.TABLE1 to user USER2; ``` -------------------------------- ### Shared Library Build for dbcrypt_example Source: https://github.com/firebirdsql/firebird/blob/master/examples/CMakeLists.txt Builds a shared library 'dbcrypt_example' from 'DbCrypt.cpp'. It sets a custom output name 'DbCrypt_example' and configures its output directory and dependencies. ```cmake add_library (dbcrypt_example SHARED dbcrypt/DbCrypt.cpp) set_target_properties (dbcrypt_example PROPERTIES OUTPUT_NAME DbCrypt_example) set_output_directory (dbcrypt_example plugins) add_dependencies_cc (dbcrypt_example UpdateCloopInterfaces) project_group (dbcrypt_example Examples) ``` -------------------------------- ### Create Batch Interface Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md Creates an IBatch interface using a prepared parameters block. This example demonstrates passing the parameters block to the createBatch() method. ```cpp IBatch* batch = att->createBatch(&status, tra, 0, sqlStmtText, SQL_DIALECT_V6, NULL, pb->getBufferLength(&status), pb->getBuffer(&status)); ``` -------------------------------- ### CMake Configuration Output Source: https://github.com/firebirdsql/firebird/blob/master/extern/libcds/build/cmake/readme.md Example output from the CMake configuration step, showing detected compilers, build type, and found dependencies. ```text -- The C compiler identification is GNU 4.8.3 -- The CXX compiler identification is GNU 4.8.3 ... -- Found Threads: TRUE -- Boost version: 1.54.0 -- Found the following Boost libraries: -- system -- thread Build type -- RELEASE -- Configuring done -- Generating done -- Build files have been written to: <...>/libcds-release ``` -------------------------------- ### Create Schema and Table Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.schemas.md Demonstrates creating a schema and a table within that schema. ```sql create schema SCHEMA1; create table SCHEMA1.TABLE1 (ID integer); ``` -------------------------------- ### Shared Library Build for cryptkeyholder_example Source: https://github.com/firebirdsql/firebird/blob/master/examples/CMakeLists.txt Builds a shared library 'cryptkeyholder_example' from 'CryptKeyHolder.cpp'. It sets a custom output name 'CryptKeyHolder_example' and configures its output directory and dependencies. ```cmake add_library (cryptkeyholder_example SHARED dbcrypt/CryptKeyHolder.cpp) set_target_properties (cryptkeyholder_example PROPERTIES OUTPUT_NAME CryptKeyHolder_example) set_output_directory (cryptkeyholder_example plugins) add_dependencies_cc (cryptkeyholder_example UpdateCloopInterfaces) project_group (cryptkeyholder_example Examples) ``` -------------------------------- ### Batch Creation and Execution Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md Demonstrates the process of creating a batch, adding messages, executing it, and processing the completion state. This includes setting up batch parameters, filling message buffers, and retrieving execution results. ```APIDOC ## Batch Operations ### Description This section covers the core operations for using the `IBatch` interface, including creation, message addition, execution, and result processing. ### Methods #### `createBatch` (Attachment/Statement) Creates a batch object for executing SQL statements in a batch. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. - `tra` (ITransaction*): The transaction object. - `attachment` (IAttachment*): The attachment object (if creating via Attachment). - `sqlStmtText` (const char*): The SQL statement text. - `sqlDialect` (int): The SQL dialect to use. - `inputMetadata` (IMessageMetadata*): Metadata for input messages (can be NULL for default). - `bufferLength` (unsigned int): Length of the parameters buffer. - `buffer` (const unsigned char*): The parameters buffer. #### `getMetadata` (IBatch) Retrieves the metadata for messages within the batch. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. - **Returns**: - `IMessageMetadata*`: Metadata object for the messages. #### `add` (IBatch) Adds a message with its data to the batch. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. - `messageNumber` (unsigned int): The message number (typically 1 for single message addition). - `data` (const unsigned char*): Pointer to the message data buffer. #### `execute` (IBatch) Executes the batched SQL statements. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. - `tra` (ITransaction*): The transaction object. - **Returns**: - `IBatchCompletionState*`: An object containing the completion state of each message. #### `cancel` (IBatch) Clears the batch buffers without executing the statements. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. #### `close` (IBatch) Closes the batch interface, releasing resources. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. #### `release` (IBatch) Releases the batch interface, similar to `close` but does not care about errors. ### Batch Completion State (`IBatchCompletionState`) #### `getSize` (IBatchCompletionState) Gets the total number of messages processed by the batch. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. - **Returns**: - `unsigned int`: The total number of messages. #### `getState` (IBatchCompletionState) Gets the execution state of a specific message. - **Parameters**: - `status` (XdrStatus*): Pointer to the status vector. - `index` (unsigned int): The index of the message. - **Returns**: - `int`: The state of the message. #### `dispose` (IBatchCompletionState) Disposes of the `IBatchCompletionState` object, releasing its resources. ### Example Usage ```cpp // Assuming 'att' is an IAttachment*, 'tra' is an ITransaction*, 'sqlStmtText' is the SQL string // and 'utl' is a utility object. XdrStatus status; IXpbBuilder* pb = utl->getXpbBuilder(&status, IXpbBuilder::BATCH, NULL, 0); pb->insertInt(&status, IBatch::RECORD_COUNTS, 1); unsigned int bufferLength = pb->getBufferLength(&status); const unsigned char* buffer = pb->getBuffer(&status); IBatch* batch = att->createBatch(&status, tra, 0, sqlStmtText, SQL_DIALECT_V6, NULL, bufferLength, buffer); if (batch) { IMessageMetadata* meta = batch->getMetadata(&status); if (meta) { unsigned char* data = new unsigned char[meta->getMessageLength(&status)]; // Fill 'data' buffer using fillNextMessage(data, meta); // Example: fillNextMessage(data, meta); batch->add(&status, 1, data); // Add more messages as needed IBatchCompletionState* cs = batch->execute(&status, tra); if (cs) { unsigned total = cs->getSize(&status); for (unsigned p = 0; p < total; ++p) printf("Msg %u state %d\n", p, cs->getState(&status, p)); cs->dispose(); } delete[] data; } batch->close(&status); } pb->dispose(); // Dispose of XpbBuilder ``` ``` -------------------------------- ### Starting a Transaction Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md Start a non-distributed transaction using the startTransaction method on the attachment interface. Default transaction parameters are used. ```cpp ITransaction* tra = att->startTransaction(&status, 0, NULL); ``` -------------------------------- ### Procedure Implementation (AS BEGIN...END) Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.packages.txt Provides the implementation for a procedure within a package body using standard SQL procedural logic. ```sql PROCEDURE [( ) [RETURNS ( )]] AS BEGIN ... END ``` -------------------------------- ### Inno Setup: Tasks Selection Source: https://github.com/firebirdsql/firebird/blob/master/builds/install/arch-specific/win32/test_installer/Innosetup-command-line-reference.md Use the /TASKS parameter to specify which tasks should be initially selected. Tasks can be selected or deselected using comma-separated names. Prefixes '*' and '!' control child task inheritance and deselection. ```bash /TASKS="desktopicon,fileassoc" ``` ```bash /TASKS="*parent,!parent\child" ``` -------------------------------- ### Time Zone String Syntax Examples Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.time_zone.md Examples of valid time zone string formats, including region names and hour/minute displacements. ```sql 'America/Sao_Paulo' ``` ```sql '-02:00' ``` ```sql '+04:00' ``` ```sql '+4:0' ``` ```sql '-04:30' ``` -------------------------------- ### Functional Example: Phone Number Validation Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.similar_to.txt This example demonstrates using SIMILAR TO within a CHECK constraint to validate phone number formats. ```SQL create table department ( number numeric(3) not null, name varchar(25) not null, phone varchar(14) check (phone similar to '\([0-9]{3}\) [0-9]{3}\-[0-9]{4}' escape '\') ); insert into department values ('000', 'Corporate Headquarters', '(408) 555-1234'); insert into department values ('100', 'Sales and Marketing', '(415) 555-1234'); insert into department values ('140', 'Field Office: Canada', '(416) 677-1000'); insert into department values ('600', 'Engineering', '(408) 555-123'); -- check constraint violation select * from department where phone not similar to '\([0-9]{3}\) 555\-%' escape '\'; ``` -------------------------------- ### Creating and Referencing Local Temporary Tables Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.created_local_temporary_tables.md Demonstrates how to create a Local Temporary Table in a specified schema and reference it. It also shows explicit schema qualification for creation. ```sql set search_path to my_schema; -- Creates LTT in my_schema create local temporary table temp_data (id integer); -- References my_schema.temp_data select * from temp_data; -- Explicit schema qualification create local temporary table other_schema.temp_work (x integer); ``` -------------------------------- ### RSAES-OAEP Encryption Example Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/notes/rsa-testvectors/oaep-vect.txt This example demonstrates the RSAES-OAEP encryption process with a specific message and seed, showing the resulting ciphertext. It is useful for validating RSAES-OAEP implementations. ```text # CRT coefficient qInv: 6f 38 52 6b 39 25 08 55 34 ef 3e 41 5a 83 6e de 8b 86 15 8a 2c 7c bf ec cb 0b d8 34 30 4f ec 68 3b a8 d4 f4 79 c4 33 d4 34 16 e6 32 69 62 3c ea 10 07 76 d8 5a ff 40 1d 3f ff 61 0e e6 54 11 ce 3b 13 63 d6 3a 97 09 ee de 42 64 7c ea 56 14 93 d5 45 70 a8 79 c1 86 82 cd 97 71 0b 96 20 5e c3 11 17 d7 3b 5f 36 22 3f ad d6 e8 ba 90 dd 7c 0e e6 1d 44 e1 63 25 1e 20 c7 f6 6e b3 05 11 7c b8 # ---------------------------------- # RSAES-OAEP Encryption Example 10.1 # ---------------------------------- # Message to be encrypted: 8b ba 6b f8 2a 6c 0f 86 d5 f1 75 6e 97 95 68 70 b0 89 53 b0 6b 4e b2 05 bc 16 94 ee # Seed: 47 e1 ab 71 19 fe e5 6c 95 ee 5e aa d8 6f 40 d0 aa 63 bd 33 # Encryption: 53 ea 5d c0 8c d2 60 fb 3b 85 85 67 28 7f a9 15 52 c3 0b 2f eb fb a2 13 f0 ae 87 70 2d 06 8d 19 ba b0 7f e5 74 52 3d fb 42 13 9d 68 c3 c5 af ee e0 bf e4 cb 79 69 cb f3 82 b8 04 d6 e6 13 96 14 4e 2d 0e 60 74 1f 89 93 c3 01 4b 58 b9 b1 95 7a 8b ab cd 23 af 85 4f 4c 35 6f b1 66 2a a7 2b fc c7 e5 86 55 9d c4 28 0d 16 0c 12 67 85 a7 23 eb ee be ff 71 f1 15 94 44 0a ae f8 7d 10 79 3a 87 74 a2 39 d4 a0 4c 87 fe 14 67 b9 da f8 52 08 ec 6c 72 55 79 4a 96 cc 29 14 2f 9a 8b d4 18 e3 c1 fd 67 34 4b 0c d0 82 9d f3 b2 be c6 02 53 19 62 93 c6 b3 4d 3f 75 d3 2f 21 3d d4 5c 62 73 d5 05 ad f4 cc ed 10 57 cb 75 8f c2 6a ee fa 44 12 55 ed 4e 64 c1 99 ee 07 5e 7f 16 64 61 82 fd b4 64 73 9b 68 ab 5d af f0 e6 3e 95 52 01 68 24 f0 54 bf 4d 3c 8c 90 a9 7b b6 b6 55 32 84 eb 42 9f cc ``` -------------------------------- ### Firebird Configuration Setting Syntax Source: https://github.com/firebirdsql/firebird/blob/master/doc/Firebird_conf.txt Illustrates the basic syntax for configuration settings, including key-value pairs and optional comments. ```firebird.conf DefaultDbCachePages=2048 CpuAffinityMask = 2 # only run on second CPU ``` -------------------------------- ### RSAES-OAEP Encryption Example 3.5 Source: https://github.com/firebirdsql/firebird/blob/master/extern/libtomcrypt/notes/rsa-testvectors/oaep-vect.txt This snippet provides the message, seed, and ciphertext for RSAES-OAEP Encryption Example 3.5. It is intended for validating RSAES-OAEP encryption processes. ```text # Message to be encrypted: df 51 51 83 2b 61 f4 f2 58 91 fb 41 72 f3 28 d2 ed df 83 71 ff cf db e9 97 93 92 95 f3 0e ca 69 18 01 7c fd a1 15 3b f7 a6 af 87 59 32 23 # Seed: 2d 76 0b fe 38 c5 9d e3 4c dc 8b 8c 78 a3 8e 66 28 4a 2d 27 ``` -------------------------------- ### Dtc Interface Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md The distributed transactions coordinator interface, used to start distributed transactions involving multiple attachments. It allows joining already started transactions. ```APIDOC ## Dtc Interface ### Description Distributed transactions coordinator. Used to start distributed (working with 2 or more attachments) transactions. Unlike the pre-FB3 approach where distributed transactions must be started in this way from the very beginning, FB3's distributed transactions coordinator also makes it possible to join already started transactions into a single distributed transaction. ### Methods - `ITransaction* join(StatusType* status, ITransaction* one, ITransaction* two)`: Joins 2 independent transactions into a distributed transaction. On success, both transactions passed to join() are released and pointers to them should not be used any more. - `IDtcStart* startBuilder(StatusType* status)`: Returns the `DtcStart` interface. ``` -------------------------------- ### Activate Read-Write Replica Mode Source: https://github.com/firebirdsql/firebird/blob/master/doc/README.replication.md Sets up the database as a read-write replica using gfix. Allows both replicator and regular user connections to modify the database concurrently. ```bash gfix -replica read_write ``` -------------------------------- ### External Aggregate Function UDR Example (C++) Source: https://github.com/firebirdsql/firebird/blob/master/doc/sql.extensions/README.custom_aggregate_functions.md Example of an external aggregate function written in C++ for Firebird SQL. This UDR calculates the sum of positive integers. ```sql create aggregate function sum_positive ( n integer ) returns integer external name 'udrcpp_example!sum_positive' engine udr; ``` ```cpp FB_UDR_BEGIN_AGGREGATE_FUNCTION(sum_positive) FB_UDR_MESSAGE(InMessage, (FB_INTEGER, n) ); FB_UDR_MESSAGE(OutMessage, (FB_INTEGER, result) ); FB_UDR_CONSTRUCTOR // , total(0) { } FB_UDR_START_AGGREGATE_FUNCTION { // total = 0; } FB_UDR_ACCUMULATE_AGGREGATE_FUNCTION { if (!in->nNull && in->n > 0) total += in->n; } FB_UDR_GROUP_AGGREGATE_FUNCTION { out->resultNull = FB_FALSE; out->result = total; } FB_UDR_FINISH_AGGREGATE_FUNCTION { // total = 0; } SINT64 total = 0; FB_UDR_END_AGGREGATE_FUNCTION ``` -------------------------------- ### Prepare Statement and Open Cursor Source: https://github.com/firebirdsql/firebird/blob/master/doc/Using_OO_API.md Prepares a statement to retrieve output metadata first, then opens a cursor. This is efficient if the cursor will be opened multiple times. ```cpp IStatement* stmt = att->prepare(&status, tra, 0, sql, SQL_DIALECT_V6, IStatement::PREPARE_PREFETCH_METADATA); IMessageMetadata* meta = stmt->getOutputMetadata(&status); IResultSet* curs = stmt->openCursor(&status, tra, NULL, NULL, NULL, 0); ```