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
22
bool
DB2Meta::HasIndexFieldInData
()
const
23
{
24
return
IndexField
!= -1;
25
}
26
27
uint32
DB2Meta::GetIndexField
()
const
28
{
29
return
IndexField
== -1 ? 0 :
uint32
(
IndexField
);
30
}
31
32
uint32
DB2Meta::GetRecordSize
()
const
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
;
63
case
FT_STRING_NOT_LOCALIZED
:
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
73
if
(!
HasIndexFieldInData
())
74
size
+= 4;
75
76
return
size
;
77
}
78
79
uint32
DB2Meta::GetIndexFieldOffset
()
const
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
;
114
case
FT_STRING_NOT_LOCALIZED
:
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
127
int32
DB2Meta::GetParentIndexFieldOffset
()
const
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
;
158
case
FT_STRING_NOT_LOCALIZED
:
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
171
uint32
DB2Meta::GetDbIndexField
()
const
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
183
uint32
DB2Meta::GetDbFieldCount
()
const
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
195
bool
DB2Meta::IsSignedField
(
uint32
field)
const
196
{
197
switch
(
Fields
[field].
Type
)
198
{
199
case
FT_STRING
:
200
case
FT_STRING_NOT_LOCALIZED
:
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
}
Common.h
DB2Meta.h
uint8
uint8_t uint8
Definition:
Define.h:144
int32
int32_t int32
Definition:
Define.h:138
FT_FLOAT
@ FT_FLOAT
Definition:
Define.h:150
FT_SHORT
@ FT_SHORT
Definition:
Define.h:153
FT_STRING
@ FT_STRING
Definition:
Define.h:148
FT_INT
@ FT_INT
Definition:
Define.h:151
FT_STRING_NOT_LOCALIZED
@ FT_STRING_NOT_LOCALIZED
Definition:
Define.h:149
FT_BYTE
@ FT_BYTE
Definition:
Define.h:152
FT_LONG
@ FT_LONG
Definition:
Define.h:154
uint32
uint32_t uint32
Definition:
Define.h:142
Errors.h
ABORT_MSG
#define ABORT_MSG
Definition:
Errors.h:75
Trainer::Type
Type
Definition:
Trainer.h:33
UF::size
constexpr std::size_t size()
Definition:
UpdateField.h:796
DB2MetaField::ArraySize
uint8 ArraySize
Definition:
DB2Meta.h:26
DB2MetaField::IsSigned
bool IsSigned
Definition:
DB2Meta.h:27
DB2Meta::FileFieldCount
uint32 FileFieldCount
Definition:
DB2Meta.h:58
DB2Meta::GetDbIndexField
uint32 GetDbIndexField() const
Definition:
DB2Meta.cpp:171
DB2Meta::IndexField
int32 IndexField
Definition:
DB2Meta.h:55
DB2Meta::Fields
DB2MetaField const * Fields
Definition:
DB2Meta.h:60
DB2Meta::GetIndexField
uint32 GetIndexField() const
Definition:
DB2Meta.cpp:27
DB2Meta::GetDbFieldCount
uint32 GetDbFieldCount() const
Definition:
DB2Meta.cpp:183
DB2Meta::GetRecordSize
uint32 GetRecordSize() const
Definition:
DB2Meta.cpp:32
DB2Meta::HasIndexFieldInData
bool HasIndexFieldInData() const
Definition:
DB2Meta.cpp:22
DB2Meta::GetIndexFieldOffset
uint32 GetIndexFieldOffset() const
Definition:
DB2Meta.cpp:79
DB2Meta::FieldCount
uint32 FieldCount
Definition:
DB2Meta.h:57
DB2Meta::IsSignedField
bool IsSignedField(uint32 field) const
Definition:
DB2Meta.cpp:195
DB2Meta::ParentIndexField
int32 ParentIndexField
Definition:
DB2Meta.h:56
DB2Meta::GetParentIndexFieldOffset
int32 GetParentIndexFieldOffset() const
Definition:
DB2Meta.cpp:127
LocalizedString
Definition:
Common.h:103
common
DataStores
DB2Meta.cpp
Generated on Thu Mar 14 2024 23:39:07 for TrinityCore by
1.9.4