1 | /* |
2 | * The contents of this file are subject to the Initial |
3 | * Developer's Public License Version 1.0 (the "License"); |
4 | * you may not use this file except in compliance with the |
5 | * License. You may obtain a copy of the License at |
6 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
7 | * |
8 | * Software distributed under the License is distributed AS IS, |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
10 | * See the License for the specific language governing rights |
11 | * and limitations under the License. |
12 | * |
13 | * The Original Code was created by Adriano dos Santos Fernandes |
14 | * for the Firebird Open Source RDBMS project. |
15 | * |
16 | * Copyright (c) 2011 Adriano dos Santos Fernandes <adrianosf at gmail.com> |
17 | * and all contributors signed below. |
18 | * |
19 | * All Rights Reserved. |
20 | * Contributor(s): ______________________________________. |
21 | * Alex Peshkov |
22 | * |
23 | */ |
24 | |
25 | #ifndef COMMON_MSG_METADATA_H |
26 | #define COMMON_MSG_METADATA_H |
27 | |
28 | #include "firebird/Provider.h" |
29 | #include "iberror.h" |
30 | #include "../common/classes/fb_string.h" |
31 | #include "../common/classes/objects_array.h" |
32 | #include "../common/classes/ImplementHelper.h" |
33 | #include "../common/dsc.h" |
34 | |
35 | namespace Firebird { |
36 | |
37 | |
38 | class MsgMetadata : public RefCntIface<IMessageMetadata, FB_MESSAGE_METADATA_VERSION> |
39 | { |
40 | public: |
41 | struct Item |
42 | { |
43 | explicit Item(MemoryPool& pool) |
44 | : field(pool), |
45 | relation(pool), |
46 | owner(pool), |
47 | alias(pool), |
48 | type(0), |
49 | subType(0), |
50 | length(0), |
51 | scale(0), |
52 | charSet(0), |
53 | offset(0), |
54 | nullInd(0), |
55 | nullable(false), |
56 | finished(false) |
57 | { |
58 | } |
59 | |
60 | Item(MemoryPool& pool, const Item& v) |
61 | : field(pool, v.field), |
62 | relation(pool, v.relation), |
63 | owner(pool, v.owner), |
64 | alias(pool, v.alias), |
65 | type(v.type), |
66 | subType(v.subType), |
67 | length(v.length), |
68 | scale(v.scale), |
69 | charSet(v.charSet), |
70 | offset(v.offset), |
71 | nullInd(v.nullInd), |
72 | nullable(v.nullable), |
73 | finished(v.finished) |
74 | { |
75 | } |
76 | |
77 | string field; |
78 | string relation; |
79 | string owner; |
80 | string alias; |
81 | unsigned type; |
82 | int subType; |
83 | unsigned length; |
84 | int scale; |
85 | unsigned charSet; |
86 | unsigned offset; |
87 | unsigned nullInd; |
88 | bool nullable; |
89 | bool finished; |
90 | }; |
91 | |
92 | public: |
93 | MsgMetadata() |
94 | : items(getPool()), |
95 | length(0) |
96 | { |
97 | } |
98 | |
99 | explicit MsgMetadata(IMessageMetadata* from) |
100 | : items(getPool()), |
101 | length(0) |
102 | { |
103 | assign(from); |
104 | } |
105 | |
106 | virtual int FB_CARG release(); |
107 | |
108 | virtual unsigned FB_CARG getCount(IStatus* /*status*/) const |
109 | { |
110 | return (unsigned) items.getCount(); |
111 | } |
112 | |
113 | virtual const char* FB_CARG getField(IStatus* status, unsigned index) const |
114 | { |
115 | if (index < items.getCount()) |
116 | return items[index].field.c_str(); |
117 | |
118 | raiseIndexError(status, index, "getField" ); |
119 | return NULL; |
120 | } |
121 | |
122 | virtual const char* FB_CARG getRelation(IStatus* status, unsigned index) const |
123 | { |
124 | if (index < items.getCount()) |
125 | return items[index].relation.c_str(); |
126 | |
127 | raiseIndexError(status, index, "getRelation" ); |
128 | return NULL; |
129 | } |
130 | |
131 | virtual const char* FB_CARG getOwner(IStatus* status, unsigned index) const |
132 | { |
133 | if (index < items.getCount()) |
134 | return items[index].owner.c_str(); |
135 | |
136 | raiseIndexError(status, index, "getOwner" ); |
137 | return NULL; |
138 | } |
139 | |
140 | virtual const char* FB_CARG getAlias(IStatus* status, unsigned index) const |
141 | { |
142 | if (index < items.getCount()) |
143 | return items[index].alias.c_str(); |
144 | |
145 | raiseIndexError(status, index, "getAlias" ); |
146 | return NULL; |
147 | } |
148 | |
149 | virtual unsigned FB_CARG getType(IStatus* status, unsigned index) const |
150 | { |
151 | if (index < items.getCount()) |
152 | return items[index].type; |
153 | |
154 | raiseIndexError(status, index, "getType" ); |
155 | return 0; |
156 | } |
157 | |
158 | virtual FB_BOOLEAN FB_CARG isNullable(IStatus* status, unsigned index) const |
159 | { |
160 | if (index < items.getCount()) |
161 | return items[index].nullable; |
162 | |
163 | raiseIndexError(status, index, "isNullable" ); |
164 | return false; |
165 | } |
166 | |
167 | virtual int FB_CARG getSubType(IStatus* status, unsigned index) const |
168 | { |
169 | if (index < items.getCount()) |
170 | return items[index].subType; |
171 | |
172 | raiseIndexError(status, index, "getSubType" ); |
173 | return 0; |
174 | } |
175 | |
176 | virtual unsigned FB_CARG getLength(IStatus* status, unsigned index) const |
177 | { |
178 | if (index < items.getCount()) |
179 | return items[index].length; |
180 | |
181 | raiseIndexError(status, index, "getLength" ); |
182 | return 0; |
183 | } |
184 | |
185 | virtual int FB_CARG getScale(IStatus* status, unsigned index) const |
186 | { |
187 | if (index < items.getCount()) |
188 | return items[index].scale; |
189 | |
190 | raiseIndexError(status, index, "getScale" ); |
191 | return 0; |
192 | } |
193 | |
194 | virtual unsigned FB_CARG getCharSet(IStatus* status, unsigned index) const |
195 | { |
196 | if (index < items.getCount()) |
197 | return items[index].charSet; |
198 | |
199 | raiseIndexError(status, index, "getCharSet" ); |
200 | return 0; |
201 | } |
202 | |
203 | virtual unsigned FB_CARG getOffset(IStatus* status, unsigned index) const |
204 | { |
205 | if (index < items.getCount()) |
206 | return items[index].offset; |
207 | |
208 | raiseIndexError(status, index, "getOffset" ); |
209 | return 0; |
210 | } |
211 | |
212 | virtual unsigned FB_CARG getNullOffset(IStatus* status, unsigned index) const |
213 | { |
214 | if (index < items.getCount()) |
215 | return items[index].nullInd; |
216 | |
217 | raiseIndexError(status, index, "getOffset" ); |
218 | return 0; |
219 | } |
220 | |
221 | virtual IMetadataBuilder* FB_CARG getBuilder(IStatus* status) const; |
222 | |
223 | virtual unsigned FB_CARG getMessageLength(IStatus* /*status*/) const |
224 | { |
225 | return length; |
226 | } |
227 | |
228 | public: |
229 | void addItem(const MetaName& name, bool nullable, const dsc& desc); |
230 | unsigned makeOffsets(); |
231 | |
232 | private: |
233 | void raiseIndexError(IStatus* status, unsigned index, const char* method) const |
234 | { |
235 | status->set((Arg::Gds(isc_invalid_index_val) << |
236 | Arg::Num(index) << (string("IMessageMetadata::" ) + method)).value()); |
237 | } |
238 | |
239 | void assign(IMessageMetadata* from); |
240 | |
241 | public: |
242 | ObjectsArray<Item> items; |
243 | unsigned length; |
244 | }; |
245 | |
246 | class AttMetadata : public MsgMetadata |
247 | { |
248 | public: |
249 | explicit AttMetadata(IAttachment* att) |
250 | : MsgMetadata(), |
251 | attachment(att) |
252 | { } |
253 | |
254 | // re-implement here release() present in MsgMetadata to call correct dtor |
255 | virtual int FB_CARG release(); |
256 | |
257 | RefPtr<IAttachment> attachment; |
258 | }; |
259 | |
260 | } // namespace Firebird |
261 | |
262 | #endif // COMMON_MSG_METADATA_H |
263 | |