Skip to content

Commit 4c8d0a1

Browse files
committed
Fix gbak backup to work with v6 engines
1 parent 3e31342 commit 4c8d0a1

File tree

5 files changed

+72
-11
lines changed

5 files changed

+72
-11
lines changed

src/burp/BurpTasks.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ void BackupRelationTask::initItem(BurpGlobals* tdgbl, Item& item)
531531

532532
if (status->getState() & IStatus::STATE_ERRORS)
533533
BURP_abort(&status);
534+
535+
item.m_att->execute(&status, item.m_tra, 0, m_masterGbl->setSearchPath.c_str(),
536+
SQL_DIALECT_CURRENT, nullptr, nullptr, nullptr, nullptr);
537+
538+
fb_assert(status->isSuccess());
534539
}
535540

536541
tdgbl->db_handle = item.m_att;

src/burp/OdsDetection.h

Lines changed: 1 addition & 0 deletions
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.0 db, FB6.0
7273

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

src/burp/backup.epp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "../burp/burp.h"
4646
#include "../jrd/ods.h"
4747
#include "../jrd/align.h"
48+
#include "../jrd/intl.h"
4849
#include "../common/gdsassert.h"
4950
#include "../jrd/constants.h"
5051
#include "../common/stuff.h"
@@ -286,6 +287,63 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name)
286287
tdgbl->gbl_sw_par_workers = 1;
287288
}
288289

290+
// decide what type of database we've got
291+
292+
detectRuntimeODS();
293+
if (tdgbl->runtimeODS < DB_VERSION_OLDEST_SUPPORTED)
294+
{
295+
BURP_error(348, true, SafeArg() << tdgbl->runtimeODS);
296+
// msg 348 database format @1 is too old to backup
297+
}
298+
else if (tdgbl->runtimeODS >= DB_VERSION_DDL13_1)
299+
{
300+
static constexpr UCHAR ODS_INFO[] = {
301+
isc_info_ods_version,
302+
isc_info_end
303+
};
304+
UCHAR infoBuffer[16];
305+
USHORT odsMajorVersion;
306+
307+
FbLocalStatus checkStatus;
308+
309+
tdgbl->db_handle->getInfo(&checkStatus, sizeof(ODS_INFO), ODS_INFO, sizeof(infoBuffer), infoBuffer);
310+
311+
if (checkStatus.isSuccess() && infoBuffer[0] == isc_info_ods_version)
312+
{
313+
USHORT len = isc_portable_integer(&infoBuffer[1], 2);
314+
odsMajorVersion = isc_portable_integer(&infoBuffer[3], len);
315+
316+
if (odsMajorVersion > ODS_VERSION13)
317+
tdgbl->runtimeODS = DB_VERSION_DDL14;
318+
}
319+
else
320+
fb_assert(false);
321+
}
322+
323+
if (tdgbl->runtimeODS >= DB_VERSION_DDL14)
324+
{
325+
const char* getSchemasSql =
326+
R""(SELECT LIST('"' || REPLACE(TRIM(RDB$SCHEMA_NAME), '"', '""') || '"') FROM RDB$SCHEMAS)"";
327+
BurpSql getSchemasQuery(tdgbl, getSchemasSql);
328+
329+
FB_MESSAGE(GetSchemas, ThrowWrapper,
330+
(FB_INTL_VARCHAR(4096 * METADATA_BYTES_PER_CHAR, CS_METADATA), schemaList)
331+
) getSchemas(&tdgbl->throwStatus, MasterInterfacePtr());
332+
333+
getSchemasQuery.singleSelect(tdgbl->tr_handle, &getSchemas);
334+
335+
fb_assert(!getSchemas->schemaListNull);
336+
337+
if (!getSchemas->schemaListNull)
338+
{
339+
const string schemaList(getSchemas->schemaList.str, getSchemas->schemaList.length);
340+
tdgbl->setSearchPath = "SET SEARCH_PATH TO " + schemaList;
341+
342+
BurpSql searchPathQuery(tdgbl, tdgbl->setSearchPath.c_str());
343+
searchPathQuery.execute(tdgbl->tr_handle);
344+
}
345+
}
346+
289347
// detect if MAKE_DBKEY is supported and decide kind of read relation query
290348
if (tdgbl->gbl_sw_par_workers > 1)
291349
{
@@ -306,15 +364,6 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name)
306364
// msg 410 use up to @1 parallel workers
307365
}
308366

309-
// decide what type of database we've got
310-
311-
detectRuntimeODS();
312-
if (tdgbl->runtimeODS < DB_VERSION_OLDEST_SUPPORTED)
313-
{
314-
BURP_error(348, true, SafeArg() << tdgbl->runtimeODS);
315-
// msg 348 database format @1 is too old to backup
316-
}
317-
318367
// Write burp record first with other valuable information
319368
// In case of split operation, write a 'split' header first to all the files
320369

src/burp/burp.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,8 @@ class BurpGlobals : public Firebird::ThreadData, public GblPool
977977
flag_on_line(true),
978978
firstMap(true),
979979
firstDbc(true),
980-
stdIoMode(false)
980+
stdIoMode(false),
981+
setSearchPath(getPool())
981982
{
982983
// this is VERY dirty hack to keep current (pre-FB2) behaviour
983984
memset (&gbl_database_file_name, 0,
@@ -1220,6 +1221,8 @@ class BurpGlobals : public Firebird::ThreadData, public GblPool
12201221
Firebird::AutoPtr<Firebird::SimilarToRegex> skipDataMatcher;
12211222
Firebird::AutoPtr<Firebird::SimilarToRegex> includeDataMatcher;
12221223

1224+
Firebird::string setSearchPath;
1225+
12231226
public:
12241227
Firebird::string toSystem(const Firebird::PathName& from);
12251228

@@ -1293,7 +1296,7 @@ class BurpSql : public Firebird::AutoStorage
12931296
: Firebird::AutoStorage(),
12941297
tdgbl(g), stmt(nullptr)
12951298
{
1296-
stmt = tdgbl->db_handle->prepare(&tdgbl->throwStatus, tdgbl->tr_handle, 0, sql, 3, 0);
1299+
stmt = tdgbl->db_handle->prepare(&tdgbl->throwStatus, tdgbl->tr_handle, 0, sql, SQL_DIALECT_CURRENT, 0);
12971300
}
12981301

12991302
template <typename M>

src/jrd/constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,7 @@ const int WITH_ADMIN_OPTION = 2;
483483
// Max length of the string returned by ERROR_TEXT context variable
484484
const USHORT MAX_ERROR_MSG_LENGTH = 1024 * METADATA_BYTES_PER_CHAR; // 1024 UTF-8 characters
485485

486+
// In v6 this is in consts_pub.h, but in v5 this should better be private
487+
inline constexpr int isc_dpb_search_path = 105;
488+
486489
#endif // JRD_CONSTANTS_H

0 commit comments

Comments
 (0)