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