Skip to content

Commit

Permalink
Apply CORE-3114 patch (Attempt to drop non-existing generator produce…
Browse files Browse the repository at this point in the history
…s bad error) with some modifications.
  • Loading branch information
asfernandes committed Nov 9, 2011
1 parent 9bac54c commit e090671
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 91 deletions.
2 changes: 2 additions & 0 deletions lang_helpers/gds_codes.ftn
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,8 @@ C --
PARAMETER (GDS__dsql_recreate_view_failed = 336397301)
INTEGER*4 GDS__dsql_drop_view_failed
PARAMETER (GDS__dsql_drop_view_failed = 336397302)
INTEGER*4 GDS__dsql_drop_sequence_failed
PARAMETER (GDS__dsql_drop_sequence_failed = 336397303)
INTEGER*4 GDS__gsec_cant_open_db
PARAMETER (GDS__gsec_cant_open_db = 336723983)
INTEGER*4 GDS__gsec_switches_error
Expand Down
1 change: 1 addition & 0 deletions lang_helpers/gds_codes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@
gds_dsql_create_alter_view_failed = 336397300;
gds_dsql_recreate_view_failed = 336397301;
gds_dsql_drop_view_failed = 336397302;
gds_dsql_drop_sequence_failed = 336397303;
gds_gsec_cant_open_db = 336723983;
gds_gsec_switches_error = 336723984;
gds_gsec_no_op_spec = 336723985;
Expand Down
45 changes: 39 additions & 6 deletions src/dsql/DdlNodes.epp
Original file line number Diff line number Diff line change
Expand Up @@ -4716,23 +4716,56 @@ void CreateSequenceNode::store(thread_db* tdbb, jrd_tra* transaction, const Meta

//----------------------

void DropSequenceNode::print(string& text, Array<dsql_nod*>& nodes) const
{
text.printf(
"DropSequenceNode\n"
" name: %s\n",
name.c_str());
}

// Delete a record from RDB$GENERATORS. Return true if succeeded.
bool DropSequenceNode::deleteGenerator(thread_db* tdbb, jrd_tra* transaction, const MetaName& name)
void DropSequenceNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction)
{
AutoCacheRequest request(tdbb, drq_e_ident_gens, DYN_REQUESTS);
AutoCacheRequest request(tdbb, drq_e_gens, DYN_REQUESTS);
bool found = false;

FOR (REQUEST_HANDLE request TRANSACTION_HANDLE transaction)
GEN IN RDB$GENERATORS
WITH GEN.RDB$GENERATOR_NAME EQ name.c_str()
{
if (!GEN.RDB$SYSTEM_FLAG.NULL && GEN.RDB$SYSTEM_FLAG != 0)
{
// msg 272: "Cannot delete system generator @1"
status_exception::raise(Arg::Gds(ENCODE_ISC_MSG(272, DYN_MSG_FAC)) << name);
}

executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_BEFORE,
DDL_TRIGGER_DROP_SEQUENCE, name);

ERASE GEN;
found = true;
}
END_FOR

return found;
if (found)
executeDdlTrigger(tdbb, dsqlScratch, transaction, DTW_AFTER, DDL_TRIGGER_DROP_SEQUENCE, name);
else
status_exception::raise(Arg::Gds(isc_gennotdef) << Arg::Str(name));
}


// Delete a record from RDB$GENERATORS, without verifying RDB$SYSTEM_FLAG.
void DropSequenceNode::deleteIdentity(thread_db* tdbb, jrd_tra* transaction, const MetaName& name)
{
AutoCacheRequest request(tdbb, drq_e_ident_gens, DYN_REQUESTS);

FOR (REQUEST_HANDLE request TRANSACTION_HANDLE transaction)
GEN IN RDB$GENERATORS
WITH GEN.RDB$GENERATOR_NAME EQ name.c_str()
{
ERASE GEN;
}
END_FOR
}


