Skip to content

Commit 53245cc

Browse files
committed
Feature #1113 - Add support for SQL Schemas. (WIP)
1 parent b3e416d commit 53245cc

File tree

179 files changed

+12228
-6365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+12228
-6365
lines changed

builds/win32/msvc15/common.vcxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
<ClInclude Include="..\..\..\src\common\classes\NoThrowTimeStamp.h" />
145145
<ClInclude Include="..\..\..\src\common\classes\objects_array.h" />
146146
<ClInclude Include="..\..\..\src\common\classes\ParsedList.h" />
147-
<ClInclude Include="..\..\..\src\common\classes\QualifiedName.h" />
147+
<ClInclude Include="..\..\..\src\common\classes\QualifiedMetaString.h" />
148148
<ClInclude Include="..\..\..\src\common\classes\RefCounted.h" />
149149
<ClInclude Include="..\..\..\src\common\classes\RefMutex.h" />
150150
<ClInclude Include="..\..\..\src\common\classes\rwlock.h" />

builds/win32/msvc15/common.vcxproj.filters

+1-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@
449449
<ClInclude Include="..\..\..\src\common\classes\objects_array.h">
450450
<Filter>headers</Filter>
451451
</ClInclude>
452-
<ClInclude Include="..\..\..\src\common\classes\QualifiedName.h">
452+
<ClInclude Include="..\..\..\src\common\classes\MetaString.h">
453453
<Filter>headers</Filter>
454454
</ClInclude>
455455
<ClInclude Include="..\..\..\src\common\classes\RefCounted.h">

builds/win32/msvc15/common_test.vcxproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@
179179
<ClCompile Include="..\..\..\src\common\tests\CommonTest.cpp" />
180180
<ClCompile Include="..\..\..\src\common\classes\tests\AlignerTest.cpp" />
181181
<ClCompile Include="..\..\..\src\common\classes\tests\ArrayTest.cpp" />
182+
<ClCompile Include="..\..\..\src\common\classes\tests\ClumpletTest.cpp" />
182183
<ClCompile Include="..\..\..\src\common\classes\tests\DoublyLinkedListTest.cpp" />
184+
<ClCompile Include="..\..\..\src\common\classes\tests\QualifiedMetaStringTest.cpp" />
185+
<ClCompile Include="..\..\..\src\common\classes\tests\VectorTest.cpp" />
183186
<ClCompile Include="..\..\..\src\yvalve\gds.cpp" />
184187
</ItemGroup>
185188
<ItemGroup>
@@ -195,4 +198,4 @@
195198
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
196199
<ImportGroup Label="ExtensionTargets">
197200
</ImportGroup>
198-
</Project>
201+
</Project>

builds/win32/msvc15/common_test.vcxproj.filters

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,20 @@
2424
<ClCompile Include="..\..\..\src\common\classes\tests\ArrayTest.cpp">
2525
<Filter>source</Filter>
2626
</ClCompile>
27+
<ClCompile Include="..\..\..\src\common\classes\tests\ClumpletTest.cpp">
28+
<Filter>source</Filter>
29+
</ClCompile>
2730
<ClCompile Include="..\..\..\src\common\classes\tests\DoublyLinkedListTest.cpp">
2831
<Filter>source</Filter>
2932
</ClCompile>
33+
<ClCompile Include="..\..\..\src\common\classes\tests\QualifiedMetaStringTest.cpp">
34+
<Filter>source</Filter>
35+
</ClCompile>
36+
<ClCompile Include="..\..\..\src\common\classes\tests\VectorTest.cpp">
37+
<Filter>source</Filter>
38+
</ClCompile>
3039
<ClCompile Include="..\..\..\src\yvalve\gds.cpp">
3140
<Filter>source</Filter>
3241
</ClCompile>
3342
</ItemGroup>
34-
</Project>
43+
</Project>

doc/sql.extensions/README.ddl_triggers.txt

