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
0 commit comments