-
-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathOdsDetection.epp
More file actions
184 lines (163 loc) · 4.94 KB
/
OdsDetection.epp
File metadata and controls
184 lines (163 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* PROGRAM: JRD Backup and Restore Program
* MODULE: OdsDetection.cpp
* DESCRIPTION: Detecting the backup (source) or restore (target) ODS
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
*/
#include "firebird.h"
#include "../burp/burp.h"
#include "../burp/burp_proto.h"
#include "../burp/OdsDetection.h"
namespace
{
// table used to determine capabilities, checking for specific
// fields in system relations
struct rel_field_t
{
const char* relation;
const char* field;
int ods_version;
};
const rel_field_t relations[] =
{
{"RDB$PROCEDURES", 0, DB_VERSION_DDL8}, // IB4
{"RDB$ROLES", 0, DB_VERSION_DDL9}, // IB5
{"RDB$PACKAGES", 0, DB_VERSION_DDL12}, // FB3
{"RDB$PUBLICATIONS", 0, DB_VERSION_DDL13}, // FB4
{"RDB$SCHEMAS", 0, DB_VERSION_DDL14}, // FB6
{"RDB$CONSTANTS", 0, DB_VERSION_DDL14},// RDB6
{0, 0, 0}
};
const rel_field_t rel_fields[] =
{
{"RDB$FIELDS", "RDB$FIELD_PRECISION", DB_VERSION_DDL10}, // FB1, FB1.5
{"RDB$ROLES", "RDB$DESCRIPTION", DB_VERSION_DDL11}, // FB2
{"RDB$RELATIONS", "RDB$RELATION_TYPE", DB_VERSION_DDL11_1}, // FB2.1
{"RDB$PROCEDURE_PARAMETERS", "RDB$FIELD_NAME", DB_VERSION_DDL11_2}, // FB2.5
{"RDB$INDICES", "RDB$CONDITION_BLR", DB_VERSION_DDL13_1}, // FB5
{0, 0, 0}
};
void general_on_error();
}
#define DB tdgbl->db_handle
#define fbTrans tdgbl->tr_handle
#define gds_trans tdgbl->tr_handle
#define fbStatus (&tdgbl->status_vector)
#define isc_status (&tdgbl->status_vector)
#define gds_status (&tdgbl->status_vector)
// unused
#define fbProvider
#define fbStatus2
DATABASE DB = STATIC FILENAME "yachts.lnk";
void detectRuntimeODS()
{
/**************************************
*
* d e t e c t R u n t i m e O D S
*
**************************************
*
* Functional description
* Find the ODS version number of the database.
* Use system_flag to avoid any possibility of ambiguity (someone using the rdb$ prefix).
*
**************************************/
BurpGlobals* tdgbl = BurpGlobals::getSpecific();
tdgbl->runtimeODS = 0;
// Detect very old server before IB4 just in case to exit gracefully.
// select count(*) from rdb$relation_fields
// where rdb$relation_name in ('RDB$RELATIONS', 'RDB$RELATION_FIELDS')
// and rdb$field_name = 'RDB$SYSTEM_FLAG';
int count = 0;
Firebird::IRequest* req_handle = nullptr;
FOR (REQUEST_HANDLE req_handle)
RFR IN RDB$RELATION_FIELDS
WITH (RFR.RDB$RELATION_NAME = 'RDB$RELATIONS' OR RFR.RDB$RELATION_NAME = 'RDB$RELATION_FIELDS') AND
RFR.RDB$FIELD_NAME = 'RDB$SYSTEM_FLAG' AND
(RFR.RDB$SCHEMA_NAME MISSING OR RFR.RDB$SCHEMA_NAME = SYSTEM_SCHEMA)
{
++count;
}
END_FOR
ON_ERROR
general_on_error();
END_ERROR
MISC_release_request_silent(req_handle);
if (count != 2)
return;
Firebird::IRequest* req_handle2 = nullptr;
for (const rel_field_t* rel = relations; rel->relation; ++rel)
{
FOR (REQUEST_HANDLE req_handle2)
FIRST 1 X IN RDB$RELATIONS
WITH X.RDB$RELATION_NAME = rel->relation AND
X.RDB$SYSTEM_FLAG = 1 AND
(X.RDB$SCHEMA_NAME MISSING OR X.RDB$SCHEMA_NAME = SYSTEM_SCHEMA)
{
if (tdgbl->runtimeODS < rel->ods_version)
tdgbl->runtimeODS = rel->ods_version;
}
END_FOR
ON_ERROR
general_on_error();
END_ERROR
}
MISC_release_request_silent(req_handle2);
if (tdgbl->runtimeODS < DB_VERSION_DDL8)
return;
Firebird::IRequest* req_handle3 = nullptr;
for (const rel_field_t* rf = rel_fields; rf->relation; ++rf)
{
FOR (REQUEST_HANDLE req_handle3)
FIRST 1 X2 IN RDB$RELATION_FIELDS
WITH X2.RDB$RELATION_NAME = rf->relation AND
X2.RDB$FIELD_NAME = rf->field AND
X2.RDB$SYSTEM_FLAG = 1 AND
(X2.RDB$SCHEMA_NAME MISSING OR X2.RDB$SCHEMA_NAME = SYSTEM_SCHEMA)
{
if (tdgbl->runtimeODS < rf->ods_version)
tdgbl->runtimeODS = rf->ods_version;
}
END_FOR
ON_ERROR
general_on_error();
END_ERROR
}
MISC_release_request_silent(req_handle3);
}
namespace
{
// copy/paste from backup.epp
void general_on_error()
{
/**************************************
*
* g e n e r a l _ o n _ e r r o r
*
**************************************
*
* Functional description
* Handle any general ON_ERROR clause during ODS level detection.
*
**************************************/
BurpGlobals* tdgbl = BurpGlobals::getSpecific();
BURP_abort(isc_status);
}
}