Skip to content

Commit 57af009

Browse files
committed
New DDL node and request type - SessionManagement. Added supoport for setting various decimal float rounding modes.
1 parent 7af54d7 commit 57af009

File tree

7 files changed

+168
-20
lines changed

7 files changed

+168
-20
lines changed

src/dsql/Nodes.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,28 @@ class TransactionNode : public Node
281281
};
282282

283283

284+
class SessionManagementNode : public Node
285+
{
286+
public:
287+
explicit SessionManagementNode(MemoryPool& pool)
288+
: Node(pool)
289+
{
290+
}
291+
292+
public:
293+
virtual SessionManagementNode* dsqlPass(DsqlCompilerScratch* dsqlScratch)
294+
{
295+
Node::dsqlPass(dsqlScratch);
296+
297+
dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_SESSION_MANAGEMENT);
298+
299+
return this;
300+
}
301+
302+
virtual void execute(thread_db* tdbb, dsql_req* request) const = 0;
303+
};
304+
305+
284306
class DmlNode : public Node
285307
{
286308
public:

src/dsql/StmtNodes.cpp

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7945,14 +7945,7 @@ void SetTransactionNode::genTableLock(DsqlCompilerScratch* dsqlScratch,
79457945
//--------------------
79467946

79477947

7948-
SetRoleNode* SetRoleNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
7949-
{
7950-
dsqlScratch->getStatement()->setType(DsqlCompiledStatement::TYPE_SET_ROLE);
7951-
7952-
return this;
7953-
}
7954-
7955-
void SetRoleNode::execute(thread_db* tdbb, dsql_req* request, jrd_tra** transaction) const
7948+
void SetRoleNode::execute(thread_db* tdbb, dsql_req* request) const
79567949
{
79577950
SET_TDBB(tdbb);
79587951
Attachment* const attachment = tdbb->getAttachment();
@@ -7976,6 +7969,58 @@ void SetRoleNode::execute(thread_db* tdbb, dsql_req* request, jrd_tra** transact
79767969
//--------------------
79777970

79787971

7972+
namespace
7973+
{
7974+
7975+
struct RoundMode
7976+
{
7977+
const char* name;
7978+
USHORT val;
7979+
};
7980+
7981+
#define FB_RMODE(x) { STRINGIZE(x), x }
7982+
7983+
const RoundMode roundModes[] = {
7984+
FB_RMODE(DEC_ROUND_CEILING),
7985+
FB_RMODE(DEC_ROUND_UP),
7986+
FB_RMODE(DEC_ROUND_HALF_UP),
7987+
FB_RMODE(DEC_ROUND_HALF_EVEN),
7988+
FB_RMODE(DEC_ROUND_HALF_DOWN),
7989+
FB_RMODE(DEC_ROUND_DOWN),
7990+
FB_RMODE(DEC_ROUND_FLOOR),
7991+
{ "DEC_ROUND_REROUND", DEC_ROUND_05UP },
7992+
{ NULL, 0 }
7993+
};
7994+
7995+
#undef FB_RMODE
7996+
7997+
//DEC_ROUND_
7998+
//0123456789
7999+
const unsigned FB_RMODE_OFFSET = 10;
8000+
8001+
}
8002+
8003+
void SetRoundNode::execute(thread_db* tdbb, dsql_req* request) const
8004+
{
8005+
SET_TDBB(tdbb);
8006+
Attachment* const attachment = tdbb->getAttachment();
8007+
8008+
for (const RoundMode* r = roundModes; r->name; ++r)
8009+
{
8010+
if (rndName == &r->name[FB_RMODE_OFFSET])
8011+
{
8012+
attachment->att_dec_status.roundingMode = r->val;
8013+
return;
8014+
}
8015+
}
8016+
8017+
(Arg::Gds(isc_random) << "Invalid round mode for decfloat").raise();
8018+
}
8019+
8020+
8021+
//--------------------
8022+
8023+
79798024
StmtNode* UpdateOrInsertNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
79808025
{
79818026
thread_db* tdbb = JRD_get_thread_data(); // necessary?

src/dsql/StmtNodes.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,22 +1545,18 @@ class SetTransactionNode : public TransactionNode
15451545
};
15461546

15471547

1548-
// This node should better be session management node,
1549-
// but as long as we do not have other session management and
1550-
// node is rather similiar internally to transaction management
1551-
// let it for now be transaction management node.
1552-
class SetRoleNode : public TransactionNode
1548+
class SetRoleNode : public SessionManagementNode
15531549
{
15541550
public:
15551551
explicit SetRoleNode(MemoryPool& pool)
1556-
: TransactionNode(pool),
1552+
: SessionManagementNode(pool),
15571553
trusted(true),
15581554
roleName(pool)
15591555
{
15601556
}
15611557

15621558
SetRoleNode(MemoryPool& pool, Firebird::MetaName* name)
1563-
: TransactionNode(pool),
1559+
: SessionManagementNode(pool),
15641560
trusted(false),
15651561
roleName(pool, *name)
15661562
{
@@ -1569,23 +1565,48 @@ class SetRoleNode : public TransactionNode
15691565
public:
15701566
virtual Firebird::string internalPrint(NodePrinter& printer) const
15711567
{
1572-
TransactionNode::internalPrint(printer);
1568+
SessionManagementNode::internalPrint(printer);
15731569

15741570
NODE_PRINT(printer, trusted);
15751571
NODE_PRINT(printer, roleName);
15761572

15771573
return "SetRoleNode";
15781574
}
15791575

1580-
virtual SetRoleNode* dsqlPass(DsqlCompilerScratch* dsqlScratch);
1581-
virtual void execute(thread_db* tdbb, dsql_req* request, jrd_tra** transaction) const;
1576+
virtual void execute(thread_db* tdbb, dsql_req* request) const;
15821577

15831578
public:
15841579
bool trusted;
15851580
Firebird::MetaName roleName;
15861581
};
15871582

15881583

1584+
class SetRoundNode : public SessionManagementNode
1585+
{
1586+
public:
1587+
SetRoundNode(MemoryPool& pool, Firebird::MetaName* name)
1588+
: SessionManagementNode(pool),
1589+
rndName(pool, *name)
1590+
{
1591+
}
1592+
1593+
public:
1594+
virtual Firebird::string internalPrint(NodePrinter& printer) const
1595+
{
1596+
SessionManagementNode::internalPrint(printer);
1597+
1598+
NODE_PRINT(printer, rndName);
1599+
1600+
return "SetRoundNode";
1601+
}
1602+
1603+
virtual void execute(thread_db* tdbb, dsql_req* request) const;
1604+
1605+
public:
1606+
Firebird::MetaName rndName;
1607+
};
1608+
1609+
15891610
class UpdateOrInsertNode : public TypedNode<DsqlOnlyStmtNode, StmtNode::TYPE_UPDATE_OR_INSERT>
15901611
{
15911612
public:

src/dsql/dsql.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,25 @@ void DsqlTransactionRequest::execute(thread_db* tdbb, jrd_tra** traHandle,
906906
}
907907

908908

909+
void DsqlSessionManagementRequest::dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch,
910+
ntrace_result_t* /*traceResult*/)
911+
{
912+
node = Node::doDsqlPass(scratch, node);
913+
914+
// Don't trace pseudo-statements (without requests associated).
915+
req_traced = false;
916+
}
917+
918+
// Execute a dynamic SQL statement.
919+
void DsqlSessionManagementRequest::execute(thread_db* tdbb, jrd_tra** traHandle,
920+
Firebird::IMessageMetadata* inMetadata, const UCHAR* inMsg,
921+
Firebird::IMessageMetadata* outMetadata, UCHAR* outMsg,
922+
bool singleton)
923+
{
924+
node->execute(tdbb, this);
925+
}
926+
927+
909928
/**
910929
911930
get_request_info
@@ -1756,7 +1775,6 @@ static void sql_info(thread_db* tdbb,
17561775
break;
17571776
case DsqlCompiledStatement::TYPE_CREATE_DB:
17581777
case DsqlCompiledStatement::TYPE_DDL:
1759-
case DsqlCompiledStatement::TYPE_SET_ROLE:
17601778
number = isc_info_sql_stmt_ddl;
17611779
break;
17621780
case DsqlCompiledStatement::TYPE_COMMIT:
@@ -1770,6 +1788,9 @@ static void sql_info(thread_db* tdbb,
17701788
case DsqlCompiledStatement::TYPE_START_TRANS:
17711789
number = isc_info_sql_stmt_start_trans;
17721790
break;
1791+
case DsqlCompiledStatement::TYPE_SESSION_MANAGEMENT:
1792+
number = isc_info_sql_stmt_ddl; // ?????????????????
1793+
break;
17731794
case DsqlCompiledStatement::TYPE_INSERT:
17741795
number = isc_info_sql_stmt_insert;
17751796
break;

src/dsql/dsql.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace Jrd
8080
class RseNode;
8181
class StmtNode;
8282
class TransactionNode;
83+
class SessionManagementNode;
8384
class ValueExprNode;
8485
class ValueListNode;
8586
class WindowClause;
@@ -431,7 +432,7 @@ class DsqlCompiledStatement : public Firebird::PermanentStorage
431432
TYPE_SELECT, TYPE_SELECT_UPD, TYPE_INSERT, TYPE_DELETE, TYPE_UPDATE, TYPE_UPDATE_CURSOR,
432433
TYPE_DELETE_CURSOR, TYPE_COMMIT, TYPE_ROLLBACK, TYPE_CREATE_DB, TYPE_DDL, TYPE_START_TRANS,
433434
TYPE_EXEC_PROCEDURE, TYPE_COMMIT_RETAIN, TYPE_ROLLBACK_RETAIN, TYPE_SET_GENERATOR,
434-
TYPE_SAVEPOINT, TYPE_EXEC_BLOCK, TYPE_SELECT_BLOCK, TYPE_SET_ROLE
435+
TYPE_SAVEPOINT, TYPE_EXEC_BLOCK, TYPE_SELECT_BLOCK, TYPE_SESSION_MANAGEMENT
435436
};
436437

437438
// Statement flags.
@@ -670,6 +671,28 @@ class DsqlTransactionRequest : public dsql_req
670671
NestConst<TransactionNode> node;
671672
};
672673

674+
class DsqlSessionManagementRequest : public dsql_req
675+
{
676+
public:
677+
explicit DsqlSessionManagementRequest(MemoryPool& pool, SessionManagementNode* aNode)
678+
: dsql_req(pool),
679+
node(aNode)
680+
{
681+
req_traced = false;
682+
}
683+
684+
virtual void dsqlPass(thread_db* tdbb, DsqlCompilerScratch* scratch,
685+
ntrace_result_t* traceResult);
686+
687+
virtual void execute(thread_db* tdbb, jrd_tra** traHandle,
688+
Firebird::IMessageMetadata* inMetadata, const UCHAR* inMsg,
689+
Firebird::IMessageMetadata* outMetadata, UCHAR* outMsg,
690+
bool singleton);
691+
692+
private:
693+
NestConst<SessionManagementNode> node;
694+
};
695+
673696
//! Implicit (NATURAL and USING) joins
674697
class ImplicitJoin : public pool_alloc<dsql_type_imp_join>
675698
{

src/dsql/parse.y

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ using namespace Firebird;
700700
Jrd::NamedWindowClause* namedWindowClause;
701701
Jrd::NamedWindowsClause* namedWindowsClause;
702702
Jrd::TransactionNode* traNode;
703+
Jrd::SessionManagementNode* mngNode;
703704
Firebird::Array<Jrd::PrivilegeClause>* privilegeArray;
704705
Jrd::GranteeClause* granteeClause;
705706
Firebird::Array<Jrd::GranteeClause>* granteeArray;
@@ -755,6 +756,7 @@ using namespace Firebird;
755756
Jrd::MappingNode* mappingNode;
756757
Jrd::MappingNode::OP mappingOp;
757758
Jrd::SetRoleNode* setRoleNode;
759+
Jrd::SetRoundNode* setRoundNode;
758760
Jrd::CreateAlterRoleNode* createAlterRoleNode;
759761
}
760762

@@ -774,6 +776,7 @@ statement
774776
: dml_statement { $$ = newNode<DsqlDmlRequest>($1); }
775777
| ddl_statement { $$ = newNode<DsqlDdlRequest>($1); }
776778
| tra_statement { $$ = newNode<DsqlTransactionRequest>($1); }
779+
| mng_statement { $$ = newNode<DsqlSessionManagementRequest>($1); }
777780
;
778781

779782
%type <stmtNode> dml_statement
@@ -808,6 +811,12 @@ tra_statement
808811
: set_transaction { $$ = $1; }
809812
| commit { $$ = $1; }
810813
| rollback { $$ = $1; }
814+
;
815+
816+
%type <mngNode> mng_statement
817+
mng_statement
818+
: set_round { $$ = $1; }
819+
// | set_traps { $$ = $1; }
811820
| set_role { $$ = $1; }
812821
;
813822

@@ -5009,6 +5018,12 @@ set_role
50095018
{ $$ = newNode<SetRoleNode>(); }
50105019
;
50115020

5021+
%type <setRoundNode> set_round
5022+
set_round
5023+
: SET DECFLOAT ROUND valid_symbol_name
5024+
{ $$ = newNode<SetRoundNode>($4); }
5025+
;
5026+
50125027
%type tran_option_list_opt(<setTransactionNode>)
50135028
tran_option_list_opt($setTransactionNode)
50145029
: // nothing

src/isql/isql.epp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4859,6 +4859,7 @@ static processing_state frontend_set(const char* cmd, const char* const* parms,
48594859
{SetOptions::maxrows, "MAXROWS", 0},
48604860
{SetOptions::sqlCont, "ROLE", 0},
48614861
{SetOptions::sqlCont, "TRUSTED", 0}, // TRUSTED ROLE, will get DSQL error other case
4862+
{SetOptions::sqlCont, "DECFLOAT", 0},
48624863
};
48634864

48644865
// Display current set options

0 commit comments

Comments
 (0)