TrinityCore
Field.h
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#ifndef TRINITY_DATABASE_FIELD_H
19#define TRINITY_DATABASE_FIELD_H
20
21#include "Define.h"
22#include <array>
23#include <string>
24#include <string_view>
25#include <vector>
26
28
30{
31 Null,
32 UInt8,
33 Int8,
34 UInt16,
35 Int16,
36 UInt32,
37 Int32,
38 UInt64,
39 Int64,
40 Float,
41 Double,
42 Decimal,
43 Date,
44 Binary
45};
46
48{
49 char const* TableName = nullptr;
50 char const* TableAlias = nullptr;
51 char const* Name = nullptr;
52 char const* Alias = nullptr;
53 char const* TypeName = nullptr;
57};
58
90{
91 friend class ResultSet;
92 friend class PreparedResultSet;
93
94 public:
95 Field();
97
98 bool GetBool() const // Wrapper, actually gets integer
99 {
100 return GetUInt8() == 1 ? true : false;
101 }
102
103 uint8 GetUInt8() const;
104 int8 GetInt8() const;
105 uint16 GetUInt16() const;
106 int16 GetInt16() const;
107 uint32 GetUInt32() const;
108 int32 GetInt32() const;
109 uint64 GetUInt64() const;
110 int64 GetInt64() const;
111 float GetFloat() const;
112 double GetDouble() const;
113 char const* GetCString() const;
114 std::string GetString() const;
115 std::string_view GetStringView() const;
116 std::vector<uint8> GetBinary() const;
117 template <size_t S>
118 std::array<uint8, S> GetBinary() const
119 {
120 std::array<uint8, S> buf;
121 GetBinarySizeChecked(buf.data(), S);
122 return buf;
123 }
124
125 bool IsNull() const
126 {
127 return _value == nullptr;
128 }
129
130 private:
131 char const* _value; // Actual data in memory
132 uint32 _length; // Length
133
134 void SetValue(char const* newValue, uint32 length);
135
137 void SetMetadata(QueryResultFieldMetadata const* meta);
138
139 void GetBinarySizeChecked(uint8* buf, size_t size) const;
140};
141
142#endif
uint8_t uint8
Definition: Define.h:144
#define TC_DATABASE_API
Definition: Define.h:111
int64_t int64
Definition: Define.h:137
int16_t int16
Definition: Define.h:139
int8_t int8
Definition: Define.h:140
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
DatabaseFieldTypes
Definition: Field.h:30
Class used to access individual fields of database query result.
Definition: Field.h:90
char const * _value
Definition: Field.h:131
QueryResultFieldMetadata const * _meta
Definition: Field.h:136
uint32 _length
Definition: Field.h:132
std::array< uint8, S > GetBinary() const
Definition: Field.h:118
bool IsNull() const
Definition: Field.h:125
bool GetBool() const
Definition: Field.h:98
constexpr std::size_t size()
Definition: UpdateField.h:796
BaseDatabaseResultValueConverter const * Converter
Definition: Field.h:56
DatabaseFieldTypes Type
Definition: Field.h:55
char const * Alias
Definition: Field.h:52
char const * TableAlias
Definition: Field.h:50
char const * TableName
Definition: Field.h:49
char const * TypeName
Definition: Field.h:53
char const * Name
Definition: Field.h:51