TrinityCore
Loading...
Searching...
No Matches
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 "Optional.h"
24#include <array>
25#include <span>
26#include <string>
27#include <string_view>
28#include <vector>
29
31
33{
34 Null,
35 UInt8,
36 Int8,
37 UInt16,
38 Int16,
39 UInt32,
40 Int32,
41 UInt64,
42 Int64,
43 Float,
44 Double,
45 Decimal,
46 Date,
47 Time,
48 Binary
49};
50
52{
53 char const* TableName = nullptr;
54 char const* TableAlias = nullptr;
55 char const* Name = nullptr;
56 char const* Alias = nullptr;
57 char const* TypeName = nullptr;
61};
62
94{
95 friend class ResultSet;
96 friend class PreparedResultSet;
97
98 public:
99 Field();
101
102 bool GetBool() const noexcept // Wrapper, actually gets integer
103 {
104 return GetUInt8() != 0;
105 }
106
107 uint8 GetUInt8() const noexcept;
108 int8 GetInt8() const noexcept;
109 uint16 GetUInt16() const noexcept;
110 int16 GetInt16() const noexcept;
111 uint32 GetUInt32() const noexcept;
112 int32 GetInt32() const noexcept;
113 uint64 GetUInt64() const noexcept;
114 int64 GetInt64() const noexcept;
115 float GetFloat() const noexcept;
116 double GetDouble() const noexcept;
117 SystemTimePoint GetDate() const noexcept;
118 char const* GetCString() const noexcept;
119 std::string GetString() const noexcept;
120 std::string_view GetStringView() const noexcept;
121 std::vector<uint8> GetBinary() const noexcept;
122 std::span<uint8 const> GetBinaryView() const noexcept;
123 template <size_t S>
124 std::array<uint8, S> GetBinary() const noexcept
125 {
126 std::array<uint8, S> buf;
127 GetBinarySizeChecked(buf.data(), S);
128 return buf;
129 }
130
131 bool IsNull() const noexcept
132 {
133 return _value == nullptr;
134 }
135
136 Optional<uint8> GetUInt8OrNull() const noexcept;
137 Optional<int8> GetInt8OrNull() const noexcept;
138 Optional<uint16> GetUInt16OrNull() const noexcept;
139 Optional<int16> GetInt16OrNull() const noexcept;
140 Optional<uint32> GetUInt32OrNull() const noexcept;
141 Optional<int32> GetInt32OrNull() const noexcept;
142 Optional<uint64> GetUInt64OrNull() const noexcept;
143 Optional<int64> GetInt64OrNull() const noexcept;
144 Optional<float> GetFloatOrNull() const noexcept;
145 Optional<double> GetDoubleOrNull() const noexcept;
146 Optional<SystemTimePoint> GetDateOrNull() const noexcept;
147 Optional<std::string> GetStringOrNull() const noexcept;
148 Optional<std::string_view> GetStringViewOrNull() const noexcept;
149 Optional<std::vector<uint8>> GetBinaryOrNull() const noexcept;
150 Optional<std::span<uint8 const>> GetBinaryViewOrNull() const noexcept;
151 template <size_t S>
152 Optional<std::array<uint8, S>> GetBinaryOrNull() const noexcept
153 {
155 if (!IsNull())
156 GetBinarySizeChecked(buf.emplace().data(), S);
157 return buf;
158 }
159
160 private:
161 char const* _value; // Actual data in memory
162 uint32 _length; // Length
163
164 void SetValue(char const* newValue, uint32 length);
165
167 void SetMetadata(QueryResultFieldMetadata const* meta);
168
169 void GetBinarySizeChecked(uint8* buf, size_t size) const noexcept;
170};
171
172#endif
uint8_t uint8
Definition Define.h:156
#define TC_DATABASE_API
Definition Define.h:111
int64_t int64
Definition Define.h:149
int16_t int16
Definition Define.h:151
int8_t int8
Definition Define.h:152
int32_t int32
Definition Define.h:150
uint64_t uint64
Definition Define.h:153
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
std::chrono::system_clock::time_point SystemTimePoint
Definition Duration.h:41
DatabaseFieldTypes
Definition Field.h:33
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
Class used to access individual fields of database query result.
Definition Field.h:94
char const * _value
Definition Field.h:161
QueryResultFieldMetadata const * _meta
Definition Field.h:166
uint32 _length
Definition Field.h:162
bool GetBool() const noexcept
Definition Field.h:102
bool IsNull() const noexcept
Definition Field.h:131
STL namespace.
BaseDatabaseResultValueConverter const * Converter
Definition Field.h:60
DatabaseFieldTypes Type
Definition Field.h:59
char const * Alias
Definition Field.h:56
char const * TableAlias
Definition Field.h:54
char const * TableName
Definition Field.h:53
char const * TypeName
Definition Field.h:57
char const * Name
Definition Field.h:55