forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_routine_impl.cc
More file actions
146 lines (107 loc) · 5.21 KB
/
Copy pathview_routine_impl.cc
File metadata and controls
146 lines (107 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Copyright (c) 2016, 2025, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "sql/dd/impl/types/view_routine_impl.h"
#include <ostream>
#include <string>
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysqld_error.h" // ER_*
#include "sql/dd/impl/raw/raw_record.h" // Raw_record
#include "sql/dd/impl/tables/view_routine_usage.h" // View_routine_usage
#include "sql/dd/impl/transaction_impl.h" // Open_dictionary_tables_ctx
#include "sql/dd/impl/types/view_impl.h" // View_impl
#include "sql/dd/types/object_table.h"
#include "sql/dd/types/weak_object.h"
namespace dd {
class Object_key;
} // namespace dd
using dd::tables::View_routine_usage;
namespace dd {
///////////////////////////////////////////////////////////////////////////
// View_routine_impl implementation.
///////////////////////////////////////////////////////////////////////////
View_routine_impl::View_routine_impl() = default;
View_routine_impl::View_routine_impl(View_impl *view) : m_view(view) {}
///////////////////////////////////////////////////////////////////////////
const View &View_routine_impl::view() const { return *m_view; }
View &View_routine_impl::view() { return *m_view; }
///////////////////////////////////////////////////////////////////////////
bool View_routine_impl::validate() const {
if (!m_view) {
my_error(ER_INVALID_DD_OBJECT, MYF(0), DD_table::instance().name().c_str(),
"No function is associated with this view stored function"
" object.");
return true;
}
return false;
}
///////////////////////////////////////////////////////////////////////////
bool View_routine_impl::restore_attributes(const Raw_record &r) {
if (check_parent_consistency(
m_view, r.read_ref_id(View_routine_usage::FIELD_VIEW_ID)))
return true;
m_routine_catalog = r.read_str(View_routine_usage::FIELD_ROUTINE_CATALOG);
m_routine_schema = r.read_str(View_routine_usage::FIELD_ROUTINE_SCHEMA);
m_routine_name = r.read_str(View_routine_usage::FIELD_ROUTINE_NAME);
return false;
}
///////////////////////////////////////////////////////////////////////////
bool View_routine_impl::store_attributes(Raw_record *r) {
return r->store(View_routine_usage::FIELD_VIEW_ID, m_view->id()) ||
r->store(View_routine_usage::FIELD_ROUTINE_CATALOG,
m_routine_catalog) ||
r->store(View_routine_usage::FIELD_ROUTINE_SCHEMA, m_routine_schema) ||
r->store(View_routine_usage::FIELD_ROUTINE_NAME, m_routine_name);
}
///////////////////////////////////////////////////////////////////////////
void View_routine_impl::debug_print(String_type &outb) const {
dd::Stringstream_type ss;
ss << "VIEW STORED FUNCTION OBJECT: { "
<< "m_view: {OID: " << m_view->id() << "}; "
<< "m_routine_catalog: " << m_routine_catalog << "; "
<< "m_routine_schema: " << m_routine_schema << "; "
<< "m_routine_name: " << m_routine_name;
outb = ss.str();
}
///////////////////////////////////////////////////////////////////////////
Object_key *View_routine_impl::create_primary_key() const {
return View_routine_usage::create_primary_key(
m_view->id(), m_routine_catalog, m_routine_schema, m_routine_name);
}
bool View_routine_impl::has_new_primary_key() const {
return m_view->has_new_primary_key();
}
///////////////////////////////////////////////////////////////////////////
View_routine_impl::View_routine_impl(const View_routine_impl &src,
View_impl *parent)
: Weak_object(src),
m_routine_catalog(src.m_routine_catalog),
m_routine_schema(src.m_routine_schema),
m_routine_name(src.m_routine_name),
m_view(parent) {}
///////////////////////////////////////////////////////////////////////////
const Object_table &View_routine_impl::object_table() const {
return DD_table::instance();
}
///////////////////////////////////////////////////////////////////////////
void View_routine_impl::register_tables(Open_dictionary_tables_ctx *otx) {
otx->add_table<View_routine_usage>();
}
///////////////////////////////////////////////////////////////////////////
} // namespace dd