- Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathblb.h
273 lines (227 loc) · 7.57 KB
/
blb.h
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* PROGRAM: JRD Access Method
* MODULE: blb.h
* DESCRIPTION: Blob handling definitions
*
* 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): ______________________________________.
*
* 2002.10.28 Sean Leyne - Code cleanup, removed obsolete "DecOSF" port
*
*/
#ifndef JRD_BLB_H
#defineJRD_BLB_H
#include"../include/fb_blk.h"
#include"../jrd/RecordNumber.h"
#include"../jrd/EngineInterface.h"
#include"../common/classes/array.h"
#include"../common/classes/File.h"
#include"../common/classes/auto.h"
#include"firebird/Interface.h"
#include"../common/classes/ImplementHelper.h"
#include"../common/dsc.h"
namespaceOds
{
structblob_page;
structblh;
}
namespaceJrd
{
classAttachment;
classBlobControl;
classjrd_rel;
classRequest;
classjrd_tra;
classvcl;
classthread_db;
structwin;
classRecord;
classArrayField;
structimpure_value;
// Your basic blob block.
classblb : publicpool_alloc<type_blb>
{
public:
blb(MemoryPool& pool, USHORT page_size)
: blb_interface(NULL),
blb_buffer(pool, page_size / sizeof(SLONG)),
blb_has_buffer(true)
{
}
jrd_rel* blb_relation; // Relation, if known
JBlob* blb_interface;
ULONG blb_length; // Total length of data sans segments
USHORT blb_flags; // Interesting stuff (see below)
SSHORT blb_sub_type; // Blob's declared sub-type
UCHAR blb_charset; // Blob's charset
// inline functions
boolhasBuffer() const;
UCHAR* getBuffer();
voidfreeBuffer();
boolisSegmented() const;
Attachment* getAttachment();
jrd_tra* getTransaction();
USHORT getLevel() const;
ULONG getMaxSequence() const;
ULONG getTempId() const;
ULONG getSegmentCount() const;
USHORT getFragmentSize() const;
USHORT getMaxSegment() const;
// end inline
voidBLB_cancel(thread_db* tdbb);
voidBLB_cancel();
voidBLB_check_well_formed(thread_db*, const dsc* desc);
boolBLB_close(thread_db*);
static blb* create(thread_db*, jrd_tra*, bid*);
static blb* create2(thread_db*, jrd_tra*, bid*, USHORT, const UCHAR*, bool = false);
static Jrd::blb* get_array(Jrd::thread_db*, Jrd::jrd_tra*, const Jrd::bid*, Ods::InternalArrayDesc*);
ULONG BLB_get_data(thread_db*, UCHAR*, SLONG, bool = true);
USHORT BLB_get_segment(thread_db*, void*, USHORT);
static SLONG get_slice(Jrd::thread_db*, Jrd::jrd_tra*, const Jrd::bid*, const UCHAR*, USHORT,
const UCHAR*, SLONG, UCHAR*);
SLONG BLB_lseek(USHORT, SLONG);
staticvoidmove(thread_db* tdbb, dsc* from_desc, dsc* to_desc, jrd_rel* relation = nullptr, Record* record = nullptr, USHORT fieldId = 0, bool bulk = false);
static blb* open(thread_db*, jrd_tra*, const bid*);
static blb* open2(thread_db*, jrd_tra*, const bid*, USHORT, const UCHAR*, bool = false);
voidBLB_put_data(thread_db*, const UCHAR*, SLONG);
voidBLB_put_segment(thread_db*, constvoid*, USHORT);
staticvoidput_slice(thread_db*, jrd_tra*, bid*, const UCHAR*, USHORT, const UCHAR*, SLONG, UCHAR*);
staticvoidrelease_array(Jrd::ArrayField*);
staticvoidscalar(Jrd::thread_db*, Jrd::jrd_tra*, const Jrd::bid*, USHORT, const SLONG*, Jrd::impure_value*);
staticvoiddelete_blob_id(thread_db*, const bid*, ULONG, jrd_rel*);
voidfromPageHeader(const Ods::blh* header);
voidtoPageHeader(Ods::blh* header) const;
voidgetFromPage(USHORT length, const UCHAR* data);
voidstoreToPage(USHORT* length, Firebird::Array<UCHAR>& buffer, const UCHAR** data, void* stack);
static bid copy(thread_db* tdbb, const bid* source)
{
bid destination;
copy_blob(tdbb, source, &destination, 0, nullptr, 0);
return destination;
}
private:
static blb* allocate_blob(thread_db*, jrd_tra*);
static blb* copy_blob(thread_db* tdbb, const bid* source, bid* destination,
USHORT bpb_length, const UCHAR* bpb, USHORT destPageSpaceID);
voiddelete_blob(thread_db*, ULONG);
Ods::blob_page* get_next_page(thread_db*, win*);
voidinsert_page(thread_db*);
voiddestroy(constbool purge_flag);
FB_SIZE_T blb_temp_size; // size stored in transaction temp space
offset_t blb_temp_offset; // offset in transaction temp space
Attachment* blb_attachment; // database attachment
jrd_tra* blb_transaction; // Parent transaction block
UCHAR* blb_segment; // Next segment to be addressed
BlobControl* blb_filter; // Blob filter control block, if any
bid blb_blob_id; // Id of materialized blob
vcl* blb_pages; // Vector of pages
Firebird::Array<SLONG> blb_buffer; // buffer used in opened blobs - must be longword aligned
ULONG blb_temp_id; // ID of newly created blob in transaction
ULONG blb_sequence; // Blob page sequence
ULONG blb_lead_page; // First page number
ULONG blb_seek; // Seek location
ULONG blb_max_sequence; // Number of data pages
ULONG blb_count; // Number of segments
USHORT blb_pointers; // Max pointer on a page
USHORT blb_clump_size; // Size of data clump
USHORT blb_space_remaining; // Data space left
USHORT blb_max_pages; // Max pages in vector
USHORT blb_level; // Storage type
USHORT blb_pg_space_id; // page space
USHORT blb_fragment_size; // Residual fragment size
USHORT blb_max_segment; // Longest segment
#ifdef CHECK_BLOB_FIELD_ACCESS_FOR_SELECT
USHORT blb_fld_id; // Field ID
#endif
bool blb_has_buffer;
};
constint BLB_temporary = 1; // Newly created blob
constint BLB_eof = 2; // This blob is exhausted
constint BLB_stream = 4; // Stream style blob
constint BLB_closed = 8; // Temporary blob has been closed
constint BLB_damaged = 16; // Blob is busted
constint BLB_seek = 32; // Seek is pending
constint BLB_large_scan = 64; // Blob is larger than page buffer cache
constint BLB_close_on_read = 128; // Temporary blob is not closed until read
constint BLB_bulk = 256; // Blob created by bulk insert operation
constint BLB_user = 512; // User-defined blob
/* Blob levels are:
0 small blob -- blob "record" is actual data
1 medium blob -- blob "record" is pointer to pages
2 large blob -- blob "record" is pointer to pages of pointers
*/
inlineboolblb::hasBuffer() const
{
return blb_has_buffer;
}
inline UCHAR* blb::getBuffer()
{
fb_assert(blb_has_buffer);
return (UCHAR*) blb_buffer.getBuffer(blb_buffer.getCapacity());
}
inlinevoidblb::freeBuffer()
{
fb_assert(blb_has_buffer);
blb_buffer.free();
blb_has_buffer = false;
}
inlineboolblb::isSegmented() const
{
return !(blb_flags & BLB_stream);
}
inline Attachment* blb::getAttachment()
{
return blb_attachment;
}
inline jrd_tra* blb::getTransaction()
{
return blb_transaction;
}
inline USHORT blb::getLevel() const
{
return blb_level;
}
inline ULONG blb::getMaxSequence() const
{
return blb_max_sequence;
}
inline ULONG blb::getTempId() const
{
return blb_temp_id;
}
inline ULONG blb::getSegmentCount() const
{
return blb_count;
}
inline USHORT blb::getFragmentSize() const
{
return blb_fragment_size;
}
inline USHORT blb::getMaxSegment() const
{
return blb_max_segment;
}
} //namespace Jrd
namespaceFirebird {
template <>
inlinevoid SimpleDelete<Jrd::blb>::clear(Jrd::blb* b)
{
if (b)
b->BLB_cancel();
}
} //namespace Firebird
#endif // JRD_BLB_H