TrinityCore
DB2Meta.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "DB2Meta.h"
19#include "Common.h"
20#include "Errors.h"
21
23{
24 return IndexField != -1;
25}
26
28{
29 return IndexField == -1 ? 0 : uint32(IndexField);
30}
31
33{
34 uint32 size = 0;
35 for (uint32 i = 0; i < FieldCount; ++i)
36 {
37 for (uint8 j = 0; j < Fields[i].ArraySize; ++j)
38 {
39 if (i >= FileFieldCount && int32(i) == ParentIndexField)
40 {
41 size += 4;
42 continue;
43 }
44
45 switch (Fields[i].Type)
46 {
47 case FT_BYTE:
48 size += 1;
49 break;
50 case FT_SHORT:
51 size += 2;
52 break;
53 case FT_FLOAT:
54 case FT_INT:
55 size += 4;
56 break;
57 case FT_LONG:
58 size += 8;
59 break;
60 case FT_STRING:
61 size += sizeof(LocalizedString);
62 break;
64 size += sizeof(char*);
65 break;
66 default:
67 ABORT_MSG("Unsupported column type specified %c", Fields[i].Type);
68 break;
69 }
70 }
71 }
72
74 size += 4;
75
76 return size;
77}
78
80{
81 if (IndexField == -1)
82 return 0;
83
84 uint32 offset = 0;
85
86 for (int32 i = 0; i < IndexField; ++i)
87 {
88 for (uint8 j = 0; j < Fields[i].ArraySize; ++j)
89 {
90 if (i >= int32(FileFieldCount) && i == ParentIndexField)
91 {
92 offset += 4;
93 continue;
94 }
95
96 switch (Fields[i].Type)
97 {
98 case FT_BYTE:
99 offset += 1;
100 break;
101 case FT_SHORT:
102 offset += 2;
103 break;
104 case FT_FLOAT:
105 case FT_INT:
106 offset += 4;
107 break;
108 case FT_LONG:
109 offset += 8;
110 break;
111 case FT_STRING:
112 offset += sizeof(LocalizedString);
113 break;
115 offset += sizeof(char*);
116 break;
117 default:
118 ABORT_MSG("Unsupported column type specified %c", Fields[i].Type);
119 break;
120 }
121 }
122 }
123
124 return offset;
125}
126
128{
129 if (ParentIndexField == -1)
130 return -1;
131
132 uint32 offset = 0;
133 if (!HasIndexFieldInData())
134 offset += 4;
135
136 for (int32 i = 0; i < ParentIndexField; ++i)
137 {
138 for (uint8 j = 0; j < Fields[i].ArraySize; ++j)
139 {
140 switch (Fields[i].Type)
141 {
142 case FT_BYTE:
143 offset += 1;
144 break;
145 case FT_SHORT:
146 offset += 2;
147 break;
148 case FT_FLOAT:
149 case FT_INT:
150 offset += 4;
151 break;
152 case FT_LONG:
153 offset += 8;
154 break;
155 case FT_STRING:
156 offset += sizeof(LocalizedString);
157 break;
159 offset += sizeof(char*);
160 break;
161 default:
162 ABORT_MSG("Unsupported column type specified %c", Fields[i].Type);
163 break;
164 }
165 }
166 }
167
168 return offset;
169}
170
172{
173 if (IndexField == -1)
174 return 0;
175
176 uint32 index = 0;
177 for (uint32 i = 0; i < FieldCount && i < uint32(IndexField); ++i)
178 index += Fields[i].ArraySize;
179
180 return index;
181}
182
184{
185 uint32 fields = 0;
186 for (uint32 i = 0; i < FieldCount; ++i)
187 fields += Fields[i].ArraySize;
188
189 if (!HasIndexFieldInData())
190 ++fields;
191
192 return fields;
193}
194
196{
197 switch (Fields[field].Type)
198 {
199 case FT_STRING:
201 case FT_FLOAT:
202 return false;
203 case FT_INT:
204 case FT_BYTE:
205 case FT_SHORT:
206 case FT_LONG:
207 default:
208 break;
209 }
210 if (field == uint32(IndexField) || field == uint32(ParentIndexField))
211 return false;
212
213 return Fields[field].IsSigned;
214}
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
@ FT_FLOAT
Definition: Define.h:150
@ FT_SHORT
Definition: Define.h:153
@ FT_STRING
Definition: Define.h:148
@ FT_INT
Definition: Define.h:151
@ FT_STRING_NOT_LOCALIZED
Definition: Define.h:149
@ FT_BYTE
Definition: Define.h:152
@ FT_LONG
Definition: Define.h:154
uint32_t uint32
Definition: Define.h:142
#define ABORT_MSG
Definition: Errors.h:75
constexpr std::size_t size()
Definition: UpdateField.h:796
uint8 ArraySize
Definition: DB2Meta.h:26
bool IsSigned
Definition: DB2Meta.h:27
uint32 FileFieldCount
Definition: DB2Meta.h:58
uint32 GetDbIndexField() const
Definition: DB2Meta.cpp:171
int32 IndexField
Definition: DB2Meta.h:55
DB2MetaField const * Fields
Definition: DB2Meta.h:60
uint32 GetIndexField() const
Definition: DB2Meta.cpp:27
uint32 GetDbFieldCount() const
Definition: DB2Meta.cpp:183
uint32 GetRecordSize() const
Definition: DB2Meta.cpp:32
bool HasIndexFieldInData() const
Definition: DB2Meta.cpp:22
uint32 GetIndexFieldOffset() const
Definition: DB2Meta.cpp:79
uint32 FieldCount
Definition: DB2Meta.h:57
bool IsSignedField(uint32 field) const
Definition: DB2Meta.cpp:195
int32 ParentIndexField
Definition: DB2Meta.h:56
int32 GetParentIndexFieldOffset() const
Definition: DB2Meta.cpp:127