-
-
Notifications
You must be signed in to change notification settings - Fork 268
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 124 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
2b27364
db5031a
8261ce6
a660ffa
0420007
d9208fc
79c9ecc
3f89c17
46912b0
39ed54f
abce28f
22d4407
53bf352
16647ca
c481a72
0174fa5
610c4b8
650c963
234f4f5
0120052
31e2946
8eea06a
c549f4b
f1c3e53
a0ec40b
0ab5acd
f8e1775
4281d2d
542045b
e78ac9a
98d54f4
a09289d
415d9c6
ccd9433
61eaae5
bcfb106
e735ba6
e69448e
10d7356
3377303
97ce417
6aabe94
970b39d
e7b1fd4
5cf5889
18092a5
fb25692
d65d7ca
f345518
26fd59b
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 referenced directly by their name inside package body elements. | ||
|
|
||
| - 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 required: | ||
|
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. I suppose not only in a "select expression", but in any place outside the package it was defined.
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. Yes, the word "select" is redundant |
||
| 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,61 @@ void write_user_privileges() | |
| MISC_release_request_silent(req_handle1); | ||
| } | ||
|
|
||
| void write_constants() | ||
| { | ||
| Firebird::IRequest* req_handle1 = nullptr; | ||
|
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. This file already has
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. Fixed. But the |
||
|
|
||
| BurpGlobals* tdgbl = BurpGlobals::getSpecific(); | ||
|
|
||
| FOR (REQUEST_HANDLE req_handle1) | ||
| CONST IN RDB$CONSTANTS CROSS | ||
| PKG IN RDB$PACKAGES WITH | ||
| CONST.RDB$SCHEMA_NAME EQ PKG.RDB$SCHEMA_NAME AND | ||
| CONST.RDB$PACKAGE_NAME EQ PKG.RDB$PACKAGE_NAME AND | ||
| PKG.RDB$SYSTEM_FLAG NE 1 | ||
| { | ||
| QualifiedMetaString name(CONST.RDB$CONSTANT_NAME); | ||
|
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. Why not put the schema and package name here directly?
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. I followed the exisitng code. Fixed |
||
|
|
||
| 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; | ||
|
Noremos marked this conversation as resolved.
Outdated
|
||
| ON_ERROR | ||
| general_on_error(); | ||
| END_ERROR; | ||
|
Noremos marked this conversation as resolved.
Outdated
|
||
|
|
||
| MISC_release_request_silent(req_handle1); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| namespace Burp { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -167,6 +167,7 @@ bool get_trigger_old (BurpGlobals* tdgbl, burp_rel*); | |
| bool get_type(BurpGlobals* tdgbl); | ||
| bool get_user_privilege(BurpGlobals* tdgbl); | ||
| bool get_view(BurpGlobals* tdgbl, burp_rel*); | ||
| bool get_constants_table(BurpGlobals* tdgbl); | ||
| void ignore_array(BurpGlobals* tdgbl, burp_rel*); | ||
| void ignore_blob(BurpGlobals* tdgbl); | ||
| rec_type ignore_data(BurpGlobals* tdgbl, burp_rel*); | ||
|
|
@@ -10556,6 +10557,85 @@ bool get_view(BurpGlobals* tdgbl, burp_rel* relation) | |
| return true; | ||
| } | ||
|
|
||
| bool get_constants_table(BurpGlobals* tdgbl) | ||
|
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. The suffix
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. I probably meant the |
||
| { | ||
| if (tdgbl->runtimeODS < DB_VERSION_DDL14) // FB6 | ||
| return false; | ||
|
|
||
| QualifiedMetaString name; | ||
|
|
||
| att_type attribute; | ||
| scan_attr_t scan_next_attr; | ||
|
|
||
| Firebird::ITransaction* local_trans = tdgbl->global_trans ? tdgbl->global_trans : gds_trans; | ||
|
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. Do not use
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. Resolved |
||
|
|
||
| STORE (TRANSACTION_HANDLE local_trans | ||
| REQUEST_HANDLE tdgbl->handles_get_type_req_handle1) | ||
| CONST IN RDB$CONSTANTS | ||
| { | ||
| skip_init(&scan_next_attr); | ||
| while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end) | ||
| { | ||
| switch (attribute) | ||
| { | ||
| case att_constant_name: | ||
| CONST.RDB$CONSTANT_NAME.NULL = FALSE; | ||
| GET_TEXT(CONST.RDB$CONSTANT_NAME); | ||
| name.object = CONST.RDB$CONSTANT_NAME; | ||
| break; | ||
|
|
||
| case att_constant_package: | ||
| CONST.RDB$PACKAGE_NAME.NULL = FALSE; | ||
| GET_TEXT(CONST.RDB$PACKAGE_NAME); | ||
| name.package = CONST.RDB$PACKAGE_NAME; | ||
| break; | ||
|
|
||
| case att_constant_field_source: | ||
| CONST.RDB$FIELD_SOURCE.NULL = FALSE; | ||
| GET_TEXT(CONST.RDB$FIELD_SOURCE); | ||
| break; | ||
|
|
||
| case att_constant_private_flag: | ||
| CONST.RDB$PRIVATE_FLAG.NULL = FALSE; | ||
| CONST.RDB$PRIVATE_FLAG = (USHORT) get_int32(tdgbl); | ||
| break; | ||
|
|
||
| case att_constant_blr: | ||
| CONST.RDB$CONSTANT_BLR.NULL = FALSE; | ||
| get_blr_blob(tdgbl, CONST.RDB$CONSTANT_BLR, true); | ||
| break; | ||
|
|
||
| case att_constant_source: | ||
| CONST.RDB$CONSTANT_SOURCE.NULL = FALSE; | ||
| get_source_blob(tdgbl, CONST.RDB$CONSTANT_SOURCE, true); | ||
| break; | ||
|
|
||
| case att_constant_schema_name: | ||
| CONST.RDB$SCHEMA_NAME.NULL = FALSE; | ||
| GET_TEXT(CONST.RDB$SCHEMA_NAME); | ||
| name.schema = CONST.RDB$SCHEMA_NAME; | ||
| break; | ||
|
|
||
| case att_constant_description: | ||
| CONST.RDB$DESCRIPTION.NULL = FALSE; | ||
| get_source_blob(tdgbl, CONST.RDB$DESCRIPTION, true); | ||
| break; | ||
| default: | ||
|
Noremos marked this conversation as resolved.
|
||
| bad_attribute(scan_next_attr, attribute, USHORT(isc_gbak_constant)); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| BURP_verbose(USHORT(isc_gbak_restoring_constant), SafeArg() << name.toQuotedString().data()); | ||
| } | ||
| END_STORE; | ||
|
Noremos marked this conversation as resolved.
Outdated
|
||
| ON_ERROR | ||
| general_on_error(); | ||
| END_ERROR; | ||
|
Noremos marked this conversation as resolved.
Outdated
|
||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void ignore_array(BurpGlobals* tdgbl, burp_rel* relation) | ||
| { | ||
| /************************************** | ||
|
|
@@ -11399,6 +11479,12 @@ bool restore(BurpGlobals* tdgbl, Firebird::IProvider* provider, const TEXT* file | |
| flag = true; | ||
| break; | ||
|
|
||
| case rec_constants: | ||
| if (!get_constants_table(tdgbl)) | ||
| return false; | ||
| flag = true; | ||
| break; | ||
|
|
||
| default: | ||
| BURP_error(43, true, SafeArg() << record); | ||
| // msg 43 don't recognize record type %ld | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.