Skip to content

Commit 1b8b7d3

Browse files
committed
Enhanced support of decimal float numbers in the client: use better names for SQL_ constants, added interfaces supporting access to decimal float fields in native format, use them in isql instead direct library access, added decimal float support in messages and a sample of it
1 parent f995ed4 commit 1b8b7d3

File tree

16 files changed

+562
-64
lines changed

16 files changed

+562
-64
lines changed

examples/interfaces/06.fb_message.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* DESCRIPTION: A sample of using static messages.
55
* Prints user-defined tables with comments.
66
*
7+
* Example for the following interface:
8+
* IDecFloat16 - support for IEEE-754 64-bit decimal float numbers
9+
*
710
* Example for the following macro:
811
*
912
* FB_MESSAGE - defines static messages
@@ -32,6 +35,7 @@
3235
#include <firebird/Message.h>
3336

3437
static IMaster* master = fb_get_master_interface();
38+
static IDecFloat16* idf = NULL;
3539

3640
int main()
3741
{
@@ -51,6 +55,8 @@ int main()
5155

5256
try
5357
{
58+
idf = master->getUtilInterface()->getDecFloat16(&status);
59+
5460
att = prov->attachDatabase(&status, dbName, 0, NULL);
5561
tra = att->startTransaction(&status, 0, NULL);
5662

@@ -72,13 +78,15 @@ int main()
7278
(FB_SMALLINT, relationId)
7379
(FB_VARCHAR(31), relationName)
7480
(FB_VARCHAR(100), description)
81+
(FB_DECFLOAT16, df16)
7582
) output(&status, master);
7683

7784
input.clear();
7885
input->systemFlag = 0;
7986

8087
rs = att->openCursor(&status, tra, 0,
81-
"select rdb$relation_id, rdb$relation_name, rdb$description"
88+
"select rdb$relation_id, rdb$relation_name, rdb$description,"
89+
" cast (rdb$relation_id as decfloat(16)) * 0.05 as df16"
8290
" from rdb$relations"
8391
" where rdb$system_flag = ?"
8492
" order by rdb$relation_id",
@@ -89,10 +97,13 @@ int main()
8997
{
9098
unsigned lRelName = output->relationNameNull ? 0 : output->relationName.length;
9199
unsigned lDesc = output->descriptionNull ? 0 : output->description.length;
92-
printf("%4d %*.*s%c%*.*s\n", output->relationId,
100+
char t[IDecFloat16::STRING_SIZE];
101+
idf->toStr(&output->df16, t);
102+
103+
printf("%4d %*.*s%c%*.*s (%s)\n", output->relationId,
93104
lRelName, lRelName, output->relationName.str,
94105
lDesc ? '/' : ' ',
95-
lDesc, lDesc, output->description.str);
106+
lDesc, lDesc, output->description.str, t);
96107
}
97108

98109
rs->close(&status);

src/common/classes/InternalMessageBuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ MetadataFromBlr::MetadataFromBlr(unsigned aBlrLength, const unsigned char* aBlr,
173173
break;
174174

175175
case blr_dec64:
176-
item->type = SQL_DEC64;
176+
item->type = SQL_DEC16;
177177
item->length = sizeof(Decimal64);
178178
break;
179179

180180
case blr_dec128:
181-
item->type = SQL_DEC128;
181+
item->type = SQL_DEC34;
182182
item->length = sizeof(Decimal128);
183183
break;
184184

src/common/dsc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,12 +1338,12 @@ void dsc::getSqlInfo(SLONG* sqlLength, SLONG* sqlSubType, SLONG* sqlScale, SLONG
13381338
break;
13391339

13401340
case dtype_dec64:
1341-
*sqlType = SQL_DEC64;
1341+
*sqlType = SQL_DEC16;
13421342
*sqlScale = 0;
13431343
break;
13441344

13451345
case dtype_dec128:
1346-
*sqlType = SQL_DEC128;
1346+
*sqlType = SQL_DEC34;
13471347
*sqlScale = 0;
13481348
break;
13491349

src/common/utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,9 +1516,9 @@ UCHAR sqlTypeToDscType(SSHORT sqlType)
15161516
return dtype_quad;
15171517
case SQL_BOOLEAN:
15181518
return dtype_boolean;
1519-
case SQL_DEC64:
1519+
case SQL_DEC16:
15201520
return dtype_dec64;
1521-
case SQL_DEC128:
1521+
case SQL_DEC34:
15221522
return dtype_dec128;
15231523
default:
15241524
return dtype_unknown;

src/dsql/sqlda_pub.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ typedef struct
7878
#define SQL_TYPE_TIME 560
7979
#define SQL_TYPE_DATE 570
8080
#define SQL_INT64 580
81-
#define SQL_DEC64 32760
82-
#define SQL_DEC128 32762
81+
#define SQL_DEC16 32760
82+
#define SQL_DEC34 32762
8383
#define SQL_BOOLEAN 32764
8484
#define SQL_NULL 32766
8585

src/include/firebird/FirebirdInterface.idl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
typedef ISC_DATE;
3030
typedef ISC_QUAD;
3131
typedef ISC_TIME;
32+
typedef FB_DEC16;
33+
typedef FB_DEC34;
3234

3335
// Versioned interface - base for all FB interfaces
3436
interface Versioned
@@ -985,6 +987,8 @@ interface Util : Versioned
985987

986988
version:
987989
EventBlock createEventBlock(Status status, const string* events);
990+
DecFloat16 getDecFloat16(Status status);
991+
DecFloat34 getDecFloat34(Status status);
988992
}
989993

990994
interface OffsetsCallback : Versioned
@@ -1365,3 +1369,23 @@ interface UdrPlugin : Versioned
13651369
void registerProcedure(Status status, const string name, UdrProcedureFactory factory);
13661370
void registerTrigger(Status status, const string name, UdrTriggerFactory factory);
13671371
}
1372+
1373+
interface DecFloat16 : Versioned
1374+
{
1375+
const uint BCD_SIZE = 16;
1376+
const uint STRING_SIZE = 25; // includes terminating \0
1377+
void scatter(const FB_DEC16* from, int* sign, uchar* bcd, int* exp);
1378+
void toStr(const FB_DEC16* from, string to);
1379+
void gather(int sign, const uchar* bcd, int exp, FB_DEC16* to);
1380+
void fromStr(Status status, const string from, FB_DEC16* to);
1381+
}
1382+
1383+
interface DecFloat34 : Versioned
1384+
{
1385+
const uint BCD_SIZE = 34;
1386+
const uint STRING_SIZE = 43; // includes terminating \0
1387+
void scatter(const FB_DEC34* from, int* sign, uchar* bcd, int* exp);
1388+
void toStr(const FB_DEC34* from, string to);
1389+
void gather(int sign, const uchar* bcd, int exp, FB_DEC34* to);
1390+
void fromStr(Status status, const string from, FB_DEC34* to);
1391+
}

0 commit comments

Comments
 (0)