Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/burp/BurpTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ void BackupRelationTask::initItem(BurpGlobals* tdgbl, Item& item)

if (status->getState() & IStatus::STATE_ERRORS)
BURP_abort(&status);

if (m_masterGbl->setSearchPath.hasData())
{
item.m_att->execute(&status, item.m_tra, 0, m_masterGbl->setSearchPath.c_str(),
SQL_DIALECT_CURRENT, nullptr, nullptr, nullptr, nullptr);

fb_assert(status->isSuccess());
}
}

tdgbl->db_handle = item.m_att;
Expand Down
1 change: 1 addition & 0 deletions src/burp/OdsDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const int DB_VERSION_DDL11_2 = 112; // ods11.2 db, FB2.5
const int DB_VERSION_DDL12 = 120; // ods12.0 db, FB3.0
const int DB_VERSION_DDL13 = 130; // ods13.0 db, FB4.0
const int DB_VERSION_DDL13_1 = 131; // ods13.1 db, FB5.0
const int DB_VERSION_DDL14 = 140; // ods14.0 db, FB6.0

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

Expand Down
68 changes: 59 additions & 9 deletions src/burp/backup.epp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "../burp/burp.h"
#include "../jrd/ods.h"
#include "../jrd/align.h"
#include "../jrd/intl.h"
#include "../common/gdsassert.h"
#include "../jrd/constants.h"
#include "../common/stuff.h"
Expand Down Expand Up @@ -286,6 +287,64 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name)
tdgbl->gbl_sw_par_workers = 1;
}

// decide what type of database we've got

detectRuntimeODS();
if (tdgbl->runtimeODS < DB_VERSION_OLDEST_SUPPORTED)
{
BURP_error(348, true, SafeArg() << tdgbl->runtimeODS);
// msg 348 database format @1 is too old to backup
}
else if (tdgbl->runtimeODS >= DB_VERSION_DDL13_1)
{
static constexpr UCHAR ODS_INFO[] = {
isc_info_ods_version,
isc_info_end
};
UCHAR infoBuffer[16];
USHORT odsMajorVersion;

FbLocalStatus checkStatus;

tdgbl->db_handle->getInfo(&checkStatus, sizeof(ODS_INFO), ODS_INFO, sizeof(infoBuffer), infoBuffer);

if (checkStatus.isSuccess() && infoBuffer[0] == isc_info_ods_version)
{
USHORT len = isc_portable_integer(&infoBuffer[1], 2);
odsMajorVersion = isc_portable_integer(&infoBuffer[3], len);

if (odsMajorVersion > ODS_VERSION13)
tdgbl->runtimeODS = DB_VERSION_DDL14;
}
else
fb_assert(false);
}

// get schema list for v6 databases
if (tdgbl->runtimeODS >= DB_VERSION_DDL14)
{
const char* getSchemasSql =
R""(SELECT LIST('"' || REPLACE(TRIM(RDB$SCHEMA_NAME), '"', '""') || '"') FROM RDB$SCHEMAS)"";
BurpSql getSchemasQuery(tdgbl, getSchemasSql);

FB_MESSAGE(GetSchemas, ThrowWrapper,
(FB_INTL_VARCHAR(4096 * METADATA_BYTES_PER_CHAR, CS_METADATA), schemaList)
) getSchemas(&tdgbl->throwStatus, MasterInterfacePtr());

getSchemasQuery.singleSelect(tdgbl->tr_handle, &getSchemas);

fb_assert(!getSchemas->schemaListNull);

if (!getSchemas->schemaListNull)
{
const string schemaList(getSchemas->schemaList.str, getSchemas->schemaList.length);
tdgbl->setSearchPath = "SET SEARCH_PATH TO " + schemaList;

BurpSql searchPathQuery(tdgbl, tdgbl->setSearchPath.c_str());
searchPathQuery.execute(tdgbl->tr_handle);
}
}

// detect if MAKE_DBKEY is supported and decide kind of read relation query
if (tdgbl->gbl_sw_par_workers > 1)
{
Expand All @@ -306,15 +365,6 @@ int BACKUP_backup(const TEXT* dbb_file, const TEXT* file_name)
// msg 410 use up to @1 parallel workers
}

// decide what type of database we've got

detectRuntimeODS();
if (tdgbl->runtimeODS < DB_VERSION_OLDEST_SUPPORTED)
{
BURP_error(348, true, SafeArg() << tdgbl->runtimeODS);
// msg 348 database format @1 is too old to backup
}

// Write burp record first with other valuable information
// In case of split operation, write a 'split' header first to all the files

Expand Down
7 changes: 5 additions & 2 deletions src/burp/burp.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,8 @@ class BurpGlobals : public Firebird::ThreadData, public GblPool
flag_on_line(true),
firstMap(true),
firstDbc(true),
stdIoMode(false)
stdIoMode(false),
setSearchPath(getPool())
{
// this is VERY dirty hack to keep current (pre-FB2) behaviour
memset (&gbl_database_file_name, 0,
Expand Down Expand Up @@ -1220,6 +1221,8 @@ class BurpGlobals : public Firebird::ThreadData, public GblPool
Firebird::AutoPtr<Firebird::SimilarToRegex> skipDataMatcher;
Firebird::AutoPtr<Firebird::SimilarToRegex> includeDataMatcher;

Firebird::string setSearchPath;

public:
Firebird::string toSystem(const Firebird::PathName& from);

Expand Down Expand Up @@ -1293,7 +1296,7 @@ class BurpSql : public Firebird::AutoStorage
: Firebird::AutoStorage(),
tdgbl(g), stmt(nullptr)
{
stmt = tdgbl->db_handle->prepare(&tdgbl->throwStatus, tdgbl->tr_handle, 0, sql, 3, 0);
stmt = tdgbl->db_handle->prepare(&tdgbl->throwStatus, tdgbl->tr_handle, 0, sql, SQL_DIALECT_CURRENT, 0);
}

template <typename M>
Expand Down
41 changes: 41 additions & 0 deletions src/common/classes/BlrReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "iberror.h"
#include "../common/classes/fb_string.h"
#include "../common/classes/MetaString.h"
#include "../common/StatusArg.h"
#include "../jrd/constants.h"

Expand Down Expand Up @@ -121,6 +122,40 @@ class BlrReader
return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
}

UCHAR parseHeader()
{
const auto version = getByte();

switch (version)
{
case blr_version4:
case blr_version5:
//case blr_version6:
break;

default:
status_exception::raise(
Arg::Gds(isc_metadata_corrupt) <<
Arg::Gds(isc_wroblrver2) << Arg::Num(blr_version4) << Arg::Num(blr_version5/*6*/) <<
Arg::Num(version));
}

auto code = getByte();

if (code == blr_flags)
{
while ((code = getByte()) != blr_end)
{
const auto len = getWord();
seekForward(len);
}
}
else
seekBackward(1);

return version;
}

UCHAR checkByte(UCHAR expected)
{
UCHAR byte = getByte();
Expand Down Expand Up @@ -177,6 +212,12 @@ class BlrReader
name.assign(str.c_str());
}

void skipMetaName()
{
MetaString name;
getMetaName(name);
}

private:
const UCHAR* start;
const UCHAR* end;
Expand Down
4 changes: 4 additions & 0 deletions src/common/classes/GenericMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ class GenericMap : public AutoStorage

size_t count() const { return mCount; }

bool hasData() const { return mCount != 0; }

bool isEmpty() const { return mCount == 0; }

Accessor accessor()
{
return Accessor(this);
Expand Down
Loading
Loading