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
23  * 02110-1301  USA
24  */
25 
26 #ifndef _XPL_STREAMING_COMMAND_DELEGATE_H_
27 #define _XPL_STREAMING_COMMAND_DELEGATE_H_
28 
29 #include "command_delegate.h"
30 
31 
32 namespace ngs
33 {
34 
35   class Protocol_encoder;
36 
37 }  // namespace ngs
38 
39 namespace xpl
40 {
41 
42   class Streaming_command_delegate : public Command_delegate
43   {
44   public:
45     Streaming_command_delegate(ngs::Protocol_encoder *proto);
46     virtual ~Streaming_command_delegate();
47 
set_compact_metadata(bool flag)48     void set_compact_metadata(bool flag) { m_compact_metadata = flag; }
compact_metadata()49     bool compact_metadata() const { return m_compact_metadata; }
50 
51     virtual void reset();
52 
53   private:
54     virtual int start_result_metadata(uint num_cols, uint flags,
55                                       const CHARSET_INFO *resultcs);
56     virtual int field_metadata(struct st_send_field *field,
57                                const CHARSET_INFO *charset);
58     virtual int end_result_metadata(uint server_status,
59                                     uint warn_count);
60 
61     virtual int start_row();
62     virtual int end_row();
63     virtual void abort_row();
64     virtual ulong get_client_capabilities();
65     virtual int get_null();
66     virtual int get_integer(longlong value);
67     virtual int get_longlong(longlong value, uint unsigned_flag);
68     virtual int get_decimal(const decimal_t *value);
69     virtual int get_double(double value, uint32 decimals);
70     virtual int get_date(const MYSQL_TIME *value);
71     virtual int get_time(const MYSQL_TIME *value, uint decimals);
72     virtual int get_datetime(const MYSQL_TIME *value, uint decimals);
73     virtual int get_string(const char * const value, size_t length,
74                            const CHARSET_INFO *const valuecs);
75     virtual void handle_ok(uint server_status, uint statement_warn_count,
76                            ulonglong affected_rows, ulonglong last_insert_id,
77                            const char * const message);
78 
representation()79     virtual enum cs_text_or_binary representation() const { return CS_BINARY_REPRESENTATION; }
80 
81     bool send_column_metadata(uint64_t xcollation, const Mysqlx::Resultset::ColumnMetaData::FieldType &xtype,
82                               uint32_t xflags, uint32_t ctype, const st_send_field *field);
83 
84     ngs::Protocol_encoder *m_proto;
85     const CHARSET_INFO *m_resultcs;
86     bool m_sent_result;
87     bool m_compact_metadata;
88   };
89 }
90 
91 #endif //  _XPL_STREAMING_COMMAND_DELEGATE_H_
92