+17-16
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ DDL_TRIGGER context namespace:
119119
- EVENT_TYPE: event type (CREATE, ALTER, DROP)
120120
- OBJECT_TYPE: object type (TABLE, VIEW, etc)
121121
- DDL_EVENT: event name (<ddl event item>), where <ddl_event_item> is EVENT_TYPE || ' ' || OBJECT_TYPE
122+
- SCHEMA_NAME: object's schema name
122123
- OBJECT_NAME: metadata object name
123124
- OLD_OBJECT_NAME: metadata object name before a rename
124125
- NEW_OBJECT_NAME: metadata object name after a rename
@@ -294,51 +295,51 @@ commit;
294295

295296
select id, ddl_event, object_name, old_object_name, new_object_name, sql_text, ok from ddl_log order by id;
296297

297-
ID DDL_EVENT OBJECT_NAME OLD_OBJECT_NAME NEW_OBJECT_NAME SQL_TEXT OK
298-
===================== ========================= =============================== =============================== =============================== ================= ======
299-
2 CREATE TABLE T1 <null> <null> 80:0 Y
298+
ID DDL_EVENT OBJECT_NAME OLD_OBJECT_NAME NEW_OBJECT_NAME SQL_TEXT OK
299+
===================== ========================= =============================== =============================== =============================== ================= ======
300+
2 CREATE TABLE T1 <null> <null> 80:0 Y
300301
==============================================================================
301-
SQL_TEXT:
302+
SQL_TEXT:
302303
recreate table t1 (
303304
n1 integer,
304305
n2 integer
305306
)
306307
==============================================================================
307-
3 CREATE TABLE T1 <null> <null> 80:1 N
308+
3 CREATE TABLE T1 <null> <null> 80:1 N
308309
==============================================================================
309-
SQL_TEXT:
310+
SQL_TEXT:
310311
create table t1 (
311312
n1 integer,
312313
n2 integer
313314
)
314315
==============================================================================
315-
4 DROP TABLE T1 <null> <null> 80:2 Y
316+
4 DROP TABLE T1 <null> <null> 80:2 Y
316317
==============================================================================
317-
SQL_TEXT:
318+
SQL_TEXT:
318319
recreate table t1 (
319320
n integer
320321
)
321322
==============================================================================
322-
5 CREATE TABLE T1 <null> <null> 80:3 Y
323+
5 CREATE TABLE T1 <null> <null> 80:3 Y
323324
==============================================================================
324-
SQL_TEXT:
325+
SQL_TEXT:
325326
recreate table t1 (
326327
n integer
327328
)
328329
==============================================================================
329-
6 CREATE DOMAIN DOM1 <null> <null> 80:4 Y
330+
6 CREATE DOMAIN DOM1 <null> <null> 80:4 Y
330331
==============================================================================
331-
SQL_TEXT:
332+
SQL_TEXT:
332333
create domain dom1 as integer
333334
==============================================================================
334-
7 ALTER DOMAIN DOM1 <null> <null> 80:5 Y
335+
7 ALTER DOMAIN DOM1 <null> <null> 80:5 Y
335336
==============================================================================
336-
SQL_TEXT:
337+
SQL_TEXT:
337338
alter domain dom1 type bigint
338339
==============================================================================
339-
8 ALTER DOMAIN DOM1 DOM1 DOM2 80:6 Y
340+
8 ALTER DOMAIN DOM1 DOM1 DOM2 80:6 Y
340341
==============================================================================
341-
SQL_TEXT:
342+
SQL_TEXT:
342343
alter domain dom1 to dom2
343344
==============================================================================
344345

doc/sql.extensions/README.profiler.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ execute procedure rdb$profiler.finish_session(true);
109109
110110
-- Data analysis
111111
112+
set search_path to plg$profiler, public, system;
113+
112114
set transaction read committed;
113115
114116
select * from plg$prof_sessions;
@@ -243,7 +245,9 @@ Input parameters:
243245

