1 /*
2    Copyright (c) 2018, 2019 MariaDB
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 as published by
6    the Free Software Foundation; version 2 of the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
16 
17 #ifndef SELECT_HANDLER_INCLUDED
18 #define SELECT_HANDLER_INCLUDED
19 
20 #include "mariadb.h"
21 #include "sql_priv.h"
22 
23 /**
24   @class select_handler
25 
26   This interface class is to be used for execution of select queries
27   by foreign engines
28 */
29 
30 class select_handler
31 {
32  public:
33   THD *thd;
34   handlerton *ht;
35 
36   SELECT_LEX *select;  // Select to be excuted
37 
38   /*
39     Temporary table where all results should be stored in record[0]
40     The table has a field for every item from the select_lex::item_list.
41     The table is actually never filled. Only its record buffer is used.
42   */
43   TABLE *table;
44   List<Item> result_columns;
45 
46   bool is_analyze;
47 
48   bool send_result_set_metadata();
49   bool send_data();
50 
51   select_handler(THD *thd_arg, handlerton *ht_arg);
52 
53   virtual ~select_handler();
54 
55   int execute();
56 
57   virtual bool prepare();
58 
59   static TABLE *create_tmp_table(THD *thd, SELECT_LEX *sel);
60 
61 protected:
62   /*
63     Functions to scan the select result set.
64     All these returns 0 if ok, error code in case of error.
65   */
66 
67   /* Initialize the process of producing rows of result set */
68   virtual int init_scan() = 0;
69 
70   /*
71     Put the next produced row of the result set in table->record[0]
72     and return 0. Return HA_ERR_END_OF_FILE if there are no more rows,
73     return other error number in case of fatal error.
74   */
75   virtual int next_row() = 0;
76 
77   /* Finish scanning */
78   virtual int end_scan() = 0;
79 
80   /* Report errors */
81   virtual void print_error(int error, myf errflag);
82 
83   bool send_eof();
84 };
85 
86 #endif /* SELECT_HANDLER_INCLUDED */
87