mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 02:03:04 +01:00
Fixed CORE-3461: DDL operations fail after backup/restore
This commit is contained in:
parent
21a3f2f293
commit
07c631f366
@ -158,6 +158,7 @@ void store_blr_gen_id(BurpGlobals* tdgbl, const TEXT* gen_name, SINT64 value,
|
||||
const ISC_QUAD* gen_desc, const char* secclass, const char* ownername, fb_sysflag sysFlag);
|
||||
void update_global_field(BurpGlobals* tdgbl);
|
||||
void update_view_dbkey_lengths(BurpGlobals* tdgbl);
|
||||
void fix_system_generators(BurpGlobals* tdgbl);
|
||||
void general_on_error();
|
||||
#ifdef DEBUG
|
||||
UCHAR debug_on = 0; // able to turn this on in the debugger
|
||||
@ -613,6 +614,9 @@ int RESTORE_restore (const TEXT* file_name, const TEXT* database_name)
|
||||
MISC_release_request_silent(req_handle1);
|
||||
}
|
||||
|
||||
// Fix values of system generators.
|
||||
fix_system_generators(tdgbl);
|
||||
|
||||
COMMIT;
|
||||
ON_ERROR
|
||||
general_on_error ();
|
||||
@ -10290,5 +10294,82 @@ void update_view_dbkey_lengths(BurpGlobals* tdgbl)
|
||||
MISC_release_request_silent(req_handle2);
|
||||
}
|
||||
|
||||
struct FixGenerator
|
||||
{
|
||||
const char* name;
|
||||
const char* table;
|
||||
const char* field;
|
||||
const char* prefix;
|
||||
};
|
||||
|
||||
void fix_generator(BurpGlobals* tdgbl, const FixGenerator* g)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
* f i x G e n e r a t o r
|
||||
*
|
||||
**************************************
|
||||
*
|
||||
* Functional description
|
||||
* Set value of system generator based on
|
||||
* current state of related table.
|
||||
*
|
||||
**************************************/
|
||||
|
||||
int start = strlen(g->prefix) + 1;
|
||||
|
||||
Firebird::string sql;
|
||||
sql.printf("EXECUTE BLOCK AS "
|
||||
"DECLARE VARIABLE maxInTable INT; "
|
||||
"DECLARE VARIABLE currentGen INT; "
|
||||
"BEGIN "
|
||||
" SELECT FIRST(1) CAST(SUBSTRING(%s FROM %d FOR 32) AS INT) FROM %s "
|
||||
" WHERE SUBSTRING(%s FROM %d FOR 32) < '999999999999999999999999999999' "
|
||||
" AND %s STARTING WITH '%s' ORDER BY 1 DESC INTO :maxInTable; "
|
||||
" "
|
||||
" SELECT gen_id(%s, 0) FROM RDB$DATABASE INTO :currentGen; "
|
||||
" IF (currentGen < maxInTable) THEN "
|
||||
" EXECUTE STATEMENT 'SET GENERATOR %s TO ' || maxInTable; "
|
||||
"END",
|
||||
/* SELECT 1 */ g->field, start, g->table, g->field, start, g->field, g->prefix,
|
||||
/* SELECT 2 */ g->name,
|
||||
/* SET GEN */ g->name);
|
||||
|
||||
if (isc_execute_immediate(isc_status, &DB, &gds_trans, 0, sql.c_str()) != 0)
|
||||
general_on_error();
|
||||
}
|
||||
|
||||
const FixGenerator genToFix[] =
|
||||
{
|
||||
{ "RDB$CONSTRAINT_NAME", "RDB$RELATION_CONSTRAINTS", "RDB$CONSTRAINT_NAME", "INTEG_" },
|
||||
{ "RDB$FIELD_NAME", "RDB$FIELDS", "RDB$FIELD_NAME", "RDB$" },
|
||||
{ "RDB$INDEX_NAME", "RDB$INDICES", "RDB$INDEX_NAME", "RDB$" },
|
||||
{ "RDB$INDEX_NAME", "RDB$INDICES", "RDB$INDEX_NAME", "RDB$PRIMARY" },
|
||||
{ "RDB$INDEX_NAME", "RDB$INDICES", "RDB$INDEX_NAME", "RDB$FOREIGN" },
|
||||
{ "RDB$TRIGGER_NAME", "RDB$TRIGGERS", "RDB$TRIGGER_NAME", "CHECK_" },
|
||||
// "RDB$BACKUP_HISTORY" // unused ???
|
||||
{ "RDB$GENERATOR_NAME", "RDB$GENERATORS", "RDB$GENERATOR_NAME", "RDB$" },
|
||||
{ NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
void fix_system_generators(BurpGlobals* tdgbl)
|
||||
{
|
||||
/**************************************
|
||||
*
|
||||
* f i x A l l G e n e r a t o r s
|
||||
*
|
||||
**************************************
|
||||
*
|
||||
* Functional description
|
||||
* Set value of system generators based on
|
||||
* current state of related tables.
|
||||
*
|
||||
**************************************/
|
||||
|
||||
for (const FixGenerator* g = genToFix; g->name; ++g)
|
||||
{
|
||||
fix_generator(tdgbl, g);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user