-
-
Notifications
You must be signed in to change notification settings - Fork 266
Package constants #8916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Package constants #8916
Changes from all commits
5aa9116
251615c
2d35ecc
75db5ab
e54c9e6
45d62b7
06411d7
3dc1d3d
d048560
6231dbc
05342aa
459354f
3c2c61e
fd208d1
8a982ac
c42bd55
4a556aa
44a7050
c2caa1b
4294bc4
3148971
51fc8d7
bd085c9
4695050
e606d59
cf7929e
12a7b2b
edca2c5
cfdf444
816ad9c
13b7df9
46e0e5d
51d9ab6
2ccea0f
8d85f05
2f11ba4
44b74d7
e7e439e
25ab034
70ffad8
edeb6f0
65ed53f
531b987
75a29bf
9100a79
bfe4542
50f39a0
81978d3
41693fc
6b64151
241a95a
71872e2
c483a69
731d65d
414bd0d
082d5e7
d273bc0
fff58ef
0284ee1
84d0d0a
b85ee52
37c4438
d3a0b9d
7b3ef78
93caf2e
5a4b657
bafdb37
e9445e3
a1488be
9edf966
10140bb
dba49c1
1dcc3df
4ddaad4
8149e09
a195eb7
f664a74
f3d7c52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,14 +19,18 @@ Syntax: | |||||
|
|
||||||
| <package_item> ::= | ||||||
| <function_decl> ; | | ||||||
| <procedure_decl> ; | ||||||
| <procedure_decl> ; | | ||||||
| <constant_decl> ; | ||||||
|
|
||||||
| <function_decl> ::= | ||||||
| FUNCTION <name> [( <parameters> )] RETURNS <type> | ||||||
|
|
||||||
| <procedure_decl> ::= | ||||||
| PROCEDURE <name> [( <parameters> ) [RETURNS ( <parameters> )]] | ||||||
|
|
||||||
| <constant_decl> ::= | ||||||
| CONSTANT <name> <type> = <constant expression> | ||||||
|
|
||||||
| <package_body> ::= | ||||||
| { CREATE [OR ALTER] | ALTER | RECREATE } PACKAGE BODY <name> | ||||||
| AS | ||||||
|
|
@@ -37,7 +41,8 @@ Syntax: | |||||
|
|
||||||
| <package_body_item> ::= | ||||||
| <function_impl> | | ||||||
| <procedure_impl> | ||||||
| <procedure_impl> | | ||||||
| <constant_decl> | ||||||
|
|
||||||
| <function_impl> ::= | ||||||
| FUNCTION <name> [( <parameters> )] RETURNS <type> | ||||||
|
|
@@ -75,7 +80,7 @@ Objectives: | |||||
| 1) The grouping is not represented in the database metadata. | ||||||
| 2) They all participate in a flat namespace and all routines are callable by everyone (not | ||||||
| talking about security permissions here). | ||||||
|
|
||||||
| - Facilitate dependency tracking between its internal routines and between other packaged and | ||||||
| unpackaged routines. | ||||||
|
|
||||||
|
|
@@ -90,9 +95,17 @@ Objectives: | |||||
| tables that the package body depends on that object. If you want to, for example, drop that | ||||||
| object, you first need to remove who depends on it. As who depends on it is a package body, | ||||||
| you can just drop it even if some other database object depends on this package. When the body | ||||||
| is dropped, the header remains, allowing you to create its body again after changing it based | ||||||
| is dropped, the header remains, allowing you to create its body again after changing it based | ||||||
| on the object removal. | ||||||
|
|
||||||
| A package constant is a value initialized by a constant expression. | ||||||
| A constant expression is defined by a simple rule: its value does not change after recompilation. | ||||||
| Constants declared in the package specification are publicly visible and can be referenced using | ||||||
| the [<schema>.]<package>.<constant_name> notation. | ||||||
| Constants declared in the package body are private and cannot be accessed from outside the package. | ||||||
| However, they can be referenced directly by <constant_name> within <procedure_impl> and <function_impl>. | ||||||
| Header constants can also be used directly with just the name for package body elements. | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| - Facilitate permission management. | ||||||
|
|
||||||
| It's generally a good practice to create routines with a privileged database user and grant | ||||||
|
|
@@ -106,6 +119,10 @@ Objectives: | |||||
| GRANT SELECT ON TABLE secret TO PACKAGE pk_secret; | ||||||
| GRANT EXECUTE ON PACKAGE pk_secret TO ROLE role_secret; | ||||||
|
|
||||||
| To use package constants in a select expression, a USAGE permission is requeued: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| GRANT USAGE ON PACKAGE [<schema>.]<package_name> to [<user|role>] <name> [<grant_option>] [<granted_by>]; | ||||||
| REVOKE USAGE ON PACKAGE [<schema>.]<package_name> FROM <user|role> <name> [<granted_by>]; | ||||||
|
|
||||||
| - Introduce private scope to routines making them available only for internal usage in the | ||||||
| defining package. | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,6 +156,7 @@ void write_triggers(); | |
| void write_trigger_messages(); | ||
| void write_types(); | ||
| void write_user_privileges(); | ||
| void write_constants(); | ||
| void general_on_error(); | ||
|
|
||
|
|
||
|
|
@@ -505,6 +506,13 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name) | |
| write_pub_tables(); | ||
| } | ||
|
|
||
| if (tdgbl->runtimeODS >= DB_VERSION_DDL14) | ||
| { | ||
| // Write constants | ||
| BURP_verbose(USHORT(isc_gbak_writing_constants)); // writing constants | ||
| write_constants(); | ||
| } | ||
|
|
||
| // Finish up | ||
|
|
||
| put(tdgbl, (UCHAR) rec_end); | ||
|
|
@@ -4845,6 +4853,58 @@ void write_user_privileges() | |
| MISC_release_request_silent(req_handle1); | ||
| } | ||
|
|
||
| void write_constants() | ||
| { | ||
| Firebird::IRequest* req_handle1 = nullptr; | ||
|
|
||
| BurpGlobals* tdgbl = BurpGlobals::getSpecific(); | ||
|
|
||
| FOR (REQUEST_HANDLE req_handle1) | ||
| CONST IN RDB$CONSTANTS | ||
| WITH CONST.RDB$SCHEMA_NAME NE SYSTEM_SCHEMA | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this check allowed or should I add the RDB$SYSTEM_FLAG field? |
||
| { | ||
| QualifiedMetaString name(CONST.RDB$CONSTANT_NAME); | ||
|
|
||
| put(tdgbl, rec_constants); | ||
| PUT_TEXT(att_constant_name, CONST.RDB$CONSTANT_NAME); | ||
|
|
||
| PUT_TEXT(att_constant_package, CONST.RDB$PACKAGE_NAME); | ||
| name.package = CONST.RDB$PACKAGE_NAME; | ||
|
|
||
| PUT_TEXT(att_constant_field_source, CONST.RDB$FIELD_SOURCE); | ||
|
|
||
| if (!CONST.RDB$PRIVATE_FLAG.NULL) | ||
| put_int32(att_constant_private_flag, CONST.RDB$PRIVATE_FLAG); | ||
|
|
||
| if (!CONST.RDB$CONSTANT_BLR.NULL) | ||
| put_blr_blob(att_constant_blr, CONST.RDB$CONSTANT_BLR); | ||
|
|
||
| if (!CONST.RDB$CONSTANT_SOURCE.NULL) | ||
| put_source_blob(att_constant_source, att_constant_source, CONST.RDB$CONSTANT_SOURCE); | ||
|
|
||
| if (!CONST.RDB$SCHEMA_NAME.NULL) | ||
| { | ||
| PUT_TEXT(att_constant_schema_name, CONST.RDB$SCHEMA_NAME); | ||
| name.schema = CONST.RDB$SCHEMA_NAME; | ||
| } | ||
|
|
||
| if (!CONST.RDB$DESCRIPTION.NULL) | ||
| { | ||
| put_source_blob (att_constant_description, att_constant_description, CONST.RDB$DESCRIPTION); | ||
| } | ||
|
|
||
| // writing constant %s | ||
| BURP_verbose(USHORT(isc_gbak_writing_constant), SafeArg() << name.toQuotedString().data()); | ||
| put(tdgbl, att_end); | ||
| } | ||
| END_FOR; | ||
| ON_ERROR | ||
| general_on_error(); | ||
| END_ERROR; | ||
|
|
||
| MISC_release_request_silent(req_handle1); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| namespace Burp { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.