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