1 /*
2   Copyright (c) 2015, 2021, Oracle and/or its affiliates.
3 
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2.0,
6   as published by the Free Software Foundation.
7 
8   This program is also distributed with certain software (including
9   but not limited to OpenSSL) that is licensed under separate terms,
10   as designated in a particular file or component or in included license
11   documentation.  The authors of MySQL hereby grant you an additional
12   permission to link the program and your derivative works with the
13   separately licensed software that they have included with MySQL.
14 
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License, version 2.0, for more details.
19 
20   You should have received a copy of the GNU General Public License
21   along with this program; if not, write to the Free Software
22   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef MYSQL_OBJECT_READER_INCLUDED
26 #define MYSQL_OBJECT_READER_INCLUDED
27 
28 #include "i_object_reader.h"
29 #include "abstract_data_formatter_wrapper.h"
30 #include "abstract_mysql_chain_element_extension.h"
31 #include "mysql_object_reader_options.h"
32 #include "row_group_dump_task.h"
33 #include "table_rows_dump_task.h"
34 #include "mysql_field.h"
35 
36 namespace Mysql{
37 namespace Tools{
38 namespace Dump{
39 
40 /**
41   Parses any DB object(excluding rows and privileges for DB objects) data using
42   connection to MySQL server.
43  */
44 class Mysql_object_reader
45   : public Abstract_data_formatter_wrapper, public I_object_reader,
46   public Abstract_mysql_chain_element_extension
47 {
48 public:
49   Mysql_object_reader(
50     I_connection_provider* connection_provider,
51     Mysql::I_callable<bool, const Mysql::Tools::Base::Message_data&>*
52     message_handler, Simple_id_generator* object_id_generator,
53     const Mysql_object_reader_options* options);
54 
55   void read_object(Item_processing_data* item_to_process);
56 
57   void format_rows(
58     Item_processing_data* item_to_process, Row_group_dump_task* row_group);
59 
60 private:
61   void read_table_rows_task(Table_rows_dump_task* table_rows_dump_task,
62     Item_processing_data* item_to_process);
63 
64   const Mysql_object_reader_options* m_options;
65 
66   class Rows_fetching_context
67   {
68   public:
69     Rows_fetching_context(Mysql_object_reader* parent,
70         Item_processing_data* item_processing, bool has_generated_column);
71 
72     int64 result_callback(
73       const Mysql::Tools::Base::Mysql_query_runner::Row& row_data);
74 
75     void process_buffer();
76     bool is_all_rows_processed();
77 
78   private:
79     void acquire_fields_information(MYSQL_RES* mysql_result);
80 
81     Mysql_object_reader* m_parent;
82     Item_processing_data* m_item_processing;
83     Row_group_dump_task m_row_group;
84     std::vector<Mysql_field> m_fields;
85   };
86 };
87 
88 }
89 }
90 }
91 
92 #endif
93