MySQL  8.0.19
Source Code Documentation
raw_record.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef DD__RAW_RECORD_INCLUDED
24 #define DD__RAW_RECORD_INCLUDED
25 
26 #include "my_config.h"
27 
28 #include "my_inttypes.h"
29 #include "my_io.h" // IWYU pragma: keep
30 
31 #ifdef HAVE_SYS_TIME_H
32 #include <sys/time.h>
33 #endif
34 #include <sys/types.h>
35 
36 #include "sql/dd/object_id.h" // dd::Object_id
37 #include "sql/dd/string_type.h" // dd::String_type
38 
39 class Json_wrapper;
40 class Field;
41 struct TABLE;
42 
43 typedef long my_time_t;
44 
45 namespace dd {
46 
47 ///////////////////////////////////////////////////////////////////////////
48 
49 class Properties;
50 
51 ///////////////////////////////////////////////////////////////////////////
52 
53 class Raw_record {
54  public:
55  Raw_record(TABLE *table);
56 
57  public:
58  bool update();
59  bool drop();
60 
61  public:
62  bool store_pk_id(int field_no, Object_id id);
63  bool store_ref_id(int field_no, Object_id id);
64  bool store(int field_no, const String_type &s, bool is_null = false);
65  bool store(int field_no, ulonglong ull, bool is_null = false);
66  bool store(int field_no, longlong ll, bool is_null = false);
67 
68  bool store(int field_no, bool b, bool is_null = false) {
69  return store(field_no, b ? 1ll : 0ll, is_null);
70  }
71 
72  bool store(int field_no, uint v, bool is_null = false) {
73  return store(field_no, (ulonglong)v, is_null);
74  }
75 
76  bool store(int field_no, int v, bool is_null = false) {
77  return store(field_no, (longlong)v, is_null);
78  }
79 
80  bool store(int field_no, const Properties &p);
81 
82  bool store_time(int field_no, my_time_t val, bool is_null = false);
83 
84  /**
85  Store timeval at field specified by field_no into the record.
86 
87  @param field_no Field position in the record.
88  @param tv Time value to store.
89 
90  @returns
91  false on success
92  true on failure
93  */
94 
95  bool store_timestamp(int field_no, const timeval &tv);
96 
97  bool store_json(int field_no, const Json_wrapper &json);
98 
99  public:
100  bool is_null(int field_no) const;
101 
102  longlong read_int(int field_no) const;
103  longlong read_int(int field_no, longlong null_value) const {
104  return is_null(field_no) ? null_value : read_int(field_no);
105  }
106 
107  ulonglong read_uint(int field_no) const;
108  ulonglong read_uint(int field_no, ulonglong null_value) const {
109  return is_null(field_no) ? null_value : read_uint(field_no);
110  }
111 
112  String_type read_str(int field_no) const;
113  String_type read_str(int field_no, const String_type &null_value) const {
114  return is_null(field_no) ? null_value : read_str(field_no);
115  }
116 
117  Object_id read_ref_id(int field_no) const;
118 
119  bool read_bool(int field_no) const { return read_int(field_no) != 0; }
120 
121  my_time_t read_time(int field_no) const;
122 
123  /**
124  Read timeval stored at field specified by field_no from the record.
125 
126  @param field_no Field position in the record.
127 
128  @returns
129  timeval stored at field_no.
130  */
131 
132  timeval read_timestamp(int field_no) const;
133 
134  bool read_json(int field_no, Json_wrapper *json_wrapper) const;
135 
136  protected:
137  void set_null(int field_no, bool is_null);
138 
139  Field *field(
140  int field_no) const; // XXX: return non-const from const-operation
141 
142  protected:
144 };
145 
146 ///////////////////////////////////////////////////////////////////////////
147 
148 class Raw_new_record : public Raw_record {
149  public:
150  Raw_new_record(TABLE *table);
151 
153 
154  public:
155  bool insert();
156 
157  Object_id get_insert_id() const;
158 
159  void finalize();
160 };
161 
162 ///////////////////////////////////////////////////////////////////////////
163 
164 } // namespace dd
165 
166 #endif // DD__RAW_RECORD_INCLUDED
dd::Raw_record::read_time
my_time_t read_time(int field_no) const
Definition: raw_record.cc:259
dd::Properties
The Properties class defines an interface for storing key=value pairs, where both key and value may b...
Definition: properties.h:73
dd::Raw_record::read_json
bool read_json(int field_no, Json_wrapper *json_wrapper) const
Definition: raw_record.cc:281
dd::Raw_record::read_ref_id
Object_id read_ref_id(int field_no) const
Definition: raw_record.cc:252
Json_wrapper
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1141
dd::String_type
Char_string_template< String_type_allocator > String_type
Definition: string_type.h:50
dd::Raw_record::store_ref_id
bool store_ref_id(int field_no, Object_id id)
Definition: raw_record.cc:126
dd::Raw_record::Raw_record
Raw_record(TABLE *table)
Definition: raw_record.cc:47
dd::Raw_record::read_bool
bool read_bool(int field_no) const
Definition: raw_record.h:119
TABLE
Definition: table.h:1305
my_time_t
[] long int my_time_t
Portable time_t replacement.
longlong
long long int longlong
Definition: my_inttypes.h:54
dd::Raw_record::m_table
TABLE * m_table
Definition: raw_record.h:143
dd::Raw_record::is_null
bool is_null(int field_no) const
Definition: raw_record.cc:223
dd::Raw_record::drop
bool drop()
Drop the record from SE.
Definition: raw_record.cc:97
dd
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:39
dd::Raw_record::store
bool store(int field_no, bool b, bool is_null=false)
Definition: raw_record.h:68
dd::Raw_record::read_int
longlong read_int(int field_no) const
Definition: raw_record.cc:229
dd::Raw_record::read_str
String_type read_str(int field_no) const
Definition: raw_record.cc:241
dd::Raw_record::field
Field * field(int field_no) const
Definition: raw_record.cc:112
object_id.h
my_time_t
long my_time_t
Definition: raw_record.h:41
dd::Raw_record::store_json
bool store_json(int field_no, const Json_wrapper &json)
Definition: raw_record.cc:216
dd::Raw_record::read_uint
ulonglong read_uint(int field_no) const
Definition: raw_record.cc:235
dd::Raw_record
Definition: raw_record.h:53
my_inttypes.h
dd::Raw_record::read_int
longlong read_int(int field_no, longlong null_value) const
Definition: raw_record.h:103
time.h
dd::Raw_record::store
bool store(int field_no, int v, bool is_null=false)
Definition: raw_record.h:76
dd::Raw_record::update
bool update()
Update table record into SE.
Definition: raw_record.cc:60
uint
unsigned int uint
Definition: uca-dump.cc:29
string_type.h
dd::Raw_record::read_timestamp
timeval read_timestamp(int field_no) const
Read timeval stored at field specified by field_no from the record.
Definition: raw_record.cc:269
dd::Raw_record::store
bool store(int field_no, uint v, bool is_null=false)
Definition: raw_record.h:72
dd::Raw_record::read_str
String_type read_str(int field_no, const String_type &null_value) const
Definition: raw_record.h:113
dd::Object_id
unsigned long long Object_id
Definition: object_id.h:30
dd::Raw_new_record::Raw_new_record
Raw_new_record(TABLE *table)
Definition: raw_record.cc:289
dd::Raw_record::store
bool store(int field_no, const String_type &s, bool is_null=false)
Definition: raw_record.cc:150
dd::Raw_record::set_null
void set_null(int field_no, bool is_null)
Definition: raw_record.cc:141
dd::Raw_record::store_time
bool store_time(int field_no, my_time_t val, bool is_null=false)
Definition: raw_record.cc:196
dd::Raw_new_record::insert
bool insert()
Create new record in SE.
Definition: raw_record.cc:308
dd::Raw_new_record::~Raw_new_record
~Raw_new_record()
Definition: raw_record.h:152
dd::Raw_record::store_pk_id
bool store_pk_id(int field_no, Object_id id)
Definition: raw_record.cc:118
ulonglong
unsigned long long int ulonglong
Definition: my_inttypes.h:55
dd::Raw_new_record::finalize
void finalize()
Definition: raw_record.cc:332
dd::Raw_record::read_uint
ulonglong read_uint(int field_no, ulonglong null_value) const
Definition: raw_record.h:108
my_io.h
Field
Definition: field.h:695
dd::Raw_new_record
Definition: raw_record.h:148
p
const char * p
Definition: ctype-mb.cc:1233
dd::Raw_new_record::get_insert_id
Object_id get_insert_id() const
Definition: raw_record.cc:323
dd::Raw_record::store_timestamp
bool store_timestamp(int field_no, const timeval &tv)
Store timeval at field specified by field_no into the record.
Definition: raw_record.cc:209