aboutsummaryrefslogtreecommitdiff
path: root/src/common/DataStores/DB2Meta.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/DataStores/DB2Meta.cpp')
-rw-r--r--src/common/DataStores/DB2Meta.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/common/DataStores/DB2Meta.cpp b/src/common/DataStores/DB2Meta.cpp
new file mode 100644
index 00000000000..bf119b52150
--- /dev/null
+++ b/src/common/DataStores/DB2Meta.cpp
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "DB2Meta.h"
+
+DB2Meta::DB2Meta(int32 indexField, uint32 fieldCount, uint32 layoutHash, char const* types, uint8 const* arraySizes)
+ : IndexField(indexField), FieldCount(fieldCount), LayoutHash(layoutHash), Types(types), ArraySizes(arraySizes)
+{
+}
+
+bool DB2Meta::HasIndexFieldInData() const
+{
+ return IndexField != -1;
+}
+
+uint32 DB2Meta::GetIndexField() const
+{
+ return IndexField == -1 ? 0 : uint32(IndexField);
+}
+
+uint32 DB2Meta::GetRecordSize() const
+{
+ uint32 size = 0;
+ for (uint32 i = 0; i < FieldCount; ++i)
+ {
+ for (uint8 j = 0; j < ArraySizes[i]; ++j)
+ {
+ switch (Types[i])
+ {
+ case FT_BYTE:
+ size += 1;
+ break;
+ case FT_SHORT:
+ size += 2;
+ break;
+ case FT_FLOAT:
+ case FT_INT:
+ size += 4;
+ break;
+ case FT_STRING:
+ case FT_STRING_NOT_LOCALIZED:
+ size += sizeof(char*);
+ break;
+ }
+ }
+ }
+
+ if (!HasIndexFieldInData())
+ size += 4;
+
+ return size;
+}
+
+uint32 DB2Meta::GetDbIndexField() const
+{
+ if (IndexField == -1)
+ return 0;
+
+ uint32 index = 0;
+ for (uint32 i = 0; i < FieldCount && i < uint32(IndexField); ++i)
+ index += ArraySizes[i];
+
+ return index;
+}
+
+uint32 DB2Meta::GetDbFieldCount() const
+{
+ uint32 fields = 0;
+ for (uint32 i = 0; i < FieldCount; ++i)
+ fields += ArraySizes[i];
+
+ if (!HasIndexFieldInData())
+ ++fields;
+
+ return fields;
+}
+
+uint32 DB2Meta::GetStringFieldCount(bool localizedOnly) const
+{
+ uint32 stringFields = 0;
+ for (uint32 i = 0; i < FieldCount; ++i)
+ if (Types[i] == FT_STRING || (Types[i] == FT_STRING_NOT_LOCALIZED && !localizedOnly))
+ for (uint8 j = 0; j < ArraySizes[i]; ++j)
+ ++stringFields;
+
+ return stringFields;
+}