1 /* Copyright (c) 2005, 2011, 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 as published by 5 the Free Software Foundation; version 2 of the License. 6 7 This program is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 GNU General Public License for more details. 11 12 You should have received a copy of the GNU General Public License 13 along with this program; if not, write to the Free Software 14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ 15 16 #ifndef _sql_cursor_h_ 17 #define _sql_cursor_h_ 18 19 #ifdef USE_PRAGMA_INTERFACE 20 #pragma interface /* gcc class interface */ 21 #endif 22 23 #include "sql_class.h" /* Query_arena */ 24 25 class JOIN; 26 27 /** 28 @file 29 30 Declarations for implementation of server side cursors. Only 31 read-only non-scrollable cursors are currently implemented. 32 */ 33 34 /** 35 Server_side_cursor -- an interface for materialized 36 implementation of cursors. All cursors are self-contained 37 (created in their own memory root). For that reason they must 38 be deleted only using a pointer to Server_side_cursor, not to 39 its base class. 40 */ 41 42 class Server_side_cursor: protected Query_arena 43 { 44 protected: 45 /** Row destination used for fetch */ 46 select_result *result; 47 public: Server_side_cursor(MEM_ROOT * mem_root_arg,select_result * result_arg)48 Server_side_cursor(MEM_ROOT *mem_root_arg, select_result *result_arg) 49 :Query_arena(mem_root_arg, STMT_INITIALIZED), result(result_arg) 50 {} 51 52 virtual bool is_open() const= 0; 53 54 virtual int open(JOIN *top_level_join)= 0; 55 virtual void fetch(ulong num_rows)= 0; 56 virtual void close()= 0; export_structure(THD * thd,Row_definition_list * defs)57 virtual bool export_structure(THD *thd, Row_definition_list *defs) 58 { 59 DBUG_ASSERT(0); 60 return true; 61 } 62 virtual ~Server_side_cursor(); 63 new(size_t size,MEM_ROOT * mem_root)64 static void *operator new(size_t size, MEM_ROOT *mem_root) 65 { return alloc_root(mem_root, size); } 66 static void operator delete(void *ptr, size_t size); delete(void *,MEM_ROOT *)67 static void operator delete(void *, MEM_ROOT *){} 68 }; 69 70 71 int mysql_open_cursor(THD *thd, select_result *result, 72 Server_side_cursor **res); 73 74 #endif /* _sql_cusor_h_ */ 75