244246
# Snapshot tables
245247

246-
Snapshot tables (as well views and sequence) are automatically created in the first usage of the profiler. They are owned by the database owner, with read/write permissions for `PUBLIC`.
248+
The profiler schema, snapshot tables, views and sequence are automatically created in the first usage of the profiler.
249+
250+
They are owned by the database owner, with usage/read/write permissions for the RDB$PROFILER role, granted by default to `PUBLIC`.
247251

248252
When a session is deleted, the related data in other profiler snapshot tables are automatically deleted too through foreign keys with `DELETE CASCADE` option.
249253

src/alice/exe.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ static void buildDpb(Firebird::ClumpletWriter& dpb, const SINT64 switches)
202202
dpb.reset(isc_dpb_version1);
203203
dpb.insertTag(isc_dpb_gfix_attach);
204204
tdgbl->uSvc->fillDpb(dpb);
205+
dpb.insertString(isc_dpb_schema_path, SYSTEM_SCHEMA, fb_strlen(SYSTEM_SCHEMA));
205206

206207
if (switches & sw_sweep) {
207208
dpb.insertByte(isc_dpb_sweep, isc_dpb_records);

src/auth/SecureRemotePassword/manage/SrpManagement.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,28 @@ class SrpManagement final : public Firebird::StdPlugin<Firebird::IManagementImpl
6868
void prepareDataStructures()
6969
{
7070
const char* script[] = {
71-
"CREATE TABLE PLG$SRP (PLG$USER_NAME SEC$USER_NAME NOT NULL PRIMARY KEY, "
71+
"CREATE TABLE PUBLIC.PLG$SRP (PLG$USER_NAME SYSTEM.SEC$USER_NAME NOT NULL PRIMARY KEY, "
7272
"PLG$VERIFIER VARCHAR(128) CHARACTER SET OCTETS NOT NULL, "
7373
"PLG$SALT VARCHAR(32) CHARACTER SET OCTETS NOT NULL, "
74-
"PLG$COMMENT RDB$DESCRIPTION, PLG$FIRST SEC$NAME_PART, "
75-
"PLG$MIDDLE SEC$NAME_PART, PLG$LAST SEC$NAME_PART, "
76-
"PLG$ATTRIBUTES RDB$DESCRIPTION, "
74+
"PLG$COMMENT SYSTEM.RDB$DESCRIPTION, PLG$FIRST SYSTEM.SEC$NAME_PART, "
75+
"PLG$MIDDLE SYSTEM.SEC$NAME_PART, PLG$LAST SYSTEM.SEC$NAME_PART, "
76+
"PLG$ATTRIBUTES SYSTEM.RDB$DESCRIPTION, "
7777
"PLG$ACTIVE BOOLEAN)"
7878
,
79-
"CREATE VIEW PLG$SRP_VIEW AS "
79+
"CREATE VIEW PUBLIC.PLG$SRP_VIEW AS "
8080
"SELECT PLG$USER_NAME, PLG$VERIFIER, PLG$SALT, PLG$COMMENT, "
8181
" PLG$FIRST, PLG$MIDDLE, PLG$LAST, PLG$ATTRIBUTES, PLG$ACTIVE "
82-
"FROM PLG$SRP WHERE RDB$SYSTEM_PRIVILEGE(USER_MANAGEMENT) "
82+
"FROM PUBLIC.PLG$SRP WHERE RDB$SYSTEM_PRIVILEGE(USER_MANAGEMENT) "
8383
" OR CURRENT_USER = PLG$SRP.PLG$USER_NAME"
8484
,
85-
"GRANT ALL ON PLG$SRP TO VIEW PLG$SRP_VIEW"
85+
"GRANT ALL ON PUBLIC.PLG$SRP TO VIEW PUBLIC.PLG$SRP_VIEW"
8686
,
87-
"GRANT SELECT ON PLG$SRP_VIEW TO PUBLIC"
87+
"GRANT SELECT ON PUBLIC.PLG$SRP_VIEW TO PUBLIC"
8888
,
8989
"GRANT UPDATE(PLG$VERIFIER, PLG$SALT, PLG$FIRST, PLG$MIDDLE, PLG$LAST, "
90-
" PLG$COMMENT, PLG$ATTRIBUTES) ON PLG$SRP_VIEW TO PUBLIC"
90+
" PLG$COMMENT, PLG$ATTRIBUTES) ON PUBLIC.PLG$SRP_VIEW TO PUBLIC"
9191
,
92-
"GRANT ALL ON PLG$SRP_VIEW TO SYSTEM PRIVILEGE USER_MANAGEMENT"
92+
"GRANT ALL ON PUBLIC.PLG$SRP_VIEW TO SYSTEM PRIVILEGE USER_MANAGEMENT"
9393
,
9494
NULL
9595
};
@@ -353,7 +353,7 @@ class SrpManagement final : public Firebird::StdPlugin<Firebird::IManagementImpl
353353
case Firebird::IUser::OP_USER_ADD:
354354
{
355355
const char* insert =
356-
"INSERT INTO plg$srp_view(PLG$USER_NAME, PLG$VERIFIER, PLG$SALT, PLG$FIRST, PLG$MIDDLE, PLG$LAST,"
356+
"INSERT INTO public.plg$srp_view(PLG$USER_NAME, PLG$VERIFIER, PLG$SALT, PLG$FIRST, PLG$MIDDLE, PLG$LAST,"
357357
"PLG$COMMENT, PLG$ATTRIBUTES, PLG$ACTIVE) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
358358

359359
Firebird::IStatement* stmt = NULL;
@@ -455,7 +455,7 @@ class SrpManagement final : public Firebird::StdPlugin<Firebird::IManagementImpl
455455

456456
case Firebird::IUser::OP_USER_MODIFY:
457457
{
458-
Firebird::string update = "UPDATE plg$srp_view SET ";
458+
Firebird::string update = "UPDATE public.plg$srp_view SET ";
459459

460460
Firebird::AutoPtr<Varfield> verifier, slt;
461461
if (user->password()->entered())
@@ -558,7 +558,7 @@ class SrpManagement final : public Firebird::StdPlugin<Firebird::IManagementImpl
558558

559559
case Firebird::IUser::OP_USER_DELETE:
560560
{
561-
const char* del = "DELETE FROM plg$srp_view WHERE PLG$USER_NAME=?";
561+
const char* del = "DELETE FROM public.plg$srp_view WHERE PLG$USER_NAME=?";
562562
Firebird::IStatement* stmt = NULL;
563563
try
564564
{
@@ -605,7 +605,7 @@ class SrpManagement final : public Firebird::StdPlugin<Firebird::IManagementImpl
605605
" WHERE RDB$RELATION_NAME = 'RDB$ADMIN' AND RDB$PRIVILEGE = 'M' GROUP BY RDB$USER) "
606606
"SELECT PLG$USER_NAME, PLG$FIRST, PLG$MIDDLE, PLG$LAST, PLG$COMMENT, PLG$ATTRIBUTES, "
607607
" CASE WHEN RDB$USER IS NULL THEN FALSE ELSE TRUE END, PLG$ACTIVE "
608-
"FROM PLG$SRP_VIEW LEFT JOIN ADMINS "
608+
"FROM system.PLG$SRP_VIEW LEFT JOIN ADMINS "
609609
" ON PLG$SRP_VIEW.PLG$USER_NAME = ADMINS.RDB$USER ";
610610
if (user->userName()->entered())
611611
{

src/auth/SecureRemotePassword/server/SrpServer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class SecurityDatabase : public VSecDb
196196
HANDSHAKE_DEBUG(fprintf(stderr, "Srv: SRP1: started transaction\n"));
197197

198198
const char* sql =
199-
"SELECT PLG$VERIFIER, PLG$SALT FROM PLG$SRP WHERE PLG$USER_NAME = ? AND PLG$ACTIVE";
199+
"SELECT PLG$VERIFIER, PLG$SALT FROM PUBLIC.PLG$SRP WHERE PLG$USER_NAME = ? AND PLG$ACTIVE";
200200
stmt = att->prepare(&status, tra, 0, sql, 3, IStatement::PREPARE_PREFETCH_METADATA);
201201
if (status->getState() & IStatus::STATE_ERRORS)
202202
{

src/auth/SecurityDatabase/LegacyManagement.epp

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void SecurityDatabaseManagement::start(Firebird::CheckStatusWrapper* st, Firebir
129129
Firebird::ClumpletWriter dpb(Firebird::ClumpletReader::dpbList, MAX_DPB_SIZE);
130130
dpb.insertByte(isc_dpb_sec_attach, TRUE);
131131
dpb.insertString(isc_dpb_config, Firebird::ParsedList::getNonLoopbackProviders(secDbName));
132+
dpb.insertString(isc_dpb_schema_path, SYSTEM_SCHEMA, fb_strlen(SYSTEM_SCHEMA));
132133

133134
unsigned int authBlockSize;
134135
const unsigned char* authBlock = logonInfo->authBlock(&authBlockSize);
@@ -343,6 +344,7 @@ int SecurityDatabaseManagement::execute(Firebird::CheckStatusWrapper* st, Firebi
343344
// this checks the "entered" flags for each parameter (except the name)
344345
// and makes all non-entered parameters null valued
345346

347+
// FIXME: epp queries outside engine has not exclusive schema search path set to SYSTEM
346348
STORE (TRANSACTION_HANDLE transaction REQUEST_HANDLE request) U IN PLG$VIEW_USERS USING
347349
STR_STORE(U.PLG$USER_NAME, user->userName()->get());
348350

src/auth/SecurityDatabase/LegacyServer.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ const UCHAR PWD_REQUEST[] =
6464
blr_begin,
6565
blr_for,
6666
blr_rse, 1,
67-
blr_relation, 9, 'P', 'L', 'G', '$', 'U', 'S', 'E', 'R', 'S', 0,
67+
blr_relation3,
68+
6, 'P', 'U', 'B', 'L', 'I', 'C', // PUBLIC_SCHEMA // FIXME:
69+
9, 'P', 'L', 'G', '$', 'U', 'S', 'E', 'R', 'S',
70+
0,
71+
0,
6872
blr_first,
6973
blr_literal, blr_short, 0, 1, 0,
7074
blr_boolean,

src/burp/BurpTasks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ bool BackupRelationTask::fileWriter(Item& item)
561561
BurpGlobals* tdgbl = item.m_gbl;
562562
fb_assert(tdgbl == m_masterGbl);
563563

564-
BURP_verbose(142, m_relation->rel_name);
564+
BURP_verbose(142, m_relation->rel_name.toString().c_str());
565565
// msg 142 writing data for relation %s
566566

567567
IOBuffer*& buf = item.m_buffer = NULL;

src/burp/OdsDetection.epp

+23-13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace
4545
{"RDB$ROLES", 0, DB_VERSION_DDL9}, // IB5
4646
{"RDB$PACKAGES", 0, DB_VERSION_DDL12}, // FB3
4747
{"RDB$PUBLICATIONS", 0, DB_VERSION_DDL13}, // FB4
48+
{"RDB$SCHEMAS", 0, DB_VERSION_DDL14}, // FB6
4849
{0, 0, 0}
4950
};
5051

@@ -102,13 +103,16 @@ void detectRuntimeODS()
102103
Firebird::IRequest* req_handle = nullptr;
103104
FOR (REQUEST_HANDLE req_handle)
104105
RFR IN RDB$RELATION_FIELDS
105-
WITH (RFR.RDB$RELATION_NAME = 'RDB$RELATIONS' OR RFR.RDB$RELATION_NAME = 'RDB$RELATION_FIELDS')
106-
AND RFR.RDB$FIELD_NAME = 'RDB$SYSTEM_FLAG'
106+
WITH (RFR.RDB$RELATION_NAME = 'RDB$RELATIONS' OR RFR.RDB$RELATION_NAME = 'RDB$RELATION_FIELDS') AND
107+
RFR.RDB$FIELD_NAME = 'RDB$SYSTEM_FLAG' AND
108+
(RFR.RDB$SCHEMA_NAME MISSING OR RFR.RDB$SCHEMA_NAME = SYSTEM_SCHEMA)
109+
{
107110
++count;
108-
END_FOR;
111+
}
112+
END_FOR
109113
ON_ERROR
110114
general_on_error();
111-
END_ERROR;
115+
END_ERROR
112116
MISC_release_request_silent(req_handle);
113117

114118
if (count != 2)
@@ -119,14 +123,17 @@ void detectRuntimeODS()
119123
{
120124
FOR (REQUEST_HANDLE req_handle2)
121125
FIRST 1 X IN RDB$RELATIONS
122-
WITH X.RDB$RELATION_NAME = rel->relation
123-
AND X.RDB$SYSTEM_FLAG = 1
126+
WITH X.RDB$RELATION_NAME = rel->relation AND
127+
X.RDB$SYSTEM_FLAG = 1 AND
128+
(X.RDB$SCHEMA_NAME MISSING OR X.RDB$SCHEMA_NAME = SYSTEM_SCHEMA)
129+
{
124130
if (tdgbl->runtimeODS < rel->ods_version)
125131
tdgbl->runtimeODS = rel->ods_version;
126-
END_FOR;
132+
}
133+
END_FOR
127134
ON_ERROR
128135
general_on_error();
129-
END_ERROR;
136+
END_ERROR
130137
}
131138
MISC_release_request_silent(req_handle2);
132139

@@ -138,15 +145,18 @@ void detectRuntimeODS()
138145
{
139146
FOR (REQUEST_HANDLE req_handle3)
140147
FIRST 1 X2 IN RDB$RELATION_FIELDS
141-
WITH X2.RDB$RELATION_NAME = rf->relation
142-
AND X2.RDB$FIELD_NAME = rf->field
143-
AND X2.RDB$SYSTEM_FLAG = 1
148+
WITH X2.RDB$RELATION_NAME = rf->relation AND
149+
X2.RDB$FIELD_NAME = rf->field AND
150+
X2.RDB$SYSTEM_FLAG = 1 AND
151+
(X2.RDB$SCHEMA_NAME MISSING OR X2.RDB$SCHEMA_NAME = SYSTEM_SCHEMA)
152+
{
144153
if (tdgbl->runtimeODS < rf->ods_version)
145154
tdgbl->runtimeODS = rf->ods_version;
146-
END_FOR;
155+
}
156+
END_FOR
147157
ON_ERROR
148158
general_on_error();
149-
END_ERROR;
159+
END_ERROR
150160
}
151161
MISC_release_request_silent(req_handle3);
152162
}

src/burp/OdsDetection.h

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const int DB_VERSION_DDL11_2 = 112; // ods11.2 db, FB2.5
6969
const int DB_VERSION_DDL12 = 120; // ods12.0 db, FB3.0
7070
const int DB_VERSION_DDL13 = 130; // ods13.0 db, FB4.0
7171
const int DB_VERSION_DDL13_1 = 131; // ods13.1 db, FB5.0
72+
const int DB_VERSION_DDL14 = 140; // ods14 db, FB6.0
7273

7374
const int DB_VERSION_OLDEST_SUPPORTED = DB_VERSION_DDL8; // IB4.0 is ods8
7475

0 commit comments

Comments
 (0)