From 0ef4980c333dc3f18519d60f06c6b62a87f835e4 Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Mon, 16 Jun 2025 12:07:20 +0300 Subject: [PATCH 01/11] Merge putDtype and putType, remove duplicate code --- src/dsql/DsqlCompilerScratch.cpp | 326 +++++++++---------------------- src/dsql/DsqlCompilerScratch.h | 6 + 2 files changed, 103 insertions(+), 229 deletions(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index 1d6f37591bb..e8b42a934d2 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -239,299 +239,166 @@ void DsqlCompilerScratch::putBlrMarkers(ULONG marks) // Write out field data type. // Taking special care to declare international text. void DsqlCompilerScratch::putDtype(const TypeClause* field, bool useSubType) +{ + fb_assert(field); + putType(*field, useSubType, field->explicitCollation); +} + +void DsqlCompilerScratch::putType(const TypeClause* type, bool useSubType) +{ + fb_assert(type); + putType(*type, useSubType, type->collate.object.hasData()); +} + +void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool useExplicitCollate) { #ifdef DEV_BUILD // Check if the field describes a known datatype - if (field->dtype > FB_NELEM(blr_dtypes) || !blr_dtypes[field->dtype]) + if (type.dtype >= FB_NELEM(blr_dtypes) || !blr_dtypes[type.dtype]) { SCHAR buffer[100]; - sprintf(buffer, "Invalid dtype %d in BlockNode::putDtype", field->dtype); + sprintf(buffer, "Invalid dtype %d in DsqlCompilerScratch::putType", type.dtype); ERRD_bugcheck(buffer); } #endif + fb_assert(type.dtype < FB_NELEM(blr_dtypes) && blr_dtypes[type.dtype]); - if (field->notNull) + if (type.notNull) appendUChar(blr_not_nullable); - if (field->typeOfName.object.hasData()) + if (type.typeOfName.object.hasData()) { - if (field->typeOfTable.object.hasData()) + if (type.typeOfTable.object.hasData()) { - if (field->explicitCollation) - { - if (field->typeOfTable.schema != ddlSchema) - { - appendUChar(blr_column_name3); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfTable.schema.c_str()); - appendMetaString(field->typeOfTable.object.c_str()); - appendMetaString(field->typeOfName.object.c_str()); - appendUChar(1); - appendUShort(field->textType); - } - else - { - appendUChar(blr_column_name2); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfTable.object.c_str()); - appendMetaString(field->typeOfName.object.c_str()); - appendUShort(field->textType); - } - } - else - { - if (field->typeOfTable.schema != ddlSchema) - { - appendUChar(blr_column_name3); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfTable.schema.c_str()); - appendMetaString(field->typeOfTable.object.c_str()); - appendMetaString(field->typeOfName.object.c_str()); - appendUChar(0); - } - else - { - appendUChar(blr_column_name); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfTable.object.c_str()); - appendMetaString(field->typeOfName.object.c_str()); - } - } + putTypeNameBlr(type, type.typeOfTable, useExplicitCollate); } else { - if (field->explicitCollation) - { - if (field->typeOfName.schema != ddlSchema) - { - appendUChar(blr_domain_name3); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfName.schema.c_str()); - appendMetaString(field->typeOfName.object.c_str()); - appendUChar(1); - appendUShort(field->textType); - } - else - { - appendUChar(blr_domain_name2); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfName.object.c_str()); - appendUShort(field->textType); - } - } - else - { - if (field->typeOfName.schema != ddlSchema) - { - appendUChar(blr_domain_name3); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfName.schema.c_str()); - appendMetaString(field->typeOfName.object.c_str()); - appendUChar(0); - } - else - { - appendUChar(blr_domain_name); - appendUChar(field->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(field->typeOfName.object.c_str()); - } - } + putTypeNameBlr(type, type.typeOfName, useExplicitCollate); } - return; } - switch (field->dtype) + // Maybe it is possible to use GEN_descriptor here? + putDTypeBlr(type, useSubType); +} + + +void DsqlCompilerScratch::putDTypeBlr(const TypeClause& type, const bool useSubType) +{ + switch (type.dtype) { case dtype_cstring: case dtype_text: case dtype_varying: case dtype_blob: if (!useSubType) - appendUChar(blr_dtypes[field->dtype]); - else if (field->dtype == dtype_varying) + appendUChar(blr_dtypes[type.dtype]); + else if (type.dtype == dtype_varying) { appendUChar(blr_varying2); - appendUShort(field->textType); + appendUShort(type.textType); } - else if (field->dtype == dtype_cstring) + else if (type.dtype == dtype_cstring) { appendUChar(blr_cstring2); - appendUShort(field->textType); + appendUShort(type.textType); } - else if (field->dtype == dtype_blob) + else if (type.dtype == dtype_blob) { appendUChar(blr_blob2); - appendUShort(field->subType); - appendUShort(field->textType); + appendUShort(type.subType); + appendUShort(type.textType); } else { appendUChar(blr_text2); - appendUShort(field->textType); + appendUShort(type.textType); } - if (field->dtype == dtype_varying) - appendUShort(field->length - sizeof(USHORT)); - else if (field->dtype != dtype_blob) - appendUShort(field->length); + if (type.dtype == dtype_varying) + appendUShort(type.length - sizeof(USHORT)); + else if (type.dtype != dtype_blob) + appendUShort(type.length); break; default: - appendUChar(blr_dtypes[field->dtype]); - if (DTYPE_IS_EXACT(field->dtype) || (dtype_quad == field->dtype)) - appendUChar(field->scale); + appendUChar(blr_dtypes[type.dtype]); + if (DTYPE_IS_EXACT(type.dtype) || dtype_quad == type.dtype) + appendUChar(type.scale); break; } } -void DsqlCompilerScratch::putType(const TypeClause* type, bool useSubType) + +template +void DsqlCompilerScratch::putTypeNameBlr(const TypeClause& type, const QualifiedName& typeOfField, const bool useExplicitCollate) { -#ifdef DEV_BUILD - // Check if the field describes a known datatype - if (type->dtype > FB_NELEM(blr_dtypes) || !blr_dtypes[type->dtype]) + struct BlrNameSet { - SCHAR buffer[100]; + UCHAR name; + UCHAR name2; + UCHAR name3; + }; - sprintf(buffer, "Invalid dtype %d in put_dtype", type->dtype); - ERRD_bugcheck(buffer); - } -#endif + static constexpr BlrNameSet BLR_COLUMN_SET{ + blr_column_name, + blr_column_name2, + blr_column_name3, + }; - if (type->notNull) - appendUChar(blr_not_nullable); + static constexpr BlrNameSet BLR_DOMAIN_SET{ + blr_domain_name, + blr_domain_name2, + blr_domain_name3, + }; + + constexpr BlrNameSet blrSet = []() + { + if constexpr(THasName) + return BLR_COLUMN_SET; + else + return BLR_DOMAIN_SET; + }(); - if (type->typeOfName.object.hasData()) + const UCHAR domainBlr = type.fullDomain ? blr_domain_full : blr_domain_type_of; + if (typeOfField.schema != ddlSchema) { - if (type->typeOfTable.object.hasData()) + appendUChar(blrSet.name3); + appendUChar(domainBlr); + appendMetaString(typeOfField.schema.c_str()); + appendMetaString(typeOfField.object.c_str()); + + if constexpr (THasName) + appendMetaString(type.typeOfName.object.c_str()); + + if (useExplicitCollate) { - if (type->collate.object.hasData()) - { - if (type->typeOfTable.schema != ddlSchema) - { - appendUChar(blr_column_name3); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfTable.schema.c_str()); - appendMetaString(type->typeOfTable.object.c_str()); - appendMetaString(type->typeOfName.object.c_str()); - appendUChar(1); - appendUShort(type->textType); - } - else - { - appendUChar(blr_column_name2); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfTable.object.c_str()); - appendMetaString(type->typeOfName.object.c_str()); - appendUShort(type->textType); - } - } - else - { - if (type->typeOfTable.schema != ddlSchema) - { - appendUChar(blr_column_name3); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfTable.schema.c_str()); - appendMetaString(type->typeOfTable.object.c_str()); - appendMetaString(type->typeOfName.object.c_str()); - appendUChar(0); - } - else - { - appendUChar(blr_column_name); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfTable.object.c_str()); - appendMetaString(type->typeOfName.object.c_str()); - } - } + appendUChar(1); + appendUShort(type.textType); } else { - if (type->collate.object.hasData()) - { - if (type->typeOfName.schema != ddlSchema) - { - appendUChar(blr_domain_name3); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfName.schema.c_str()); - appendMetaString(type->typeOfName.object.c_str()); - appendUChar(1); - appendUShort(type->textType); - } - else - { - appendUChar(blr_domain_name2); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfName.object.c_str()); - appendUShort(type->textType); - } - } - else - { - if (type->typeOfName.schema != ddlSchema) - { - appendUChar(blr_domain_name3); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfName.schema.c_str()); - appendMetaString(type->typeOfName.object.c_str()); - appendUChar(0); - } - else - { - appendUChar(blr_domain_name); - appendUChar(type->fullDomain ? blr_domain_full : blr_domain_type_of); - appendMetaString(type->typeOfName.object.c_str()); - } - } + appendUChar(0); } - - return; } - - switch (type->dtype) + else { - case dtype_cstring: - case dtype_text: - case dtype_varying: - case dtype_blob: - if (!useSubType) - appendUChar(blr_dtypes[type->dtype]); - else if (type->dtype == dtype_varying) - { - appendUChar(blr_varying2); - appendUShort(type->textType); - } - else if (type->dtype == dtype_cstring) - { - appendUChar(blr_cstring2); - appendUShort(type->textType); - } - else if (type->dtype == dtype_blob) - { - appendUChar(blr_blob2); - appendUShort(type->subType); - appendUShort(type->textType); - } - else - { - appendUChar(blr_text2); - appendUShort(type->textType); - } + const UCHAR nameBlr = useExplicitCollate ? blrSet.name2 : blrSet.name; - if (type->dtype == dtype_varying) - appendUShort(type->length - sizeof(USHORT)); - else if (type->dtype != dtype_blob) - appendUShort(type->length); - break; + appendUChar(nameBlr); + appendUChar(domainBlr); + appendMetaString(typeOfField.object.c_str()); - default: - appendUChar(blr_dtypes[type->dtype]); - if (DTYPE_IS_EXACT(type->dtype) || dtype_quad == type->dtype) - appendUChar(type->scale); - break; + if constexpr (THasName) + appendMetaString(type.typeOfName.object.c_str()); + + if (useExplicitCollate) + { + appendUShort(type.textType); + } } } @@ -1296,3 +1163,4 @@ BoolExprNode* DsqlCompilerScratch::pass1JoinIsRecursive(RecordSourceNode*& input return NULL; } + diff --git a/src/dsql/DsqlCompilerScratch.h b/src/dsql/DsqlCompilerScratch.h index dbb2d3657cc..74f76b5cdc0 100644 --- a/src/dsql/DsqlCompilerScratch.h +++ b/src/dsql/DsqlCompilerScratch.h @@ -172,6 +172,7 @@ class DsqlCompilerScratch : public BlrDebugWriter void putBlrMarkers(ULONG marks); void putDtype(const TypeClause* field, bool useSubType); void putType(const TypeClause* type, bool useSubType); + void putType(const TypeClause& type, bool useSubType, bool useExplicitCollate); void putLocalVariableDecl(dsql_var* variable, DeclareVariableNode* hostParam, QualifiedName& collationName); void putLocalVariableInit(dsql_var* variable, const DeclareVariableNode* hostParam); @@ -289,6 +290,11 @@ class DsqlCompilerScratch : public BlrDebugWriter bool pass1RelProcIsRecursive(RecordSourceNode* input); BoolExprNode* pass1JoinIsRecursive(RecordSourceNode*& input); + void putDTypeBlr(const TypeClause& type, const bool useSubType); + + template + void putTypeNameBlr(const TypeClause& type, const QualifiedName& typeOfField, const bool useExplicitCollate); + dsql_dbb* dbb = nullptr; // DSQL attachment jrd_tra* transaction = nullptr; // Transaction DsqlStatement* dsqlStatement = nullptr; // DSQL statement From a8a673986cd904cbd6b1c37fa1aaa820c38c9c27 Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Wed, 18 Jun 2025 14:15:43 +0300 Subject: [PATCH 02/11] Remove extra line --- src/dsql/DsqlCompilerScratch.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index e8b42a934d2..db10024d697 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -285,7 +285,6 @@ void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool putDTypeBlr(type, useSubType); } - void DsqlCompilerScratch::putDTypeBlr(const TypeClause& type, const bool useSubType) { switch (type.dtype) From c6f7d3f1fd5a4d23b676b2aa069b7e19e55fd87b Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Wed, 18 Jun 2025 16:58:16 +0300 Subject: [PATCH 03/11] Simplify typeOfTable and typeOfName choice in blr generation --- src/dsql/DsqlCompilerScratch.cpp | 41 ++++++++++++++++++++++---------- src/dsql/DsqlCompilerScratch.h | 10 ++++++-- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index db10024d697..b6037716e9b 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -272,11 +272,11 @@ void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool { if (type.typeOfTable.object.hasData()) { - putTypeNameBlr(type, type.typeOfTable, useExplicitCollate); + putTypeNameBlr(type, useExplicitCollate); } else { - putTypeNameBlr(type, type.typeOfName, useExplicitCollate); + putTypeNameBlr(type, useExplicitCollate); } return; } @@ -332,8 +332,8 @@ void DsqlCompilerScratch::putDTypeBlr(const TypeClause& type, const bool useSubT } -template -void DsqlCompilerScratch::putTypeNameBlr(const TypeClause& type, const QualifiedName& typeOfField, const bool useExplicitCollate) +template +void DsqlCompilerScratch::putTypeNameBlr(const TypeClause& type, const bool useExplicitCollate) { struct BlrNameSet { @@ -356,22 +356,34 @@ void DsqlCompilerScratch::putTypeNameBlr(const TypeClause& type, const Qualified constexpr BlrNameSet blrSet = []() { - if constexpr(THasName) + if constexpr(THasTableName) return BLR_COLUMN_SET; else return BLR_DOMAIN_SET; }(); + bool differentSchema; + if constexpr (THasTableName) + differentSchema = type.typeOfTable.schema != ddlSchema; + else + differentSchema = type.typeOfName.schema != ddlSchema; + const UCHAR domainBlr = type.fullDomain ? blr_domain_full : blr_domain_type_of; - if (typeOfField.schema != ddlSchema) + if (differentSchema) { appendUChar(blrSet.name3); appendUChar(domainBlr); - appendMetaString(typeOfField.schema.c_str()); - appendMetaString(typeOfField.object.c_str()); + if constexpr (THasTableName) + { + appendMetaString(type.typeOfTable.schema.c_str()); + appendMetaString(type.typeOfTable.object.c_str()); + } + else + { + appendMetaString(type.typeOfName.schema.c_str()); + } - if constexpr (THasName) - appendMetaString(type.typeOfName.object.c_str()); + appendMetaString(type.typeOfName.object.c_str()); if (useExplicitCollate) { @@ -389,10 +401,13 @@ void DsqlCompilerScratch::putTypeNameBlr(const TypeClause& type, const Qualified appendUChar(nameBlr); appendUChar(domainBlr); - appendMetaString(typeOfField.object.c_str()); - if constexpr (THasName) - appendMetaString(type.typeOfName.object.c_str()); + if constexpr (THasTableName) + { + appendMetaString(type.typeOfTable.object.c_str()); + } + + appendMetaString(type.typeOfName.object.c_str()); if (useExplicitCollate) { diff --git a/src/dsql/DsqlCompilerScratch.h b/src/dsql/DsqlCompilerScratch.h index 74f76b5cdc0..e6ccbb22598 100644 --- a/src/dsql/DsqlCompilerScratch.h +++ b/src/dsql/DsqlCompilerScratch.h @@ -171,6 +171,12 @@ class DsqlCompilerScratch : public BlrDebugWriter void putBlrMarkers(ULONG marks); void putDtype(const TypeClause* field, bool useSubType); + + // * Generate TypeClause blr and put it to this Scratch + // Depends on: typeOfName, typeOfTable and schema: + // blr_column_name3/blr_domain_name3 for field with schema + // blr_column_name2/blr_domain_name2 for explicit collate + // blr_column_name/blr_domain_name for regular field void putType(const TypeClause* type, bool useSubType); void putType(const TypeClause& type, bool useSubType, bool useExplicitCollate); void putLocalVariableDecl(dsql_var* variable, DeclareVariableNode* hostParam, QualifiedName& collationName); @@ -292,8 +298,8 @@ class DsqlCompilerScratch : public BlrDebugWriter void putDTypeBlr(const TypeClause& type, const bool useSubType); - template - void putTypeNameBlr(const TypeClause& type, const QualifiedName& typeOfField, const bool useExplicitCollate); + template + void putTypeNameBlr(const TypeClause& type, const bool useExplicitCollate); dsql_dbb* dbb = nullptr; // DSQL attachment jrd_tra* transaction = nullptr; // Transaction From e1da005b6f62d8060095f435747a413ef7c6875a Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Wed, 18 Jun 2025 17:11:19 +0300 Subject: [PATCH 04/11] Add tests for DsqlCompilerScratch::putDType --- src/jrd/tests/BlrGenTest.cpp | 337 +++++++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 src/jrd/tests/BlrGenTest.cpp diff --git a/src/jrd/tests/BlrGenTest.cpp b/src/jrd/tests/BlrGenTest.cpp new file mode 100644 index 00000000000..a1b0fce3608 --- /dev/null +++ b/src/jrd/tests/BlrGenTest.cpp @@ -0,0 +1,337 @@ +#include "firebird.h" +#include "boost/test/unit_test.hpp" +#include "../dsql/DsqlCompilerScratch.h" + +using namespace Firebird; +using namespace Jrd; + +BOOST_AUTO_TEST_SUITE(EngineSuite) +BOOST_AUTO_TEST_SUITE(BlrGenSuite) + + +BOOST_AUTO_TEST_SUITE(DsqlCompilerScratchTests) + +// HELPERS +// -------- + +DsqlCompilerScratch* makeScratch() +{ + auto& pool = *getDefaultMemoryPool(); + return FB_NEW DsqlCompilerScratch(pool, nullptr, nullptr); +} + +const std::string_view typeOfTableObject = "TABLE OBJECT A"; +const std::string_view typeOfTablePackage = "TABLE PACKAGE A"; +const std::string_view typeOfTableSchema = "TABLE SCHEMA A";\ + +const std::string_view typeOfNameObject = "NAME OBJECT A"; +const std::string_view typeOfNamePackage = "NAME PACKAGE A"; +const std::string_view typeOfNameSchema = "NAME SCHEMA A"; + +const std::string_view collate = "COLLATE A"; + +Jrd::TypeClause genDefaultFiled(MemoryPool& pool) +{ + Jrd::TypeClause field(pool, {}); + + field.dtype = dtype_text; + field.typeOfTable.object = typeOfTableObject.data(); + field.typeOfTable.package = typeOfTablePackage.data(); + field.typeOfTable.schema = typeOfTableSchema.data(); + + field.typeOfName.object = typeOfNameObject.data(); + field.typeOfName.package = typeOfNamePackage.data(); + field.typeOfName.schema = typeOfNameSchema.data(); + + field.fullDomain = true; + field.textType = ttype_utf8; + field.notNull = false; + field.explicitCollation = true; + field.collate.object = collate.data(); + return field; +} + + +void genDomainFiled(DsqlCompilerScratch& expected, UCHAR domainBlr) +{ + expected.appendUChar(blr_column_name3); + expected.appendUChar(domainBlr); + expected.appendMetaString(typeOfTableSchema.data()); + expected.appendMetaString(typeOfTableObject.data()); + expected.appendMetaString(typeOfNameObject.data()); + expected.appendUChar(1); + expected.appendUShort(ttype_utf8); +} + + +// TESTS +// -------- + +BOOST_AUTO_TEST_CASE(TestDefaultTextField) +{ + ThreadContextHolder context; + auto& pool = *getDefaultMemoryPool(); + context->setDatabase(Database::create(nullptr, false)); + + Jrd::TypeClause field = genDefaultFiled(pool); + + DsqlCompilerScratch& scratch = *makeScratch(); + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + genDomainFiled(expected, blr_domain_full); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); +} + + +BOOST_AUTO_TEST_CASE(TestDefaultTextFieldSameSchema) +{ + ThreadContextHolder context; + auto& pool = *getDefaultMemoryPool(); + context->setDatabase(Database::create(nullptr, false)); + + Jrd::TypeClause field = genDefaultFiled(pool); + + DsqlCompilerScratch& scratch = *makeScratch(); + scratch.ddlSchema = field.typeOfTable.schema; + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_column_name2); + expected.appendUChar(blr_domain_full); + expected.appendMetaString(field.typeOfTable.object.c_str()); + expected.appendMetaString(field.typeOfName.object.c_str()); + expected.appendUShort(field.textType); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); +} + + +BOOST_AUTO_TEST_CASE(TestFalseDomain) +{ + ThreadContextHolder context; + auto& pool = *getDefaultMemoryPool(); + context->setDatabase(Database::create(nullptr, false)); + + // Test domain false with different schema + { + Jrd::TypeClause field = genDefaultFiled(pool); + field.fullDomain = false; + + DsqlCompilerScratch& scratch = *makeScratch(); + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + genDomainFiled(expected, blr_domain_type_of); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } + + // Test domain false with same schema + { + Jrd::TypeClause field = genDefaultFiled(pool); + field.fullDomain = false; + + DsqlCompilerScratch& scratch = *makeScratch(); + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_column_name3); + expected.appendUChar(blr_domain_type_of); + expected.appendMetaString(field.typeOfTable.schema.c_str()); + expected.appendMetaString(field.typeOfTable.object.c_str()); + expected.appendMetaString(field.typeOfName.object.c_str()); + expected.appendUChar(1); + expected.appendUShort(field.textType); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } +} + + +BOOST_AUTO_TEST_CASE(TestUseSubType) +{ + ThreadContextHolder context; + auto& pool = *getDefaultMemoryPool(); + context->setDatabase(Database::create(nullptr, false)); + + // Test subType true + { + DsqlCompilerScratch& scratch = *makeScratch(); + Jrd::TypeClause field = genDefaultFiled(pool); + field.typeOfName.clear(); + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_text2); + expected.appendUShort(field.textType); + expected.appendUShort(field.length); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } + + { + DsqlCompilerScratch& scratch = *makeScratch(); + Jrd::TypeClause field = genDefaultFiled(pool); + field.typeOfName.clear(); + scratch.putDtype(&field, false); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_text); + expected.appendUShort(field.length); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } +} + + +BOOST_AUTO_TEST_CASE(TestFalseExplicitCollation) +{ + ThreadContextHolder context; + auto& pool = *getDefaultMemoryPool(); + context->setDatabase(Database::create(nullptr, false)); + + { // Different shame + + DsqlCompilerScratch& scratch = *makeScratch(); + + Jrd::TypeClause field = genDefaultFiled(pool); + field.explicitCollation = false; + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_column_name3); + expected.appendUChar(blr_domain_full); + expected.appendMetaString(field.typeOfTable.schema.c_str()); + expected.appendMetaString(field.typeOfTable.object.c_str()); + expected.appendMetaString(field.typeOfName.object.c_str()); + expected.appendUChar(0); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } + + { // Same shame + DsqlCompilerScratch& scratch = *makeScratch(); + + Jrd::TypeClause field = genDefaultFiled(pool); + field.explicitCollation = false; + scratch.ddlSchema = field.typeOfTable.schema; + + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_column_name); + expected.appendUChar(blr_domain_full); + expected.appendMetaString(field.typeOfTable.object.c_str()); + expected.appendMetaString(field.typeOfName.object.c_str()); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } + +} + + +BOOST_AUTO_TEST_CASE(TestPutTypeEmptyCollate) +{ + ThreadContextHolder context; + auto& pool = *getDefaultMemoryPool(); + context->setDatabase(Database::create(nullptr, false)); + DsqlCompilerScratch& scratch = *makeScratch(); + + Jrd::TypeClause field = genDefaultFiled(pool); + field.collate.clear(); + scratch.putType(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_column_name3); + expected.appendUChar(blr_domain_full); + expected.appendMetaString(field.typeOfTable.schema.c_str()); + expected.appendMetaString(field.typeOfTable.object.c_str()); + expected.appendMetaString(field.typeOfName.object.c_str()); + expected.appendUChar(0); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); +} + + +BOOST_AUTO_TEST_CASE(TestEmptyTypeOfTable) +{ + ThreadContextHolder context; + auto& pool = *getDefaultMemoryPool(); + context->setDatabase(Database::create(nullptr, false)); + + { // Different schema + DsqlCompilerScratch& scratch = *makeScratch(); + Jrd::TypeClause field = genDefaultFiled(pool); + field.typeOfTable.clear(); + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_domain_name3); + expected.appendUChar(blr_domain_full); + expected.appendMetaString(field.typeOfName.schema.c_str()); + expected.appendMetaString(field.typeOfName.object.c_str()); + expected.appendUChar(1); + expected.appendUShort(field.textType); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } + + + { // Same schema + DsqlCompilerScratch& scratch = *makeScratch(); + Jrd::TypeClause field = genDefaultFiled(pool); + field.typeOfTable.clear(); + + scratch.ddlSchema = field.typeOfName.schema; + scratch.putDtype(&field, true); + + DsqlCompilerScratch& expected = *makeScratch(); + expected.appendUChar(blr_domain_name2); + expected.appendUChar(blr_domain_full); + expected.appendMetaString(field.typeOfName.object.c_str()); + expected.appendUShort(field.textType); + + BOOST_CHECK_EQUAL_COLLECTIONS( + scratch.getBlrData().begin(), scratch.getBlrData().end(), + expected.getBlrData().begin(), expected.getBlrData().end() + ); + } +} + +BOOST_AUTO_TEST_SUITE_END() // DsqlCompilerScratchTests + + +BOOST_AUTO_TEST_SUITE_END() // CompressorSuite +BOOST_AUTO_TEST_SUITE_END() // EngineSuite From f360f39483b88f9d560e556cb683bed5b3b628db Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Thu, 19 Jun 2025 13:08:08 +0300 Subject: [PATCH 05/11] Rename putDtype to putType with dsql_fld* overload --- src/dsql/DsqlCompilerScratch.cpp | 2 +- src/dsql/DsqlCompilerScratch.h | 2 +- src/dsql/ExprNodes.cpp | 2 +- src/jrd/RecordSourceNodes.cpp | 2 +- src/jrd/tests/BlrGenTest.cpp | 20 ++++++++++---------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index b6037716e9b..befc59df623 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -238,7 +238,7 @@ void DsqlCompilerScratch::putBlrMarkers(ULONG marks) // Write out field data type. // Taking special care to declare international text. -void DsqlCompilerScratch::putDtype(const TypeClause* field, bool useSubType) +void DsqlCompilerScratch::putType(const dsql_fld* field, bool useSubType) { fb_assert(field); putType(*field, useSubType, field->explicitCollation); diff --git a/src/dsql/DsqlCompilerScratch.h b/src/dsql/DsqlCompilerScratch.h index e6ccbb22598..ab23fba1426 100644 --- a/src/dsql/DsqlCompilerScratch.h +++ b/src/dsql/DsqlCompilerScratch.h @@ -170,7 +170,7 @@ class DsqlCompilerScratch : public BlrDebugWriter std::initializer_list objectTypes); void putBlrMarkers(ULONG marks); - void putDtype(const TypeClause* field, bool useSubType); + void putType(const dsql_fld* field, bool useSubType); // * Generate TypeClause blr and put it to this Scratch // Depends on: typeOfName, typeOfTable and schema: diff --git a/src/dsql/ExprNodes.cpp b/src/dsql/ExprNodes.cpp index 1fccbee3e11..59440a49524 100644 --- a/src/dsql/ExprNodes.cpp +++ b/src/dsql/ExprNodes.cpp @@ -3604,7 +3604,7 @@ void CastNode::genBlr(DsqlCompilerScratch* dsqlScratch) else dsqlScratch->appendUChar(blr_cast); - dsqlScratch->putDtype(dsqlField, true); + dsqlScratch->putType(dsqlField, true); GEN_expr(dsqlScratch, source); } diff --git a/src/jrd/RecordSourceNodes.cpp b/src/jrd/RecordSourceNodes.cpp index 67c2c5142fb..00266437b2f 100644 --- a/src/jrd/RecordSourceNodes.cpp +++ b/src/jrd/RecordSourceNodes.cpp @@ -4168,7 +4168,7 @@ void TableValueFunctionSourceNode::genBlr(DsqlCompilerScratch* dsqlScratch) for (const auto& fld : arrayFld) { - dsqlScratch->putDtype(fld, true); + dsqlScratch->putType(fld, true); dsqlScratch->appendMetaString(fld->fld_name.c_str()); } } diff --git a/src/jrd/tests/BlrGenTest.cpp b/src/jrd/tests/BlrGenTest.cpp index a1b0fce3608..cf42745afb9 100644 --- a/src/jrd/tests/BlrGenTest.cpp +++ b/src/jrd/tests/BlrGenTest.cpp @@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(TestDefaultTextField) Jrd::TypeClause field = genDefaultFiled(pool); DsqlCompilerScratch& scratch = *makeScratch(); - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); genDomainFiled(expected, blr_domain_full); @@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(TestDefaultTextFieldSameSchema) DsqlCompilerScratch& scratch = *makeScratch(); scratch.ddlSchema = field.typeOfTable.schema; - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_column_name2); @@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE(TestFalseDomain) field.fullDomain = false; DsqlCompilerScratch& scratch = *makeScratch(); - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); genDomainFiled(expected, blr_domain_type_of); @@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(TestFalseDomain) field.fullDomain = false; DsqlCompilerScratch& scratch = *makeScratch(); - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_column_name3); @@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(TestUseSubType) DsqlCompilerScratch& scratch = *makeScratch(); Jrd::TypeClause field = genDefaultFiled(pool); field.typeOfName.clear(); - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_text2); @@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(TestUseSubType) DsqlCompilerScratch& scratch = *makeScratch(); Jrd::TypeClause field = genDefaultFiled(pool); field.typeOfName.clear(); - scratch.putDtype(&field, false); + scratch.putType(&field, false); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_text); @@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE(TestFalseExplicitCollation) Jrd::TypeClause field = genDefaultFiled(pool); field.explicitCollation = false; - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_column_name3); @@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(TestFalseExplicitCollation) field.explicitCollation = false; scratch.ddlSchema = field.typeOfTable.schema; - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_column_name); @@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(TestEmptyTypeOfTable) DsqlCompilerScratch& scratch = *makeScratch(); Jrd::TypeClause field = genDefaultFiled(pool); field.typeOfTable.clear(); - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_domain_name3); @@ -315,7 +315,7 @@ BOOST_AUTO_TEST_CASE(TestEmptyTypeOfTable) field.typeOfTable.clear(); scratch.ddlSchema = field.typeOfName.schema; - scratch.putDtype(&field, true); + scratch.putType(&field, true); DsqlCompilerScratch& expected = *makeScratch(); expected.appendUChar(blr_domain_name2); From 18b1ce74f738ee7611772a011dafdea5ccb370a7 Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Thu, 19 Jun 2025 13:09:51 +0300 Subject: [PATCH 06/11] Use better names for TypeClause gen blr functions and make putField private --- src/dsql/DsqlCompilerScratch.cpp | 21 ++++++++++----------- src/dsql/DsqlCompilerScratch.h | 7 ++++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index befc59df623..35b4a12cd7b 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -241,16 +241,16 @@ void DsqlCompilerScratch::putBlrMarkers(ULONG marks) void DsqlCompilerScratch::putType(const dsql_fld* field, bool useSubType) { fb_assert(field); - putType(*field, useSubType, field->explicitCollation); + putField(*field, useSubType, field->explicitCollation); } void DsqlCompilerScratch::putType(const TypeClause* type, bool useSubType) { fb_assert(type); - putType(*type, useSubType, type->collate.object.hasData()); + putField(*type, useSubType, type->collate.object.hasData()); } -void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool useExplicitCollate) +void DsqlCompilerScratch::putField(const TypeClause& type, bool useSubType, bool useExplicitCollate) { #ifdef DEV_BUILD // Check if the field describes a known datatype @@ -259,7 +259,7 @@ void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool { SCHAR buffer[100]; - sprintf(buffer, "Invalid dtype %d in DsqlCompilerScratch::putType", type.dtype); + sprintf(buffer, "Invalid dtype %d in DsqlCompilerScratch::putField", type.dtype); ERRD_bugcheck(buffer); } #endif @@ -272,20 +272,20 @@ void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool { if (type.typeOfTable.object.hasData()) { - putTypeNameBlr(type, useExplicitCollate); + putFieldName(type, useExplicitCollate); } else { - putTypeNameBlr(type, useExplicitCollate); + putFieldName(type, useExplicitCollate); } return; } // Maybe it is possible to use GEN_descriptor here? - putDTypeBlr(type, useSubType); + putFieldType(type, useSubType); } -void DsqlCompilerScratch::putDTypeBlr(const TypeClause& type, const bool useSubType) +void DsqlCompilerScratch::putFieldType(const TypeClause& type, const bool useSubType) { switch (type.dtype) { @@ -331,9 +331,8 @@ void DsqlCompilerScratch::putDTypeBlr(const TypeClause& type, const bool useSubT } } - template -void DsqlCompilerScratch::putTypeNameBlr(const TypeClause& type, const bool useExplicitCollate) +void DsqlCompilerScratch::putFieldName(const TypeClause& type, const bool useExplicitCollate) { struct BlrNameSet { @@ -426,7 +425,7 @@ void DsqlCompilerScratch::putLocalVariableDecl(dsql_var* variable, DeclareVariab appendUShort(variable->number); DDL_resolve_intl_type(this, field, collationName); - putDtype(field, true); + putType(field, true); if (variable->field->fld_name.hasData()) // Not a function return value putDebugVariable(variable->number, variable->field->fld_name); diff --git a/src/dsql/DsqlCompilerScratch.h b/src/dsql/DsqlCompilerScratch.h index ab23fba1426..cb19bcf5b3f 100644 --- a/src/dsql/DsqlCompilerScratch.h +++ b/src/dsql/DsqlCompilerScratch.h @@ -178,7 +178,6 @@ class DsqlCompilerScratch : public BlrDebugWriter // blr_column_name2/blr_domain_name2 for explicit collate // blr_column_name/blr_domain_name for regular field void putType(const TypeClause* type, bool useSubType); - void putType(const TypeClause& type, bool useSubType, bool useExplicitCollate); void putLocalVariableDecl(dsql_var* variable, DeclareVariableNode* hostParam, QualifiedName& collationName); void putLocalVariableInit(dsql_var* variable, const DeclareVariableNode* hostParam); @@ -296,10 +295,12 @@ class DsqlCompilerScratch : public BlrDebugWriter bool pass1RelProcIsRecursive(RecordSourceNode* input); BoolExprNode* pass1JoinIsRecursive(RecordSourceNode*& input); - void putDTypeBlr(const TypeClause& type, const bool useSubType); + void putField(const TypeClause& type, bool useSubType, bool useExplicitCollate); template - void putTypeNameBlr(const TypeClause& type, const bool useExplicitCollate); + void putFieldName(const TypeClause& type, const bool useExplicitCollate); + + void putFieldType(const TypeClause& type, const bool useSubType); dsql_dbb* dbb = nullptr; // DSQL attachment jrd_tra* transaction = nullptr; // Transaction From 04a9ae7f023fb5351200bbd022f27596c125043c Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Thu, 19 Jun 2025 13:15:19 +0300 Subject: [PATCH 07/11] Resolve code style issues --- src/dsql/DsqlCompilerScratch.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index 35b4a12cd7b..3883378d3dd 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -341,13 +341,15 @@ void DsqlCompilerScratch::putFieldName(const TypeClause& type, const bool useExp UCHAR name3; }; - static constexpr BlrNameSet BLR_COLUMN_SET{ + static constexpr BlrNameSet BLR_COLUMN_SET + { blr_column_name, blr_column_name2, blr_column_name3, }; - static constexpr BlrNameSet BLR_DOMAIN_SET{ + static constexpr BlrNameSet BLR_DOMAIN_SET + { blr_domain_name, blr_domain_name2, blr_domain_name3, @@ -355,7 +357,7 @@ void DsqlCompilerScratch::putFieldName(const TypeClause& type, const bool useExp constexpr BlrNameSet blrSet = []() { - if constexpr(THasTableName) + if constexpr (THasTableName) return BLR_COLUMN_SET; else return BLR_DOMAIN_SET; @@ -378,9 +380,7 @@ void DsqlCompilerScratch::putFieldName(const TypeClause& type, const bool useExp appendMetaString(type.typeOfTable.object.c_str()); } else - { appendMetaString(type.typeOfName.schema.c_str()); - } appendMetaString(type.typeOfName.object.c_str()); @@ -390,9 +390,7 @@ void DsqlCompilerScratch::putFieldName(const TypeClause& type, const bool useExp appendUShort(type.textType); } else - { appendUChar(0); - } } else { @@ -402,16 +400,12 @@ void DsqlCompilerScratch::putFieldName(const TypeClause& type, const bool useExp appendUChar(domainBlr); if constexpr (THasTableName) - { appendMetaString(type.typeOfTable.object.c_str()); - } appendMetaString(type.typeOfName.object.c_str()); if (useExplicitCollate) - { appendUShort(type.textType); - } } } From 8cbc03f2d2ff49c0328f8c74b0feedf17da11e66 Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Thu, 19 Jun 2025 16:18:44 +0300 Subject: [PATCH 08/11] Fix unit tests for putType with dsql_fld --- src/jrd/tests/BlrGenTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/jrd/tests/BlrGenTest.cpp b/src/jrd/tests/BlrGenTest.cpp index cf42745afb9..4f9b8def047 100644 --- a/src/jrd/tests/BlrGenTest.cpp +++ b/src/jrd/tests/BlrGenTest.cpp @@ -30,9 +30,9 @@ const std::string_view typeOfNameSchema = "NAME SCHEMA A"; const std::string_view collate = "COLLATE A"; -Jrd::TypeClause genDefaultFiled(MemoryPool& pool) +Jrd::dsql_fld genDefaultFiled(MemoryPool& pool) { - Jrd::TypeClause field(pool, {}); + Jrd::dsql_fld field(pool); field.dtype = dtype_text; field.typeOfTable.object = typeOfTableObject.data(); @@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(TestFalseExplicitCollation) DsqlCompilerScratch& scratch = *makeScratch(); - Jrd::TypeClause field = genDefaultFiled(pool); + Jrd::dsql_fld field = genDefaultFiled(pool); field.explicitCollation = false; scratch.putType(&field, true); @@ -235,7 +235,7 @@ BOOST_AUTO_TEST_CASE(TestFalseExplicitCollation) { // Same shame DsqlCompilerScratch& scratch = *makeScratch(); - Jrd::TypeClause field = genDefaultFiled(pool); + Jrd::dsql_fld field = genDefaultFiled(pool); field.explicitCollation = false; scratch.ddlSchema = field.typeOfTable.schema; From 7445aaeab0382cdd60cee41742f1beac70291eb0 Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Mon, 30 Jun 2025 09:27:33 +0300 Subject: [PATCH 09/11] Use better names for TypeClause blr generation methods --- src/dsql/DsqlCompilerScratch.cpp | 10 +++++----- src/dsql/DsqlCompilerScratch.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index 3883378d3dd..33cf7493c0c 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -272,20 +272,20 @@ void DsqlCompilerScratch::putField(const TypeClause& type, bool useSubType, bool { if (type.typeOfTable.object.hasData()) { - putFieldName(type, useExplicitCollate); + putTypeName(type, useExplicitCollate); } else { - putFieldName(type, useExplicitCollate); + putTypeName(type, useExplicitCollate); } return; } // Maybe it is possible to use GEN_descriptor here? - putFieldType(type, useSubType); + putDtype(type, useSubType); } -void DsqlCompilerScratch::putFieldType(const TypeClause& type, const bool useSubType) +void DsqlCompilerScratch::putDtype(const TypeClause& type, const bool useSubType) { switch (type.dtype) { @@ -332,7 +332,7 @@ void DsqlCompilerScratch::putFieldType(const TypeClause& type, const bool useSub } template -void DsqlCompilerScratch::putFieldName(const TypeClause& type, const bool useExplicitCollate) +void DsqlCompilerScratch::putTypeName(const TypeClause& type, const bool useExplicitCollate) { struct BlrNameSet { diff --git a/src/dsql/DsqlCompilerScratch.h b/src/dsql/DsqlCompilerScratch.h index cb19bcf5b3f..ad077de99ab 100644 --- a/src/dsql/DsqlCompilerScratch.h +++ b/src/dsql/DsqlCompilerScratch.h @@ -298,9 +298,9 @@ class DsqlCompilerScratch : public BlrDebugWriter void putField(const TypeClause& type, bool useSubType, bool useExplicitCollate); template - void putFieldName(const TypeClause& type, const bool useExplicitCollate); + void putTypeName(const TypeClause& type, const bool useExplicitCollate); - void putFieldType(const TypeClause& type, const bool useSubType); + void putDtype(const TypeClause& type, const bool useSubType); dsql_dbb* dbb = nullptr; // DSQL attachment jrd_tra* transaction = nullptr; // Transaction From 9829b8604758a8c6df6f1251508345c734f8584b Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Mon, 30 Jun 2025 16:51:31 +0300 Subject: [PATCH 10/11] Renamed putField to putType --- src/dsql/DsqlCompilerScratch.cpp | 6 +++--- src/dsql/DsqlCompilerScratch.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index e9adcbc7722..dd6fb785c88 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -241,16 +241,16 @@ void DsqlCompilerScratch::putBlrMarkers(ULONG marks) void DsqlCompilerScratch::putType(const dsql_fld* field, bool useSubType) { fb_assert(field); - putField(*field, useSubType, field->explicitCollation); + putType(*field, useSubType, field->explicitCollation); } void DsqlCompilerScratch::putType(const TypeClause* type, bool useSubType) { fb_assert(type); - putField(*type, useSubType, type->collate.object.hasData()); + putType(*type, useSubType, type->collate.object.hasData()); } -void DsqlCompilerScratch::putField(const TypeClause& type, bool useSubType, bool useExplicitCollate) +void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool useExplicitCollate) { #ifdef DEV_BUILD // Check if the field describes a known datatype diff --git a/src/dsql/DsqlCompilerScratch.h b/src/dsql/DsqlCompilerScratch.h index ad077de99ab..68854524f46 100644 --- a/src/dsql/DsqlCompilerScratch.h +++ b/src/dsql/DsqlCompilerScratch.h @@ -295,7 +295,7 @@ class DsqlCompilerScratch : public BlrDebugWriter bool pass1RelProcIsRecursive(RecordSourceNode* input); BoolExprNode* pass1JoinIsRecursive(RecordSourceNode*& input); - void putField(const TypeClause& type, bool useSubType, bool useExplicitCollate); + void putType(const TypeClause& type, bool useSubType, bool useExplicitCollate); template void putTypeName(const TypeClause& type, const bool useExplicitCollate); From c4304e90f97c89a0018f5b3c2c11bd59d433ae4f Mon Sep 17 00:00:00 2001 From: Artyom Abakumov Date: Mon, 30 Jun 2025 16:51:39 +0300 Subject: [PATCH 11/11] Postfix after merge --- src/dsql/DsqlCompilerScratch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dsql/DsqlCompilerScratch.cpp b/src/dsql/DsqlCompilerScratch.cpp index dd6fb785c88..dc778faff07 100644 --- a/src/dsql/DsqlCompilerScratch.cpp +++ b/src/dsql/DsqlCompilerScratch.cpp @@ -258,7 +258,7 @@ void DsqlCompilerScratch::putType(const TypeClause& type, bool useSubType, bool if (type.dtype >= FB_NELEM(blr_dtypes) || !blr_dtypes[type.dtype]) { SCHAR buffer[100]; - snprintf(buffer, sizeof(buffer), "Invalid dtype %d in DsqlCompilerScratch::putField", type->dtype); + snprintf(buffer, sizeof(buffer), "Invalid dtype %d in DsqlCompilerScratch::putField", type.dtype); ERRD_bugcheck(buffer); } #endif