1 /* Copyright (c) 2005, 2012, 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 Foundation,
21    51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef _sql_cursor_h_
24 #define _sql_cursor_h_
25 
26 #include "sql_class.h"                          /* Query_arena */
27 
28 class JOIN;
29 
30 /**
31   @file
32 
33   Declarations for implementation of server side cursors. Only
34   read-only non-scrollable cursors are currently implemented.
35 */
36 
37 /**
38   Server_side_cursor -- an interface for materialized
39   implementation of cursors. All cursors are self-contained
40   (created in their own memory root).  For that reason they must
41   be deleted only using a pointer to Server_side_cursor, not to
42   its base class.
43 */
44 
45 class Server_side_cursor: protected Query_arena, public Sql_alloc
46 {
47 protected:
48   /** Row destination used for fetch */
49   select_result *result;
50 public:
Server_side_cursor(MEM_ROOT * mem_root_arg,select_result * result_arg)51   Server_side_cursor(MEM_ROOT *mem_root_arg, select_result *result_arg)
52     :Query_arena(mem_root_arg, STMT_INITIALIZED), result(result_arg)
53   {}
54 
55   virtual bool is_open() const= 0;
56 
57   virtual int open(JOIN *top_level_join)= 0;
58   virtual void fetch(ulong num_rows)= 0;
59   virtual void close()= 0;
60   virtual ~Server_side_cursor();
61 
62   static void operator delete(void *ptr, size_t size);
63 };
64 
65 
66 bool mysql_open_cursor(THD *thd, select_result *result,
67                        Server_side_cursor **res);
68 
69 #endif /* _sql_cusor_h_ */
70