Expand Down Expand Up @@ -5036,7 +5069,7 @@ void RelationNode::deleteLocalField(thread_db* tdbb, jrd_tra* transaction,
RFR.RDB$RELATION_NAME EQ relationName.c_str()
{
if (!RFR.RDB$GENERATOR_NAME.NULL)
DropSequenceNode::deleteGenerator(tdbb, transaction, RFR.RDB$GENERATOR_NAME);
DropSequenceNode::deleteIdentity(tdbb, transaction, RFR.RDB$GENERATOR_NAME);

ERASE RFR;

Expand Down Expand Up @@ -7230,7 +7263,7 @@ void DropRelationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
WITH RFR.RDB$RELATION_NAME EQ name.c_str()
{
if (!RFR.RDB$GENERATOR_NAME.NULL)
DropSequenceNode::deleteGenerator(tdbb, transaction, RFR.RDB$GENERATOR_NAME);
DropSequenceNode::deleteIdentity(tdbb, transaction, RFR.RDB$GENERATOR_NAME);

ERASE RFR;

Expand Down
23 changes: 21 additions & 2 deletions src/dsql/DdlNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,30 @@ class CreateSequenceNode : public DdlNode
};


class DropSequenceNode
class DropSequenceNode : public DdlNode
{
public:
static bool deleteGenerator(thread_db* tdbb, jrd_tra* transaction,
DropSequenceNode(MemoryPool& pool, const Firebird::MetaName&aName)
: DdlNode(pool),
name(pool, aName)
{
}

static void deleteIdentity(thread_db* tdbb, jrd_tra* transaction,
const Firebird::MetaName& name);

public:
virtual void print(Firebird::string& text, Firebird::Array<dsql_nod*>& nodes) const;
virtual void execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch, jrd_tra* transaction);

protected:
virtual void putErrorPrefix(Firebird::Arg::StatusVector& statusVector)
{
statusVector << Firebird::Arg::Gds(isc_dsql_drop_sequence_failed) << name;
}

private:
Firebird::MetaName name;
};


Expand Down
6 changes: 0 additions & 6 deletions src/dsql/ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,12 +1041,6 @@ static void generate_dyn(DsqlCompilerScratch* dsqlScratch, dsql_nod* node)
define_filter(dsqlScratch);
break;

case nod_del_generator:
string = (dsql_str*) node->nod_arg[0];
dsqlScratch->appendNullString(isc_dyn_delete_generator, string->str_data);
dsqlScratch->appendUChar(isc_dyn_end);
break;

case nod_del_filter:
string = (dsql_str*) node->nod_arg[0];
dsqlScratch->appendNullString(isc_dyn_delete_filter, string->str_data);
Expand Down
1 change: 0 additions & 1 deletion src/dsql/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ enum nod_t
nod_def_index,
nod_del_index,
nod_def_constraint,
nod_del_generator,
nod_def_filter,
nod_del_filter,
nod_def_shadow,
Expand Down
4 changes: 2 additions & 2 deletions src/dsql/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -3528,9 +3528,9 @@ drop_clause
| ROLE symbol_role_name
{ $$ = make_node (nod_del_role, (int) 1, $2); }
| GENERATOR symbol_generator_name
{ $$ = make_node (nod_del_generator, (int) 1, $2); }
{ $$ = makeClassNode(FB_NEW(getPool()) DropSequenceNode(getPool(), toName($2))); }
| SEQUENCE symbol_generator_name
{ $$ = make_node (nod_del_generator, (int) 1, $2); }
{ $$ = makeClassNode(FB_NEW(getPool()) DropSequenceNode(getPool(), toName($2))); }
| COLLATION symbol_collation_name
{ $$ = makeClassNode(newNode<DropCollationNode>(toName($2))); }
| USER drop_user_clause
Expand Down
4 changes: 0 additions & 4 deletions src/dsql/pass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,6 @@ dsql_nod* PASS1_statement(DsqlCompilerScratch* dsqlScratch, dsql_nod* input)
case nod_grant:
case nod_revoke:
case nod_mod_database:
case nod_del_generator:
case nod_def_role:
case nod_del_role:
case nod_def_filter:
Expand Down Expand Up @@ -4777,9 +4776,6 @@ void DSQL_pretty(const dsql_nod* node, int column)
case nod_del_filter:
verb = "delete filter";
break;
case nod_del_generator:
verb = "delete generator";
break;
case nod_del_index:
verb = "delete index";
break;
Expand Down
1 change: 1 addition & 0 deletions src/include/gen/codetext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ static const struct {
{"dsql_create_alter_view_failed", 336397300},
{"dsql_recreate_view_failed", 336397301},
{"dsql_drop_view_failed", 336397302},
{"dsql_drop_sequence_failed", 336397303},
{"gsec_cant_open_db", 336723983},
{"gsec_switches_error", 336723984},
{"gsec_no_op_spec", 336723985},
Expand Down
6 changes: 4 additions & 2 deletions src/include/gen/iberror.h
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ const ISC_STATUS isc_dsql_alter_view_failed = 336397299L;
const ISC_STATUS isc_dsql_create_alter_view_failed = 336397300L;
const ISC_STATUS isc_dsql_recreate_view_failed = 336397301L;
const ISC_STATUS isc_dsql_drop_view_failed = 336397302L;
const ISC_STATUS isc_dsql_drop_sequence_failed = 336397303L;
const ISC_STATUS isc_gsec_cant_open_db = 336723983L;
const ISC_STATUS isc_gsec_switches_error = 336723984L;
const ISC_STATUS isc_gsec_no_op_spec = 336723985L;
Expand Down Expand Up @@ -1188,7 +1189,7 @@ const ISC_STATUS isc_trace_switch_user_only = 337182757L;
const ISC_STATUS isc_trace_switch_param_miss = 337182758L;
const ISC_STATUS isc_trace_param_act_notcompat = 337182759L;
const ISC_STATUS isc_trace_mandatory_switch_miss = 337182760L;
const ISC_STATUS isc_err_max = 1132;
const ISC_STATUS isc_err_max = 1133;

#else /* c definitions */

Expand Down Expand Up @@ -2245,6 +2246,7 @@ const ISC_STATUS isc_err_max = 1132;
#define isc_dsql_create_alter_view_failed 336397300L
#define isc_dsql_recreate_view_failed 336397301L
#define isc_dsql_drop_view_failed 336397302L
#define isc_dsql_drop_sequence_failed 336397303L
#define isc_gsec_cant_open_db 336723983L
#define isc_gsec_switches_error 336723984L
#define isc_gsec_no_op_spec 336723985L
Expand Down Expand Up @@ -2346,7 +2348,7 @@ const ISC_STATUS isc_err_max = 1132;
#define isc_trace_switch_param_miss 337182758L
#define isc_trace_param_act_notcompat 337182759L
#define isc_trace_mandatory_switch_miss 337182760L
#define isc_err_max 1132
#define isc_err_max 1133

#endif

Expand Down
1 change: 1 addition & 0 deletions src/include/gen/msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ Data source : @4"}, /* eds_statement */
{336397300, "CREATE OR ALTER VIEW @1 failed"}, /* dsql_create_alter_view_failed */
{336397301, "RECREATE VIEW @1 failed"}, /* dsql_recreate_view_failed */
{336397302, "DROP VIEW @1 failed"}, /* dsql_drop_view_failed */
{336397303, "DROP SEQUENCE @1 failed"}, /* dsql_drop_sequence_failed */
{336723983, "unable to open database"}, /* gsec_cant_open_db */
{336723984, "error in switch specifications"}, /* gsec_switches_error */
{336723985, "no operation specified"}, /* gsec_no_op_spec */
Expand Down
1 change: 1 addition & 0 deletions src/include/gen/sql_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ static const struct {
{336397300, -901}, /* 1012 dsql_create_alter_view_failed */
{336397301, -901}, /* 1013 dsql_recreate_view_failed */
{336397302, -901}, /* 1014 dsql_drop_view_failed */
{336397303, -901}, /* 1015 dsql_drop_sequence_failed */
{336723983, -901}, /* 15 gsec_cant_open_db */
{336723984, -901}, /* 16 gsec_switches_error */
{336723985, -901}, /* 17 gsec_no_op_spec */
Expand Down
1 change: 1 addition & 0 deletions src/include/gen/sql_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ static const struct {
{336397300, "42000"}, // 1012 dsql_create_alter_view_failed
{336397301, "42000"}, // 1013 dsql_recreate_view_failed
{336397302, "42000"}, // 1014 dsql_drop_view_failed
{336397303, "42000"}, // 1015 dsql_drop_sequence_failed
{336723983, "00000"}, // 15 gsec_cant_open_db
{336723984, "00000"}, // 16 gsec_switches_error
{336723985, "00000"}, // 17 gsec_no_op_spec
Expand Down
4 changes: 0 additions & 4 deletions src/jrd/dyn.epp
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,6 @@ void DYN_execute(Global* gbl,
DYN_modify_function(gbl, ptr);
break;

case isc_dyn_delete_generator:
DYN_delete_generator(gbl, ptr);
break;

case isc_dyn_def_sql_role:
DYN_define_role(gbl, ptr);
break;
Expand Down
61 changes: 0 additions & 61 deletions src/jrd/dyn_del.epp
Original file line number Diff line number Diff line change
Expand Up @@ -121,67 +121,6 @@ void DYN_delete_filter( Global* gbl, const UCHAR** ptr)
}


void DYN_delete_generator(Global* gbl, const UCHAR**ptr)
{
/**************************************
*
* D Y N _ d e l e t e _ g e n e r a t o r
*
**************************************
*
* Functional description
* Execute a dynamic ddl statement that
* deletes a generator from rdb$generator but the
* space allocated in the page won't be released.
*
**************************************/
thread_db* tdbb = JRD_get_thread_data();

bool found = false;
Firebird::MetaName t;
GET_STRING(ptr, t);

try
{
AutoCacheRequest request(tdbb, drq_e_gens, DYN_REQUESTS);

found = false;
FOR (REQUEST_HANDLE request TRANSACTION_HANDLE gbl->gbl_transaction)
X IN RDB$GENERATORS
WITH X.RDB$GENERATOR_NAME EQ t.c_str()
{
if (X.RDB$SYSTEM_FLAG != 0)
DYN_error_punt(false, 272); // msg 272: "Cannot delete system generator"

found = true;

DdlNode::executeDdlTrigger(tdbb, gbl->gbl_transaction, DdlNode::DTW_BEFORE,
DDL_TRIGGER_DROP_SEQUENCE, t, gbl->sqlText);

ERASE X;
}
END_FOR
}
catch (const Firebird::Exception& ex)
{
Firebird::stuff_exception(tdbb->tdbb_status_vector, ex);
DYN_error_punt(true, 213);
// msg 213: "ERASE GENERATOR failed"
}

if (found)
{
DdlNode::executeDdlTrigger(tdbb, gbl->gbl_transaction, DdlNode::DTW_AFTER,
DDL_TRIGGER_DROP_SEQUENCE, t, gbl->sqlText);
}
else
{
DYN_error_punt(false, 214, t.c_str());
// msg 214: "Generator %s not found"
}
}


void DYN_delete_index( Global* gbl, const UCHAR** ptr)
{
/**************************************
Expand Down
1 change: 0 additions & 1 deletion src/jrd/dyn_dl_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#define JRD_DYN_DL_PROTO_H

void DYN_delete_filter(Jrd::Global*, const UCHAR**);
void DYN_delete_generator(Jrd::Global*, const UCHAR**);
void DYN_delete_index(Jrd::Global*, const UCHAR**);
void DYN_delete_role(Jrd::Global*, const UCHAR**);
void DYN_delete_shadow(Jrd::Global*, const UCHAR**);
Expand Down
2 changes: 1 addition & 1 deletion src/msgs/facilities2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set bulk_insert INSERT INTO FACILITIES (LAST_CHANGE, FACILITY, FAC_CODE, MAX_NUM
('1996-11-07 13:39:40', 'INSTALL', 10, 1)
('1996-11-07 13:38:41', 'TEST', 11, 4)
('2011-06-01 12:57:44', 'GBAK', 12, 351)
('2010-08-01 13:05:00', 'SQLERR', 13, 1015)
('2010-08-01 13:05:00', 'SQLERR', 13, 1016)
('1996-11-07 13:38:42', 'SQLWARN', 14, 613)
('2006-09-10 03:04:31', 'JRD_BUGCHK', 15, 307)
--
Expand Down
3 changes: 2 additions & 1 deletion src/msgs/messages2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ COMMIT WORK;
('dyn_package_body_exists', NULL, 'DdlNodes.epp/PackageNodes.epp', NULL, 8, 269, NULL, 'Package body @1 already exists', NULL, NULL);
('dyn_invalid_ddl_func', 'CreateAlterFunctionNode::compile', 'DdlNodes.epp', NULL, 8, 270, NULL, 'Invalid DDL statement for function @1', NULL, NULL);
('dyn_newfc_oldsyntax', 'DYN_modify_function', 'dyn_mod.epp', NULL, 8, 271, NULL, 'Cannot alter new style function @1 with ALTER EXTERNAL FUNCTION. Use ALTER FUNCTION instead.', NULL, NULL);
(NULL, 'DYN_delete_generator', 'dyn_del.epp', NULL, 8, 272, NULL, 'Cannot delete system generator', NULL, NULL);
(NULL, 'DYN_delete_generator', 'dyn_del.epp', NULL, 8, 272, NULL, 'Cannot delete system generator @1', NULL, NULL);
(NULL, 'DYN_define_sql_field', 'dyn_def.epp', NULL, 8, 273, NULL, 'Identity column @1 of table @2 must be of exact number type with zero scale', NULL, NULL);
(NULL, 'DYN_modify_local_field', 'dyn_mod.epp', NULL, 8, 274, NULL, 'Identity column @1 of table @2 cannot be changed to NULLable', NULL, NULL);
(NULL, 'DYN_modify_sql_field', 'dyn_mod.epp', NULL, 8, 275, NULL, 'Identity column @1 of table @2 cannot have default value', NULL, NULL);
Expand Down Expand Up @@ -2482,6 +2482,7 @@ ERROR: Backup incomplete', NULL, NULL);
('dsql_create_alter_view_failed', 'getMainErrorCode', 'DdlNodes.h', NULL, 13, 1012, NULL, 'CREATE OR ALTER VIEW @1 failed', NULL, NULL);
('dsql_recreate_view_failed', 'getMainErrorCode', 'DdlNodes.h', NULL, 13, 1013, NULL, 'RECREATE VIEW @1 failed', NULL, NULL);
('dsql_drop_view_failed', 'getMainErrorCode', 'DdlNodes.h', NULL, 13, 1014, NULL, 'DROP VIEW @1 failed', NULL, NULL);
('dsql_drop_sequence_failed', 'getMainErrorCode', 'DdlNodes.h', NULL, 13, 1015, NULL, 'DROP SEQUENCE @1 failed', NULL, NULL);
-- SQLWARN
(NULL, NULL, NULL, NULL, 14, 100, NULL, 'Row not found for fetch, update or delete, or the result of a query is an empty table.', NULL, NULL);
(NULL, NULL, NULL, NULL, 14, 101, NULL, 'segment buffer length shorter than expected', NULL, NULL);
Expand Down
1 change: 1 addition & 0 deletions src/msgs/system_errors2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ COMMIT WORK;
(-901, '42', '000', 13, 1012, 'dsql_create_alter_view_failed', NULL, NULL);
(-901, '42', '000', 13, 1013, 'dsql_recreate_view_failed', NULL, NULL);
(-901, '42', '000', 13, 1014, 'dsql_drop_view_failed', NULL, NULL);
(-901, '42', '000', 13, 1015, 'dsql_drop_sequence_failed', NULL, NULL);
-- GSEC
(-901, '00', '000', 18, 15, 'gsec_cant_open_db', NULL, NULL)
(-901, '00', '000', 18, 16, 'gsec_switches_error', NULL, NULL)
Expand Down

0 comments on commit e090671

Please sign in to comment.