From c2413fb667c8731a5ac5f28583d0b57413320e31 Mon Sep 17 00:00:00 2001 From: AlexPeshkoff Date: Wed, 27 Mar 2024 20:39:18 +0300 Subject: [PATCH] Use appropriate type CSetId/CollId/TTypeId instead plain SSHORT/USHORT --- src/burp/backup.epp | 8 +- src/burp/burp.h | 5 +- src/burp/restore.epp | 12 +- src/common/CharSet.h | 5 +- src/common/TextType.cpp | 3 +- src/common/TextType.h | 7 +- src/common/cvt.cpp | 48 ++--- src/common/cvt.h | 17 +- src/common/dsc.cpp | 16 +- src/common/dsc.h | 47 +++-- src/common/dsc_proto.h | 3 +- src/common/sdl.cpp | 6 +- src/dsql/AggNodes.cpp | 2 +- src/dsql/BoolNodes.cpp | 29 +-- src/dsql/DSqlDataTypeUtil.cpp | 2 +- src/dsql/DSqlDataTypeUtil.h | 2 +- src/dsql/DdlNodes.epp | 22 +-- src/dsql/DdlNodes.h | 6 +- src/dsql/DsqlRequests.cpp | 2 +- src/dsql/ExprNodes.cpp | 75 ++++---- src/dsql/PackageNodes.epp | 12 +- src/dsql/Parser.cpp | 2 +- src/dsql/Parser.h | 5 +- src/dsql/StmtNodes.cpp | 8 +- src/dsql/ddl.cpp | 2 +- src/dsql/dsql.cpp | 2 +- src/dsql/dsql.h | 20 +- src/dsql/gen.cpp | 16 +- src/dsql/make.cpp | 13 +- src/dsql/make_proto.h | 7 +- src/dsql/metd.epp | 58 +++--- src/dsql/metd_proto.h | 6 +- src/include/fb_types.h | 5 - src/intl/charsets.h | 116 ++++++------ src/jrd/Attachment.cpp | 2 +- src/jrd/Attachment.h | 4 +- src/jrd/CharSetContainer.h | 43 +---- src/jrd/Collation.cpp | 6 +- src/jrd/Collation.h | 4 +- src/jrd/DataTypeUtil.cpp | 18 +- src/jrd/DataTypeUtil.h | 11 +- src/jrd/ExtEngineManager.cpp | 6 +- src/jrd/ExtEngineManager.h | 4 +- src/jrd/Function.epp | 10 +- src/jrd/IntlManager.cpp | 312 +++++++++++++++---------------- src/jrd/IntlManager.h | 9 +- src/jrd/PreparedStatement.cpp | 6 +- src/jrd/RecordSourceNodes.cpp | 8 +- src/jrd/Routine.cpp | 2 +- src/jrd/Statement.h | 3 +- src/jrd/SysFunction.cpp | 16 +- src/jrd/SystemPackages.h | 1 + src/jrd/UserManagement.cpp | 2 +- src/jrd/blb.cpp | 14 +- src/jrd/blb.h | 2 +- src/jrd/btr.cpp | 6 +- src/jrd/cvt.cpp | 14 +- src/jrd/cvt2.cpp | 25 ++- src/jrd/cvt2_proto.h | 3 +- src/jrd/cvt_proto.h | 12 +- src/jrd/dflt.h | 2 + src/jrd/dfw.epp | 2 +- src/jrd/dfw_proto.h | 5 +- src/jrd/evl.cpp | 2 +- src/jrd/filters.cpp | 6 +- src/jrd/grant.epp | 4 +- src/jrd/ini.epp | 15 +- src/jrd/ini.h | 1 + src/jrd/intl.cpp | 164 ++++++---------- src/jrd/intl.h | 112 ++++++----- src/jrd/intl_proto.h | 12 +- src/jrd/jrd.cpp | 18 +- src/jrd/met.epp | 60 ++++-- src/jrd/met.h | 24 ++- src/jrd/mov.cpp | 14 +- src/jrd/mov_proto.h | 10 +- src/jrd/obj.h | 2 + src/jrd/optimizer/Optimizer.cpp | 2 +- src/jrd/optimizer/Retrieval.cpp | 6 +- src/jrd/par.cpp | 28 +-- src/jrd/recsrc/ProcedureScan.cpp | 4 +- src/jrd/replication/Applier.cpp | 8 +- src/jrd/replication/Applier.h | 2 +- src/jrd/tdbb.h | 3 +- src/jrd/trace/TraceObjects.cpp | 4 +- src/jrd/vio.cpp | 4 +- 86 files changed, 796 insertions(+), 850 deletions(-) diff --git a/src/burp/backup.epp b/src/burp/backup.epp index fccf58b0627..c01ea315311 100644 --- a/src/burp/backup.epp +++ b/src/burp/backup.epp @@ -741,13 +741,13 @@ burp_fld* get_fields( burp_rel* relation) if (!Y.RDB$CHARACTER_SET_ID.NULL) { - field->fld_character_set_id = Y.RDB$CHARACTER_SET_ID; + field->fld_character_set_id = CSetId(Y.RDB$CHARACTER_SET_ID); field->fld_flags |= FLD_charset_flag; } if (!X.RDB$COLLATION_ID.NULL) { - field->fld_collation_id = X.RDB$COLLATION_ID; + field->fld_collation_id = CollId(X.RDB$COLLATION_ID); field->fld_flags |= FLD_collate_flag; } @@ -860,13 +860,13 @@ burp_fld* get_fields( burp_rel* relation) if (!Y.RDB$CHARACTER_SET_ID.NULL) { - field->fld_character_set_id = Y.RDB$CHARACTER_SET_ID; + field->fld_character_set_id = CSetId(Y.RDB$CHARACTER_SET_ID); field->fld_flags |= FLD_charset_flag; } if (!X.RDB$COLLATION_ID.NULL) { - field->fld_collation_id = X.RDB$COLLATION_ID; + field->fld_collation_id = CollId(X.RDB$COLLATION_ID); field->fld_flags |= FLD_collate_flag; } diff --git a/src/burp/burp.h b/src/burp/burp.h index ac432471f54..6cef72ee02c 100644 --- a/src/burp/burp.h +++ b/src/burp/burp.h @@ -47,6 +47,7 @@ #include "../common/status.h" #include "../common/sha.h" #include "../common/classes/ImplementHelper.h" +#include "../jrd/intl.h" #ifdef HAVE_UNISTD_H #include @@ -722,8 +723,8 @@ struct burp_fld SSHORT fld_null_flag; ISC_QUAD fld_default_value; ISC_QUAD fld_default_source; - SSHORT fld_character_set_id; - SSHORT fld_collation_id; + CSetId fld_character_set_id; + CollId fld_collation_id; RCRD_OFFSET fld_sql; RCRD_OFFSET fld_null; }; diff --git a/src/burp/restore.epp b/src/burp/restore.epp index 7ee9578e7cb..b7d6c5078bc 100644 --- a/src/burp/restore.epp +++ b/src/burp/restore.epp @@ -3888,11 +3888,11 @@ burp_fld* get_field(BurpGlobals* tdgbl, burp_rel* relation) break; case att_field_character_set: - field->fld_character_set_id = (USHORT) get_int32(tdgbl); + field->fld_character_set_id = CSetId(get_int32(tdgbl)); break; case att_field_collation_id: - field->fld_collation_id = (USHORT) get_int32(tdgbl); + field->fld_collation_id = CollId(get_int32(tdgbl)); X.RDB$COLLATION_ID.NULL = FALSE; X.RDB$COLLATION_ID = field->fld_collation_id; break; @@ -4092,11 +4092,11 @@ burp_fld* get_field(BurpGlobals* tdgbl, burp_rel* relation) break; case att_field_character_set: - field->fld_character_set_id = (USHORT) get_int32(tdgbl); + field->fld_character_set_id = CSetId(get_int32(tdgbl)); break; case att_field_collation_id: - field->fld_collation_id = (USHORT) get_int32(tdgbl); + field->fld_collation_id = CollId(get_int32(tdgbl)); X.RDB$COLLATION_ID.NULL = FALSE; X.RDB$COLLATION_ID = field->fld_collation_id; break; @@ -11775,13 +11775,13 @@ bool WriteRelationMeta::prepareBatch(BurpGlobals* tdgbl) SLONG sqlLength, sqlSubType, sqlScale, sqlType; desc.getSqlInfo(&sqlLength, &sqlSubType, &sqlScale, &sqlType); - SLONG characterSetId = field->fld_character_set_id; + CSetId characterSetId = field->fld_character_set_id; if (tdgbl->gbl_sw_fix_fss_data && field->fld_character_set_id == CS_UNICODE_FSS && ((sqlType == SQL_BLOB && field->fld_sub_type == isc_blob_text && !(field->fld_flags & FLD_array)) || sqlType == SQL_TEXT || sqlType == SQL_VARYING)) { - characterSetId = tdgbl->gbl_sw_fix_fss_data_id; + characterSetId = CSetId(tdgbl->gbl_sw_fix_fss_data_id); } else if (field->fld_flags & FLD_array) { diff --git a/src/common/CharSet.h b/src/common/CharSet.h index 8c9f686fafb..d5f4e72c41c 100644 --- a/src/common/CharSet.h +++ b/src/common/CharSet.h @@ -32,6 +32,7 @@ #include "CsConvert.h" #include "IntlUtil.h" +#include "../jrd/intl.h" namespace Firebird { @@ -89,7 +90,7 @@ class CharSet public: virtual ~CharSet() {} - USHORT getId() const { return id; } + CSetId getId() const { return id; } const char* getName() const { return cs->charset_name; } UCHAR minBytesPerChar() const { return cs->charset_min_bytes_per_char; } UCHAR maxBytesPerChar() const { return cs->charset_max_bytes_per_char; } @@ -138,7 +139,7 @@ class CharSet const ULONG startPos, const ULONG length) const = 0; private: - USHORT id; + CSetId id; charset* cs; UCHAR sqlMatchAny[sizeof(ULONG)]; UCHAR sqlMatchOne[sizeof(ULONG)]; diff --git a/src/common/TextType.cpp b/src/common/TextType.cpp index c13420ad301..ce30500ce81 100644 --- a/src/common/TextType.cpp +++ b/src/common/TextType.cpp @@ -94,6 +94,7 @@ #include "firebird.h" #include "iberror.h" #include "../jrd/intl_classes.h" +#include "../common/TextType.h" #include "../common/IntlUtil.h" #include "../common/classes/Aligner.h" @@ -101,7 +102,7 @@ namespace Jrd { -TextType::TextType(TTYPE_ID _type, texttype *_tt, USHORT _attributes, CharSet* _cs) +TextType::TextType(TTypeId _type, texttype *_tt, USHORT _attributes, CharSet* _cs) : tt(_tt), cs(_cs), type(_type), attributes(_attributes) { if (cs->getSqlMatchAnyLength() != 0) diff --git a/src/common/TextType.h b/src/common/TextType.h index 4b958a2b7d2..9ab0c548012 100644 --- a/src/common/TextType.h +++ b/src/common/TextType.h @@ -31,6 +31,7 @@ #define JRD_TEXTTYPE_H #include "../common/classes/MetaString.h" +#include "../jrd/intl.h" struct texttype; @@ -41,7 +42,7 @@ class CharSet; class TextType { public: - TextType(TTYPE_ID _type, texttype* _tt, USHORT _attributes, CharSet* _cs); + TextType(TTypeId _type, texttype* _tt, USHORT _attributes, CharSet* _cs); private: TextType(const TextType&); // Not implemented @@ -77,7 +78,7 @@ class TextType ULONG dstLen, UCHAR* dst); - USHORT getType() const + TTypeId getType() const { return type; } @@ -108,7 +109,7 @@ class TextType CharSet* cs; private: - TTYPE_ID type; + TTypeId type; USHORT attributes; public: diff --git a/src/common/cvt.cpp b/src/common/cvt.cpp index 67ed3e46a83..aaa6cc3fd57 100644 --- a/src/common/cvt.cpp +++ b/src/common/cvt.cpp @@ -276,7 +276,7 @@ static void float_to_text(const dsc* from, dsc* to, Callbacks* cb) dsc intermediate; intermediate.dsc_dtype = dtype_text; - intermediate.dsc_ttype() = ttype_ascii; + intermediate.setTextType(ttype_ascii); // CVC: If you think this is dangerous, replace the "else" with a call to // MEMMOVE(temp, temp + 1, chars_printed) or something cleverer. // Paranoid assumption: @@ -321,7 +321,7 @@ static void decimal_float_to_text(const dsc* from, dsc* to, DecimalStatus decSt, dsc intermediate; intermediate.dsc_dtype = dtype_text; - intermediate.dsc_ttype() = ttype_ascii; + intermediate.setTextType(ttype_ascii); intermediate.dsc_address = reinterpret_cast(temp); intermediate.dsc_length = strlen(temp); @@ -349,7 +349,7 @@ static void int128_to_text(const dsc* from, dsc* to, Callbacks* cb) dsc intermediate; intermediate.dsc_dtype = dtype_text; - intermediate.dsc_ttype() = ttype_ascii; + intermediate.setTextType(ttype_ascii); intermediate.dsc_address = reinterpret_cast(temp); intermediate.dsc_length = strlen(temp); @@ -492,7 +492,7 @@ static void integer_to_text(const dsc* from, dsc* to, Callbacks* cb) ULONG trailing = ULONG(to->dsc_length) - length; if (trailing > 0) { - CHARSET_ID chid = cb->getChid(to); // : DSC_GET_CHARSET(to); + CSetId chid = cb->getChid(to); // : DSC_GET_CHARSET(to); const char pad = chid == ttype_binary ? '\0' : ' '; memset(q, pad, trailing); @@ -1555,11 +1555,11 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c if ((from->dsc_dtype == dtype_text && to->dsc_dtype == dtype_dbkey && - from->dsc_ttype() == ttype_binary && + from->getTextType() == ttype_binary && from->dsc_length == to->dsc_length) || (to->dsc_dtype == dtype_text && from->dsc_dtype == dtype_dbkey && - to->dsc_ttype() == ttype_binary && + to->getTextType() == ttype_binary && from->dsc_length == to->dsc_length)) { memcpy(p, q, length); @@ -1853,12 +1853,12 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c * unless really required is a good optimization. */ - CHARSET_ID charset2; + CSetId charset2; if (cb->transliterate(from, to, charset2)) return; { // scope - USHORT strtype_unused; + TTypeId strtype_unused; UCHAR *ptr; length = CVT_get_string_ptr_common(from, &strtype_unused, &ptr, NULL, 0, decSt, cb); q = ptr; @@ -1948,7 +1948,7 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c dsc intermediate; intermediate.dsc_dtype = dtype_text; - intermediate.dsc_ttype() = ttype_ascii; + intermediate.setTextType(ttype_ascii); intermediate.makeText(static_cast(strlen(text)), CS_ASCII, reinterpret_cast(text)); @@ -2019,7 +2019,7 @@ void CVT_move_common(const dsc* from, dsc* to, DecimalStatus decSt, Callbacks* c case dtype_dbkey: if (from->isText()) { - USHORT strtype_unused; + TTypeId strtype_unused; UCHAR* ptr; USHORT len = CVT_get_string_ptr_common(from, &strtype_unused, &ptr, NULL, 0, decSt, cb); @@ -2281,7 +2281,7 @@ static void datetime_to_text(const dsc* from, dsc* to, Callbacks* cb) MOVE_CLEAR(&desc, sizeof(desc)); desc.dsc_address = (UCHAR*) temp; desc.dsc_dtype = dtype_text; - desc.dsc_ttype() = ttype_ascii; + desc.setTextType(ttype_ascii); desc.dsc_length = (p - temp); if (from->isTimeStamp() && version4) @@ -2301,7 +2301,7 @@ static void datetime_to_text(const dsc* from, dsc* to, Callbacks* cb) void CVT_make_null_string(const dsc* desc, - USHORT to_interp, + TTypeId to_interp, const char** address, vary* temp, USHORT length, @@ -2343,7 +2343,7 @@ void CVT_make_null_string(const dsc* desc, USHORT CVT_make_string(const dsc* desc, - USHORT to_interp, + TTypeId to_interp, const char** address, vary* temp, USHORT length, @@ -2495,7 +2495,7 @@ static SSHORT cvt_decompose(const char* string, dsc errd; MOVE_CLEAR(&errd, sizeof(errd)); errd.dsc_dtype = dtype_text; - errd.dsc_ttype() = ttype_ascii; + errd.setTextType(ttype_ascii); errd.dsc_length = length; errd.dsc_address = reinterpret_cast(const_cast(string)); @@ -2885,7 +2885,7 @@ Int128 CVT_hex_to_int128(const char* str, USHORT len) } -USHORT CVT_get_string_ptr_common(const dsc* desc, USHORT* ttype, UCHAR** address, +USHORT CVT_get_string_ptr_common(const dsc* desc, TTypeId* ttype, UCHAR** address, vary* temp, USHORT length, DecimalStatus decSt, Callbacks* cb) { /************************************** @@ -3608,11 +3608,11 @@ namespace } public: - virtual bool transliterate(const dsc* from, dsc* to, CHARSET_ID&); - virtual CHARSET_ID getChid(const dsc* d); - virtual Jrd::CharSet* getToCharset(CHARSET_ID charset2); + virtual bool transliterate(const dsc* from, dsc* to, CSetId&); + virtual CSetId getChid(const dsc* d); + virtual Jrd::CharSet* getToCharset(CSetId charset2); virtual void validateData(Jrd::CharSet* toCharset, SLONG length, const UCHAR* q); - virtual ULONG validateLength(Jrd::CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, + virtual ULONG validateLength(Jrd::CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start, const USHORT size); virtual SLONG getLocalDate(); virtual ISC_TIMESTAMP getCurrentGmtTimeStamp(); @@ -3620,13 +3620,13 @@ namespace virtual void isVersion4(bool& v4); } commonCallbacks(status_exception::raise); - bool CommonCallbacks::transliterate(const dsc*, dsc* to, CHARSET_ID& charset2) + bool CommonCallbacks::transliterate(const dsc*, dsc* to, CSetId& charset2) { charset2 = INTL_TTYPE(to); return false; } - Jrd::CharSet* CommonCallbacks::getToCharset(CHARSET_ID) + Jrd::CharSet* CommonCallbacks::getToCharset(CSetId) { return NULL; } @@ -3635,7 +3635,7 @@ namespace { } - ULONG CommonCallbacks::validateLength(Jrd::CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, + ULONG CommonCallbacks::validateLength(Jrd::CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start, const USHORT size) { if (length > size) @@ -3663,7 +3663,7 @@ namespace return MIN(length, size); } - CHARSET_ID CommonCallbacks::getChid(const dsc* d) + CSetId CommonCallbacks::getChid(const dsc* d) { return INTL_TTYPE(d); } @@ -3692,7 +3692,7 @@ namespace Firebird { Callbacks* CVT_commonCallbacks = &commonCallbacks; } -USHORT CVT_get_string_ptr(const dsc* desc, USHORT* ttype, UCHAR** address, +USHORT CVT_get_string_ptr(const dsc* desc, TTypeId* ttype, UCHAR** address, vary* temp, USHORT length, DecimalStatus decSt, ErrorFunction err) { /************************************** diff --git a/src/common/cvt.h b/src/common/cvt.h index 04923f99b89..0ec2600ca5e 100644 --- a/src/common/cvt.h +++ b/src/common/cvt.h @@ -30,6 +30,7 @@ #define COMMON_CVT_H #include "../common/DecFloat.h" +#include "../jrd/intl.h" namespace Jrd { @@ -54,11 +55,11 @@ class Callbacks } public: - virtual bool transliterate(const dsc* from, dsc* to, CHARSET_ID&) = 0; - virtual CHARSET_ID getChid(const dsc* d) = 0; - virtual Jrd::CharSet* getToCharset(CHARSET_ID charset2) = 0; + virtual bool transliterate(const dsc* from, dsc* to, CSetId&) = 0; + virtual CSetId getChid(const dsc* d) = 0; + virtual Jrd::CharSet* getToCharset(CSetId charset2) = 0; virtual void validateData(Jrd::CharSet* toCharset, SLONG length, const UCHAR* q) = 0; - virtual ULONG validateLength(Jrd::CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, + virtual ULONG validateLength(Jrd::CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start, const USHORT size) = 0; virtual SLONG getLocalDate() = 0; virtual ISC_TIMESTAMP getCurrentGmtTimeStamp() = 0; @@ -94,16 +95,16 @@ Firebird::Decimal64 CVT_get_dec64(const dsc*, Firebird::DecimalStatus, ErrorFunc Firebird::Decimal128 CVT_get_dec128(const dsc*, Firebird::DecimalStatus, ErrorFunction); Firebird::Int128 CVT_get_int128(const dsc*, SSHORT, Firebird::DecimalStatus, ErrorFunction); Firebird::Int128 CVT_hex_to_int128(const char* str, USHORT len); -USHORT CVT_make_string(const dsc*, USHORT, const char**, vary*, USHORT, Firebird::DecimalStatus, ErrorFunction); -void CVT_make_null_string(const dsc*, USHORT, const char**, vary*, USHORT, Firebird::DecimalStatus, ErrorFunction); +USHORT CVT_make_string(const dsc*, TTypeId, const char**, vary*, USHORT, Firebird::DecimalStatus, ErrorFunction); +void CVT_make_null_string(const dsc*, TTypeId, const char**, vary*, USHORT, Firebird::DecimalStatus, ErrorFunction); void CVT_move_common(const dsc*, dsc*, Firebird::DecimalStatus, Firebird::Callbacks*); void CVT_move(const dsc*, dsc*, Firebird::DecimalStatus, ErrorFunction); SSHORT CVT_decompose(const char*, USHORT, SSHORT*, ErrorFunction); SSHORT CVT_decompose(const char*, USHORT, SLONG*, ErrorFunction); SSHORT CVT_decompose(const char*, USHORT, SINT64*, ErrorFunction); SSHORT CVT_decompose(const char*, USHORT, Firebird::Int128*, ErrorFunction); -USHORT CVT_get_string_ptr(const dsc*, USHORT*, UCHAR**, vary*, USHORT, Firebird::DecimalStatus, ErrorFunction); -USHORT CVT_get_string_ptr_common(const dsc*, USHORT*, UCHAR**, vary*, USHORT, Firebird::DecimalStatus, Firebird::Callbacks*); +USHORT CVT_get_string_ptr(const dsc*, TTypeId*, UCHAR**, vary*, USHORT, Firebird::DecimalStatus, ErrorFunction); +USHORT CVT_get_string_ptr_common(const dsc*, TTypeId*, UCHAR**, vary*, USHORT, Firebird::DecimalStatus, Firebird::Callbacks*); SINT64 CVT_get_int64(const dsc*, SSHORT, Firebird::DecimalStatus, ErrorFunction); SQUAD CVT_get_quad(const dsc*, SSHORT, Firebird::DecimalStatus, ErrorFunction); void CVT_string_to_datetime(const dsc*, ISC_TIMESTAMP_TZ*, bool*, const Firebird::EXPECT_DATETIME, diff --git a/src/common/dsc.cpp b/src/common/dsc.cpp index fdfab54dce1..7b91f09af25 100644 --- a/src/common/dsc.cpp +++ b/src/common/dsc.cpp @@ -1376,8 +1376,8 @@ bool DSC_make_descriptor(DSC* desc, SSHORT scale, USHORT length, SSHORT sub_type, - SSHORT charset, - SSHORT collation) + CSetId charset, + CollId collation) { /************************************** * @@ -1412,13 +1412,13 @@ bool DSC_make_descriptor(DSC* desc, { case blr_text: desc->dsc_dtype = dtype_text; - desc->setTextType(INTL_CS_COLL_TO_TTYPE(charset, collation)); + desc->setTextType(TTypeId(charset, collation)); break; case blr_varying: desc->dsc_dtype = dtype_varying; desc->dsc_length += sizeof(USHORT); - desc->setTextType(INTL_CS_COLL_TO_TTYPE(charset, collation)); + desc->setTextType(TTypeId(charset, collation)); break; case blr_short: @@ -1507,15 +1507,15 @@ bool DSC_make_descriptor(DSC* desc, desc->dsc_dtype = dtype_blob; if (sub_type == isc_blob_text) { - fb_assert(charset <= MAX_SCHAR); - desc->dsc_scale = (SCHAR) charset; - desc->dsc_flags = collation << 8; // collation of blob + fb_assert(USHORT(charset) <= MAX_SCHAR); + desc->dsc_scale = (SCHAR) USHORT(charset); + desc->dsc_flags = USHORT(collation) << 8; // collation of blob } break; case blr_cstring: desc->dsc_dtype = dtype_cstring; - desc->setTextType(INTL_CS_COLL_TO_TTYPE(charset, collation)); + desc->setTextType(TTypeId(charset, collation)); break; case blr_bool: diff --git a/src/common/dsc.h b/src/common/dsc.h index e48e3d3a20e..62f303b58fc 100644 --- a/src/common/dsc.h +++ b/src/common/dsc.h @@ -30,6 +30,7 @@ #include "firebird/impl/dsc_pub.h" #include "firebird/impl/consts_pub.h" #include "../jrd/ods.h" +#include "../jrd/intl.h" #include "../intl/charsets.h" #include "../common/DecFloat.h" #include "../common/Int128.h" @@ -101,10 +102,6 @@ typedef struct dsc UCHAR* dsc_address; // Used either as offset in a message or as a pointer #ifdef __cplusplus - SSHORT dsc_blob_ttype() const { return dsc_scale | (dsc_flags & 0xFF00);} - SSHORT& dsc_ttype() { return dsc_sub_type;} - SSHORT dsc_ttype() const { return dsc_sub_type;} - bool isNullable() const { return dsc_flags & DSC_nullable; @@ -241,15 +238,15 @@ typedef struct dsc dsc_sub_type = subType; } - UCHAR getCharSet() const + CSetId getCharSet() const { if (isText()) - return dsc_sub_type & 0xFF; + return CSetId(dsc_sub_type); if (isBlob()) { if (dsc_sub_type == isc_blob_text) - return dsc_scale; + return CSetId(dsc_scale); return CS_BINARY; } @@ -260,39 +257,39 @@ typedef struct dsc return CS_NONE; } - USHORT getTextType() const + TTypeId getTextType() const { if (isText()) - return dsc_sub_type; + return TTypeId(dsc_sub_type); if (isBlob()) { if (dsc_sub_type == isc_blob_text) - return dsc_scale | (dsc_flags & 0xFF00); + return TTypeId(CSetId(dsc_scale), CollId(dsc_flags > 8)); - return CS_BINARY; + return TTypeId(CS_BINARY); } if (isDbKey()) - return CS_BINARY; + return TTypeId(CS_BINARY); - return CS_NONE; + return TTypeId(CS_NONE); } - void setTextType(USHORT ttype) + void setTextType(TTypeId ttype) { if (isText()) dsc_sub_type = ttype; else if (isBlob() && dsc_sub_type == isc_blob_text) { - dsc_scale = ttype & 0xFF; - dsc_flags = (dsc_flags & 0xFF) | (ttype & 0xFF00); + dsc_scale = CSetId(ttype); + dsc_flags = (dsc_flags & 0xFF) | (CollId(ttype) < 8); } } - USHORT getCollation() const + CollId getCollation() const { - return getTextType() >> 8; + return CollId(getTextType()); } void clear() @@ -308,7 +305,7 @@ typedef struct dsc dsc_flags = 0; } - void makeBlob(SSHORT subType, USHORT ttype, ISC_QUAD* address = NULL) + void makeBlob(SSHORT subType, TTypeId ttype, ISC_QUAD* address = NULL) { clear(); dsc_dtype = dtype_blob; @@ -413,7 +410,7 @@ typedef struct dsc dsc_address = (UCHAR*) address; } - void makeText(USHORT length, USHORT ttype, UCHAR* address = NULL) + void makeText(USHORT length, TTypeId ttype, UCHAR* address = NULL) { clear(); dsc_dtype = dtype_text; @@ -476,7 +473,7 @@ typedef struct dsc dsc_address = (UCHAR*) address; } - void makeVarying(USHORT length, USHORT ttype, UCHAR* address = NULL) + void makeVarying(USHORT length, TTypeId ttype, UCHAR* address = NULL) { clear(); dsc_dtype = dtype_varying; @@ -527,14 +524,14 @@ typedef struct dsc #endif // __cpluplus } DSC; -inline SSHORT DSC_GET_CHARSET(const dsc* desc) +inline CSetId DSC_GET_CHARSET(const dsc* desc) { - return (desc->dsc_sub_type & 0x00FF); + return desc->getCharSet(); } -inline SSHORT DSC_GET_COLLATE(const dsc* desc) +inline CollId DSC_GET_COLLATE(const dsc* desc) { - return (desc->dsc_sub_type >> 8); + return desc->getCollation(); } struct alt_dsc diff --git a/src/common/dsc_proto.h b/src/common/dsc_proto.h index 1664edabed2..c4724188441 100644 --- a/src/common/dsc_proto.h +++ b/src/common/dsc_proto.h @@ -25,12 +25,13 @@ #define JRD_DSC_PROTO_H #include "../common/dsc.h" +#include "../jrd/intl.h" int DSC_string_length(const struct dsc*); const TEXT* DSC_dtype_tostring(UCHAR); void DSC_get_dtype_name(const dsc*, TEXT*, USHORT); bool DSC_make_descriptor(dsc*, USHORT, SSHORT, - USHORT, SSHORT, SSHORT, SSHORT); + USHORT, SSHORT, CSetId, CollId); USHORT DSC_convert_to_text_length(USHORT dsc_type); extern const BYTE DSC_add_result[DTYPE_TYPE_MAX][DTYPE_TYPE_MAX]; diff --git a/src/common/sdl.cpp b/src/common/sdl.cpp index 0059a6bda39..29ef7e6b1af 100644 --- a/src/common/sdl.cpp +++ b/src/common/sdl.cpp @@ -780,7 +780,7 @@ static const UCHAR* sdl_desc(const UCHAR* ptr, DSC* desc) { case blr_text2: desc->dsc_dtype = dtype_text; - desc->setTextType(get_word(sdl)); + desc->setTextType(TTypeId(get_word(sdl))); break; case blr_text: @@ -791,7 +791,7 @@ static const UCHAR* sdl_desc(const UCHAR* ptr, DSC* desc) case blr_cstring2: desc->dsc_dtype = dtype_cstring; - desc->setTextType(get_word(sdl)); + desc->setTextType(TTypeId(get_word(sdl))); break; case blr_cstring: @@ -802,7 +802,7 @@ static const UCHAR* sdl_desc(const UCHAR* ptr, DSC* desc) case blr_varying2: desc->dsc_dtype = dtype_cstring; - desc->setTextType(get_word(sdl)); + desc->setTextType(TTypeId(get_word(sdl))); desc->dsc_length = sizeof(USHORT); break; diff --git a/src/dsql/AggNodes.cpp b/src/dsql/AggNodes.cpp index 0e9a9d3dd8c..282ef6db4f3 100644 --- a/src/dsql/AggNodes.cpp +++ b/src/dsql/AggNodes.cpp @@ -407,7 +407,7 @@ bool AggNode::aggPass(thread_db* tdbb, Request* request) const to.dsc_flags = 0; to.dsc_sub_type = 0; to.dsc_scale = 0; - to.dsc_ttype() = ttype_sort_key; + to.setTextType(ttype_sort_key); to.dsc_length = asb->keyItems[0].getSkdLength(); to.dsc_address = data; INTL_string_to_key(tdbb, INTL_TEXT_TO_INDEX(desc->getTextType()), diff --git a/src/dsql/BoolNodes.cpp b/src/dsql/BoolNodes.cpp index 56c28b7a1f5..8b959cf2ede 100644 --- a/src/dsql/BoolNodes.cpp +++ b/src/dsql/BoolNodes.cpp @@ -822,18 +822,11 @@ bool ComparativeBoolNode::stringBoolean(thread_db* tdbb, Request* request, dsc* { SET_TDBB(tdbb); - USHORT type1; + TTypeId type1 = desc1->getTextType(); - if (!desc1->isBlob()) - type1 = INTL_TEXT_TYPE(*desc1); - else - { - // No MATCHES support for blob - if (blrOp == blr_matching) - return false; - - type1 = desc1->dsc_sub_type == isc_blob_text ? desc1->dsc_blob_ttype() : ttype_none; - } + // No MATCHES support for blob + if (desc1->isBlob() && (blrOp == blr_matching)) + return false; Collation* obj = INTL_texttype_lookup(tdbb, type1); CharSet* charset = obj->getCharSet(); @@ -884,7 +877,7 @@ bool ComparativeBoolNode::stringBoolean(thread_db* tdbb, Request* request, dsc* } UCHAR* patternStr = nullptr; - SLONG patternLen = 0; + ULONG patternLen = 0; MoveBuffer patternBuffer; auto createMatcher = [&]() @@ -1030,17 +1023,7 @@ bool ComparativeBoolNode::sleuth(thread_db* tdbb, Request* request, const dsc* d // Choose interpretation for the operation - USHORT ttype; - if (desc1->isBlob()) - { - if (desc1->dsc_sub_type == isc_blob_text) - ttype = desc1->dsc_blob_ttype(); // Load blob character set and collation - else - ttype = INTL_TTYPE(desc2); - } - else - ttype = INTL_TTYPE(desc1); - + auto ttype = (desc1->isBlob() && (desc1->dsc_sub_type != isc_blob_text) ? desc2 : desc1)->getTextType(); Collation* obj = INTL_texttype_lookup(tdbb, ttype); // Get operator definition string (control string) diff --git a/src/dsql/DSqlDataTypeUtil.cpp b/src/dsql/DSqlDataTypeUtil.cpp index 53c3311216f..8d87a1dde5a 100644 --- a/src/dsql/DSqlDataTypeUtil.cpp +++ b/src/dsql/DSqlDataTypeUtil.cpp @@ -27,7 +27,7 @@ #include "../dsql/DsqlCompilerScratch.h" #include "../dsql/metd_proto.h" -UCHAR Jrd::DSqlDataTypeUtil::maxBytesPerChar(UCHAR charSet) +UCHAR Jrd::DSqlDataTypeUtil::maxBytesPerChar(CSetId charSet) { return METD_get_charset_bpc(dsqlScratch->getTransaction(), charSet); } diff --git a/src/dsql/DSqlDataTypeUtil.h b/src/dsql/DSqlDataTypeUtil.h index 7a11ea1aba5..bf5ef3093f2 100644 --- a/src/dsql/DSqlDataTypeUtil.h +++ b/src/dsql/DSqlDataTypeUtil.h @@ -40,7 +40,7 @@ namespace Jrd { } public: - virtual UCHAR maxBytesPerChar(UCHAR charSet); + virtual UCHAR maxBytesPerChar(CSetId charSet); virtual USHORT getDialect() const; private: diff --git a/src/dsql/DdlNodes.epp b/src/dsql/DdlNodes.epp index 013582276e0..90bcad2db25 100644 --- a/src/dsql/DdlNodes.epp +++ b/src/dsql/DdlNodes.epp @@ -4004,7 +4004,7 @@ void CreateCollationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScra if (fromName.hasData()) { if (MET_get_char_coll_subtype_info(tdbb, - INTL_CS_COLL_TO_TTYPE(forCharSetId, fromCollationId), &info) && + TTypeId(forCharSetId, fromCollationId), &info) && forCharSetId != CS_METADATA && info.specificAttributes.hasData()) { @@ -4927,8 +4927,8 @@ void AlterDomainNode::getDomainType(thread_db* tdbb, jrd_tra* transaction, dyn_f WITH FLD.RDB$FIELD_NAME EQ dynFld.dyn_fld_source.c_str(); { DSC_make_descriptor(&dynFld.dyn_dsc, FLD.RDB$FIELD_TYPE, FLD.RDB$FIELD_SCALE, - FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, FLD.RDB$CHARACTER_SET_ID, - FLD.RDB$COLLATION_ID); + FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, CSetId(FLD.RDB$CHARACTER_SET_ID), + CollId(FLD.RDB$COLLATION_ID)); dynFld.dyn_charbytelen = FLD.RDB$FIELD_LENGTH; dynFld.dyn_dtype = FLD.RDB$FIELD_TYPE; @@ -5145,8 +5145,8 @@ void AlterDomainNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, dyn_fld origDom, newDom; DSC_make_descriptor(&origDom.dyn_dsc, FLD.RDB$FIELD_TYPE, FLD.RDB$FIELD_SCALE, - FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, FLD.RDB$CHARACTER_SET_ID, - FLD.RDB$COLLATION_ID); + FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, CSetId(FLD.RDB$CHARACTER_SET_ID), + CollId(FLD.RDB$COLLATION_ID)); origDom.dyn_fld_name = name; origDom.dyn_charbytelen = FLD.RDB$FIELD_LENGTH; @@ -8018,8 +8018,8 @@ void AlterRelationNode::modifyField(thread_db* tdbb, DsqlCompilerScratch* dsqlSc dyn_fld origDom; DSC_make_descriptor(&origDom.dyn_dsc, FLD.RDB$FIELD_TYPE, FLD.RDB$FIELD_SCALE, - FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, FLD.RDB$CHARACTER_SET_ID, - FLD.RDB$COLLATION_ID); + FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, CSetId(FLD.RDB$CHARACTER_SET_ID), + CollId(FLD.RDB$COLLATION_ID)); origDom.dyn_fld_name = field->fld_name; origDom.dyn_charbytelen = FLD.RDB$FIELD_LENGTH; @@ -9595,15 +9595,15 @@ void CreateIndexNode::store(thread_db* tdbb, jrd_tra* transaction, MetaName& nam if (!F.RDB$COLLATION_ID.NULL) { length = INTL_key_length(tdbb, - INTL_TEXT_TO_INDEX(INTL_CS_COLL_TO_TTYPE( - GF.RDB$CHARACTER_SET_ID, F.RDB$COLLATION_ID)), + INTL_TEXT_TO_INDEX(TTypeId(CSetId(GF.RDB$CHARACTER_SET_ID), + CollId(F.RDB$COLLATION_ID))), GF.RDB$FIELD_LENGTH); } else if (!GF.RDB$COLLATION_ID.NULL) { length = INTL_key_length(tdbb, - INTL_TEXT_TO_INDEX(INTL_CS_COLL_TO_TTYPE( - GF.RDB$CHARACTER_SET_ID, GF.RDB$COLLATION_ID)), + INTL_TEXT_TO_INDEX(TTypeId(CSetId(GF.RDB$CHARACTER_SET_ID), + CollId(GF.RDB$COLLATION_ID))), GF.RDB$FIELD_LENGTH); } else diff --git a/src/dsql/DdlNodes.h b/src/dsql/DdlNodes.h index cfb9dffce61..b10dfcfe6d4 100644 --- a/src/dsql/DdlNodes.h +++ b/src/dsql/DdlNodes.h @@ -885,8 +885,8 @@ class CreateCollationNode : public DdlNode private: USHORT attributesOn; USHORT attributesOff; - USHORT forCharSetId; - USHORT fromCollationId; + CSetId forCharSetId; + CollId fromCollationId; }; @@ -1211,7 +1211,7 @@ class RelationNode : public DdlNode MetaName fieldSource; MetaName identitySequence; Nullable identityType; - Nullable collationId; + Nullable collationId; Nullable notNullFlag; // true = NOT NULL / false = NULL Nullable position; Firebird::string defaultSource; diff --git a/src/dsql/DsqlRequests.cpp b/src/dsql/DsqlRequests.cpp index eb2934cfe25..e5fc3535282 100644 --- a/src/dsql/DsqlRequests.cpp +++ b/src/dsql/DsqlRequests.cpp @@ -281,7 +281,7 @@ USHORT DsqlRequest::parseMetadata(IMessageMetadata* meta, const Array checkD(&st); desc.dsc_sub_type = meta->getSubType(&st, index); checkD(&st); - unsigned textType = meta->getCharSet(&st, index); + auto textType = CSetId(meta->getCharSet(&st, index)); checkD(&st); desc.setTextType(textType); desc.dsc_address = (UCHAR*)(IPTR) dataOffset; diff --git a/src/dsql/ExprNodes.cpp b/src/dsql/ExprNodes.cpp index 87eaac6ec1c..eb349be92da 100644 --- a/src/dsql/ExprNodes.cpp +++ b/src/dsql/ExprNodes.cpp @@ -3396,7 +3396,7 @@ DmlNode* CastNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb if (csb->collectingDependencies() && itemInfo.explicitCollation) { Dependency dependency(obj_collation); - dependency.number = INTL_TEXT_TYPE(node->castDesc); + dependency.number = node->castDesc.getTextType(); csb->addDependency(dependency); } @@ -3543,10 +3543,10 @@ ValueExprNode* CastNode::pass1(thread_db* tdbb, CompilerScratch* csb) { ValueExprNode::pass1(tdbb, csb); - const USHORT ttype = INTL_TEXT_TYPE(castDesc); + const auto ttype = castDesc.getTextType(); // Are we using a collation? - if (TTYPE_TO_COLLATION(ttype) != 0) + if (CollId(ttype) != CollId(0)) INTL_texttype_lookup(tdbb, ttype); return this; @@ -3827,15 +3827,10 @@ void CollateNode::assignFieldDtypeFromDsc(dsql_fld* field, const dsc* desc) field->subType = desc->dsc_sub_type; field->length = desc->dsc_length; - if (desc->dsc_dtype <= dtype_any_text) - { - field->collationId = DSC_GET_COLLATE(desc); - field->charSetId = DSC_GET_CHARSET(desc); - } - else if (desc->dsc_dtype == dtype_blob) + if (desc->dsc_dtype <= dtype_any_text || desc->dsc_dtype == dtype_blob) { - field->charSetId = desc->dsc_scale; - field->collationId = desc->dsc_flags >> 8; + field->collationId = desc->getCollation(); + field->charSetId = desc->getCharSet(); } if (desc->dsc_flags & DSC_nullable) @@ -4432,14 +4427,14 @@ void CurrentRoleNode::make(DsqlCompilerScratch* dsqlScratch, dsc* desc) desc->dsc_dtype = dtype_varying; desc->dsc_scale = 0; desc->dsc_flags = 0; - desc->dsc_ttype() = ttype_metadata; + desc->setTextType(ttype_metadata); desc->dsc_length = USERNAME_LENGTH + sizeof(USHORT); } void CurrentRoleNode::getDesc(thread_db* /*tdbb*/, CompilerScratch* /*csb*/, dsc* desc) { desc->dsc_dtype = dtype_text; - desc->dsc_ttype() = ttype_metadata; + desc->setTextType(ttype_metadata); desc->dsc_length = USERNAME_LENGTH; desc->dsc_scale = 0; desc->dsc_flags = 0; @@ -4519,14 +4514,14 @@ void CurrentUserNode::make(DsqlCompilerScratch* dsqlScratch, dsc* desc) desc->dsc_dtype = dtype_varying; desc->dsc_scale = 0; desc->dsc_flags = 0; - desc->dsc_ttype() = ttype_metadata; + desc->setTextType(ttype_metadata); desc->dsc_length = USERNAME_LENGTH + sizeof(USHORT); } void CurrentUserNode::getDesc(thread_db* /*tdbb*/, CompilerScratch* /*csb*/, dsc* desc) { desc->dsc_dtype = dtype_text; - desc->dsc_ttype() = ttype_metadata; + desc->setTextType(ttype_metadata); desc->dsc_length = USERNAME_LENGTH; desc->dsc_scale = 0; desc->dsc_flags = 0; @@ -6561,13 +6556,11 @@ ValueExprNode* FieldNode::pass1(thread_db* tdbb, CompilerScratch* csb) dsc desc; getDesc(tdbb, csb, &desc); - const USHORT ttype = INTL_TEXT_TYPE(desc); + const auto ttype = desc.getTextType(); // Are we using a collation? - if (TTYPE_TO_COLLATION(ttype) != 0) + if (CollId(ttype) != CollId(0)) { - Collation* collation = NULL; - try { ThreadStatusGuard local_status(tdbb); @@ -9476,8 +9469,8 @@ bool ParameterNode::setParameterType(DsqlCompilerScratch* dsqlScratch, if (tdbb->getCharSet() != CS_NONE && tdbb->getCharSet() != CS_BINARY) { - const USHORT fromCharSet = dsqlParameter->par_desc.getCharSet(); - const USHORT toCharSet = (fromCharSet == CS_NONE || fromCharSet == CS_BINARY) ? + const auto fromCharSet = dsqlParameter->par_desc.getCharSet(); + const auto toCharSet = (fromCharSet == CS_NONE || fromCharSet == CS_BINARY) ? fromCharSet : tdbb->getCharSet(); if (dsqlParameter->par_desc.dsc_dtype <= dtype_any_text) @@ -9503,8 +9496,8 @@ bool ParameterNode::setParameterType(DsqlCompilerScratch* dsqlScratch, const USHORT toCharSetBPC = METD_get_charset_bpc( dsqlScratch->getTransaction(), toCharSet); - dsqlParameter->par_desc.setTextType(INTL_CS_COLL_TO_TTYPE(toCharSet, - (fromCharSet == toCharSet ? INTL_GET_COLLATE(&dsqlParameter->par_desc) : 0))); + dsqlParameter->par_desc.setTextType(TTypeId(toCharSet, + (fromCharSet == toCharSet ? INTL_GET_COLLATE(&dsqlParameter->par_desc) : CollId(0)))); dsqlParameter->par_desc.dsc_length = UTLD_char_length_to_byte_length( dsqlParameter->par_desc.dsc_length / fromCharSetBPC, toCharSetBPC, diff); @@ -10038,7 +10031,7 @@ void RecordKeyNode::make(DsqlCompilerScratch* /*dsqlScratch*/, dsc* desc) desc->dsc_dtype = dtype_text; desc->dsc_length = dbKeyLength; desc->dsc_flags = DSC_nullable; - desc->dsc_ttype() = ttype_binary; + desc->setTextType(ttype_binary); } else // blr_record_version2 { @@ -10095,7 +10088,7 @@ void RecordKeyNode::getDesc(thread_db* /*tdbb*/, CompilerScratch* /*csb*/, dsc* case blr_record_version: desc->dsc_dtype = dtype_text; - desc->dsc_ttype() = ttype_binary; + desc->setTextType(ttype_binary); desc->dsc_length = sizeof(SINT64); desc->dsc_scale = 0; desc->dsc_flags = 0; @@ -10195,7 +10188,7 @@ ValueExprNode* RecordKeyNode::pass1(thread_db* tdbb, CompilerScratch* csb) LiteralNode* literal = FB_NEW_POOL(csb->csb_pool) LiteralNode(csb->csb_pool); literal->litDesc.dsc_dtype = dtype_text; - literal->litDesc.dsc_ttype() = CS_BINARY; + literal->litDesc.setTextType(CS_BINARY); literal->litDesc.dsc_scale = 0; literal->litDesc.dsc_length = 8; literal->litDesc.dsc_address = reinterpret_cast( @@ -10233,7 +10226,7 @@ ValueExprNode* RecordKeyNode::pass1(thread_db* tdbb, CompilerScratch* csb) LiteralNode* literal = FB_NEW_POOL(csb->csb_pool) LiteralNode(csb->csb_pool); literal->litDesc.dsc_dtype = dtype_text; - literal->litDesc.dsc_ttype() = CS_BINARY; + literal->litDesc.setTextType(CS_BINARY); literal->litDesc.dsc_scale = 0; literal->litDesc.dsc_length = 0; literal->litDesc.dsc_address = reinterpret_cast( @@ -10319,7 +10312,7 @@ dsc* RecordKeyNode::execute(thread_db* /*tdbb*/, Request* request) const impure->vlu_desc.dsc_address = (UCHAR*) impure->vlu_misc.vlu_dbkey; impure->vlu_desc.dsc_dtype = dtype_dbkey; impure->vlu_desc.dsc_length = type_lengths[dtype_dbkey]; - impure->vlu_desc.dsc_ttype() = ttype_binary; + impure->vlu_desc.setTextType(ttype_binary); } else if (blrOp == blr_record_version) { @@ -10352,7 +10345,7 @@ dsc* RecordKeyNode::execute(thread_db* /*tdbb*/, Request* request) const impure->vlu_desc.dsc_address = (UCHAR*) &impure->vlu_misc.vlu_int64; impure->vlu_desc.dsc_dtype = dtype_text; impure->vlu_desc.dsc_length = sizeof(SINT64); - impure->vlu_desc.dsc_ttype() = ttype_binary; + impure->vlu_desc.setTextType(ttype_binary); } else if (blrOp == blr_record_version2) { @@ -10624,7 +10617,7 @@ void StrCaseNode::make(DsqlCompilerScratch* dsqlScratch, dsc* desc) desc->dsc_length = static_cast(sizeof(USHORT)) + DSC_string_length(desc); desc->dsc_dtype = dtype_varying; desc->dsc_scale = 0; - desc->dsc_ttype() = ttype_ascii; + desc->setTextType(ttype_ascii); desc->dsc_flags = desc->dsc_flags & DSC_nullable; } } @@ -10637,7 +10630,7 @@ void StrCaseNode::getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc) { desc->dsc_length = DSC_convert_to_text_length(desc->dsc_dtype); desc->dsc_dtype = dtype_text; - desc->dsc_ttype() = ttype_ascii; + desc->setTextType(ttype_ascii); desc->dsc_scale = 0; desc->dsc_flags = 0; } @@ -10739,7 +10732,7 @@ dsc* StrCaseNode::execute(thread_db* tdbb, Request* request) const { UCHAR* ptr; VaryStr temp; - USHORT ttype; + TTypeId ttype; ULONG len = MOV_get_string_ptr(tdbb, value, &ttype, &ptr, &temp, sizeof(temp)); dsc desc; @@ -10934,7 +10927,7 @@ dsc* StrLenNode::execute(thread_db* tdbb, Request* request) const case blr_strlen_char: { - CharSet* charSet = INTL_charset_lookup(tdbb, value->dsc_blob_ttype()); + CharSet* charSet = INTL_charset_lookup(tdbb, value->getTextType()); if (charSet->isMultiByte()) { @@ -10969,7 +10962,7 @@ dsc* StrLenNode::execute(thread_db* tdbb, Request* request) const } VaryStr temp; - USHORT ttype; + TTypeId ttype; UCHAR* p; length = MOV_get_string_ptr(tdbb, value, &ttype, &p, &temp, sizeof(temp)); @@ -11800,7 +11793,7 @@ dsc* SubstringNode::perform(thread_db* tdbb, impure_value* impure, const dsc* va // routines because the "temp" is not enough are blob and array but at this time // they aren't accepted, so they will cause error() to be called anyway. VaryStr temp; - USHORT ttype; + TTypeId ttype; desc.dsc_length = MOV_get_string_ptr(tdbb, valueDsc, &ttype, &desc.dsc_address, &temp, sizeof(temp)); desc.setTextType(ttype); @@ -12003,7 +11996,7 @@ dsc* SubstringSimilarNode::execute(thread_db* tdbb, Request* request) const if (!exprDesc || !patternDesc || !escapeDesc) return NULL; - USHORT textType = exprDesc->getTextType(); + auto textType = exprDesc->getTextType(); Collation* collation = INTL_texttype_lookup(tdbb, textType); CharSet* charSet = collation->getCharSet(); @@ -12477,7 +12470,7 @@ void TrimNode::make(DsqlCompilerScratch* dsqlScratch, dsc* desc) { desc->dsc_dtype = dtype_varying; desc->dsc_scale = 0; - desc->dsc_ttype() = ttype_ascii; + desc->setTextType(ttype_ascii); desc->dsc_length = static_cast(sizeof(USHORT)) + DSC_string_length(&desc1); desc->dsc_flags = (desc1.dsc_flags | desc2.dsc_flags) & DSC_nullable; } @@ -12500,7 +12493,7 @@ void TrimNode::getDesc(thread_db* tdbb, CompilerScratch* csb, dsc* desc) if (!DTYPE_IS_TEXT(desc->dsc_dtype)) { - desc->dsc_ttype() = ttype_ascii; + desc->setTextType(ttype_ascii); desc->dsc_scale = 0; } @@ -12565,7 +12558,7 @@ dsc* TrimNode::execute(thread_db* tdbb, Request* request) const if (request->req_flags & req_null) return NULL; - USHORT ttype = INTL_TEXT_TYPE(*valueDesc); + auto ttype = INTL_GET_TTYPE(valueDesc); Collation* tt = INTL_texttype_lookup(tdbb, ttype); CharSet* cs = tt->getCharSet(); @@ -12860,9 +12853,9 @@ void UdfCallNode::make(DsqlCompilerScratch* /*dsqlScratch*/, dsc* desc) desc->setNullable(true); if (desc->dsc_dtype <= dtype_any_text) - desc->dsc_ttype() = dsqlFunction->udf_character_set_id; + desc->setTextType(dsqlFunction->udf_character_set_id); else - desc->dsc_ttype() = dsqlFunction->udf_sub_type; + desc->dsc_sub_type = dsqlFunction->udf_sub_type; } void UdfCallNode::getDesc(thread_db* tdbb, CompilerScratch* /*csb*/, dsc* desc) diff --git a/src/dsql/PackageNodes.epp b/src/dsql/PackageNodes.epp index e58fa27d20d..a26fdd0ef0d 100644 --- a/src/dsql/PackageNodes.epp +++ b/src/dsql/PackageNodes.epp @@ -91,7 +91,7 @@ namespace if (!ARG.RDB$RELATION_NAME.NULL) parameter.relationName = ARG.RDB$RELATION_NAME; if (!ARG.RDB$COLLATION_ID.NULL) - parameter.collationId = ARG.RDB$COLLATION_ID; + parameter.collationId = CollId(ARG.RDB$COLLATION_ID); if (!ARG.RDB$NULL_FLAG.NULL) parameter.nullFlag = ARG.RDB$NULL_FLAG; @@ -110,9 +110,9 @@ namespace if (!FLD.RDB$CHARACTER_LENGTH.NULL) parameter.fieldCharLength = FLD.RDB$CHARACTER_LENGTH; if (!FLD.RDB$COLLATION_ID.NULL) - parameter.fieldCollationId = FLD.RDB$COLLATION_ID; + parameter.fieldCollationId = CollId(FLD.RDB$COLLATION_ID); if (!FLD.RDB$CHARACTER_SET_ID.NULL) - parameter.fieldCharSetId = FLD.RDB$CHARACTER_SET_ID; + parameter.fieldCharSetId = CSetId(FLD.RDB$CHARACTER_SET_ID); if (!FLD.RDB$FIELD_PRECISION.NULL) parameter.fieldPrecision = FLD.RDB$FIELD_PRECISION; @@ -156,7 +156,7 @@ namespace if (!PRM.RDB$RELATION_NAME.NULL) parameter.relationName = PRM.RDB$RELATION_NAME; if (!PRM.RDB$COLLATION_ID.NULL) - parameter.collationId = PRM.RDB$COLLATION_ID; + parameter.collationId = CollId(PRM.RDB$COLLATION_ID); if (!PRM.RDB$NULL_FLAG.NULL) parameter.nullFlag = PRM.RDB$NULL_FLAG; @@ -175,9 +175,9 @@ namespace if (!FLD.RDB$CHARACTER_LENGTH.NULL) parameter.fieldCharLength = FLD.RDB$CHARACTER_LENGTH; if (!FLD.RDB$COLLATION_ID.NULL) - parameter.fieldCollationId = FLD.RDB$COLLATION_ID; + parameter.fieldCollationId = CollId(FLD.RDB$COLLATION_ID); if (!FLD.RDB$CHARACTER_SET_ID.NULL) - parameter.fieldCharSetId = FLD.RDB$CHARACTER_SET_ID; + parameter.fieldCharSetId = CSetId(FLD.RDB$CHARACTER_SET_ID); if (!FLD.RDB$FIELD_PRECISION.NULL) parameter.fieldPrecision = FLD.RDB$FIELD_PRECISION; diff --git a/src/dsql/Parser.cpp b/src/dsql/Parser.cpp index af0f9ab9f45..c46b70dbf6d 100644 --- a/src/dsql/Parser.cpp +++ b/src/dsql/Parser.cpp @@ -99,7 +99,7 @@ namespace Parser::Parser(thread_db* tdbb, MemoryPool& pool, MemoryPool* aStatementPool, DsqlCompilerScratch* aScratch, - USHORT aClientDialect, USHORT aDbDialect, const TEXT* string, size_t length, SSHORT characterSet) + USHORT aClientDialect, USHORT aDbDialect, const TEXT* string, size_t length, CSetId characterSet) : PermanentStorage(pool), statementPool(aStatementPool), scratch(aScratch), diff --git a/src/dsql/Parser.h b/src/dsql/Parser.h index 28e22323f5c..15dba19bf17 100644 --- a/src/dsql/Parser.h +++ b/src/dsql/Parser.h @@ -34,6 +34,7 @@ #include "../jrd/RecordSourceNodes.h" #include "../common/classes/Nullable.h" #include "../common/classes/stack.h" +#include "../jrd/intl.h" #include "gen/parse.h" @@ -99,7 +100,7 @@ class Parser : public Firebird::PermanentStorage const TEXT* line_start; const TEXT* last_token_bk; const TEXT* line_start_bk; - SSHORT att_charset; + CSetId att_charset; SLONG lines, lines_bk; int prev_keyword; USHORT param_number; @@ -131,7 +132,7 @@ class Parser : public Firebird::PermanentStorage public: Parser(thread_db* tdbb, MemoryPool& pool, MemoryPool* aStatementPool, DsqlCompilerScratch* aScratch, - USHORT aClientDialect, USHORT aDbDialect, const TEXT* string, size_t length, SSHORT characterSet); + USHORT aClientDialect, USHORT aDbDialect, const TEXT* string, size_t length, CSetId characterSet); ~Parser(); public: diff --git a/src/dsql/StmtNodes.cpp b/src/dsql/StmtNodes.cpp index 8252b94417a..65ca82d04d9 100644 --- a/src/dsql/StmtNodes.cpp +++ b/src/dsql/StmtNodes.cpp @@ -2142,7 +2142,7 @@ DmlNode* DeclareVariableNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerS if (csb->collectingDependencies() && itemInfo.explicitCollation) { Dependency dependency(obj_collation); - dependency.number = INTL_TEXT_TYPE(node->varDesc); + dependency.number = node->varDesc.getTextType(); csb->addDependency(dependency); } @@ -3864,7 +3864,7 @@ void ExecStatementNode::getString(thread_db* tdbb, Request* request, const Value if (dsc && !(request->req_flags & req_null)) { const Jrd::Attachment* att = tdbb->getAttachment(); - len = MOV_make_string2(tdbb, dsc, (useAttCS ? att->att_charset : dsc->getTextType()), + len = MOV_make_string2(tdbb, dsc, (useAttCS ? TTypeId(att->att_charset) : dsc->getTextType()), &p, buffer, false); } @@ -8297,7 +8297,7 @@ void SelectNode::genBlr(DsqlCompilerScratch* dsqlScratch) paramContexts.put(parameter, context); parameter->par_desc.dsc_dtype = dtype_text; - parameter->par_desc.dsc_ttype() = ttype_binary; + parameter->par_desc.setTextType(ttype_binary); parameter->par_desc.dsc_length = relation->rel_dbkey_length; // Set up record version. @@ -8306,7 +8306,7 @@ void SelectNode::genBlr(DsqlCompilerScratch* dsqlScratch) paramContexts.put(parameter, context); parameter->par_desc.dsc_dtype = dtype_text; - parameter->par_desc.dsc_ttype() = ttype_binary; + parameter->par_desc.setTextType(ttype_binary); parameter->par_desc.dsc_length = sizeof(SINT64); } } diff --git a/src/dsql/ddl.cpp b/src/dsql/ddl.cpp index ce05c19496d..276c9cb3e4e 100644 --- a/src/dsql/ddl.cpp +++ b/src/dsql/ddl.cpp @@ -321,7 +321,7 @@ void DDL_resolve_intl_type(DsqlCompilerScratch* dsqlScratch, dsql_fld* field, defaultCharSet = METD_get_default_charset(dsqlScratch->getTransaction()); else { - USHORT charSet = dsqlScratch->getAttachment()->dbb_attachment->att_charset; + auto charSet = dsqlScratch->getAttachment()->dbb_attachment->att_charset; if (charSet != CS_NONE) defaultCharSet = METD_get_charset_name(dsqlScratch->getTransaction(), charSet); } diff --git a/src/dsql/dsql.cpp b/src/dsql/dsql.cpp index 66e2d784edd..b36a228923a 100644 --- a/src/dsql/dsql.cpp +++ b/src/dsql/dsql.cpp @@ -695,7 +695,7 @@ static UCHAR* put_item( UCHAR item, // Return as UTF8 string IntlString::toUtf8(jrd_tra* transaction) const { - CHARSET_ID id = CS_dynamic; + CSetId id = CS_dynamic; if (charset.hasData()) { diff --git a/src/dsql/dsql.h b/src/dsql/dsql.h index 7fe355e82f4..0393798f114 100644 --- a/src/dsql/dsql.h +++ b/src/dsql/dsql.h @@ -238,8 +238,8 @@ class TypeClause USHORT segLength; // Segment length for blobs USHORT precision; // Precision for exact numeric types USHORT charLength; // Length of field in characters - Nullable charSetId; - SSHORT collationId; + Nullable charSetId; + CollId collationId; SSHORT textType; bool fullDomain; // Domain name without TYPE OF prefix bool notNull; // NOT NULL was explicit specified @@ -344,7 +344,7 @@ class dsql_udf : public pool_alloc SSHORT udf_scale; SSHORT udf_sub_type; USHORT udf_length; - SSHORT udf_character_set_id; + CSetId udf_character_set_id; //USHORT udf_character_length; USHORT udf_flags; QualifiedName udf_name; @@ -412,9 +412,9 @@ class dsql_intlsym : public pool_alloc MetaName intlsym_name; USHORT intlsym_type; // what type of name USHORT intlsym_flags; - SSHORT intlsym_ttype; // id of implementation - SSHORT intlsym_charset_id; - SSHORT intlsym_collate_id; + TTypeId intlsym_ttype; // id of implementation + CSetId intlsym_charset_id; + CollId intlsym_collate_id; USHORT intlsym_bytes_per_char; }; @@ -763,7 +763,7 @@ struct SignatureParameter MetaName charSetName; MetaName collationName; MetaName subTypeName; - Nullable collationId; + Nullable collationId; Nullable nullFlag; SSHORT mechanism; Nullable fieldLength; @@ -773,8 +773,8 @@ struct SignatureParameter Nullable fieldSegmentLength; Nullable fieldNullFlag; Nullable fieldCharLength; - Nullable fieldCollationId; - Nullable fieldCharSetId; + Nullable fieldCollationId; + Nullable fieldCharSetId; Nullable fieldPrecision; bool operator >(const SignatureParameter& o) const @@ -805,7 +805,7 @@ struct SignatureParameter charSetName == o.charSetName && collationName == o.collationName && subTypeName == o.subTypeName && - fieldCollationId.orElse(0) == o.fieldCollationId.orElse(0) && + fieldCollationId.orElse(CollId()) == o.fieldCollationId.orElse(CollId()) && fieldCharSetId == o.fieldCharSetId && fieldPrecision == o.fieldPrecision; } diff --git a/src/dsql/gen.cpp b/src/dsql/gen.cpp index 0caef73dbf2..9da5f9c403f 100644 --- a/src/dsql/gen.cpp +++ b/src/dsql/gen.cpp @@ -165,8 +165,8 @@ void GEN_port(DsqlCompilerScratch* dsqlScratch, dsql_msg* message) parameter->par_parameter = (USHORT) i; - const USHORT fromCharSet = parameter->par_desc.getCharSet(); - const USHORT toCharSet = (fromCharSet == CS_NONE || fromCharSet == CS_BINARY) ? + const auto fromCharSet = parameter->par_desc.getCharSet(); + const auto toCharSet = (fromCharSet == CS_NONE || fromCharSet == CS_BINARY) ? fromCharSet : tdbb->getCharSet(); if (parameter->par_desc.dsc_dtype <= dtype_any_text && @@ -183,8 +183,8 @@ void GEN_port(DsqlCompilerScratch* dsqlScratch, dsql_msg* message) const USHORT fromCharSetBPC = METD_get_charset_bpc(dsqlScratch->getTransaction(), fromCharSet); const USHORT toCharSetBPC = METD_get_charset_bpc(dsqlScratch->getTransaction(), toCharSet); - parameter->par_desc.setTextType(INTL_CS_COLL_TO_TTYPE(toCharSet, - (fromCharSet == toCharSet ? INTL_GET_COLLATE(¶meter->par_desc) : 0))); + parameter->par_desc.setTextType(TTypeId(toCharSet, + (fromCharSet == toCharSet ? INTL_GET_COLLATE(¶meter->par_desc) : CollId(0)))); parameter->par_desc.dsc_length = UTLD_char_length_to_byte_length( parameter->par_desc.dsc_length / fromCharSetBPC, toCharSetBPC, adjust); @@ -299,10 +299,10 @@ void GEN_descriptor( DsqlCompilerScratch* dsqlScratch, const dsc* desc, bool tex switch (desc->dsc_dtype) { case dtype_text: - if (texttype || desc->dsc_ttype() == ttype_binary || desc->dsc_ttype() == ttype_none) + if (texttype || desc->getTextType() == ttype_binary || desc->getTextType() == ttype_none) { dsqlScratch->appendUChar(blr_text2); - dsqlScratch->appendUShort(desc->dsc_ttype()); + dsqlScratch->appendUShort(desc->getTextType()); } else { @@ -314,10 +314,10 @@ void GEN_descriptor( DsqlCompilerScratch* dsqlScratch, const dsc* desc, bool tex break; case dtype_varying: - if (texttype || desc->dsc_ttype() == ttype_binary || desc->dsc_ttype() == ttype_none) + if (texttype || desc->getTextType() == ttype_binary || desc->getTextType() == ttype_none) { dsqlScratch->appendUChar(blr_varying2); - dsqlScratch->appendUShort(desc->dsc_ttype()); + dsqlScratch->appendUShort(desc->getTextType()); } else { diff --git a/src/dsql/make.cpp b/src/dsql/make.cpp index dc1d7a6b9ef..404bbfa3eaf 100644 --- a/src/dsql/make.cpp +++ b/src/dsql/make.cpp @@ -128,8 +128,8 @@ void DsqlDescMaker::composeDesc(dsc* desc, SSHORT scale, SSHORT subType, FLD_LENGTH length, - SSHORT charsetId, - SSHORT collationId, + CSetId charsetId, + CollId collationId, bool nullable) { desc->clear(); @@ -139,8 +139,7 @@ void DsqlDescMaker::composeDesc(dsc* desc, desc->dsc_length = length; desc->dsc_flags = nullable ? DSC_nullable : 0; - if (desc->isText() || desc->isBlob()) - desc->setTextType(INTL_CS_COLL_TO_TTYPE(charsetId, collationId)); + desc->setTextType(TTypeId(charsetId, collationId)); } @@ -256,7 +255,7 @@ ValueExprNode* MAKE_constant(const char* str, dsql_constant_type numeric_flag, S tmp.dsc_dtype = dtype_text; tmp.dsc_scale = 0; tmp.dsc_flags = 0; - tmp.dsc_ttype() = ttype_ascii; + tmp.setTextType(ttype_ascii); tmp.dsc_length = static_cast(strlen(str)); tmp.dsc_address = (UCHAR*) str; @@ -342,7 +341,7 @@ ValueExprNode* MAKE_constant(const char* str, dsql_constant_type numeric_flag, S @param character_set **/ -LiteralNode* MAKE_str_constant(const IntlString* constant, SSHORT character_set) +LiteralNode* MAKE_str_constant(const IntlString* constant, CSetId character_set) { thread_db* tdbb = JRD_get_thread_data(); @@ -354,7 +353,7 @@ LiteralNode* MAKE_str_constant(const IntlString* constant, SSHORT character_set) literal->litDesc.dsc_scale = 0; literal->litDesc.dsc_length = static_cast(str.length()); literal->litDesc.dsc_address = (UCHAR*) str.c_str(); - literal->litDesc.dsc_ttype() = character_set; + literal->litDesc.setTextType(character_set); literal->dsqlStr = constant; diff --git a/src/dsql/make_proto.h b/src/dsql/make_proto.h index d68df999fb4..5f10c266198 100644 --- a/src/dsql/make_proto.h +++ b/src/dsql/make_proto.h @@ -27,6 +27,7 @@ #define DSQL_MAKE_PROTO_H #include "../dsql/sym.h" +#include "../jrd/intl.h" namespace Jrd { class dsql_ctx; @@ -72,8 +73,8 @@ namespace Jrd { SSHORT scale, SSHORT subType, FLD_LENGTH length, - const SSHORT charsetId, - SSHORT collationId, + const CSetId charsetId, + CollId collationId, bool nullable); }; } @@ -82,7 +83,7 @@ namespace Jrd { Jrd::LiteralNode* MAKE_const_slong(SLONG); Jrd::LiteralNode* MAKE_const_sint64(SINT64 value, SCHAR scale); Jrd::ValueExprNode* MAKE_constant(const char*, Jrd::dsql_constant_type, SSHORT = 0); -Jrd::LiteralNode* MAKE_str_constant(const Jrd::IntlString*, SSHORT); +Jrd::LiteralNode* MAKE_str_constant(const Jrd::IntlString*, CSetId); Jrd::FieldNode* MAKE_field(Jrd::dsql_ctx*, Jrd::dsql_fld*, Jrd::ValueListNode*); Jrd::FieldNode* MAKE_field_name(const char*); Jrd::dsql_par* MAKE_parameter(Jrd::dsql_msg*, bool, bool, USHORT, const Jrd::ValueExprNode*); diff --git a/src/dsql/metd.epp b/src/dsql/metd.epp index 2c57210b1fd..2454119a83e 100644 --- a/src/dsql/metd.epp +++ b/src/dsql/metd.epp @@ -272,7 +272,7 @@ void METD_drop_relation(jrd_tra* transaction, const MetaName& name) } -dsql_intlsym* METD_get_collation(jrd_tra* transaction, const MetaName& name, USHORT charset_id) +dsql_intlsym* METD_get_collation(jrd_tra* transaction, const MetaName& name, CSetId charset_id) { /************************************** * @@ -313,15 +313,15 @@ dsql_intlsym* METD_get_collation(jrd_tra* transaction, const MetaName& name, USH X IN RDB$COLLATIONS CROSS Y IN RDB$CHARACTER_SETS OVER RDB$CHARACTER_SET_ID WITH X.RDB$COLLATION_NAME EQ name.c_str() AND - X.RDB$CHARACTER_SET_ID EQ charset_id; + X.RDB$CHARACTER_SET_ID EQ charset_id { symbol = FB_NEW_POOL(dbb->dbb_pool) dsql_intlsym(dbb->dbb_pool); symbol->intlsym_name = name; symbol->intlsym_flags = 0; - symbol->intlsym_charset_id = X.RDB$CHARACTER_SET_ID; - symbol->intlsym_collate_id = X.RDB$COLLATION_ID; + symbol->intlsym_charset_id = CSetId(X.RDB$CHARACTER_SET_ID); + symbol->intlsym_collate_id = CollId(X.RDB$COLLATION_ID); symbol->intlsym_ttype = - INTL_CS_COLL_TO_TTYPE(symbol->intlsym_charset_id, symbol->intlsym_collate_id); + TTypeId(symbol->intlsym_charset_id, symbol->intlsym_collate_id); symbol->intlsym_bytes_per_char = (Y.RDB$BYTES_PER_CHARACTER.NULL) ? 1 : (Y.RDB$BYTES_PER_CHARACTER); } @@ -386,10 +386,10 @@ dsql_intlsym* METD_get_charset(jrd_tra* transaction, USHORT length, const char* symbol = FB_NEW_POOL(dbb->dbb_pool) dsql_intlsym(dbb->dbb_pool); symbol->intlsym_name = metaName; symbol->intlsym_flags = 0; - symbol->intlsym_charset_id = X.RDB$CHARACTER_SET_ID; - symbol->intlsym_collate_id = X.RDB$COLLATION_ID; + symbol->intlsym_charset_id = CSetId(X.RDB$CHARACTER_SET_ID); + symbol->intlsym_collate_id = CollId(X.RDB$COLLATION_ID); symbol->intlsym_ttype = - INTL_CS_COLL_TO_TTYPE(symbol->intlsym_charset_id, symbol->intlsym_collate_id); + TTypeId(CSetId(symbol->intlsym_charset_id), CollId(symbol->intlsym_collate_id)); symbol->intlsym_bytes_per_char = (Y.RDB$BYTES_PER_CHARACTER.NULL) ? 1 : (Y.RDB$BYTES_PER_CHARACTER); } @@ -406,7 +406,7 @@ dsql_intlsym* METD_get_charset(jrd_tra* transaction, USHORT length, const char* } -USHORT METD_get_charset_bpc(jrd_tra* transaction, SSHORT charset_id) +USHORT METD_get_charset_bpc(jrd_tra* transaction, CSetId charset_id) { /************************************** * @@ -442,7 +442,7 @@ USHORT METD_get_charset_bpc(jrd_tra* transaction, SSHORT charset_id) } -MetaName METD_get_charset_name(jrd_tra* transaction, SSHORT charset_id) +MetaName METD_get_charset_name(jrd_tra* transaction, CSetId charset_id) { /************************************** * @@ -562,12 +562,12 @@ bool METD_get_domain(jrd_tra* transaction, TypeClause* field, const MetaName& na field->subType = FLX.RDB$FIELD_SUB_TYPE; field->dimensions = FLX.RDB$DIMENSIONS.NULL ? 0 : FLX.RDB$DIMENSIONS; - field->charSetId = Nullable::empty(); + field->charSetId = Nullable::empty(); if (!FLX.RDB$CHARACTER_SET_ID.NULL) - field->charSetId = FLX.RDB$CHARACTER_SET_ID; - field->collationId = 0; + field->charSetId = CSetId(FLX.RDB$CHARACTER_SET_ID); + field->collationId = CollId(0); if (!FLX.RDB$COLLATION_ID.NULL) - field->collationId = FLX.RDB$COLLATION_ID; + field->collationId = CollId(FLX.RDB$COLLATION_ID); field->charLength = 0; if (!FLX.RDB$CHARACTER_LENGTH.NULL) field->charLength = FLX.RDB$CHARACTER_LENGTH; @@ -710,7 +710,7 @@ dsql_udf* METD_get_function(jrd_tra* transaction, DsqlCompilerScratch* dsqlScrat userFunc->udf_length = F.RDB$FIELD_LENGTH; if (!F.RDB$CHARACTER_SET_ID.NULL) { - userFunc->udf_character_set_id = F.RDB$CHARACTER_SET_ID; + userFunc->udf_character_set_id = CSetId(F.RDB$CHARACTER_SET_ID); } if (!X.RDB$ARGUMENT_MECHANISM.NULL && X.RDB$ARGUMENT_MECHANISM == prm_mech_type_of && @@ -752,12 +752,7 @@ dsql_udf* METD_get_function(jrd_tra* transaction, DsqlCompilerScratch* dsqlScrat if (!F.RDB$CHARACTER_SET_ID.NULL) { - if (d.dsc_dtype != dtype_blob) { - d.dsc_ttype() = F.RDB$CHARACTER_SET_ID; - } - else { - d.dsc_scale = F.RDB$CHARACTER_SET_ID; - } + d.setTextType(CSetId(F.RDB$CHARACTER_SET_ID)); } if (X.RDB$MECHANISM != FUN_value && X.RDB$MECHANISM != FUN_reference) @@ -798,7 +793,7 @@ dsql_udf* METD_get_function(jrd_tra* transaction, DsqlCompilerScratch* dsqlScrat userFunc->udf_length = X.RDB$FIELD_LENGTH; if (!X.RDB$CHARACTER_SET_ID.NULL) { - userFunc->udf_character_set_id = X.RDB$CHARACTER_SET_ID; + userFunc->udf_character_set_id = CSetId(X.RDB$CHARACTER_SET_ID); } } else @@ -825,12 +820,7 @@ dsql_udf* METD_get_function(jrd_tra* transaction, DsqlCompilerScratch* dsqlScrat if (!X.RDB$CHARACTER_SET_ID.NULL) { - if (d.dsc_dtype != dtype_blob) { - d.dsc_ttype() = X.RDB$CHARACTER_SET_ID; - } - else { - d.dsc_scale = X.RDB$CHARACTER_SET_ID; - } + d.setTextType(CSetId(X.RDB$CHARACTER_SET_ID)); } if (X.RDB$MECHANISM != FUN_value && X.RDB$MECHANISM != FUN_reference) @@ -1054,7 +1044,7 @@ dsql_prc* METD_get_procedure(jrd_tra* transaction, DsqlCompilerScratch* dsqlScra SORTED BY DESCENDING PR.RDB$PARAMETER_NUMBER { const SSHORT pr_collation_id_null = PR.RDB$COLLATION_ID.NULL; - const SSHORT pr_collation_id = PR.RDB$COLLATION_ID; + const CollId pr_collation_id(PR.RDB$COLLATION_ID); const SSHORT pr_default_value_null = PR.RDB$DEFAULT_VALUE.NULL; @@ -1086,12 +1076,12 @@ dsql_prc* METD_get_procedure(jrd_tra* transaction, DsqlCompilerScratch* dsqlScra parameter->fld_procedure = procedure; if (!FLD.RDB$CHARACTER_SET_ID.NULL) - parameter->charSetId = FLD.RDB$CHARACTER_SET_ID; + parameter->charSetId = CSetId(FLD.RDB$CHARACTER_SET_ID); if (!pr_collation_id_null) parameter->collationId = pr_collation_id; else if (!FLD.RDB$COLLATION_ID.NULL) - parameter->collationId = FLD.RDB$COLLATION_ID; + parameter->collationId = CollId(FLD.RDB$COLLATION_ID); convert_dtype(parameter, FLD.RDB$FIELD_TYPE); @@ -1327,12 +1317,12 @@ dsql_rel* METD_get_relation(jrd_tra* transaction, DsqlCompilerScratch* dsqlScrat } if (!FLX.RDB$CHARACTER_SET_ID.NULL) - field->charSetId = FLX.RDB$CHARACTER_SET_ID; + field->charSetId = CSetId(FLX.RDB$CHARACTER_SET_ID); if (!RFR.RDB$COLLATION_ID.NULL) - field->collationId = RFR.RDB$COLLATION_ID; + field->collationId = CollId(RFR.RDB$COLLATION_ID); else if (!FLX.RDB$COLLATION_ID.NULL) - field->collationId = FLX.RDB$COLLATION_ID; + field->collationId = CollId(FLX.RDB$COLLATION_ID); if (!(RFR.RDB$NULL_FLAG || FLX.RDB$NULL_FLAG) || (relation->rel_flags & REL_view)) { diff --git a/src/dsql/metd_proto.h b/src/dsql/metd_proto.h index f2130052ecb..84cb7989d27 100644 --- a/src/dsql/metd_proto.h +++ b/src/dsql/metd_proto.h @@ -52,9 +52,9 @@ void METD_drop_procedure(Jrd::jrd_tra*, const Jrd::QualifiedName&); void METD_drop_relation(Jrd::jrd_tra*, const Jrd::MetaName&); Jrd::dsql_intlsym* METD_get_charset(Jrd::jrd_tra*, USHORT, const char* name); -USHORT METD_get_charset_bpc(Jrd::jrd_tra*, SSHORT); -Jrd::MetaName METD_get_charset_name(Jrd::jrd_tra*, SSHORT); -Jrd::dsql_intlsym* METD_get_collation(Jrd::jrd_tra*, const Jrd::MetaName&, USHORT charset_id); +USHORT METD_get_charset_bpc(Jrd::jrd_tra*, CSetId); +Jrd::MetaName METD_get_charset_name(Jrd::jrd_tra*, CSetId); +Jrd::dsql_intlsym* METD_get_collation(Jrd::jrd_tra*, const Jrd::MetaName&, CSetId charset_id); Jrd::MetaName METD_get_default_charset(Jrd::jrd_tra*); bool METD_get_domain(Jrd::jrd_tra*, class Jrd::TypeClause*, const Jrd::MetaName& name); Jrd::dsql_udf* METD_get_function(Jrd::jrd_tra*, Jrd::DsqlCompilerScratch*, diff --git a/src/include/fb_types.h b/src/include/fb_types.h index 8fbfc053a3e..84a60e81f73 100644 --- a/src/include/fb_types.h +++ b/src/include/fb_types.h @@ -135,11 +135,6 @@ typedef int (*lock_ast_t)(void*); /* Number of elements in an array */ #define FB_NELEM(x) ((int)(sizeof(x) / sizeof(x[0]))) -// Intl types -typedef SSHORT CHARSET_ID; -typedef SSHORT COLLATE_ID; -typedef USHORT TTYPE_ID; - // Stream type, had to move it from dsql/Nodes.h due to circular dependencies. typedef ULONG StreamType; diff --git a/src/intl/charsets.h b/src/intl/charsets.h index 446b9220222..8b919fa3c4a 100644 --- a/src/intl/charsets.h +++ b/src/intl/charsets.h @@ -22,82 +22,84 @@ CS_737, CS_775, CS_858, CS_862, CS_864, CS_866, CS_869 #ifndef INTL_CHARSETS_H #define INTL_CHARSETS_H +#include "../jrd/intl.h" + #define DEFAULT_ATTACHMENT_CHARSET CS_NONE -#define CS_NONE 0 /* No Character Set */ -#define CS_BINARY 1 /* BINARY BYTES */ -#define CS_ASCII 2 /* ASCII */ -#define CS_UNICODE_FSS 3 /* UNICODE in FSS format */ -#define CS_UTF8 4 /* UTF-8 */ +#define CS_NONE CSetId(0) /* No Character Set */ +#define CS_BINARY CSetId(1) /* BINARY BYTES */ +#define CS_ASCII CSetId(2) /* ASCII */ +#define CS_UNICODE_FSS CSetId(3) /* UNICODE in FSS format */ +#define CS_UTF8 CSetId(4) /* UTF-8 */ -#define CS_SJIS 5 /* SJIS */ -#define CS_EUCJ 6 /* EUC-J */ +#define CS_SJIS CSetId(5) /* SJIS */ +#define CS_EUCJ CSetId(6) /* EUC-J */ -#define CS_JIS_0208 7 /* JIS 0208; 1990 */ -#define CS_UNICODE_UCS2 8 /* UNICODE v 1.10 */ +#define CS_JIS_0208 CSetId(7) /* JIS 0208; 1990 */ +#define CS_UNICODE_UCS2 CSetId(8) /* UNICODE v 1.10 */ -#define CS_DOS_737 9 -#define CS_DOS_437 10 /* DOS CP 437 */ -#define CS_DOS_850 11 /* DOS CP 850 */ -#define CS_DOS_865 12 /* DOS CP 865 */ -#define CS_DOS_860 13 /* DOS CP 860 */ -#define CS_DOS_863 14 /* DOS CP 863 */ +#define CS_DOS_737 CSetId(9) +#define CS_DOS_437 CSetId(10) /* DOS CP 437 */ +#define CS_DOS_850 CSetId(11) /* DOS CP 850 */ +#define CS_DOS_865 CSetId(12) /* DOS CP 865 */ +#define CS_DOS_860 CSetId(13) /* DOS CP 860 */ +#define CS_DOS_863 CSetId(14) /* DOS CP 863 */ -#define CS_DOS_775 15 -#define CS_DOS_858 16 -#define CS_DOS_862 17 -#define CS_DOS_864 18 +#define CS_DOS_775 CSetId(15) +#define CS_DOS_858 CSetId(16) +#define CS_DOS_862 CSetId(17) +#define CS_DOS_864 CSetId(18) -#define CS_NEXT 19 /* NeXTSTEP OS native charset */ +#define CS_NEXT CSetId(19) /* NeXTSTEP OS native charset */ -#define CS_ISO8859_1 21 /* ISO-8859.1 */ -#define CS_ISO8859_2 22 /* ISO-8859.2 */ -#define CS_ISO8859_3 23 /* ISO-8859.3 */ -#define CS_ISO8859_4 34 /* ISO-8859.4 */ -#define CS_ISO8859_5 35 /* ISO-8859.5 */ -#define CS_ISO8859_6 36 /* ISO-8859.6 */ -#define CS_ISO8859_7 37 /* ISO-8859.7 */ -#define CS_ISO8859_8 38 /* ISO-8859.8 */ -#define CS_ISO8859_9 39 /* ISO-8859.9 */ -#define CS_ISO8859_13 40 /* ISO-8859.13 */ +#define CS_ISO8859_1 CSetId(21) /* ISO-8859.1 */ +#define CS_ISO8859_2 CSetId(22) /* ISO-8859.2 */ +#define CS_ISO8859_3 CSetId(23) /* ISO-8859.3 */ +#define CS_ISO8859_4 CSetId(34) /* ISO-8859.4 */ +#define CS_ISO8859_5 CSetId(35) /* ISO-8859.5 */ +#define CS_ISO8859_6 CSetId(36) /* ISO-8859.6 */ +#define CS_ISO8859_7 CSetId(37) /* ISO-8859.7 */ +#define CS_ISO8859_8 CSetId(38) /* ISO-8859.8 */ +#define CS_ISO8859_9 CSetId(39) /* ISO-8859.9 */ +#define CS_ISO8859_13 CSetId(40) /* ISO-8859.13 */ -#define CS_KSC5601 44 /* KOREAN STANDARD 5601 */ +#define CS_KSC5601 CSetId(44) /* KOREAN STANDARD 5601 */ -#define CS_DOS_852 45 /* DOS CP 852 */ -#define CS_DOS_857 46 /* DOS CP 857 */ -#define CS_DOS_861 47 /* DOS CP 861 */ +#define CS_DOS_852 CSetId(45) /* DOS CP 852 */ +#define CS_DOS_857 CSetId(46) /* DOS CP 857 */ +#define CS_DOS_861 CSetId(47) /* DOS CP 861 */ -#define CS_DOS_866 48 -#define CS_DOS_869 49 +#define CS_DOS_866 CSetId(48) +#define CS_DOS_869 CSetId(49) -#define CS_CYRL 50 -#define CS_WIN1250 51 /* Windows cp 1250 */ -#define CS_WIN1251 52 /* Windows cp 1251 */ -#define CS_WIN1252 53 /* Windows cp 1252 */ -#define CS_WIN1253 54 /* Windows cp 1253 */ -#define CS_WIN1254 55 /* Windows cp 1254 */ +#define CS_CYRL CSetId(50) +#define CS_WIN1250 CSetId(51) /* Windows cp 1250 */ +#define CS_WIN1251 CSetId(52) /* Windows cp 1251 */ +#define CS_WIN1252 CSetId(53) /* Windows cp 1252 */ +#define CS_WIN1253 CSetId(54) /* Windows cp 1253 */ +#define CS_WIN1254 CSetId(55) /* Windows cp 1254 */ -#define CS_BIG5 56 /* Big Five unicode cs */ -#define CS_GB2312 57 /* GB 2312-80 cs */ +#define CS_BIG5 CSetId(56) /* Big Five unicode cs */ +#define CS_GB2312 CSetId(57) /* GB 2312-80 cs */ -#define CS_WIN1255 58 /* Windows cp 1255 */ -#define CS_WIN1256 59 /* Windows cp 1256 */ -#define CS_WIN1257 60 /* Windows cp 1257 */ +#define CS_WIN1255 CSetId(58) /* Windows cp 1255 */ +#define CS_WIN1256 CSetId(59) /* Windows cp 1256 */ +#define CS_WIN1257 CSetId(60) /* Windows cp 1257 */ -#define CS_UTF16 61 /* UTF-16 */ -#define CS_UTF32 62 /* UTF-32 */ +#define CS_UTF16 CSetId(61) /* UTF-16 */ +#define CS_UTF32 CSetId(62) /* UTF-32 */ -#define CS_KOI8R 63 /* Russian KOI8R */ -#define CS_KOI8U 64 /* Ukrainian KOI8U */ +#define CS_KOI8R CSetId(63) /* Russian KOI8R */ +#define CS_KOI8U CSetId(64) /* Ukrainian KOI8U */ -#define CS_WIN1258 65 /* Windows cp 1258 */ +#define CS_WIN1258 CSetId(65) /* Windows cp 1258 */ -#define CS_TIS620 66 /* TIS620 */ -#define CS_GBK 67 /* GBK */ -#define CS_CP943C 68 /* CP943C */ +#define CS_TIS620 CSetId(66) /* TIS620 */ +#define CS_GBK CSetId(67) /* GBK */ +#define CS_CP943C CSetId(68) /* CP943C */ -#define CS_GB18030 69 // GB18030 +#define CS_GB18030 CSetId(69) // GB18030 -#define CS_dynamic 127 // Pseudo number for runtime charset +#define CS_dynamic CSetId(127) // Pseudo number for runtime charset #endif /* INTL_CHARSETS_H */ diff --git a/src/jrd/Attachment.cpp b/src/jrd/Attachment.cpp index 679ebbcdcac..04c8bcf5a50 100644 --- a/src/jrd/Attachment.cpp +++ b/src/jrd/Attachment.cpp @@ -319,7 +319,7 @@ MetaName Jrd::Attachment::nameToUserCharSet(thread_db* tdbb, const MetaName& nam string Jrd::Attachment::stringToMetaCharSet(thread_db* tdbb, const string& str, const char* charSet) { - USHORT charSetId = att_charset; + auto charSetId = att_charset; if (charSet) { diff --git a/src/jrd/Attachment.h b/src/jrd/Attachment.h index 9661faf5d1c..552dd96140f 100644 --- a/src/jrd/Attachment.h +++ b/src/jrd/Attachment.h @@ -545,8 +545,8 @@ class Attachment : public pool_alloc RuntimeStatistics att_stats; RuntimeStatistics att_base_stats; ULONG att_flags; // Flags describing the state of the attachment - SSHORT att_client_charset; // user's charset specified in dpb - SSHORT att_charset; // current (client or external) attachment charset + CSetId att_client_charset; // user's charset specified in dpb + CSetId att_charset; // current (client or external) attachment charset bool att_in_system_routine = false; // running a system routine Lock* att_long_locks; // outstanding two phased locks #ifdef DEBUG_LCK_LIST diff --git a/src/jrd/CharSetContainer.h b/src/jrd/CharSetContainer.h index 7ddd34fb664..a1093235139 100644 --- a/src/jrd/CharSetContainer.h +++ b/src/jrd/CharSetContainer.h @@ -35,12 +35,10 @@ struct SubtypeInfo; namespace Jrd { -typedef UCHAR CollId; - class CharSetContainer : public Firebird::PermanentStorage { public: - CharSetContainer(thread_db* tdbb, MemoryPool& p, MetaId cs_id, /*const SubtypeInfo* info*/Lock* lock); + CharSetContainer(thread_db* tdbb, MemoryPool& p, MetaId cs_id, Lock* lock); void destroy() { @@ -61,10 +59,9 @@ class CharSetContainer : public Firebird::PermanentStorage return cs; } - CsConvert lookupConverter(thread_db* tdbb, CHARSET_ID to_cs); + CsConvert lookupConverter(thread_db* tdbb, CSetId to_cs); - static CharSetContainer* lookupCharset(thread_db* tdbb, USHORT ttype); - static Lock* createCollationLock(thread_db* tdbb, USHORT ttype, void* object = NULL); + static CharSetContainer* lookupCharset(thread_db* tdbb, TTypeId ttype); bool hasData() const { @@ -89,7 +86,7 @@ class CharSetContainer : public Firebird::PermanentStorage } private: - static bool lookupInternalCharSet(USHORT id, SubtypeInfo* info); + static bool lookupInternalCharSet(CSetId id, SubtypeInfo* info); private: CharSet* cs; @@ -137,42 +134,14 @@ class CharSetVers final : public ObjectBase void scan(thread_db* tdbb, ObjectBase::Flag flags); static Lock* makeLock(thread_db*, MemoryPool&); - Collation* lookupCollation(thread_db* tdbb, MetaId tt_id); - Collation* lookupCollation(thread_db* tdbb, MetaName name); - Collation* getCollation(CollId collId); + Collation* getCollation(TTypeId tt_id); + Collation* getCollation(MetaName name); private: CharSetContainer* perm; Firebird::HalfStaticArray charset_collations; }; -namespace Rsc -{ - -class Coll -{ -public: - Coll(CSet* cs, CollId id) - : cSet(cs), collId(id) - { } - - Collation* operator()(const VersionedObjects* runTime) const - { - return (*cSet)(runTime)->getCollation(collId); - } - - Collation* operator()(thread_db* tdbb) const - { - return (*cSet)(tdbb)->getCollation(collId); - } - -private: - CSet* cSet; - CollId collId; -}; - -} // namespace Rsc - } // namespace Jrd #endif // JRD_CHARSETCONTAINER_H diff --git a/src/jrd/Collation.cpp b/src/jrd/Collation.cpp index 1e469ab8ac1..ddb44bf1d75 100644 --- a/src/jrd/Collation.cpp +++ b/src/jrd/Collation.cpp @@ -990,7 +990,7 @@ template < class CollationImpl : public Collation { public: - CollationImpl(TTYPE_ID a_type, texttype* a_tt, USHORT a_attributes, CharSet* a_cs) + CollationImpl(TTypeId a_type, texttype* a_tt, USHORT a_attributes, CharSet* a_cs) : Collation(a_type, a_tt, a_attributes, a_cs) { } @@ -1068,7 +1068,7 @@ class CollationImpl : public Collation }; template -Collation* newCollation(MemoryPool& pool, TTYPE_ID id, texttype* tt, USHORT attributes, CharSet* cs) +Collation* newCollation(MemoryPool& pool, TTypeId id, texttype* tt, USHORT attributes, CharSet* cs) { using namespace Firebird; @@ -1107,7 +1107,7 @@ Collation* newCollation(MemoryPool& pool, TTYPE_ID id, texttype* tt, USHORT attr namespace Jrd { -Collation* Collation::createInstance(MemoryPool& pool, TTYPE_ID id, texttype* tt, USHORT attributes, CharSet* cs) +Collation* Collation::createInstance(MemoryPool& pool, TTypeId id, texttype* tt, USHORT attributes, CharSet* cs) { switch (tt->texttype_canonical_width) { diff --git a/src/jrd/Collation.h b/src/jrd/Collation.h index 5412a251e56..273419a21b4 100644 --- a/src/jrd/Collation.h +++ b/src/jrd/Collation.h @@ -43,11 +43,11 @@ class BaseSubstringSimilarMatcher; class Collation : public TextType { public: - static Collation* createInstance(MemoryPool& pool, TTYPE_ID id, texttype* tt, USHORT attributes, CharSet* cs); + static Collation* createInstance(MemoryPool& pool, TTypeId id, texttype* tt, USHORT attributes, CharSet* cs); typedef const char* Key; protected: - Collation(TTYPE_ID id, texttype *a_tt, USHORT a_attributes, CharSet* a_cs) + Collation(TTypeId id, texttype *a_tt, USHORT a_attributes, CharSet* a_cs) : TextType(id, a_tt, a_attributes, a_cs), existenceLock(NULL), obsolete(false) diff --git a/src/jrd/DataTypeUtil.cpp b/src/jrd/DataTypeUtil.cpp index b6fef634c0d..9e38a4dac53 100644 --- a/src/jrd/DataTypeUtil.cpp +++ b/src/jrd/DataTypeUtil.cpp @@ -56,13 +56,13 @@ SSHORT DataTypeUtilBase::getResultBlobSubType(const dsc* value1, const dsc* valu } -USHORT DataTypeUtilBase::getResultTextType(const dsc* value1, const dsc* value2) +TTypeId DataTypeUtilBase::getResultTextType(const dsc* value1, const dsc* value2) { - const USHORT cs1 = value1->getCharSet(); - const USHORT cs2 = value2->getCharSet(); + const auto cs1 = value1->getCharSet(); + const auto cs2 = value2->getCharSet(); - const USHORT ttype1 = value1->getTextType(); - const USHORT ttype2 = value2->getTextType(); + const auto ttype1 = value1->getTextType(); + const auto ttype2 = value2->getTextType(); if (cs1 == CS_NONE || cs2 == CS_BINARY) return ttype2; @@ -219,7 +219,7 @@ void DataTypeUtilBase::makeFromList(dsc* result, const char* expressionName, int } -ULONG DataTypeUtilBase::convertLength(ULONG len, USHORT srcCharSet, USHORT dstCharSet) +ULONG DataTypeUtilBase::convertLength(ULONG len, CSetId srcCharSet, CSetId dstCharSet) { if (dstCharSet == CS_NONE || dstCharSet == CS_BINARY) return len; @@ -312,7 +312,7 @@ void DataTypeUtilBase::makeSubstr(dsc* result, const dsc* value, const dsc* offs result->dsc_dtype = dtype_varying; } - result->setTextType(value->isText() || value->isBlob() ? value->getTextType() : CS_ASCII); + result->setTextType(value->isText() || value->isBlob() ? value->getTextType() : TTypeId(CS_ASCII)); result->setNullable(value->isNullable() || (offset && offset->isNullable()) || (length && length->isNullable())); @@ -357,7 +357,7 @@ bool DataTypeUtilBase::makeBlobOrText(dsc* result, const dsc* arg, bool force) namespace Jrd { -UCHAR DataTypeUtil::maxBytesPerChar(UCHAR charSet) +UCHAR DataTypeUtil::maxBytesPerChar(CSetId charSet) { return INTL_charset_lookup(tdbb, charSet)->maxBytesPerChar(); } @@ -368,7 +368,7 @@ USHORT DataTypeUtil::getDialect() const } // Returns false if conversion is not needed. -bool DataTypeUtil::convertToUTF8(const string& src, string& dst, CHARSET_ID charset, ErrorFunction err) +bool DataTypeUtil::convertToUTF8(const string& src, string& dst, CSetId charset, ErrorFunction err) { thread_db* tdbb = JRD_get_thread_data(); diff --git a/src/jrd/DataTypeUtil.h b/src/jrd/DataTypeUtil.h index 5232e031f45..957687d713d 100644 --- a/src/jrd/DataTypeUtil.h +++ b/src/jrd/DataTypeUtil.h @@ -30,6 +30,7 @@ #include "../intl/charsets.h" #include "../common/classes/fb_string.h" #include "../jrd/err_proto.h" +#include "../jrd/intl.h" struct dsc; @@ -40,11 +41,11 @@ class DataTypeUtilBase public: static SSHORT getResultBlobSubType(const dsc* value1, const dsc* value2); - static USHORT getResultTextType(const dsc* value1, const dsc* value2); + static TTypeId getResultTextType(const dsc* value1, const dsc* value2); public: void makeFromList(dsc* result, const char* expressionName, int argsCount, const dsc** args); - ULONG convertLength(ULONG len, USHORT srcCharSet, USHORT dstCharSet); + ULONG convertLength(ULONG len, CSetId srcCharSet, CSetId dstCharSet); ULONG convertLength(const dsc* src, const dsc* dst); ULONG fixLength(const dsc* desc, ULONG length); @@ -55,7 +56,7 @@ class DataTypeUtilBase bool makeBlobOrText(dsc* result, const dsc* arg, bool force); public: - virtual UCHAR maxBytesPerChar(UCHAR charSet) = 0; + virtual UCHAR maxBytesPerChar(CSetId charSet) = 0; virtual USHORT getDialect() const = 0; // returns client dialect in DSQL and database dialect in JRD }; @@ -73,12 +74,12 @@ class DataTypeUtil : public DataTypeUtilBase } public: - virtual UCHAR maxBytesPerChar(UCHAR charSet); + virtual UCHAR maxBytesPerChar(CSetId charSet); virtual USHORT getDialect() const; public: static bool convertToUTF8(const Firebird::string& src, Firebird::string& dst, - CHARSET_ID charset = CS_dynamic, ErrorFunction err = ERR_post); + CSetId charset = CS_dynamic, ErrorFunction err = ERR_post); private: thread_db* tdbb; diff --git a/src/jrd/ExtEngineManager.cpp b/src/jrd/ExtEngineManager.cpp index 1aaaacbd5d4..e04ac6203ed 100644 --- a/src/jrd/ExtEngineManager.cpp +++ b/src/jrd/ExtEngineManager.cpp @@ -513,7 +513,7 @@ template class ExtEngineManager::ContextManager setCharSet(tdbb, attInfo, obj); } - ContextManager(thread_db* tdbb, EngineAttachmentInfo* aAttInfo, USHORT aCharSet, + ContextManager(thread_db* tdbb, EngineAttachmentInfo* aAttInfo, CSetId aCharSet, CallerName aCallerName = CallerName()) : attInfo(aAttInfo), attachment(tdbb->getAttachment()), @@ -570,7 +570,7 @@ template class ExtEngineManager::ContextManager charSetName[MAX_SQL_IDENTIFIER_LEN] = '\0'; } - USHORT charSetId; + TTypeId charSetId; if (!MetadataCache::get_char_coll_subtype(tdbb, &charSetId, reinterpret_cast(charSetName), static_cast(strlen(charSetName)))) @@ -586,7 +586,7 @@ template class ExtEngineManager::ContextManager Jrd::Attachment* attachment; jrd_tra* transaction; // These data members are to restore the original information. - const USHORT charSet; + const CSetId charSet; const bool attInUse; const bool traInUse; CallerName callerName; diff --git a/src/jrd/ExtEngineManager.h b/src/jrd/ExtEngineManager.h index 39f076d59cd..7e4982f9a85 100644 --- a/src/jrd/ExtEngineManager.h +++ b/src/jrd/ExtEngineManager.h @@ -207,7 +207,7 @@ class ExtEngineManager final : public Firebird::PermanentStorage Firebird::IExternalEngine* engine; Firebird::AutoPtr context; - USHORT adminCharSet; + TTypeId adminCharSet; }; public: @@ -276,7 +276,7 @@ class ExtEngineManager final : public Firebird::PermanentStorage bool firstFetch; EngineAttachmentInfo* attInfo; Firebird::IExternalResultSet* resultSet; - USHORT charSet; + CSetId charSet; }; class Trigger : public ExtRoutine diff --git a/src/jrd/Function.epp b/src/jrd/Function.epp index 4cdbe280090..ab1b4fefc0f 100644 --- a/src/jrd/Function.epp +++ b/src/jrd/Function.epp @@ -224,7 +224,7 @@ void Function::scan(thread_db* tdbb, ObjectBase::Flag) prm_mech_normal : (prm_mech_t) Y.RDB$ARGUMENT_MECHANISM; const SSHORT collation_id_null = Y.RDB$COLLATION_ID.NULL; - const SSHORT collation_id = Y.RDB$COLLATION_ID; + const CollId collation_id(Y.RDB$COLLATION_ID); SSHORT default_value_null = Y.RDB$DEFAULT_VALUE.NULL; bid default_value = Y.RDB$DEFAULT_VALUE; @@ -241,8 +241,8 @@ void Function::scan(thread_db* tdbb, ObjectBase::Flag) { DSC_make_descriptor(¶meter->prm_desc, F.RDB$FIELD_TYPE, F.RDB$FIELD_SCALE, F.RDB$FIELD_LENGTH, - F.RDB$FIELD_SUB_TYPE, F.RDB$CHARACTER_SET_ID, - (collation_id_null ? F.RDB$COLLATION_ID : collation_id)); + F.RDB$FIELD_SUB_TYPE, CSetId(F.RDB$CHARACTER_SET_ID), + (collation_id_null ? CollId(F.RDB$COLLATION_ID) : collation_id)); if (default_value_null && fb_utils::implicit_domain(F.RDB$FIELD_NAME)) { @@ -256,8 +256,8 @@ void Function::scan(thread_db* tdbb, ObjectBase::Flag) { DSC_make_descriptor(¶meter->prm_desc, Y.RDB$FIELD_TYPE, Y.RDB$FIELD_SCALE, Y.RDB$FIELD_LENGTH, - Y.RDB$FIELD_SUB_TYPE, Y.RDB$CHARACTER_SET_ID, - (collation_id_null ? 0 : collation_id)); + Y.RDB$FIELD_SUB_TYPE, CSetId(Y.RDB$CHARACTER_SET_ID), + (collation_id_null ? CollId(0) : collation_id)); } if (parameter->prm_desc.isText() && parameter->prm_desc.getTextType() != CS_NONE) diff --git a/src/jrd/IntlManager.cpp b/src/jrd/IntlManager.cpp index 765038bcc37..7aa2fdc2794 100644 --- a/src/jrd/IntlManager.cpp +++ b/src/jrd/IntlManager.cpp @@ -159,7 +159,7 @@ const IntlManager::CharSetDefinition IntlManager::defaultCharSets[] = {"GBK", CS_GBK, 2}, {"CP943C", CS_CP943C, 2}, {"GB18030", CS_GB18030, 4}, - {NULL, 0, 0} + {NULL, CS_NONE, 0} }; const IntlManager::CharSetAliasDefinition IntlManager::defaultCharSetAliases[] = @@ -235,182 +235,182 @@ const IntlManager::CharSetAliasDefinition IntlManager::defaultCharSetAliases[] = {"GB2312", CS_GB2312}, {"DOS_936", CS_GB2312}, {"WIN_936", CS_GB2312}, - {NULL, 0} + {NULL, CS_NONE} }; const IntlManager::CollationDefinition IntlManager::defaultCollations[] = { - {CS_NONE, 0, "NONE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_BINARY, 0, "OCTETS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ASCII, 0, "ASCII", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UNICODE_FSS, 0, "UNICODE_FSS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UTF8, 0, "UTF8", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UTF8, 1, "UCS_BASIC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UTF8, 2, "UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UTF8, 3, "UNICODE_CI", "UNICODE", + {CS_NONE, CollId(0), "NONE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_BINARY, CollId(0), "OCTETS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ASCII, CollId(0), "ASCII", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UNICODE_FSS, CollId(0), "UNICODE_FSS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF8, CollId(0), "UTF8", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF8, CollId(1), "UCS_BASIC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF8, CollId(2), "UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF8, CollId(3), "UNICODE_CI", "UNICODE", TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE, NULL}, - {CS_UTF8, 4, "UNICODE_CI_AI", "UNICODE", + {CS_UTF8, CollId(4), "UNICODE_CI_AI", "UNICODE", TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE, NULL}, #ifdef FB_NEW_INTL_ALLOW_NOT_READY - {CS_UTF16, 0, "UTF16", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UTF16, 1, "UCS_BASIC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UTF32, 0, "UTF32", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_UTF32, 1, "UCS_BASIC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF16, CollId(0), "UTF16", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF16, CollId(1), "UCS_BASIC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF32, CollId(0), "UTF32", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_UTF32, CollId(1), "UCS_BASIC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, #endif // FB_NEW_INTL_NOT_READY - {CS_SJIS, 0, "SJIS_0208", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_EUCJ, 0, "EUCJ_0208", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 0, "DOS437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 1, "PDOX_ASCII", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 2, "PDOX_INTL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 3, "PDOX_SWEDFIN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 4, "DB_DEU437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 5, "DB_ESP437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 6, "DB_FIN437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 7, "DB_FRA437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 8, "DB_ITA437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 9, "DB_NLD437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 10, "DB_SVE437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 11, "DB_UK437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_437, 12, "DB_US437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 0, "DOS850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 1, "DB_FRC850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 2, "DB_DEU850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 3, "DB_ESP850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 4, "DB_FRA850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 5, "DB_ITA850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 6, "DB_NLD850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 7, "DB_PTB850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 8, "DB_SVE850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 9, "DB_UK850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_850, 10, "DB_US850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_865, 0, "DOS865", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_865, 1, "PDOX_NORDAN4", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_865, 2, "DB_DAN865", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_865, 3, "DB_NOR865", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 0, "ISO8859_1", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 1, "DA_DA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 2, "DU_NL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 3, "FI_FI", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 4, "FR_FR", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 5, "FR_CA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 6, "DE_DE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 7, "IS_IS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 8, "IT_IT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 9, "NO_NO", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 10, "ES_ES", NULL, TEXTTYPE_ATTR_PAD_SPACE, "DISABLE-COMPRESSIONS=1;SPECIALS-FIRST=1"}, - {CS_ISO8859_1, 11, "SV_SV", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 12, "EN_UK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 14, "EN_US", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 15, "PT_PT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_1, 16, "PT_BR", NULL, + {CS_SJIS, CollId(0), "SJIS_0208", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_EUCJ, CollId(0), "EUCJ_0208", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(0), "DOS437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(1), "PDOX_ASCII", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(2), "PDOX_INTL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(3), "PDOX_SWEDFIN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(4), "DB_DEU437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(5), "DB_ESP437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(6), "DB_FIN437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(7), "DB_FRA437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(8), "DB_ITA437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(9), "DB_NLD437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(10), "DB_SVE437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(11), "DB_UK437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_437, CollId(12), "DB_US437", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(0), "DOS850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(1), "DB_FRC850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(2), "DB_DEU850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(3), "DB_ESP850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(4), "DB_FRA850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(5), "DB_ITA850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(6), "DB_NLD850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(7), "DB_PTB850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(8), "DB_SVE850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(9), "DB_UK850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_850, CollId(10), "DB_US850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_865, CollId(0), "DOS865", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_865, CollId(1), "PDOX_NORDAN4", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_865, CollId(2), "DB_DAN865", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_865, CollId(3), "DB_NOR865", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(0), "ISO8859_1", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(1), "DA_DA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(2), "DU_NL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(3), "FI_FI", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(4), "FR_FR", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(5), "FR_CA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(6), "DE_DE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(7), "IS_IS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(8), "IT_IT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(9), "NO_NO", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(10), "ES_ES", NULL, TEXTTYPE_ATTR_PAD_SPACE, "DISABLE-COMPRESSIONS=1;SPECIALS-FIRST=1"}, + {CS_ISO8859_1, CollId(11), "SV_SV", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(12), "EN_UK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(14), "EN_US", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(15), "PT_PT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_1, CollId(16), "PT_BR", NULL, TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE, NULL}, - {CS_ISO8859_1, 17, "ES_ES_CI_AI", NULL, + {CS_ISO8859_1, CollId(17), "ES_ES_CI_AI", NULL, TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE, "DISABLE-COMPRESSIONS=1;SPECIALS-FIRST=1"}, - {CS_ISO8859_1, 18, "FR_FR_CI_AI", "FR_FR", + {CS_ISO8859_1, CollId(18), "FR_FR_CI_AI", "FR_FR", TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE, "SPECIALS-FIRST=1"}, - {CS_ISO8859_1, 19, "FR_CA_CI_AI", "FR_CA", + {CS_ISO8859_1, CollId(19), "FR_CA_CI_AI", "FR_CA", TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE, "SPECIALS-FIRST=1"}, - {CS_ISO8859_2, 0, "ISO8859_2", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_2, 1, "CS_CZ", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_2, 2, "ISO_HUN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_2, 3, "ISO_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_3, 0, "ISO8859_3", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_4, 0, "ISO8859_4", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_5, 0, "ISO8859_5", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_6, 0, "ISO8859_6", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_7, 0, "ISO8859_7", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_8, 0, "ISO8859_8", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_9, 0, "ISO8859_9", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_13, 0, "ISO8859_13", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_ISO8859_13, 1, "LT_LT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 0, "DOS852", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 1, "DB_CSY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 2, "DB_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 4, "DB_SLO", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 5, "PDOX_CSY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 6, "PDOX_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 7, "PDOX_HUN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_852, 8, "PDOX_SLO", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_857, 0, "DOS857", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_857, 1, "DB_TRK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_860, 0, "DOS860", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_860, 1, "DB_PTG860", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_861, 0, "DOS861", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_861, 1, "PDOX_ISL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_863, 0, "DOS863", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_863, 1, "DB_FRC863", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_CYRL, 0, "CYRL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_CYRL, 1, "DB_RUS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_CYRL, 2, "PDOX_CYRL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_737, 0, "DOS737", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_775, 0, "DOS775", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_858, 0, "DOS858", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_862, 0, "DOS862", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_864, 0, "DOS864", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_866, 0, "DOS866", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_DOS_869, 0, "DOS869", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 0, "WIN1250", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 1, "PXW_CSY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 2, "PXW_HUNDC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 3, "PXW_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 4, "PXW_SLOV", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 5, "PXW_HUN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 6, "BS_BA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1250, 7, "WIN_CZ", NULL, TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE, NULL}, - {CS_WIN1250, 8, "WIN_CZ_CI_AI", NULL, + {CS_ISO8859_2, CollId(0), "ISO8859_2", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_2, CollId(1), "CS_CZ", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_2, CollId(2), "ISO_HUN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_2, CollId(3), "ISO_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_3, CollId(0), "ISO8859_3", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_4, CollId(0), "ISO8859_4", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_5, CollId(0), "ISO8859_5", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_6, CollId(0), "ISO8859_6", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_7, CollId(0), "ISO8859_7", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_8, CollId(0), "ISO8859_8", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_9, CollId(0), "ISO8859_9", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_13, CollId(0), "ISO8859_13", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_ISO8859_13, CollId(1), "LT_LT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(0), "DOS852", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(1), "DB_CSY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(2), "DB_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(4), "DB_SLO", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(5), "PDOX_CSY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(6), "PDOX_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(7), "PDOX_HUN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_852, CollId(8), "PDOX_SLO", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_857, CollId(0), "DOS857", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_857, CollId(1), "DB_TRK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_860, CollId(0), "DOS860", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_860, CollId(1), "DB_PTG860", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_861, CollId(0), "DOS861", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_861, CollId(1), "PDOX_ISL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_863, CollId(0), "DOS863", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_863, CollId(1), "DB_FRC863", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_CYRL, CollId(0), "CYRL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_CYRL, CollId(1), "DB_RUS", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_CYRL, CollId(2), "PDOX_CYRL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_737, CollId(0), "DOS737", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_775, CollId(0), "DOS775", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_858, CollId(0), "DOS858", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_862, CollId(0), "DOS862", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_864, CollId(0), "DOS864", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_866, CollId(0), "DOS866", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_DOS_869, CollId(0), "DOS869", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(0), "WIN1250", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(1), "PXW_CSY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(2), "PXW_HUNDC", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(3), "PXW_PLK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(4), "PXW_SLOV", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(5), "PXW_HUN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(6), "BS_BA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1250, CollId(7), "WIN_CZ", NULL, TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE, NULL}, + {CS_WIN1250, CollId(8), "WIN_CZ_CI_AI", NULL, TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE, NULL}, - {CS_WIN1251, 0, "WIN1251", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1251, 1, "PXW_CYRL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1251, 2, "WIN1251_UA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1252, 0, "WIN1252", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1252, 1, "PXW_INTL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1252, 2, "PXW_INTL850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1252, 3, "PXW_NORDAN4", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1252, 4, "PXW_SPAN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1252, 5, "PXW_SWEDFIN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1252, 6, "WIN_PTBR", NULL, + {CS_WIN1251, CollId(0), "WIN1251", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1251, CollId(1), "PXW_CYRL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1251, CollId(2), "WIN1251_UA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1252, CollId(0), "WIN1252", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1252, CollId(1), "PXW_INTL", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1252, CollId(2), "PXW_INTL850", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1252, CollId(3), "PXW_NORDAN4", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1252, CollId(4), "PXW_SPAN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1252, CollId(5), "PXW_SWEDFIN", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1252, CollId(6), "WIN_PTBR", NULL, TEXTTYPE_ATTR_PAD_SPACE | TEXTTYPE_ATTR_CASE_INSENSITIVE | TEXTTYPE_ATTR_ACCENT_INSENSITIVE, NULL}, - {CS_WIN1253, 0, "WIN1253", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1253, 1, "PXW_GREEK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1254, 0, "WIN1254", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1254, 1, "PXW_TURK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_NEXT, 0, "NEXT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_NEXT, 1, "NXT_US", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_NEXT, 2, "NXT_DEU", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_NEXT, 3, "NXT_FRA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_NEXT, 4, "NXT_ITA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_NEXT, 5, "NXT_ESP", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1255, 0, "WIN1255", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1256, 0, "WIN1256", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1257, 0, "WIN1257", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1257, 1, "WIN1257_EE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1257, 2, "WIN1257_LT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1257, 3, "WIN1257_LV", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_KSC5601, 0, "KSC_5601", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_KSC5601, 1, "KSC_DICTIONARY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_BIG5, 0, "BIG_5", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_GB2312, 0, "GB_2312", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_KOI8R, 0, "KOI8R", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_KOI8R, 1, "KOI8R_RU", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_KOI8U, 0, "KOI8U", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_KOI8U, 1, "KOI8U_UA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_WIN1258, 0, "WIN1258", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_TIS620, 0, "TIS620", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_TIS620, 1, "TIS620_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_GBK, 0, "GBK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_GBK, 1, "GBK_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_CP943C, 0, "CP943C", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_CP943C, 1, "CP943C_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_GB18030, 0, "GB18030", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {CS_GB18030, 1, "GB18030_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, - {0, 0, NULL, NULL, 0, NULL} + {CS_WIN1253, CollId(0), "WIN1253", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1253, CollId(1), "PXW_GREEK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1254, CollId(0), "WIN1254", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1254, CollId(1), "PXW_TURK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_NEXT, CollId(0), "NEXT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_NEXT, CollId(1), "NXT_US", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_NEXT, CollId(2), "NXT_DEU", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_NEXT, CollId(3), "NXT_FRA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_NEXT, CollId(4), "NXT_ITA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_NEXT, CollId(5), "NXT_ESP", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1255, CollId(0), "WIN1255", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1256, CollId(0), "WIN1256", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1257, CollId(0), "WIN1257", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1257, CollId(1), "WIN1257_EE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1257, CollId(2), "WIN1257_LT", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1257, CollId(3), "WIN1257_LV", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_KSC5601, CollId(0), "KSC_5601", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_KSC5601, CollId(1), "KSC_DICTIONARY", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_BIG5, CollId(0), "BIG_5", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_GB2312, CollId(0), "GB_2312", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_KOI8R, CollId(0), "KOI8R", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_KOI8R, CollId(1), "KOI8R_RU", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_KOI8U, CollId(0), "KOI8U", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_KOI8U, CollId(1), "KOI8U_UA", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_WIN1258, CollId(0), "WIN1258", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_TIS620, CollId(0), "TIS620", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_TIS620, CollId(1), "TIS620_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_GBK, CollId(0), "GBK", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_GBK, CollId(1), "GBK_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_CP943C, CollId(0), "CP943C", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_CP943C, CollId(1), "CP943C_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_GB18030, CollId(0), "GB18030", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_GB18030, CollId(1), "GB18030_UNICODE", NULL, TEXTTYPE_ATTR_PAD_SPACE, NULL}, + {CS_NONE, CollId(0), NULL, NULL, 0, NULL} }; diff --git a/src/jrd/IntlManager.h b/src/jrd/IntlManager.h index c35ecf9705b..7a58ec6d5d9 100644 --- a/src/jrd/IntlManager.h +++ b/src/jrd/IntlManager.h @@ -29,6 +29,7 @@ #include "../common/classes/fb_string.h" #include "../common/config/config_file.h" +#include "../jrd/intl.h" struct charset; struct texttype; @@ -61,20 +62,20 @@ class IntlManager struct CharSetDefinition { const char* name; - UCHAR id; + CSetId id; USHORT maxBytes; }; struct CharSetAliasDefinition { const char* name; - UCHAR charSetId; + CSetId charSetId; }; struct CollationDefinition { - UCHAR charSetId; - UCHAR collationId; + CSetId charSetId; + CollId collationId; const char* name; const char* baseName; USHORT attributes; diff --git a/src/jrd/PreparedStatement.cpp b/src/jrd/PreparedStatement.cpp index 371e1c161ae..77d0e5bfe98 100644 --- a/src/jrd/PreparedStatement.cpp +++ b/src/jrd/PreparedStatement.cpp @@ -54,13 +54,13 @@ namespace { case dtype_text: item.type = SQL_TEXT; - item.charSet = desc->dsc_ttype(); + item.charSet = desc->getTextType(); item.length = desc->dsc_length; break; case dtype_varying: item.type = SQL_VARYING; - item.charSet = desc->dsc_ttype(); + item.charSet = desc->getTextType(); fb_assert(desc->dsc_length >= sizeof(USHORT)); item.length = desc->dsc_length - sizeof(USHORT); break; @@ -312,7 +312,7 @@ PreparedStatement::~PreparedStatement() void PreparedStatement::init(thread_db* tdbb, Attachment* attachment, jrd_tra* transaction, const Firebird::string& text, bool isInternalRequest) { - AutoSetRestore autoAttCharset(&attachment->att_charset, + AutoSetRestore autoAttCharset(&attachment->att_charset, (isInternalRequest ? CS_METADATA : attachment->att_charset)); dsqlRequest = NULL; diff --git a/src/jrd/RecordSourceNodes.cpp b/src/jrd/RecordSourceNodes.cpp index b7fe4572ea8..608354ba957 100644 --- a/src/jrd/RecordSourceNodes.cpp +++ b/src/jrd/RecordSourceNodes.cpp @@ -3600,8 +3600,8 @@ static void processMap(thread_db* tdbb, CompilerScratch* csb, MapNode* map, Form *desc = desc2; else if (max == dtype_blob) { - USHORT subtype = DataTypeUtil::getResultBlobSubType(desc, &desc2); - USHORT ttype = DataTypeUtil::getResultTextType(desc, &desc2); + auto subtype = DataTypeUtil::getResultBlobSubType(desc, &desc2); + auto ttype = DataTypeUtil::getResultTextType(desc, &desc2); desc->makeBlob(subtype, ttype); } else if (min <= dtype_any_text) @@ -3615,7 +3615,7 @@ static void processMap(thread_db* tdbb, CompilerScratch* csb, MapNode* map, Form // pick the max text type, so any transparent casts from ints are // not left in ASCII format, but converted to the richer text format - desc->setTextType(MAX(INTL_TEXT_TYPE(*desc), INTL_TEXT_TYPE(desc2))); + desc->setTextType(MAX(desc->getTextType(), desc2.getTextType())); desc->dsc_scale = 0; desc->dsc_flags = 0; } @@ -3623,7 +3623,7 @@ static void processMap(thread_db* tdbb, CompilerScratch* csb, MapNode* map, Form { desc->dsc_dtype = dtype_varying; desc->dsc_length = DSC_convert_to_text_length(max) + sizeof(USHORT); - desc->dsc_ttype() = ttype_ascii; + desc->setTextType(ttype_ascii); desc->dsc_scale = 0; desc->dsc_flags = 0; } diff --git a/src/jrd/Routine.cpp b/src/jrd/Routine.cpp index a514cf0b25a..a083ef2fb47 100644 --- a/src/jrd/Routine.cpp +++ b/src/jrd/Routine.cpp @@ -101,7 +101,7 @@ Format* Routine::createFormat(MemoryPool& pool, IMessageMetadata* params, bool a status.check(); desc->dsc_sub_type = params->getSubType(&status, i); status.check(); - desc->setTextType(params->getCharSet(&status, i)); + desc->setTextType(TTypeId(params->getCharSet(&status, i))); status.check(); desc->dsc_address = (UCHAR*)(IPTR) descOffset; desc->dsc_flags = (params->isNullable(&status, i) ? DSC_nullable : 0); diff --git a/src/jrd/Statement.h b/src/jrd/Statement.h index b207bc3fefe..8755c77c939 100644 --- a/src/jrd/Statement.h +++ b/src/jrd/Statement.h @@ -26,6 +26,7 @@ #include "../jrd/req.h" #include "../jrd/EngineInterface.h" #include "../jrd/HazardPtr.h" +#include "../jrd/intl.h" #include namespace Jrd { @@ -122,7 +123,7 @@ class Statement : public pool_alloc unsigned blrVersion; ULONG impureSize; // Size of impure area mutable StmtNumber id; // statement identifier - USHORT charSetId; // client character set (CS_METADATA for internal statements) + CSetId charSetId; // client character set (CS_METADATA for internal statements) Firebird::Array rpbsSetup; private: diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index 38be6b4be58..6c60e3412ef 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -218,7 +218,7 @@ void setParamsInt64(DataTypeUtilBase* dataTypeUtil, const SysFunction* function, void setParamsSecondInteger(DataTypeUtilBase* dataTypeUtil, const SysFunction* function, int argsCount, dsc** args); // helper functions for setParams -void setParamVarying(dsc* param, USHORT textType, bool condition = false); +void setParamVarying(dsc* param, TTypeId textType, bool condition = false); bool dscHasData(const dsc* param); // specific setParams functions @@ -676,7 +676,7 @@ void setParamsUnicodeVal(DataTypeUtilBase*, const SysFunction*, int argsCount, d } -void setParamVarying(dsc* param, USHORT textType, bool condition) +void setParamVarying(dsc* param, TTypeId textType, bool condition) { if (!param) return; @@ -1266,7 +1266,7 @@ bool makeBlobAppendBlob(dsc* result, const dsc* arg, bid* blob_id = nullptr) if (arg->isText()) { - USHORT ttype = arg->getTextType(); + auto ttype = arg->getTextType(); if (ttype == ttype_binary) result->makeBlob(isc_blob_untyped, ttype_binary, ptr); else @@ -4531,7 +4531,7 @@ dsc* evlGetContext(thread_db* tdbb, const SysFunction*, const NestValueArray& ar const string nameStr(MOV_make_string2(tdbb, name, ttype_none)); string resultStr; - USHORT resultType = ttype_none; + auto resultType = ttype_none; request->req_flags |= req_null; if (nameSpaceStr == SYSTEM_NAMESPACE) // Handle system variables @@ -5546,7 +5546,7 @@ dsc* evlOverlay(thread_db* tdbb, const SysFunction* function, const NestValueArr Arg::Str(function->name)); } - const USHORT resultTextType = DataTypeUtil::getResultTextType(value, placing); + const auto resultTextType = DataTypeUtil::getResultTextType(value, placing); CharSet* cs = INTL_charset_lookup(tdbb, resultTextType); MoveBuffer temp1; @@ -5713,7 +5713,7 @@ dsc* evlPad(thread_db* tdbb, const SysFunction* function, const NestValueArray& return NULL; } - const USHORT ttype = value1->getTextType(); + const auto ttype = value1->getTextType(); CharSet* cs = INTL_charset_lookup(tdbb, ttype); MoveBuffer buffer1; @@ -5891,7 +5891,7 @@ dsc* evlPosition(thread_db* tdbb, const SysFunction* function, const NestValueAr impure->vlu_desc.makeLong(0, &impure->vlu_misc.vlu_long); // we'll use the collation from the second string - const USHORT ttype = value2->getTextType(); + const auto ttype = value2->getTextType(); TextType* tt = INTL_texttype_lookup(tdbb, ttype); CharSet* cs = tt->getCharSet(); const UCHAR canonicalWidth = tt->getCanonicalWidth(); @@ -6075,7 +6075,7 @@ dsc* evlReplace(thread_db* tdbb, const SysFunction*, const NestValueArray& args, firstBlob = values[i]; } - const USHORT ttype = values[0]->getTextType(); + const auto ttype = values[0]->getTextType(); TextType* tt = INTL_texttype_lookup(tdbb, ttype); CharSet* cs = tt->getCharSet(); const UCHAR canonicalWidth = tt->getCanonicalWidth(); diff --git a/src/jrd/SystemPackages.h b/src/jrd/SystemPackages.h index cab1f703a86..9135c479f0c 100644 --- a/src/jrd/SystemPackages.h +++ b/src/jrd/SystemPackages.h @@ -25,6 +25,7 @@ #include "firebird.h" #include "../common/status.h" +#include "../common/dsc.h" #include "../common/classes/init.h" #include "../common/classes/array.h" #include "../common/classes/objects_array.h" diff --git a/src/jrd/UserManagement.cpp b/src/jrd/UserManagement.cpp index 107df898571..4ae30d42bbd 100644 --- a/src/jrd/UserManagement.cpp +++ b/src/jrd/UserManagement.cpp @@ -141,7 +141,7 @@ namespace bool present; }; - class ChangeCharset : public AutoSetRestore + class ChangeCharset : public AutoSetRestore { public: ChangeCharset(Attachment* att) diff --git a/src/jrd/blb.cpp b/src/jrd/blb.cpp index eae5aee99cc..12bd6123147 100644 --- a/src/jrd/blb.cpp +++ b/src/jrd/blb.cpp @@ -2559,12 +2559,12 @@ static void move_from_string(thread_db* tdbb, const dsc* from_desc, dsc* to_desc **************************************/ SET_TDBB (tdbb); - const UCHAR charSet = INTL_GET_CHARSET(from_desc); + const auto charSet = INTL_GET_CHARSET(from_desc); UCHAR* fromstr = NULL; MoveBuffer buffer; const int length = MOV_make_string2(tdbb, from_desc, charSet, &fromstr, buffer); - const UCHAR toCharSet = to_desc->getCharSet(); + const auto toCharSet = to_desc->getCharSet(); if ((charSet == CS_NONE || charSet == CS_BINARY || charSet == toCharSet) && toCharSet != CS_NONE && toCharSet != CS_BINARY) @@ -2678,9 +2678,9 @@ static void move_to_string(thread_db* tdbb, dsc* fromDesc, dsc* toDesc) blobAsText.dsc_dtype = dtype_text; if (DTYPE_IS_TEXT(toDesc->dsc_dtype)) - blobAsText.dsc_ttype() = toDesc->dsc_ttype(); + blobAsText.setTextType(toDesc->getTextType()); else - blobAsText.dsc_ttype() = ttype_ascii; + blobAsText.setTextType(ttype_ascii); Request* request = tdbb->getRequest(); jrd_tra* transaction = request ? request->req_transaction : tdbb->getTransaction(); @@ -2692,7 +2692,7 @@ static void move_to_string(thread_db* tdbb, dsc* fromDesc, dsc* toDesc) blb* blob = blb::open2(tdbb, transaction, (bid*) fromDesc->dsc_address, bpb.getCount(), bpb.begin()); - const CharSet* fromCharSet = INTL_charset_lookup(tdbb, fromDesc->dsc_scale); + const CharSet* fromCharSet = INTL_charset_lookup(tdbb, fromDesc->getCharSet()); const CharSet* toCharSet = INTL_charset_lookup(tdbb, INTL_GET_CHARSET(&blobAsText)); HalfStaticArray buffer; @@ -2811,7 +2811,7 @@ static void slice_callback(array_slice* arg, ULONG /*count*/, DSC* descriptors) DynamicVaryStr<1024> tmp_buffer; const USHORT tmp_len = array_desc->dsc_length; const char* p; - const USHORT len = MOV_make_string(tdbb, slice_desc, INTL_TEXT_TYPE(*array_desc), &p, + const USHORT len = MOV_make_string(tdbb, slice_desc, INTL_GET_TTYPE(array_desc), &p, tmp_buffer.getBuffer(tmp_len), tmp_len); memcpy(array_desc->dsc_address, &len, sizeof(USHORT)); memcpy(array_desc->dsc_address + sizeof(USHORT), p, (int) len); @@ -2926,7 +2926,7 @@ void blb::fromPageHeader(const Ods::blh* header) blb_max_segment = header->blh_max_segment; blb_level = header->blh_level; blb_sub_type = header->blh_sub_type; - blb_charset = header->blh_charset; + blb_charset = CSetId(header->blh_charset); #ifdef CHECK_BLOB_FIELD_ACCESS_FOR_SELECT blb_fld_id = header->blh_fld_id; #endif diff --git a/src/jrd/blb.h b/src/jrd/blb.h index a20ea572ab6..b446a7f28ed 100644 --- a/src/jrd/blb.h +++ b/src/jrd/blb.h @@ -81,7 +81,7 @@ class blb : public pool_alloc USHORT blb_flags; // Interesting stuff (see below) SSHORT blb_sub_type; // Blob's declared sub-type - UCHAR blb_charset; // Blob's charset + CSetId blb_charset; // Blob's charset // inline functions bool hasBuffer() const; diff --git a/src/jrd/btr.cpp b/src/jrd/btr.cpp index 0f91cbf2dff..97f5424a00f 100644 --- a/src/jrd/btr.cpp +++ b/src/jrd/btr.cpp @@ -1821,7 +1821,7 @@ void BTR_make_null_key(thread_db* tdbb, const index_desc* idx, temporary_key* ke null_desc.dsc_sub_type = 0; null_desc.dsc_scale = 0; null_desc.dsc_length = 1; - null_desc.dsc_ttype() = ttype_ascii; + null_desc.setTextType(ttype_ascii); null_desc.dsc_address = (UCHAR*) " "; temporary_key temp; @@ -2632,7 +2632,7 @@ static void compress(thread_db* tdbb, to.dsc_flags = 0; to.dsc_sub_type = 0; to.dsc_scale = 0; - to.dsc_ttype() = ttype_sort_key; + to.setTextType(ttype_sort_key); to.dsc_length = MIN(MAX_COLUMN_SIZE, MAX_KEY * 4); ptr = to.dsc_address = reinterpret_cast(buffer.vary_string); multiKeyLength = length = INTL_string_to_key(tdbb, itype, desc, &to, key_type); @@ -3504,7 +3504,7 @@ static DSC* eval(thread_db* tdbb, const ValueExprNode* node, DSC* temp, bool* is temp->dsc_sub_type = 0; temp->dsc_scale = 0; temp->dsc_length = 1; - temp->dsc_ttype() = ttype_ascii; + temp->setTextType(ttype_ascii); temp->dsc_address = (UCHAR*) " "; return temp; diff --git a/src/jrd/cvt.cpp b/src/jrd/cvt.cpp index 46ed9e3e890..3fc8cdffa28 100644 --- a/src/jrd/cvt.cpp +++ b/src/jrd/cvt.cpp @@ -205,7 +205,7 @@ UCHAR CVT_get_numeric(const UCHAR* string, const USHORT length, SSHORT* scale, v MOVE_CLEAR(&desc, sizeof(desc)); desc.dsc_dtype = dtype_text; - desc.dsc_ttype() = ttype_ascii; + desc.setTextType(ttype_ascii); desc.dsc_length = length; desc.dsc_address = const_cast(string); // The above line allows the assignment, but "string" is treated as const @@ -456,9 +456,9 @@ ISC_TIMESTAMP_TZ CVT_get_timestamp_tz(const dsc* desc) Firebird::GlobalPtr EngineCallbacks::instance; -bool EngineCallbacks::transliterate(const dsc* from, dsc* to, CHARSET_ID& charset2) +bool EngineCallbacks::transliterate(const dsc* from, dsc* to, CSetId& charset2) { - CHARSET_ID charset1; + CSetId charset1; if (INTL_TTYPE(from) == ttype_dynamic) charset1 = INTL_charset(NULL, INTL_TTYPE(from)); else @@ -487,7 +487,7 @@ bool EngineCallbacks::transliterate(const dsc* from, dsc* to, CHARSET_ID& charse } -CharSet* EngineCallbacks::getToCharset(CHARSET_ID charSetId) +CharSet* EngineCallbacks::getToCharset(CSetId charSetId) { thread_db* tdbb = JRD_get_thread_data(); return INTL_charset_lookup(tdbb, charSetId); @@ -501,7 +501,7 @@ void EngineCallbacks::validateData(CharSet* toCharSet, SLONG length, const UCHAR } -ULONG EngineCallbacks::validateLength(CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, +ULONG EngineCallbacks::validateLength(CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start, const USHORT size) { fb_assert(charSet); @@ -531,7 +531,7 @@ ULONG EngineCallbacks::validateLength(CharSet* charSet, CHARSET_ID charSetId, UL } -ULONG TruncateCallbacks::validateLength(CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, +ULONG TruncateCallbacks::validateLength(CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start, const USHORT size) { fb_assert(charSet); @@ -567,7 +567,7 @@ ULONG TruncateCallbacks::validateLength(CharSet* charSet, CHARSET_ID charSetId, } -CHARSET_ID EngineCallbacks::getChid(const dsc* to) +CSetId EngineCallbacks::getChid(const dsc* to) { if (INTL_TTYPE(to) == ttype_dynamic) return INTL_charset(NULL, INTL_TTYPE(to)); diff --git a/src/jrd/cvt2.cpp b/src/jrd/cvt2.cpp index 6ed5ed14e29..c427b7914c2 100644 --- a/src/jrd/cvt2.cpp +++ b/src/jrd/cvt2.cpp @@ -378,11 +378,11 @@ int CVT2_compare(const dsc* arg1, const dsc* arg2, Firebird::DecimalStatus decSt */ SET_TDBB(tdbb); - CHARSET_ID charset1 = INTL_TTYPE(arg1); + CSetId charset1 = INTL_TTYPE(arg1); if (charset1 == ttype_dynamic) charset1 = INTL_charset(tdbb, charset1); - CHARSET_ID charset2 = INTL_TTYPE(arg2); + CSetId charset2 = INTL_TTYPE(arg2); if (charset2 == ttype_dynamic) charset2 = INTL_charset(tdbb, charset2); @@ -398,7 +398,7 @@ int CVT2_compare(const dsc* arg1, const dsc* arg2, Firebird::DecimalStatus decSt UCHAR* p1 = NULL; UCHAR* p2 = NULL; - USHORT t1, t2; // unused later + TTypeId t1, t2; // unused later USHORT length = CVT_get_string_ptr(arg1, &t1, &p1, NULL, 0, decSt); USHORT length2 = CVT_get_string_ptr(arg2, &t2, &p2, NULL, 0, decSt); @@ -624,7 +624,7 @@ int CVT2_compare(const dsc* arg1, const dsc* arg2, Firebird::DecimalStatus decSt if (arg2->isText()) { UCHAR* p = NULL; - USHORT ttype; + TTypeId ttype; const USHORT length = CVT_get_string_ptr(arg2, &ttype, &p, NULL, 0, decSt); // Compare DBKEY with a compatible binary string with respect to @@ -707,7 +707,6 @@ int CVT2_blob_compare(const dsc* arg1, const dsc* arg2, DecimalStatus decSt) **************************************/ SLONG l1, l2; - USHORT ttype2; int ret_val = 0; thread_db* tdbb = NULL; @@ -718,9 +717,9 @@ int CVT2_blob_compare(const dsc* arg1, const dsc* arg2, DecimalStatus decSt) if (arg1->dsc_dtype != dtype_blob) ERR_post(Arg::Gds(isc_wish_list) << Arg::Gds(isc_datnotsup)); - USHORT ttype1; + TTypeId ttype1, ttype2; if (arg1->dsc_sub_type == isc_blob_text) - ttype1 = arg1->dsc_blob_ttype(); // Load blob character set and collation + ttype1 = arg1->getTextType(); // Load blob character set and collation else ttype1 = ttype_binary; @@ -743,7 +742,7 @@ int CVT2_blob_compare(const dsc* arg1, const dsc* arg2, DecimalStatus decSt) } if (arg2->dsc_sub_type == isc_blob_text) - ttype2 = arg2->dsc_blob_ttype(); // Load blob character set and collation + ttype2 = arg2->getTextType(); // Load blob character set and collation else ttype2 = ttype_binary; @@ -831,7 +830,7 @@ int CVT2_blob_compare(const dsc* arg1, const dsc* arg2, DecimalStatus decSt) // The second parameter should be a string. if (arg2->dsc_dtype <= dtype_varying) { - if ((ttype2 = arg2->dsc_ttype()) != ttype_binary) + if ((ttype2 = arg2->getTextType()) != ttype_binary) ttype2 = ttype1; } else @@ -875,7 +874,7 @@ int CVT2_blob_compare(const dsc* arg1, const dsc* arg2, DecimalStatus decSt) } -USHORT CVT2_make_string2(const dsc* desc, USHORT to_interp, UCHAR** address, MoveBuffer& temp, DecimalStatus decSt) +USHORT CVT2_make_string2(const dsc* desc, TTypeId to_interp, UCHAR** address, MoveBuffer& temp, DecimalStatus decSt) { /************************************** * @@ -891,7 +890,7 @@ USHORT CVT2_make_string2(const dsc* desc, USHORT to_interp, UCHAR** address, Mov **************************************/ UCHAR* from_buf; USHORT from_len; - USHORT from_interp; + TTypeId from_interp; fb_assert(desc != NULL); fb_assert(address != NULL); @@ -929,8 +928,8 @@ USHORT CVT2_make_string2(const dsc* desc, USHORT to_interp, UCHAR** address, Mov } thread_db* tdbb = JRD_get_thread_data(); - const USHORT cs1 = INTL_charset(tdbb, to_interp); - const USHORT cs2 = INTL_charset(tdbb, from_interp); + const auto cs1 = INTL_charset(tdbb, to_interp); + const auto cs2 = INTL_charset(tdbb, from_interp); if (cs1 == cs2) { *address = from_buf; diff --git a/src/jrd/cvt2_proto.h b/src/jrd/cvt2_proto.h index c04f62439c6..eea767ceb1f 100644 --- a/src/jrd/cvt2_proto.h +++ b/src/jrd/cvt2_proto.h @@ -25,12 +25,13 @@ #define JRD_CVT2_PROTO_H #include "../jrd/jrd.h" +#include "../jrd/intl.h" extern const BYTE CVT2_compare_priority[]; bool CVT2_get_binary_comparable_desc(dsc*, const dsc*, const dsc*); int CVT2_compare(const dsc*, const dsc*, Firebird::DecimalStatus); int CVT2_blob_compare(const dsc*, const dsc*, Firebird::DecimalStatus); -USHORT CVT2_make_string2(const dsc*, USHORT, UCHAR**, Jrd::MoveBuffer&, Firebird::DecimalStatus); +USHORT CVT2_make_string2(const dsc*, TTypeId, UCHAR**, Jrd::MoveBuffer&, Firebird::DecimalStatus); #endif // JRD_CVT2_PROTO_H diff --git a/src/jrd/cvt_proto.h b/src/jrd/cvt_proto.h index a8a5fb32ce3..b856a615438 100644 --- a/src/jrd/cvt_proto.h +++ b/src/jrd/cvt_proto.h @@ -53,11 +53,11 @@ namespace Jrd } public: - virtual bool transliterate(const dsc* from, dsc* to, CHARSET_ID&); - virtual CHARSET_ID getChid(const dsc* d); - virtual CharSet* getToCharset(CHARSET_ID charset2); + virtual bool transliterate(const dsc* from, dsc* to, CSetId&); + virtual CSetId getChid(const dsc* d); + virtual CharSet* getToCharset(CSetId charset2); virtual void validateData(CharSet* toCharset, SLONG length, const UCHAR* q); - virtual ULONG validateLength(CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, + virtual ULONG validateLength(CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start, const USHORT size); virtual SLONG getLocalDate(); virtual ISC_TIMESTAMP getCurrentGmtTimeStamp(); @@ -76,7 +76,7 @@ namespace Jrd { } - virtual ULONG validateLength(CharSet* charSet, CHARSET_ID charSetId, ULONG length, const UCHAR* start, + virtual ULONG validateLength(CharSet* charSet, CSetId charSetId, ULONG length, const UCHAR* start, const USHORT size); private: @@ -89,7 +89,7 @@ inline void CVT_move(const dsc* from, dsc* to, Firebird::DecimalStatus decSt) CVT_move_common(from, to, decSt, &Jrd::EngineCallbacks::instance); } -inline USHORT CVT_get_string_ptr(const dsc* desc, USHORT* ttype, UCHAR** address, +inline USHORT CVT_get_string_ptr(const dsc* desc, TTypeId* ttype, UCHAR** address, vary* temp, USHORT length, Firebird::DecimalStatus decSt) { return CVT_get_string_ptr_common(desc, ttype, address, temp, length, decSt, diff --git a/src/jrd/dflt.h b/src/jrd/dflt.h index 2e2181bcea6..c20323a7259 100644 --- a/src/jrd/dflt.h +++ b/src/jrd/dflt.h @@ -24,6 +24,8 @@ #ifndef JRD_DFLT_H #define JRD_DFLT_H +#include "firebird/impl/blr.h" + /* This file contains the blr for the default values for fields in system relations. The GDEF source for these fields is in DFLT.GDL in the JRD component. When modifying a system field default value, diff --git a/src/jrd/dfw.epp b/src/jrd/dfw.epp index bdfef949c7c..7fdbc3b170c 100644 --- a/src/jrd/dfw.epp +++ b/src/jrd/dfw.epp @@ -153,7 +153,7 @@ using namespace Jrd; using namespace Firebird; USHORT DFW_assign_index_type(thread_db* tdbb, const MetaName& name, SSHORT field_type, - SSHORT ttype) + TTypeId ttype) { /************************************** * diff --git a/src/jrd/dfw_proto.h b/src/jrd/dfw_proto.h index 1681e9d727b..e5cc457334b 100644 --- a/src/jrd/dfw_proto.h +++ b/src/jrd/dfw_proto.h @@ -24,14 +24,15 @@ #ifndef JRD_DFW_PROTO_H #define JRD_DFW_PROTO_H -#include "../jrd/btr.h" // defines SelectivityList +#include "../jrd/btr.h" // defines SelectivityList +#include "../jrd/intl.h" // defined TTypeId namespace Jrd { enum dfw_t; } -USHORT DFW_assign_index_type(Jrd::thread_db*, const Jrd::MetaName&, SSHORT, SSHORT); +USHORT DFW_assign_index_type(Jrd::thread_db*, const Jrd::MetaName&, SSHORT, TTypeId); void DFW_delete_deferred(Jrd::jrd_tra*, SavNumber); Firebird::SortedArray& DFW_get_ids(Jrd::DeferredWork* work); void DFW_merge_work(Jrd::jrd_tra*, SavNumber, SavNumber); diff --git a/src/jrd/evl.cpp b/src/jrd/evl.cpp index b9335ee36d5..b13c178daf2 100644 --- a/src/jrd/evl.cpp +++ b/src/jrd/evl.cpp @@ -565,7 +565,7 @@ void EVL_make_value(thread_db* tdbb, const dsc* desc, impure_value* value, Memor VaryStr temp; UCHAR* address; - USHORT ttype; + TTypeId ttype; // Get string. If necessary, get_string will convert the string into a // temporary buffer. Since this will always be the result of a conversion, diff --git a/src/jrd/filters.cpp b/src/jrd/filters.cpp index c8fec42111d..763162ec772 100644 --- a/src/jrd/filters.cpp +++ b/src/jrd/filters.cpp @@ -804,7 +804,7 @@ ISC_STATUS filter_transliterate_text(USHORT action, BlobControl* control) BlobControl* source; ISC_STATUS status; ULONG err_position; - SSHORT source_cs, dest_cs; + TTypeId source_cs, dest_cs; USHORT result_length; switch (action) @@ -818,8 +818,8 @@ ISC_STATUS filter_transliterate_text(USHORT action, BlobControl* control) source = control->ctl_handle; control->ctl_number_segments = source->ctl_number_segments; - source_cs = control->ctl_from_sub_type; - dest_cs = control->ctl_to_sub_type; + source_cs = TTypeId(control->ctl_from_sub_type); + dest_cs = TTypeId(control->ctl_to_sub_type); aux = (ctlaux*) gds__alloc((SLONG) sizeof(*aux)); // FREE: on isc_blob_filter_close in this routine diff --git a/src/jrd/grant.epp b/src/jrd/grant.epp index 08e54c975da..48d5ede0cc3 100644 --- a/src/jrd/grant.epp +++ b/src/jrd/grant.epp @@ -245,7 +245,7 @@ static void define_default_class(thread_db* tdbb, desc.dsc_dtype = dtype_text; desc.dsc_sub_type = 0; desc.dsc_scale = 0; - desc.dsc_ttype() = ttype_metadata; + desc.setTextType(ttype_metadata); desc.dsc_address = (UCHAR *) relation_name; desc.dsc_length = static_cast(strlen(relation_name)); DFW_post_work(transaction, dfw_scan_relation, &desc, 0); @@ -841,7 +841,7 @@ static SecurityClass::flags_t save_field_privileges(thread_db* tdbb, desc.dsc_dtype = dtype_text; desc.dsc_sub_type = 0; desc.dsc_scale = 0; - desc.dsc_ttype() = ttype_metadata; + desc.setTextType(ttype_metadata); desc.dsc_address = (UCHAR *) relation_name; desc.dsc_length = static_cast(strlen(relation_name)); DFW_post_work(transaction, dfw_update_format, &desc, 0); diff --git a/src/jrd/ini.epp b/src/jrd/ini.epp index 466e8656a39..ba6b936663f 100644 --- a/src/jrd/ini.epp +++ b/src/jrd/ini.epp @@ -224,7 +224,7 @@ namespace return formatNumber; } - bool getCharsetByTextType(SSHORT& charSet, const USHORT subType) + bool getCharsetByTextType(CSetId& charSet, const USHORT subType) { switch (subType) { @@ -1076,8 +1076,9 @@ void INI_init(thread_db* tdbb) if (desc->isText()) { - if (!getCharsetByTextType(desc->dsc_sub_type, gfield->gfld_sub_type)) - desc->dsc_sub_type = CS_NONE; + CSetId cs = CS_NONE; + getCharsetByTextType(cs, gfield->gfld_sub_type); + desc->setTextType(cs); } else desc->dsc_sub_type = gfield->gfld_sub_type; @@ -1198,9 +1199,8 @@ void INI_init_dsql(thread_db* tdbb, dsql_dbb* database) dsql_intlsym* csSymbol = FB_NEW_POOL(database->dbb_pool) dsql_intlsym(database->dbb_pool); csSymbol->intlsym_name = csDef->name; csSymbol->intlsym_charset_id = csDef->id; - csSymbol->intlsym_collate_id = 0; - csSymbol->intlsym_ttype = - INTL_CS_COLL_TO_TTYPE(csSymbol->intlsym_charset_id, csSymbol->intlsym_collate_id); + csSymbol->intlsym_collate_id = CollId(0); + csSymbol->intlsym_ttype = TTypeId(csSymbol->intlsym_charset_id, csSymbol->intlsym_collate_id); csSymbol->intlsym_bytes_per_char = csDef->maxBytes; // Mark the charset as invalid to reload it ASAP. This is done because we cannot know here @@ -1222,8 +1222,7 @@ void INI_init_dsql(thread_db* tdbb, dsql_dbb* database) colSymbol->intlsym_flags = 0; colSymbol->intlsym_charset_id = csDef->id; colSymbol->intlsym_collate_id = colDef->collationId; - colSymbol->intlsym_ttype = - INTL_CS_COLL_TO_TTYPE(colSymbol->intlsym_charset_id, colSymbol->intlsym_collate_id); + colSymbol->intlsym_ttype = TTypeId(colSymbol->intlsym_charset_id, colSymbol->intlsym_collate_id); colSymbol->intlsym_bytes_per_char = csDef->maxBytes; database->dbb_collations.put(colDef->name, colSymbol); diff --git a/src/jrd/ini.h b/src/jrd/ini.h index 9cc22cf22f0..a06046c797f 100644 --- a/src/jrd/ini.h +++ b/src/jrd/ini.h @@ -36,6 +36,7 @@ #include "../jrd/dflt.h" #include "../jrd/constants.h" #include "../jrd/ods.h" +#include "../common/dsc.h" //****************************** // names.h diff --git a/src/jrd/intl.cpp b/src/jrd/intl.cpp index d9fdc12585e..5a2159e8967 100644 --- a/src/jrd/intl.cpp +++ b/src/jrd/intl.cpp @@ -134,7 +134,7 @@ using namespace Firebird; static bool allSpaces(CharSet*, const BYTE*, ULONG, ULONG); //static int blocking_ast_collation(void* ast_object); -static void pad_spaces(thread_db*, CHARSET_ID, BYTE *, ULONG); +static void pad_spaces(thread_db*, CSetId, BYTE *, ULONG); static GlobalPtr createCollationMtx; @@ -171,7 +171,7 @@ static int blocking_ast_charset(void* ast_object) // Classes and structures used internally to this file and intl implementation -CharSetContainer* CharSetContainer::lookupCharset(thread_db* tdbb, USHORT ttype) +CharSetContainer* CharSetContainer::lookupCharset(thread_db* tdbb, TTypeId ttype) { /************************************** * @@ -195,7 +195,7 @@ CharSetContainer* CharSetContainer::lookupCharset(thread_db* tdbb, USHORT ttype) **************************************/ SET_TDBB(tdbb); - USHORT id = TTYPE_TO_CHARSET(ttype); + auto id = CSetId(ttype); if (id == CS_dynamic) id = tdbb->getCharSet(); @@ -204,7 +204,7 @@ CharSetContainer* CharSetContainer::lookupCharset(thread_db* tdbb, USHORT ttype) // Lookup a system character set without looking in the database. -bool CharSetContainer::lookupInternalCharSet(USHORT id, SubtypeInfo* info) +bool CharSetContainer::lookupInternalCharSet(CSetId id, SubtypeInfo* info) { if (id == CS_UTF16) { @@ -276,12 +276,13 @@ Lock* CharSetContainer::makeLock(thread_db* tdbb, MemoryPool& p) return FB_NEW_RPT(p, 0) Lock(tdbb, sizeof(SLONG), LCK_tt_exist, nullptr, blocking_ast_charset); } -CharSetContainer::CharSetContainer(thread_db* tdbb, MemoryPool& p, USHORT cs_id, Lock* lock) +CharSetContainer::CharSetContainer(thread_db* tdbb, MemoryPool& p, MetaId id, Lock* lock) : PermanentStorage(p), cs(NULL), cs_lock(lock) { SubtypeInfo info; + CSetId cs_id(id); if (!(lookupInternalCharSet(cs_id, &info) || MET_get_char_coll_subtype_info(tdbb, cs_id, &info))) ERR_post(Arg::Gds(isc_text_subtype) << Arg::Num(cs_id)); @@ -304,7 +305,7 @@ CharSetContainer::CharSetContainer(thread_db* tdbb, MemoryPool& p, USHORT cs_id, cs_lock->lck_object = this; } -CsConvert CharSetContainer::lookupConverter(thread_db* tdbb, CHARSET_ID toCsId) +CsConvert CharSetContainer::lookupConverter(thread_db* tdbb, CSetId toCsId) { if (toCsId == CS_UTF16) return CsConvert(cs->getStruct(), NULL); @@ -316,74 +317,24 @@ CsConvert CharSetContainer::lookupConverter(thread_db* tdbb, CHARSET_ID toCsId) return CsConvert(cs->getStruct(), toCs->getStruct()); } -Collation* CharSetVers::lookupCollation(thread_db* tdbb, MetaId tt_id) +Collation* CharSetVers::getCollation(TTypeId tt_id) { - const USHORT id = TTYPE_TO_COLLATION(tt_id); -/* - if (Collation* coll = charset_collations[id]) - return coll; - - CheckoutLockGuard guard(tdbb, createCollationMtx, FB_FUNCTION); // do we need it ? - - SubtypeInfo info; - if (MET_get_char_coll_subtype_info(tdbb, tt_id, &info)) - { - CharSet* charset = perm->getCharSet(); - - if (TTYPE_TO_CHARSET(tt_id) != CS_METADATA) - { - Firebird::UCharBuffer specificAttributes; - ULONG size = info.specificAttributes.getCount() * charset->maxBytesPerChar(); - - size = INTL_convert_bytes(tdbb, TTYPE_TO_CHARSET(tt_id), - specificAttributes.getBuffer(size), size, - CS_METADATA, info.specificAttributes.begin(), - info.specificAttributes.getCount(), ERR_post); - specificAttributes.shrink(size); - info.specificAttributes = specificAttributes; - } - - Database* const dbb = tdbb->getDatabase(); - AutoPtr tt = FB_NEW_POOL(*dbb->dbb_permanent) texttype; - memset(tt, 0, sizeof(texttype)); - - INTL_lookup_texttype(tt, &info); - - if (charset_collations.getCount() <= id) - charset_collations.grow(id + 1); - - fb_assert((tt->texttype_canonical_width == 0 && tt->texttype_fn_canonical == NULL) || - (tt->texttype_canonical_width != 0 && tt->texttype_fn_canonical != NULL)); - - if (tt->texttype_canonical_width == 0) - { - if (charset->isMultiByte()) - tt->texttype_canonical_width = sizeof(ULONG); // UTF-32 - else - { - tt->texttype_canonical_width = charset->minBytesPerChar(); - // canonical is equal to string, then TEXTTYPE_DIRECT_MATCH can be turned on - tt->texttype_flags |= TEXTTYPE_DIRECT_MATCH; - } - } - - Collation* collation = Collation::createInstance(*dbb->dbb_permanent, tt_id, - tt, info.attributes, charset); - collation->name = info.collationName; - - tt.release(); - - charset_collations[id] = collation; - } - else - ERR_post(Arg::Gds(isc_text_subtype) << Arg::Num(tt_id)); -*/ + const auto id = CollId(tt_id); if (!charset_collations[id]) ERR_post(Arg::Gds(isc_text_subtype) << Arg::Num(tt_id)); return charset_collations[id]; } +Collation* CharSetVers::getCollation(MetaName name) +{ + FB_SIZE_T pos; + if (charset_collations.find([name](Collation* col) { return col->name == name; }, pos)) + return charset_collations[pos]; + + ERR_post(Arg::Gds(isc_text_subtype) << name); +} + /* void CharSetContainer::unloadCollation(thread_db* tdbb, USHORT tt_id) { @@ -469,7 +420,7 @@ void INTL_adjust_text_descriptor(thread_db* tdbb, dsc* desc) { SET_TDBB(tdbb); - USHORT ttype = INTL_TTYPE(desc); + auto ttype = desc->getTextType(); CharSet* charSet = INTL_charset_lookup(tdbb, ttype); @@ -485,7 +436,7 @@ void INTL_adjust_text_descriptor(thread_db* tdbb, dsc* desc) } -CHARSET_ID INTL_charset(thread_db* tdbb, USHORT ttype) +CSetId INTL_charset(thread_db* tdbb, TTypeId ttype) { /************************************** * @@ -498,20 +449,13 @@ CHARSET_ID INTL_charset(thread_db* tdbb, USHORT ttype) * **************************************/ - switch (ttype) + if (ttype == ttype_dynamic) { - case ttype_none: - return (CS_NONE); - case ttype_ascii: - return (CS_ASCII); - case ttype_binary: - return (CS_BINARY); - case ttype_dynamic: SET_TDBB(tdbb); - return (tdbb->getCharSet()); - default: - return (TTYPE_TO_CHARSET(ttype)); + return tdbb->getCharSet(); } + + return CSetId(ttype); } @@ -539,23 +483,23 @@ int INTL_compare(thread_db* tdbb, const dsc* pText1, const dsc* pText2, ErrorFun // trailing spaces in strings are ignored for comparision UCHAR* p1; - USHORT t1; + TTypeId t1; ULONG length1 = CVT_get_string_ptr(pText1, &t1, &p1, NULL, 0, tdbb->getAttachment()->att_dec_status, err); UCHAR* p2; - USHORT t2; + TTypeId t2; ULONG length2 = CVT_get_string_ptr(pText2, &t2, &p2, NULL, 0, tdbb->getAttachment()->att_dec_status, err); // YYY - by SQL II compare_type must be explicit in the // SQL statement if there is any doubt - USHORT compare_type = MAX(t1, t2); // YYY + TTypeId compare_type = MAX(t1, t2); // YYY HalfStaticArray buffer; if (t1 != t2) { - CHARSET_ID cs1 = INTL_charset(tdbb, t1); - CHARSET_ID cs2 = INTL_charset(tdbb, t2); + CSetId cs1 = INTL_charset(tdbb, t1); + CSetId cs2 = INTL_charset(tdbb, t2); if (cs1 != cs2) { if (compare_type != t2) @@ -596,10 +540,10 @@ int INTL_compare(thread_db* tdbb, const dsc* pText1, const dsc* pText2, ErrorFun ULONG INTL_convert_bytes(thread_db* tdbb, - CHARSET_ID dest_type, + CSetId dest_type, BYTE* dest_ptr, const ULONG dest_len, - CHARSET_ID src_type, + CSetId src_type, const BYTE* src_ptr, const ULONG src_len, ErrorFunction err) @@ -629,21 +573,21 @@ ULONG INTL_convert_bytes(thread_db* tdbb, fb_assert(src_type != dest_type); fb_assert(err != NULL); - dest_type = INTL_charset(tdbb, dest_type); - src_type = INTL_charset(tdbb, src_type); + auto destCs = INTL_charset(tdbb, dest_type); + auto srcCs = INTL_charset(tdbb, src_type); const UCHAR* const start_dest_ptr = dest_ptr; - if (dest_type == CS_BINARY || dest_type == CS_NONE || - src_type == CS_BINARY || src_type == CS_NONE) + if (destCs == CS_BINARY || destCs == CS_NONE || + srcCs == CS_BINARY || srcCs == CS_NONE) { // See if we just need a length estimate if (dest_ptr == NULL) return (src_len); - if (dest_type != CS_BINARY && dest_type != CS_NONE) + if (destCs != CS_BINARY && destCs != CS_NONE) { - CharSet* toCharSet = INTL_charset_lookup(tdbb, dest_type); + CharSet* toCharSet = INTL_charset_lookup(tdbb, destCs); if (!toCharSet->wellFormed(src_len, src_ptr)) err(Arg::Gds(isc_malformed_string)); @@ -659,7 +603,7 @@ ULONG INTL_convert_bytes(thread_db* tdbb, // See if only space characters are remaining len = src_len - MIN(dest_len, src_len); - if (len == 0 || allSpaces(INTL_charset_lookup(tdbb, src_type), src_ptr, len, 0)) + if (len == 0 || allSpaces(INTL_charset_lookup(tdbb, srcCs), src_ptr, len, 0)) return dest_ptr - start_dest_ptr; err(Arg::Gds(isc_arith_except) << Arg::Gds(isc_string_truncation) << @@ -670,7 +614,7 @@ ULONG INTL_convert_bytes(thread_db* tdbb, // character sets are known to be different // Do we know an object from cs1 to cs2? - CsConvert cs_obj = INTL_convert_lookup(tdbb, dest_type, src_type); + CsConvert cs_obj = INTL_convert_lookup(tdbb, destCs, srcCs); return cs_obj.convert(src_len, src_ptr, dest_len, dest_ptr, NULL, true); } @@ -678,7 +622,7 @@ ULONG INTL_convert_bytes(thread_db* tdbb, } -CsConvert INTL_convert_lookup(thread_db* tdbb, CHARSET_ID to_cs, CHARSET_ID from_cs) +CsConvert INTL_convert_lookup(thread_db* tdbb, CSetId to_cs, CSetId from_cs) { /************************************** * @@ -730,15 +674,15 @@ void INTL_convert_string(dsc* to, const dsc* from, Firebird::Callbacks* cb) fb_assert(from != NULL); fb_assert(IS_TEXT(to) && IS_TEXT(from)); - const CHARSET_ID from_cs = INTL_charset(tdbb, INTL_TTYPE(from)); - const CHARSET_ID to_cs = INTL_charset(tdbb, INTL_TTYPE(to)); + const CSetId from_cs = INTL_charset(tdbb, INTL_TTYPE(from)); + const CSetId to_cs = INTL_charset(tdbb, INTL_TTYPE(to)); UCHAR* p = to->dsc_address; // Must convert dtype(cstring,text,vary) and ttype(ascii,binary,..intl..) UCHAR* from_ptr; - USHORT from_type; + TTypeId from_type; const USHORT from_len = CVT_get_string_ptr(from, &from_type, &from_ptr, NULL, 0, tdbb->getAttachment()->att_dec_status, cb->err); @@ -873,11 +817,11 @@ bool INTL_data_or_binary(const dsc* pText) * **************************************/ - return (INTL_data(pText) || (pText->dsc_ttype() == ttype_binary)); + return (INTL_data(pText) || (pText->getTextType() == ttype_binary)); } -bool INTL_defined_type(thread_db* tdbb, USHORT t_type) +bool INTL_defined_type(thread_db* tdbb, TTypeId t_type) { /************************************** * @@ -930,7 +874,7 @@ USHORT INTL_key_length(thread_db* tdbb, USHORT idxType, USHORT iLength) fb_assert(idxType >= idx_first_intl_string); - const USHORT ttype = INTL_INDEX_TO_TEXT(idxType); + const auto ttype = INTL_INDEX_TO_TEXT(idxType); USHORT key_length; if (ttype <= ttype_last_internal) @@ -953,7 +897,7 @@ USHORT INTL_key_length(thread_db* tdbb, USHORT idxType, USHORT iLength) } -CharSet* INTL_charset_lookup(thread_db* tdbb, USHORT parm1) +CharSet* INTL_charset_lookup(thread_db* tdbb, CSetId parm1) { /************************************** * @@ -980,7 +924,7 @@ CharSet* INTL_charset_lookup(thread_db* tdbb, USHORT parm1) } -Collation* INTL_texttype_lookup(thread_db* tdbb, MetaId parm1) +Collation* INTL_texttype_lookup(thread_db* tdbb, TTypeId parm1) { /************************************** * @@ -1005,11 +949,11 @@ Collation* INTL_texttype_lookup(thread_db* tdbb, MetaId parm1) SET_TDBB(tdbb); if (parm1 == ttype_dynamic) - parm1 = MAP_CHARSET_TO_TTYPE(tdbb->getCharSet()); + parm1 = tdbb->getCharSet(); - auto* vers = MetadataCache::lookup_charset(tdbb, TTYPE_TO_CHARSET(parm1)); + auto* vers = MetadataCache::lookup_charset(tdbb, parm1, CacheFlag::AUTOCREATE); - return vers ? vers->lookupCollation(tdbb, parm1) : nullptr; + return vers ? vers->getCollation(parm1) : nullptr; } @@ -1085,7 +1029,7 @@ void INTL_pad_spaces(thread_db* tdbb, DSC* type, UCHAR* string, ULONG length) fb_assert(IS_TEXT(type)); fb_assert(string != NULL); - const USHORT charset = INTL_charset(tdbb, type->dsc_ttype()); + const auto charset = INTL_charset(tdbb, type->getTextType()); pad_spaces(tdbb, charset, string, length); } @@ -1121,7 +1065,7 @@ USHORT INTL_string_to_key(thread_db* tdbb, fb_assert(pByte->dsc_dtype == dtype_text); UCHAR pad_char; - USHORT ttype; + TTypeId ttype; switch (idxType) { @@ -1273,7 +1217,7 @@ static int blocking_ast_collation(void* ast_object) */ -static void pad_spaces(thread_db* tdbb, CHARSET_ID charset, BYTE* ptr, ULONG len) +static void pad_spaces(thread_db* tdbb, CSetId charset, BYTE* ptr, ULONG len) { /* byte count */ /************************************** * diff --git a/src/jrd/intl.h b/src/jrd/intl.h index 8a6ec721ae6..f9f81133643 100644 --- a/src/jrd/intl.h +++ b/src/jrd/intl.h @@ -24,7 +24,53 @@ #ifndef JRD_INTL_H #define JRD_INTL_H -#include "../common/dsc.h" +// Maps a Character_set_id & collation_id to a text_type (driver ID) + +struct TTypeId; +struct CSetId; +struct CollId; + +struct IdStorage +{ + constexpr explicit IdStorage(USHORT id) : val(id) { } + + constexpr operator USHORT() const { return val; } + bool operator==(const IdStorage& id) const { return val == id.val; } + bool operator!=(const IdStorage& id) const { return val != id.val; } + + USHORT val; +}; + +struct TTypeId : public IdStorage +{ + TTypeId() : IdStorage(0) { } + explicit TTypeId(USHORT id) : IdStorage(id & 0xFF) { } + constexpr TTypeId(CSetId id); + TTypeId(CSetId cs, CollId col); +}; + +struct CSetId : public IdStorage +{ + CSetId() : IdStorage(0) { } + constexpr explicit CSetId(USHORT id) : IdStorage(id & 0xFF) { } + constexpr CSetId(TTypeId tt) : IdStorage(tt.val & 0xFF) { } +}; + +struct CollId : public IdStorage +{ + CollId() : IdStorage(0) { } + constexpr explicit CollId(USHORT id) : IdStorage(id) { } + constexpr CollId(TTypeId tt) : IdStorage(tt.val >> 8) { } +}; + +inline TTypeId::TTypeId(CSetId cs, CollId col) + : IdStorage((col.val << 8) | (cs.val & 0xFF)) +{ } + +inline constexpr TTypeId::TTypeId(CSetId cs) + : IdStorage(cs.val & 0xFF) +{ } + #include "../intl/charsets.h" #define ASCII_SPACE 32 // ASCII code for space @@ -49,13 +95,13 @@ // text type definitions -#define ttype_none CS_NONE // 0 -#define ttype_ascii CS_ASCII // 2 -#define ttype_binary CS_BINARY // 1 -#define ttype_utf8 CS_UTF8 // 4 -#define ttype_last_internal CS_UTF8 // 4 +#define ttype_none TTypeId(CS_NONE) // 0 +#define ttype_binary TTypeId(CS_BINARY) // 1 +#define ttype_ascii TTypeId(CS_ASCII) // 2 +#define ttype_utf8 TTypeId(CS_UTF8) // 4 +#define ttype_last_internal ttype_utf8 // 4 -#define ttype_dynamic CS_dynamic // use att_charset +#define ttype_dynamic TTypeId(CS_dynamic) // use att_charset #define ttype_sort_key ttype_binary #define ttype_metadata ttype_utf8 @@ -68,41 +114,27 @@ #define COLLATE_NONE 0 // No special collation, use codepoint order - -#define INTL_ASSIGN_DSC(dsc, cs, coll) \ - { (dsc)->dsc_sub_type = (SSHORT) ((coll) << 8 | (cs)); } - -#define INTL_GET_TTYPE(dsc) \ - ((dsc)->dsc_sub_type) - -#define INTL_GET_CHARSET(dsc) ((UCHAR)((dsc)->dsc_sub_type & 0x00FF)) -#define INTL_GET_COLLATE(dsc) ((UCHAR)((dsc)->dsc_sub_type >> 8)) +/* ????????????????? +inline void INTL_ASSIGN_DSC(dsc* desc, CSetId cs, CollId coll) +{ + desc->setTextType(TTypeId(cs, coll)); +} +*/ +#define INTL_GET_TTYPE(dsc) ((dsc)->getTextType()) +#define INTL_GET_CHARSET(dsc) ((dsc)->getCharSet()) +#define INTL_GET_COLLATE(dsc) ((dsc)->getCollation()) // Define tests for international data -#define INTL_TTYPE(desc) ((desc)->dsc_ttype()) - -#define INTERNAL_TTYPE(d) (((USHORT)((d)->dsc_ttype())) <= ttype_last_internal) +#define INTL_TTYPE(desc) ((desc)->getTextType()) -#define IS_INTL_DATA(d) ((d)->dsc_dtype <= dtype_any_text && \ - (((USHORT)((d)->dsc_ttype())) > ttype_last_internal)) +#define INTL_SET_TTYPE(desc, a) ((desc)->setTextType((a))) -inline USHORT INTL_TEXT_TYPE(const dsc& desc) -{ - if (DTYPE_IS_TEXT(desc.dsc_dtype)) - return INTL_TTYPE(&desc); - - if (desc.dsc_dtype == dtype_blob || desc.dsc_dtype == dtype_quad) - { - if (desc.dsc_sub_type == isc_blob_text) - return desc.dsc_blob_ttype(); +#define INTERNAL_TTYPE(d) (((USHORT)((d)->getTextType())) <= ttype_last_internal) - return ttype_binary; - } - - return ttype_ascii; -} +#define IS_INTL_DATA(d) ((d)->getTextType() <= dtype_any_text && \ + (((USHORT)((d)->getTextType())) > ttype_last_internal)) #define INTL_DYNAMIC_CHARSET(desc) (INTL_GET_CHARSET(desc) == CS_dynamic) @@ -114,7 +146,7 @@ inline USHORT INTL_TEXT_TYPE(const dsc& desc) * 2) As a CHARACTER_SET_ID (when collation isn't relevent, like UDF parms) * 3) As an index type - (btr.h) * 4) As a driver ID (used to lookup the code which implements the locale) - * This is also known as dsc_ttype() (aka text subtype). + * This is also known as dsc::getTextType() (aka text subtype). * * In Descriptors (DSC) the data is encoded as: * dsc_charset overloaded into dsc_scale @@ -134,7 +166,7 @@ inline USHORT INTL_TEXT_TYPE(const dsc& desc) * Index type, which is derived from the datatype of the target. * */ -#define INTL_INDEX_TO_TEXT(idxType) ((USHORT)((idxType) - idx_offset_intl_range)) +#define INTL_INDEX_TO_TEXT(idxType) TTypeId((USHORT)((idxType) - idx_offset_intl_range)) // Maps a text_type to an index ID #define INTL_TEXT_TO_INDEX(tType) ((USHORT)((tType) + idx_offset_intl_range)) @@ -147,10 +179,4 @@ inline USHORT INTL_TEXT_TYPE(const dsc& desc) #define INTL_INDEX_TYPE(desc) INTL_TEXT_TO_INDEX (INTL_RES_TTYPE (desc)) -// Maps a Character_set_id & collation_id to a text_type (driver ID) -#define INTL_CS_COLL_TO_TTYPE(cs, coll) ((TTYPE_ID) ((coll) << 8 | ((cs) & 0x00FF))) - -#define TTYPE_TO_CHARSET(tt) ((USHORT)((tt) & 0x00FF)) -#define TTYPE_TO_COLLATION(tt) ((USHORT)((tt) >> 8)) - #endif // JRD_INTL_H diff --git a/src/jrd/intl_proto.h b/src/jrd/intl_proto.h index bd9caae7b2f..6765d139ec0 100644 --- a/src/jrd/intl_proto.h +++ b/src/jrd/intl_proto.h @@ -39,18 +39,18 @@ struct SubtypeInfo; struct texttype; void INTL_adjust_text_descriptor(Jrd::thread_db* tdbb, dsc* desc); -CHARSET_ID INTL_charset(Jrd::thread_db*, USHORT); +CSetId INTL_charset(Jrd::thread_db*, TTypeId); int INTL_compare(Jrd::thread_db*, const dsc*, const dsc*, ErrorFunction); -ULONG INTL_convert_bytes(Jrd::thread_db*, CHARSET_ID, UCHAR*, const ULONG, CHARSET_ID, +ULONG INTL_convert_bytes(Jrd::thread_db*, CSetId, UCHAR*, const ULONG, CSetId, const BYTE*, const ULONG, ErrorFunction); -Jrd::CsConvert INTL_convert_lookup(Jrd::thread_db*, CHARSET_ID, CHARSET_ID); +Jrd::CsConvert INTL_convert_lookup(Jrd::thread_db*, CSetId, CSetId); void INTL_convert_string(dsc*, const dsc*, Firebird::Callbacks* cb); bool INTL_data(const dsc*); bool INTL_data_or_binary(const dsc*); -bool INTL_defined_type(Jrd::thread_db*, USHORT); +bool INTL_defined_type(Jrd::thread_db*, TTypeId); USHORT INTL_key_length(Jrd::thread_db*, USHORT, USHORT); -Jrd::CharSet* INTL_charset_lookup(Jrd::thread_db* tdbb, USHORT parm1); -Jrd::Collation* INTL_texttype_lookup(Jrd::thread_db* tdbb, USHORT parm1); +Jrd::CharSet* INTL_charset_lookup(Jrd::thread_db* tdbb, CSetId parm1); +Jrd::Collation* INTL_texttype_lookup(Jrd::thread_db* tdbb, TTypeId parm1); //void INTL_texttype_unload(Jrd::thread_db*, USHORT); bool INTL_texttype_validate(Jrd::thread_db*, const SubtypeInfo*); void INTL_pad_spaces(Jrd::thread_db*, dsc*, UCHAR*, ULONG); diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index b9e22362221..5bcdeb5c926 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -1330,7 +1330,7 @@ static ISC_STATUS transliterateException(thread_db* tdbb, const Exception& ex, F void JRD_transliterate(thread_db* tdbb, Firebird::IStatus* vector) throw() { Jrd::Attachment* attachment = tdbb->getAttachment(); - USHORT charSet; + CSetId charSet; if (!attachment || (charSet = attachment->att_client_charset) == CS_METADATA || charSet == CS_NONE) { @@ -1640,7 +1640,7 @@ JAttachment* JProvider::internalAttach(CheckStatusWrapper* user_status, const ch tdbb->tdbb_status_vector = user_status; attachment->att_crypt_callback = getDefCryptCallback(cryptCallback); - attachment->att_client_charset = attachment->att_charset = options.dpb_interp; + attachment->att_client_charset = attachment->att_charset = CSetId(options.dpb_interp); if (existingId) attachment->att_flags |= ATT_overwrite_check; @@ -2842,7 +2842,7 @@ JAttachment* JProvider::createDatabase(CheckStatusWrapper* user_status, const ch break; } - attachment->att_client_charset = attachment->att_charset = options.dpb_interp; + attachment->att_client_charset = attachment->att_charset = CSetId(options.dpb_interp); if (options.dpb_page_size <= 0) { options.dpb_page_size = DEFAULT_PAGE_SIZE; @@ -6709,19 +6709,19 @@ static void find_intl_charset(thread_db* tdbb, Jrd::Attachment* attachment, cons return; } - USHORT id; + TTypeId id; const UCHAR* lc_ctype = reinterpret_cast(options->dpb_lc_ctype.c_str()); if (MetadataCache::get_char_coll_subtype(tdbb, &id, lc_ctype, options->dpb_lc_ctype.length()) && - INTL_defined_type(tdbb, id & 0xFF)) + INTL_defined_type(tdbb, id)) { - if ((id & 0xFF) == CS_BINARY) + if (CSetId(id) == CS_BINARY) { ERR_post(Arg::Gds(isc_bad_dpb_content) << Arg::Gds(isc_invalid_attachment_charset) << Arg::Str(options->dpb_lc_ctype)); } - attachment->att_client_charset = attachment->att_charset = id & 0xFF; + attachment->att_client_charset = attachment->att_charset = CSetId(id); } else { @@ -9019,9 +9019,9 @@ void thread_db::setRequest(Request* val) reqStat = val ? &val->req_stats : RuntimeStatistics::getDummy(); } -SSHORT thread_db::getCharSet() const +CSetId thread_db::getCharSet() const { - USHORT charSetId; + CSetId charSetId; if (request && (charSetId = request->getStatement()->charSetId) != CS_dynamic) return charSetId; diff --git a/src/jrd/met.epp b/src/jrd/met.epp index 74b0a94c048..e006948215c 100644 --- a/src/jrd/met.epp +++ b/src/jrd/met.epp @@ -151,8 +151,8 @@ void MET_get_domain(thread_db* tdbb, MemoryPool& csbPool, const MetaName& name, FLD.RDB$FIELD_SCALE, FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, - FLD.RDB$CHARACTER_SET_ID, - FLD.RDB$COLLATION_ID)) + CSetId(FLD.RDB$CHARACTER_SET_ID), + CollId(FLD.RDB$COLLATION_ID))) { found = true; @@ -219,8 +219,8 @@ MetaName MET_get_relation_field(thread_db* tdbb, MemoryPool& csbPool, const Meta FLD.RDB$FIELD_SCALE, FLD.RDB$FIELD_LENGTH, FLD.RDB$FIELD_SUB_TYPE, - FLD.RDB$CHARACTER_SET_ID, - (RFL.RDB$COLLATION_ID.NULL ? FLD.RDB$COLLATION_ID : RFL.RDB$COLLATION_ID))) + CSetId(FLD.RDB$CHARACTER_SET_ID), + CollId(RFL.RDB$COLLATION_ID.NULL ? FLD.RDB$COLLATION_ID : RFL.RDB$COLLATION_ID))) { found = true; sourceName = RFL.RDB$FIELD_SOURCE; @@ -1194,7 +1194,7 @@ Format* MET_format(thread_db* tdbb, RelationPermanent* relation, USHORT number) } -bool MetadataCache::get_char_coll_subtype(thread_db* tdbb, USHORT* id, const UCHAR* name, USHORT length) +bool MetadataCache::get_texttype(thread_db* tdbb, TTypeId* id, const UCHAR* name, USHORT length) { /************************************** * @@ -2700,6 +2700,15 @@ jrd_rel* MetadataCache::lookup_relation_id(thread_db* tdbb, MetaId id, ObjectBas } +CharSetVers* MetadataCache::lookup_charset(thread_db* tdbb, MetaId id, ObjectBase::Flag flags) +{ + SET_TDBB(tdbb); + MetadataCache* mdc = tdbb->getDatabase()->dbb_mdc; + + return mdc->mdc_charsets.getObject(tdbb, id, flags); +} + + DmlNode* MET_parse_blob(thread_db* tdbb, Cached::Relation* relation, bid* blob_id, @@ -2961,7 +2970,7 @@ void jrd_prc::scan(thread_db* tdbb, ObjectBase::Flag) PA.RDB$PACKAGE_NAME EQUIV NULLIF(packageName.c_str(), '') { const SSHORT pa_collation_id_null = PA.RDB$COLLATION_ID.NULL; - const SSHORT pa_collation_id = PA.RDB$COLLATION_ID; + const CollId pa_collation_id(PA.RDB$COLLATION_ID); const SSHORT pa_default_value_null = PA.RDB$DEFAULT_VALUE.NULL; bid pa_default_value = pa_default_value_null ? F.RDB$DEFAULT_VALUE : PA.RDB$DEFAULT_VALUE; @@ -2982,8 +2991,8 @@ void jrd_prc::scan(thread_db* tdbb, ObjectBase::Flag) DSC_make_descriptor(¶meter->prm_desc, F.RDB$FIELD_TYPE, F.RDB$FIELD_SCALE, F.RDB$FIELD_LENGTH, - F.RDB$FIELD_SUB_TYPE, F.RDB$CHARACTER_SET_ID, - (pa_collation_id_null ? F.RDB$COLLATION_ID : pa_collation_id)); + F.RDB$FIELD_SUB_TYPE, CSetId(F.RDB$CHARACTER_SET_ID), + (pa_collation_id_null ? CollId(F.RDB$COLLATION_ID) : pa_collation_id)); if (parameter->prm_desc.isText() && parameter->prm_desc.getTextType() != CS_NONE) { @@ -4098,7 +4107,7 @@ static BoolExprNode* parse_field_validation_blr(thread_db* tdbb, bid* blob_id, c } -bool MetadataCache::resolve_charset_and_collation(thread_db* tdbb, USHORT* id, +bool MetadataCache::resolve_charset_and_collation(thread_db* tdbb, TTypeId* id, const UCHAR* charset, const UCHAR* collation) { /************************************** @@ -4169,13 +4178,13 @@ bool MetadataCache::resolve_charset_and_collation(thread_db* tdbb, USHORT* id, if (!collation) { - *id = cs->getId(); + *id = TTypeId(cs->getId()); return true; } if (!csVer) csVer = cs->getObject(tdbb); - Collation* coll = csVer->lookupCollation(tdbb, (const char*)collation); + Collation* coll = csVer->getCollation((const char*)collation); if (!coll) return false; @@ -4191,7 +4200,7 @@ bool MetadataCache::resolve_charset_and_collation(thread_db* tdbb, USHORT* id, WITH COL.RDB$COLLATION_NAME EQ collation { found = true; - *id = COL.RDB$CHARACTER_SET_ID | (COL.RDB$COLLATION_ID << 8); + *id = TTypeId(CSetId(COL.RDB$CHARACTER_SET_ID), CollId(COL.RDB$COLLATION_ID)); } END_FOR } @@ -4207,7 +4216,6 @@ void CharSetVers::scan(thread_db* tdbb, ObjectBase::Flag flags) Attachment* attachment = tdbb->getAttachment(); AutoRequest handle; - bool found = false; FOR(REQUEST_HANDLE handle) CS IN RDB$CHARACTER_SETS @@ -4215,7 +4223,6 @@ void CharSetVers::scan(thread_db* tdbb, ObjectBase::Flag flags) WITH CS.RDB$CHARACTER_SET_ID EQ getId() { fb_assert(getName() == CS.RDB$CHARACTER_SET_NAME); - found = true; SubtypeInfo info; info.charsetName = getName(); @@ -4229,7 +4236,8 @@ void CharSetVers::scan(thread_db* tdbb, ObjectBase::Flag flags) info.baseCollationName = COL.RDB$BASE_COLLATION_NAME; CharSet* charset = perm->getCharSet(); - unsigned colId = COL.RDB$COLLATION_ID; + CollId colId(COL.RDB$COLLATION_ID); + CSetId id(getId()); if (COL.RDB$SPECIFIC_ATTRIBUTES.NULL) info.specificAttributes.clear(); @@ -4241,12 +4249,12 @@ void CharSetVers::scan(thread_db* tdbb, ObjectBase::Flag flags) // ASF: Here info.specificAttributes is in UNICODE_FSS charset. blob->BLB_get_data(tdbb, info.specificAttributes.getBuffer(length), length); - if (getId() != CS_METADATA) + if (id != CS_METADATA) { Firebird::UCharBuffer specificAttributes; ULONG size = info.specificAttributes.getCount() * charset->maxBytesPerChar(); - size = INTL_convert_bytes(tdbb, getId(), + size = INTL_convert_bytes(tdbb, id, specificAttributes.getBuffer(size), size, CS_METADATA, info.specificAttributes.begin(), info.specificAttributes.getCount(), ERR_post); @@ -4278,7 +4286,7 @@ void CharSetVers::scan(thread_db* tdbb, ObjectBase::Flag flags) } Collation* collation = Collation::createInstance(perm->getPool(), - INTL_CS_COLL_TO_TTYPE(getId(), colId), tt, info.attributes, charset); + TTypeId(id, colId), tt, info.attributes, charset); collation->name = info.collationName; tt.release(); @@ -5199,7 +5207,23 @@ Cached::Procedure* MetadataCache::lookupProcedure(thread_db* tdbb, const Qualifi END_FOR return rc; +} + +Cached::Function* MetadataCache::lookupFunction(thread_db* tdbb, const QualifiedName& name, ObjectBase::Flag flags) +{ + SET_TDBB(tdbb); + + Attachment* attachment = tdbb->getAttachment(); + MetadataCache* mdc = tdbb->getDatabase()->dbb_mdc; + + // See if we already know the relation by name + auto* rc = mdc->mdc_functions.lookup([name](RoutinePermanent* func) { return func->name == name; }); + + if (rc || !(flags & CacheFlag::AUTOCREATE)) + return rc; + auto* fun = Function::lookup(tdbb, name, flags); + return fun ? fun->getPermanent() : nullptr; } Cached::Procedure* MetadataCache::lookupProcedure(thread_db* tdbb, MetaId id, ObjectBase::Flag flags) diff --git a/src/jrd/met.h b/src/jrd/met.h index 26c15f0b9af..e745c7259b7 100644 --- a/src/jrd/met.h +++ b/src/jrd/met.h @@ -295,7 +295,7 @@ class MetadataCache : public Firebird::PermanentStorage static Cached::Procedure* lookupProcedure(thread_db* tdbb, const QualifiedName& name, ObjectBase::Flag flags = 0); static Cached::Procedure* lookupProcedure(thread_db* tdbb, MetaId id, ObjectBase::Flag flags = 0); static Cached::Function* lookupFunction(thread_db* tdbb, const QualifiedName& name, ObjectBase::Flag flags = 0); - static Cached::Function* lookupFunction(thread_db* tdbb, MetaId id, ObjectBase::Flag flags); + //static Cached::Function* lookupFunction(thread_db* tdbb, MetaId id, ObjectBase::Flag flags); static jrd_rel* lookup_relation(thread_db*, const MetaName&); static jrd_rel* lookup_relation_id(thread_db*, MetaId, ObjectBase::Flag flags); static Cached::Relation* lookupRelation(thread_db* tdbb, const MetaName& name, ObjectBase::Flag flags = 0); @@ -307,16 +307,30 @@ class MetadataCache : public Firebird::PermanentStorage static void post_existence(thread_db* tdbb, jrd_rel* relation); static jrd_prc* findProcedure(thread_db* tdbb, MetaId id, ObjectBase::Flag flags); static jrd_rel* findRelation(thread_db* tdbb, MetaId id); - static bool get_char_coll_subtype(thread_db* tdbb, MetaId* id, const UCHAR* name, USHORT length); - bool resolve_charset_and_collation(thread_db* tdbb, MetaId* id, + + template + static bool get_char_coll_subtype(thread_db* tdbb, ID* id, const UCHAR* name, USHORT length) + { + fb_assert(id); + + TTypeId ttId; + bool rc = get_texttype(tdbb, &ttId, name, length); + *id = ttId; + return rc; + } + +private: + static bool get_texttype(thread_db* tdbb, TTypeId* id, const UCHAR* name, USHORT length); + +public: + bool resolve_charset_and_collation(thread_db* tdbb, TTypeId* id, const UCHAR* charset, const UCHAR* collation); static DSqlCacheItem* get_dsql_cache_item(thread_db* tdbb, sym_type type, const QualifiedName& name); static void dsql_cache_release(thread_db* tdbb, sym_type type, const MetaName& name, const MetaName& package = ""); static bool dsql_cache_use(thread_db* tdbb, sym_type type, const MetaName& name, const MetaName& package = ""); // end of met_proto.h - static Cached::Charset* lookupCharset(thread_db* tdbb, MetaId id); - static CharSetVers* lookup_charset(thread_db* tdbb, MetaId id); + static CharSetVers* lookup_charset(thread_db* tdbb, MetaId id, ObjectBase::Flag flags); static void release_temp_tables(thread_db* tdbb, jrd_tra* transaction); static void retain_temp_tables(thread_db* tdbb, jrd_tra* transaction, TraNumber new_number); diff --git a/src/jrd/mov.cpp b/src/jrd/mov.cpp index 1e8a618171c..81c3276c550 100644 --- a/src/jrd/mov.cpp +++ b/src/jrd/mov.cpp @@ -201,7 +201,7 @@ SQUAD MOV_get_quad(Jrd::thread_db* tdbb, const dsc* desc, SSHORT scale) int MOV_get_string_ptr(Jrd::thread_db* tdbb, const dsc* desc, - USHORT* ttype, + TTypeId* ttype, UCHAR** address, vary* temp, USHORT length) { /************************************** @@ -236,7 +236,7 @@ int MOV_get_string(Jrd::thread_db* tdbb, const dsc* desc, UCHAR** address, vary* * Functional description * **************************************/ - USHORT ttype; + TTypeId ttype; return MOV_get_string_ptr(tdbb, desc, &ttype, address, temp, length); } @@ -329,7 +329,7 @@ ISC_TIMESTAMP_TZ MOV_get_timestamp_tz(const dsc* desc) USHORT MOV_make_string(Jrd::thread_db* tdbb, const dsc* desc, - USHORT ttype, + TTypeId ttype, const char** address, vary* temp, USHORT length) @@ -359,7 +359,7 @@ USHORT MOV_make_string(Jrd::thread_db* tdbb, ULONG MOV_make_string2(Jrd::thread_db* tdbb, const dsc* desc, - USHORT ttype, + TTypeId ttype, UCHAR** address, Jrd::MoveBuffer& buffer, bool limit) @@ -419,7 +419,7 @@ ULONG MOV_make_string2(Jrd::thread_db* tdbb, } -Firebird::string MOV_make_string2(Jrd::thread_db* tdbb, const dsc* desc, USHORT ttype, bool limit) +Firebird::string MOV_make_string2(Jrd::thread_db* tdbb, const dsc* desc, TTypeId ttype, bool limit) { Jrd::MoveBuffer buffer; UCHAR* ptr; @@ -488,7 +488,7 @@ Int128 MOV_get_int128(Jrd::thread_db* tdbb, const dsc* desc, SSHORT scale) namespace Jrd { -DescPrinter::DescPrinter(thread_db* tdbb, const dsc* desc, FB_SIZE_T mLen, USHORT charSetId) +DescPrinter::DescPrinter(thread_db* tdbb, const dsc* desc, FB_SIZE_T mLen, TTypeId charSetId) : maxLen(mLen) { const char* const NULL_KEY_STRING = "NULL"; @@ -502,7 +502,7 @@ DescPrinter::DescPrinter(thread_db* tdbb, const dsc* desc, FB_SIZE_T mLen, USHOR fb_assert(!desc->isBlob()); const bool isBinary = (desc->isText() && desc->getCharSet() == CS_BINARY); - value = MOV_make_string2(tdbb, desc, isBinary ? CS_BINARY : charSetId); + value = MOV_make_string2(tdbb, desc, isBinary ? TTypeId(CS_BINARY) : charSetId); const char* const str = value.c_str(); diff --git a/src/jrd/mov_proto.h b/src/jrd/mov_proto.h index 8edfd15923a..8bd87e85e5d 100644 --- a/src/jrd/mov_proto.h +++ b/src/jrd/mov_proto.h @@ -40,16 +40,16 @@ SLONG MOV_get_long(Jrd::thread_db*, const dsc*, SSHORT); void MOV_get_metaname(Jrd::thread_db*, const dsc*, Jrd::MetaName&); SQUAD MOV_get_quad(Jrd::thread_db*, const dsc*, SSHORT); SINT64 MOV_get_int64(Jrd::thread_db*, const dsc*, SSHORT); -int MOV_get_string_ptr(Jrd::thread_db*, const dsc*, USHORT*, UCHAR**, vary*, USHORT); +int MOV_get_string_ptr(Jrd::thread_db*, const dsc*, TTypeId*, UCHAR**, vary*, USHORT); int MOV_get_string(Jrd::thread_db*, const dsc*, UCHAR**, vary*, USHORT); GDS_DATE MOV_get_sql_date(const dsc*); GDS_TIME MOV_get_sql_time(const dsc*); ISC_TIME_TZ MOV_get_sql_time_tz(const dsc*); GDS_TIMESTAMP MOV_get_timestamp(const dsc*); ISC_TIMESTAMP_TZ MOV_get_timestamp_tz(const dsc*); -USHORT MOV_make_string(Jrd::thread_db*, const dsc*, USHORT, const char**, vary*, USHORT); -ULONG MOV_make_string2(Jrd::thread_db*, const dsc*, USHORT, UCHAR**, Jrd::MoveBuffer&, bool = true); -Firebird::string MOV_make_string2(Jrd::thread_db* tdbb, const dsc* desc, USHORT ttype, +USHORT MOV_make_string(Jrd::thread_db*, const dsc*, TTypeId, const char**, vary*, USHORT); +ULONG MOV_make_string2(Jrd::thread_db*, const dsc*, TTypeId, UCHAR**, Jrd::MoveBuffer&, bool = true); +Firebird::string MOV_make_string2(Jrd::thread_db* tdbb, const dsc* desc, TTypeId ttype, bool limit = true); void MOV_move(Jrd::thread_db*, /*const*/ dsc*, dsc*); Firebird::Decimal64 MOV_get_dec64(Jrd::thread_db*, const dsc*); @@ -62,7 +62,7 @@ namespace Jrd class DescPrinter { public: - DescPrinter(thread_db* tdbb, const dsc* desc, FB_SIZE_T mLen, USHORT charSetId); + DescPrinter(thread_db* tdbb, const dsc* desc, FB_SIZE_T mLen, TTypeId charSetId); const Firebird::string& get() const { diff --git a/src/jrd/obj.h b/src/jrd/obj.h index 0bfd7bd55d9..0d6f6f2726e 100644 --- a/src/jrd/obj.h +++ b/src/jrd/obj.h @@ -24,6 +24,8 @@ #ifndef JRD_OBJ_H #define JRD_OBJ_H +#include "../common/gdsassert.h" + // Object types used in RDB$DEPENDENCIES and RDB$USER_PRIVILEGES and stored in backup. // Note: some values are hard coded in grant.gdl // Keep existing constants unchanged. diff --git a/src/jrd/optimizer/Optimizer.cpp b/src/jrd/optimizer/Optimizer.cpp index 103fbd6a2ff..cb5108a5716 100644 --- a/src/jrd/optimizer/Optimizer.cpp +++ b/src/jrd/optimizer/Optimizer.cpp @@ -1449,7 +1449,7 @@ SortedStream* Optimizer::generateSort(const StreamList& streams, if (sort_key->skd_dtype == SKD_varying || sort_key->skd_dtype == SKD_cstring) { - if (desc->dsc_ttype() == ttype_binary) + if (desc->getTextType() == ttype_binary) sort_key->skd_flags |= SKD_binary; } diff --git a/src/jrd/optimizer/Retrieval.cpp b/src/jrd/optimizer/Retrieval.cpp index e1f05a4be6e..151dca8841a 100644 --- a/src/jrd/optimizer/Retrieval.cpp +++ b/src/jrd/optimizer/Retrieval.cpp @@ -508,12 +508,12 @@ void Retrieval::analyzeNavigation(const InversionCandidateList& inversions) dsc desc; node->getDesc(tdbb, csb, &desc); - // ASF: "desc.dsc_ttype() > ttype_last_internal" is to avoid recursion + // ASF: "desc.getTextType() > ttype_last_internal" is to avoid recursion // when looking for charsets/collations - if (DTYPE_IS_TEXT(desc.dsc_dtype) && desc.dsc_ttype() > ttype_last_internal) + if (DTYPE_IS_TEXT(desc.dsc_dtype) && desc.getTextType() > ttype_last_internal) { - auto tt = INTL_texttype_lookup(tdbb, desc.dsc_ttype()); + auto tt = INTL_texttype_lookup(tdbb, desc.getTextType()); if (idx->idx_flags & idx_unique) { diff --git a/src/jrd/par.cpp b/src/jrd/par.cpp index 7b8b50a50bc..ca568d48015 100644 --- a/src/jrd/par.cpp +++ b/src/jrd/par.cpp @@ -256,7 +256,7 @@ USHORT PAR_datatype(BlrReader& blrReader, dsc* desc) desc->clear(); const USHORT dtype = blrReader.getByte(); - USHORT textType; + TTypeId textType; switch (dtype) { @@ -278,18 +278,18 @@ USHORT PAR_datatype(BlrReader& blrReader, dsc* desc) break; case blr_text2: - textType = blrReader.getWord(); + textType = TTypeId(blrReader.getWord()); desc->makeText(blrReader.getWord(), textType); break; case blr_cstring2: desc->dsc_dtype = dtype_cstring; - desc->setTextType(blrReader.getWord()); + desc->setTextType(TTypeId(blrReader.getWord())); desc->dsc_length = blrReader.getWord(); break; case blr_varying2: - textType = blrReader.getWord(); + textType = TTypeId(blrReader.getWord()); desc->makeVarying(blrReader.getWord(), textType); break; @@ -383,7 +383,7 @@ USHORT PAR_datatype(BlrReader& blrReader, dsc* desc) desc->dsc_dtype = dtype_blob; desc->dsc_length = sizeof(ISC_QUAD); desc->dsc_sub_type = blrReader.getWord(); - textType = blrReader.getWord(); + textType = TTypeId(blrReader.getWord()); desc->dsc_scale = textType & 0xFF; // BLOB character set desc->dsc_flags = textType & 0xFF00; // BLOB collation break; @@ -453,19 +453,15 @@ USHORT PAR_desc(thread_db* tdbb, CompilerScratch* csb, dsc* desc, ItemInfo* item if (dtype == blr_domain_name2) { - const USHORT ttype = csb->csb_blr_reader.getWord(); + const auto ttype = TTypeId(csb->csb_blr_reader.getWord()); switch (desc->dsc_dtype) { case dtype_cstring: case dtype_text: case dtype_varying: - desc->setTextType(ttype); - break; - case dtype_blob: - desc->dsc_scale = ttype & 0xFF; // BLOB character set - desc->dsc_flags = ttype & 0xFF00; // BLOB collation + desc->setTextType(ttype); break; default: @@ -518,19 +514,15 @@ USHORT PAR_desc(thread_db* tdbb, CompilerScratch* csb, dsc* desc, ItemInfo* item if (dtype == blr_column_name2) { - const USHORT ttype = csb->csb_blr_reader.getWord(); + const auto ttype = TTypeId(csb->csb_blr_reader.getWord()); switch (desc->dsc_dtype) { case dtype_cstring: case dtype_text: case dtype_varying: - desc->setTextType(ttype); - break; - case dtype_blob: - desc->dsc_scale = ttype & 0xFF; // BLOB character set - desc->dsc_flags = ttype & 0xFF00; // BLOB collation + desc->setTextType(ttype); break; default: @@ -562,7 +554,7 @@ USHORT PAR_desc(thread_db* tdbb, CompilerScratch* csb, dsc* desc, ItemInfo* item if (csb->collectingDependencies() && desc->getTextType() != CS_NONE) { Dependency dependency(obj_collation); - dependency.number = INTL_TEXT_TYPE(*desc); + dependency.number = INTL_GET_TTYPE(desc); csb->addDependency(dependency); } diff --git a/src/jrd/recsrc/ProcedureScan.cpp b/src/jrd/recsrc/ProcedureScan.cpp index 57aa2582fcc..e218486d1bc 100644 --- a/src/jrd/recsrc/ProcedureScan.cpp +++ b/src/jrd/recsrc/ProcedureScan.cpp @@ -305,11 +305,11 @@ void ProcedureScan::assignParams(thread_db* tdbb, /* YYY for text formats that don't have trailing spaces */ if (len) { - const CHARSET_ID chid = DSC_GET_CHARSET(to_desc); + const CSetId chid = DSC_GET_CHARSET(to_desc); /* CVC: I don't know if we have to check for dynamic-127 charset here. If that is needed, the line above should be replaced by the commented code here. - CHARSET_ID chid = INTL_TTYPE(to_desc); + CSetId chid = INTL_TTYPE(to_desc); if (chid == ttype_dynamic) chid = INTL_charset(tdbb, chid); */ diff --git a/src/jrd/replication/Applier.cpp b/src/jrd/replication/Applier.cpp index e838209808f..46f1eae7d6f 100644 --- a/src/jrd/replication/Applier.cpp +++ b/src/jrd/replication/Applier.cpp @@ -405,8 +405,8 @@ void Applier::process(thread_db* tdbb, ULONG length, const UCHAR* data) case opExecuteSqlIntl: { const auto ownerName = reader.getMetaName(); - const unsigned charset = - (op == opExecuteSql) ? CS_UTF8 : reader.getByte(); + const auto charset = + (op == opExecuteSql) ? CS_UTF8 : CSetId(reader.getByte()); const string sql = reader.getString(); executeSql(tdbb, traNum, charset, sql, ownerName); } @@ -944,7 +944,7 @@ void Applier::storeBlob(thread_db* tdbb, TraNumber traNum, bid* blobId, void Applier::executeSql(thread_db* tdbb, TraNumber traNum, - unsigned charset, + CSetId charset, const string& sql, const MetaName& ownerName) { @@ -960,7 +960,7 @@ void Applier::executeSql(thread_db* tdbb, const auto dialect = (dbb->dbb_flags & DBB_DB_SQL_dialect_3) ? SQL_DIALECT_V6 : SQL_DIALECT_V5; - AutoSetRestore autoCharset(&attachment->att_charset, charset); + AutoSetRestore autoCharset(&attachment->att_charset, charset); UserId* const owner = attachment->getUserId(ownerName); AutoSetRestore autoOwner(&attachment->att_ss_user, owner); diff --git a/src/jrd/replication/Applier.h b/src/jrd/replication/Applier.h index b6074957702..f6fea40aa39 100644 --- a/src/jrd/replication/Applier.h +++ b/src/jrd/replication/Applier.h @@ -181,7 +181,7 @@ namespace Jrd ULONG length, const UCHAR* data); void executeSql(thread_db* tdbb, TraNumber traNum, - unsigned charset, + CSetId charset, const Firebird::string& sql, const MetaName& owner); diff --git a/src/jrd/tdbb.h b/src/jrd/tdbb.h index 0bf68942b93..f05fb81dec3 100644 --- a/src/jrd/tdbb.h +++ b/src/jrd/tdbb.h @@ -40,6 +40,7 @@ #include "../jrd/RuntimeStatistics.h" #include "../jrd/status.h" #include "../jrd/err_proto.h" +#include "../jrd/intl.h" #define BUGCHECK(number) ERR_bugcheck(number, __FILE__, __LINE__) @@ -295,7 +296,7 @@ class thread_db : public Firebird::ThreadData void setRequest(Request* val); - SSHORT getCharSet() const; + CSetId getCharSet() const; void markAsSweeper() { diff --git a/src/jrd/trace/TraceObjects.cpp b/src/jrd/trace/TraceObjects.cpp index 90d32d863f1..aa0076f4fa9 100644 --- a/src/jrd/trace/TraceObjects.cpp +++ b/src/jrd/trace/TraceObjects.cpp @@ -321,7 +321,7 @@ const char* TraceSQLStatementImpl::DSQLParamsImpl::getTextUTF8(CheckStatusWrappe try { - if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->dsc_sub_type, status_exception::raise)) + if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->getCharSet(), status_exception::raise)) temp_utf8_text = src; } catch (const Firebird::Exception&) @@ -385,7 +385,7 @@ const char* TraceParamsImpl::getTextUTF8(CheckStatusWrapper* status, FB_SIZE_T i try { - if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->dsc_sub_type, status_exception::raise)) + if (!DataTypeUtil::convertToUTF8(src, temp_utf8_text, param->getCharSet(), status_exception::raise)) temp_utf8_text = src; } catch (const Firebird::Exception&) diff --git a/src/jrd/vio.cpp b/src/jrd/vio.cpp index aa835cebb4d..510c9725f47 100644 --- a/src/jrd/vio.cpp +++ b/src/jrd/vio.cpp @@ -2082,7 +2082,7 @@ bool VIO_erase(thread_db* tdbb, record_param* rpb, jrd_tra* transaction) id = MOV_get_long(tdbb, &desc2, 0); EVL_field(0, rpb->rpb_record, f_coll_id, &desc2); - id = INTL_CS_COLL_TO_TTYPE(id, MOV_get_long(tdbb, &desc2, 0)); + id = TTypeId(CSetId(id), CollId(MOV_get_long(tdbb, &desc2, 0))); EVL_field(0, rpb->rpb_record, f_coll_name, &desc); DFW_post_work(transaction, dfw_delete_collation, &desc, id); @@ -4272,7 +4272,7 @@ void VIO_store(thread_db* tdbb, record_param* rpb, jrd_tra* transaction) USHORT id = MOV_get_long(tdbb, &desc, 0); EVL_field(0, rpb->rpb_record, f_coll_id, &desc); - id = INTL_CS_COLL_TO_TTYPE(id, MOV_get_long(tdbb, &desc, 0)); + id = TTypeId(CSetId(id), CollId(MOV_get_long(tdbb, &desc, 0))); EVL_field(0, rpb->rpb_record, f_coll_name, &desc); DFW_post_work(transaction, dfw_create_collation, &desc, id);