Skip to content

Commit

Permalink
Fixed #8006: Int128 datatype not supported in UDR
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPeshkoff committed Feb 14, 2024
1 parent 1192082 commit 0475c32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 11 additions & 5 deletions examples/interfaces/06.fb_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

static IMaster* master = fb_get_master_interface();
static IDecFloat16* idf16 = NULL;
static IInt128* ii128 = NULL;

int main()
{
Expand All @@ -56,6 +57,7 @@ int main()
try
{
idf16 = master->getUtilInterface()->getDecFloat16(&status);
ii128 = master->getUtilInterface()->getInt128(&status);

att = prov->attachDatabase(&status, dbName, 0, NULL);
tra = att->startTransaction(&status, 0, NULL);
Expand All @@ -79,32 +81,36 @@ int main()
(FB_VARCHAR(31), relationName)
(FB_VARCHAR(100), description)
(FB_DECFLOAT16, df16)
(FB_INT128, iHuge)
) output(&status, master);

input.clear();
input->systemFlag = 0;

rs = att->openCursor(&status, tra, 0,
"select rdb$relation_id, rdb$relation_name, rdb$description,"
" cast (rdb$relation_id as decfloat(16)) * 0.05 as df16"
" cast (rdb$relation_id as decfloat(16)) * 0.05 as df16,"
" cast (rdb$relation_id as int128) * 212778764464767 as iHuge"
" from rdb$relations"
" where rdb$system_flag = ?"
" order by rdb$relation_id",
SAMPLES_DIALECT, input.getMetadata(), input.getData(), output.getMetadata(), NULL, 0);

printf(" ID Name/comment\n");
printf(" ID Name datatype-tests (perform some arithmetics) /comment\n");
while (rs->fetchNext(&status, output.getData()) == IStatus::RESULT_OK)
{
unsigned lRelName = output->relationNameNull ? 0 : output->relationName.length;
unsigned lDesc = output->descriptionNull ? 0 : output->description.length;
char t16[IDecFloat16::STRING_SIZE];
idf16->toString(&status, &output->df16, sizeof(t16), t16);
char huge[IInt128::STRING_SIZE];
ii128->toString(&status, &output->iHuge, -3, sizeof(huge), huge);

printf("%4d %*.*s%c%*.*s (%s)\n", output->relationId,
printf("%4d %*.*s [Decfloat16:%s Int128:%s] %c%*.*s\n", output->relationId,
lRelName, lRelName, output->relationName.str,
t16, huge,
lDesc ? '/' : ' ',
lDesc, lDesc, output->description.str,
t16);
lDesc, lDesc, output->description.str);
}

rs->close(&status);
Expand Down
8 changes: 8 additions & 0 deletions src/include/firebird/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
builder->setLength(status, index, sizeof(ISC_INT64)); \
builder->setScale(status, index, scale);

#define FB__META_FB_SCALED_INT128(scale) \
builder->setType(status, index, SQL_INT128); \
builder->setLength(status, index, sizeof(FB_I128)); \
builder->setScale(status, index, scale);

#define FB__META_FB_FLOAT \
builder->setType(status, index, SQL_FLOAT); \
builder->setLength(status, index, sizeof(float));
Expand Down Expand Up @@ -204,15 +209,18 @@
#define FB__META_FB_SMALLINT FB__META_FB_SCALED_SMALLINT(0)
#define FB__META_FB_INTEGER FB__META_FB_SCALED_INTEGER(0)
#define FB__META_FB_BIGINT FB__META_FB_SCALED_BIGINT(0)
#define FB__META_FB_INT128 FB__META_FB_SCALED_INT128(0)

// Types - struct

#define FB__TYPE_FB_SCALED_SMALLINT(x) ISC_SHORT
#define FB__TYPE_FB_SCALED_INTEGER(x) ISC_LONG
#define FB__TYPE_FB_SCALED_BIGINT(x) FB__INT64_ALIGNAS ISC_INT64
#define FB__TYPE_FB_SCALED_INT128(x) FB__INT64_ALIGNAS FB_I128

This comment has been minimized.

Copy link
@aafemt

aafemt Feb 14, 2024

Contributor

Shouldn't be FB__INT128_ALIGNAS instead? I understand that currently they are the same but still hope that int128 will get right alignment someday.

This comment has been minimized.

Copy link
@AlexPeshkoff

AlexPeshkoff via email Feb 15, 2024

Author Member

This comment has been minimized.

Copy link
@aafemt

aafemt Feb 15, 2024

Contributor

I think alignment should be based on host language type we would like users to use. For Int128 and C/C++ natural choice is __int128 and problem here is that alignas() doesn't allow to reduce alignment requirement so as long as FB_MESSAGE is forming a proper C struct, it cannot use custom alignment.

BTW, I still don't understand how message buffer is able to work between platforms having different alignment requirements (i.e. for double). In my test of artificial raising alignment above native it works for remote connection but fail for embedded. That's puzzling.

#define FB__TYPE_FB_SMALLINT ISC_SHORT
#define FB__TYPE_FB_INTEGER ISC_LONG
#define FB__TYPE_FB_BIGINT FB__INT64_ALIGNAS ISC_INT64
#define FB__TYPE_FB_INT128 FB__INT64_ALIGNAS FB_I128
#define FB__TYPE_FB_FLOAT float
#define FB__TYPE_FB_DOUBLE double
#define FB__TYPE_FB_DECFLOAT16 FB__INT64_ALIGNAS FB_DEC16
Expand Down

0 comments on commit 0475c32

Please sign in to comment.