Skip to content

Commit 785a411

Browse files
author
Alexander Zhdanov
committed
Added CREATE IF NOT EXISTS for tablespaces
1 parent 39553b7 commit 785a411

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

src/dsql/TablespaceNodes.epp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,14 @@ void CreateAlterTablespaceNode::executeCreate(thread_db* tdbb, DsqlCompilerScrat
126126

127127
const MetaName& userName = attachment->att_user->getUserName();
128128

129+
if (createIfNotExistsOnly && !DYN_UTIL_check_unique_name_nothrow(tdbb, transaction, name, obj_tablespace))
130+
return;
131+
129132
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE,
130133
DDL_TRIGGER_CREATE_TABLESPACE, name, NULL);
131134

135+
DYN_UTIL_check_unique_name(tdbb, transaction, name, obj_tablespace);
136+
132137
AutoCacheRequest requestHandle(tdbb, drq_s_tablespace, DYN_REQUESTS);
133138

134139
int faults = 0;

src/dsql/TablespaceNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class CreateAlterTablespaceNode : public DdlNode
6969
bool alter;
7070
bool offline;
7171
bool readonly;
72+
bool createIfNotExistsOnly = false;
7273
};
7374

7475

src/dsql/parse.y

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,12 @@ create_clause
16771677
node->createIfNotExistsOnly = $3;
16781678
$$ = node;
16791679
}
1680-
| TABLESPACE tablespace_clause { $$ = $2; }
1680+
| TABLESPACE if_not_exists_opt tablespace_clause
1681+
{
1682+
const auto node = $3;
1683+
node->createIfNotExistsOnly = $2;
1684+
$$ = node;
1685+
}
16811686
;
16821687

16831688

src/include/firebird/impl/msg/dyn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,4 @@ FB_IMPL_MSG_SYMBOL(DYN, 313, dyn_dup_package, "Package @1 already exists")
306306
FB_IMPL_MSG(DYN, 314, dyn_ts_not_found, -901, "42", "000", "Tablespace @1 not found")
307307
FB_IMPL_MSG(DYN, 315, dyn_cant_set_ts_table, -901, "42", "000", "Cannot set tablespace for temporary table @1")
308308
FB_IMPL_MSG(DYN, 316, dyn_cant_set_ts_index, -901, "42", "000", "Cannot set tablespace for temporary index @1")
309+
FB_IMPL_MSG(DYN, 317, dyn_ts_already_exists, -901, "42", "000", "Tablespace @1 already exists")

src/include/gen/Firebird.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5892,6 +5892,7 @@ IProfilerStatsImpl = class(IProfilerStats)
58925892
isc_dyn_ts_not_found = 336068922;
58935893
isc_dyn_cant_set_ts_table = 336068923;
58945894
isc_dyn_cant_set_ts_index = 336068924;
5895+
isc_dyn_ts_already_exists = 336068925;
58955896
isc_gbak_unknown_switch = 336330753;
58965897
isc_gbak_page_size_missing = 336330754;
58975898
isc_gbak_page_size_toobig = 336330755;

src/jrd/drq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ enum drq_type_t
260260
drq_l_pkg_name, // lookup package name
261261
drq_l_rel_con, // lookup relation constraint
262262
drq_l_rel_fld_name, // lookup relation field name
263+
drq_l_ts_name, // lookup tablespace name
263264
drq_ts_drop_idx_dfw, // find index of tablespace in dfw for drop
264265
drq_ts_drop_rel_dfw, // find relation of tablespace in dfw for drop
265266

src/jrd/dyn_util.epp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,19 @@ bool DYN_UTIL_check_unique_name_nothrow(thread_db* tdbb, jrd_tra* transaction,
220220

221221
break;
222222

223+
case obj_tablespace:
224+
request.reset(tdbb, drq_l_ts_name, DYN_REQUESTS);
225+
226+
FOR(REQUEST_HANDLE request TRANSACTION_HANDLE transaction)
227+
TS IN RDB$TABLESPACES
228+
WITH TS.RDB$TABLESPACE_NAME EQ object_name.c_str()
229+
{
230+
*errorCode = 317;
231+
}
232+
END_FOR
233+
234+
break;
235+
223236
default:
224237
fb_assert(false);
225238
}

0 commit comments

Comments
 (0)