My Project
|
00001 #ifndef SQL_PREPARE_H 00002 #define SQL_PREPARE_H 00003 /* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; version 2 of the License. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software Foundation, 00016 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 00017 00018 #include "sql_error.h" 00019 00020 class THD; 00021 struct LEX; 00022 00051 class Reprepare_observer 00052 { 00053 public: 00060 bool report_error(THD *thd); 00061 bool is_invalidated() const { return m_invalidated; } 00062 void reset_reprepare_observer() { m_invalidated= FALSE; } 00063 private: 00064 bool m_invalidated; 00065 }; 00066 00067 00068 void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length); 00069 void mysqld_stmt_execute(THD *thd, char *packet, uint packet_length); 00070 void mysqld_stmt_close(THD *thd, char *packet, uint packet_length); 00071 void mysql_sql_stmt_prepare(THD *thd); 00072 void mysql_sql_stmt_execute(THD *thd); 00073 void mysql_sql_stmt_close(THD *thd); 00074 void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length); 00075 void mysqld_stmt_reset(THD *thd, char *packet, uint packet_length); 00076 void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length); 00077 void reinit_stmt_before_use(THD *thd, LEX *lex); 00078 00086 class Server_runnable 00087 { 00088 public: 00089 virtual bool execute_server_code(THD *thd)= 0; 00090 virtual ~Server_runnable(); 00091 }; 00092 00093 00100 class Ed_row; 00101 00108 class Ed_result_set: public Sql_alloc 00109 { 00110 public: 00111 operator List<Ed_row>&() { return *m_rows; } 00112 unsigned int size() const { return m_rows->elements; } 00113 00114 Ed_result_set(List<Ed_row> *rows_arg, size_t column_count, 00115 MEM_ROOT *mem_root_arg); 00116 00118 ~Ed_result_set() {} 00119 00120 size_t get_field_count() const { return m_column_count; } 00121 00122 static void operator delete(void *ptr, size_t size) throw (); 00123 private: 00124 Ed_result_set(const Ed_result_set &); /* not implemented */ 00125 Ed_result_set &operator=(Ed_result_set &); /* not implemented */ 00126 private: 00127 MEM_ROOT m_mem_root; 00128 size_t m_column_count; 00129 List<Ed_row> *m_rows; 00130 Ed_result_set *m_next_rset; 00131 friend class Ed_connection; 00132 }; 00133 00134 00135 class Ed_connection 00136 { 00137 public: 00153 Ed_connection(THD *thd); 00154 00192 bool execute_direct(LEX_STRING sql_text); 00193 00205 bool execute_direct(Server_runnable *server_runnable); 00206 00217 ulong get_field_count() const 00218 { 00219 return m_current_rset ? m_current_rset->get_field_count() : 0; 00220 } 00221 00230 ulonglong get_affected_rows() const 00231 { 00232 return m_diagnostics_area.affected_rows(); 00233 } 00234 00240 ulonglong get_last_insert_id() const 00241 { 00242 return m_diagnostics_area.last_insert_id(); 00243 } 00244 00253 ulong get_warn_count() const 00254 { 00255 return m_diagnostics_area.warn_count(); 00256 } 00257 00264 const char *get_last_error() const { return m_diagnostics_area.message(); } 00265 unsigned int get_last_errno() const { return m_diagnostics_area.sql_errno(); } 00266 const char *get_last_sqlstate() const { return m_diagnostics_area.get_sqlstate(); } 00267 00276 Ed_result_set *use_result_set() { return m_current_rset; } 00284 Ed_result_set *store_result_set(); 00285 00292 bool has_next_result() const { return MY_TEST(m_current_rset->m_next_rset); } 00297 bool move_to_next_result() 00298 { 00299 m_current_rset= m_current_rset->m_next_rset; 00300 return MY_TEST(m_current_rset); 00301 } 00302 00303 ~Ed_connection() { free_old_result(); } 00304 private: 00305 Diagnostics_area m_diagnostics_area; 00313 THD *m_thd; 00314 Ed_result_set *m_rsets; 00315 Ed_result_set *m_current_rset; 00316 friend class Protocol_local; 00317 private: 00318 void free_old_result(); 00319 void add_result_set(Ed_result_set *ed_result_set); 00320 private: 00321 Ed_connection(const Ed_connection &); /* not implemented */ 00322 Ed_connection &operator=(Ed_connection &); /* not implemented */ 00323 }; 00324 00325 00328 struct Ed_column: public LEX_STRING 00329 { 00331 }; 00332 00333 00336 class Ed_row: public Sql_alloc 00337 { 00338 public: 00339 const Ed_column &operator[](const unsigned int column_index) const 00340 { 00341 return *get_column(column_index); 00342 } 00343 const Ed_column *get_column(const unsigned int column_index) const 00344 { 00345 DBUG_ASSERT(column_index < size()); 00346 return m_column_array + column_index; 00347 } 00348 size_t size() const { return m_column_count; } 00349 00350 Ed_row(Ed_column *column_array_arg, size_t column_count_arg) 00351 :m_column_array(column_array_arg), 00352 m_column_count(column_count_arg) 00353 {} 00354 private: 00355 Ed_column *m_column_array; 00356 size_t m_column_count; /* TODO: change to point to metadata */ 00357 }; 00358 00359 #endif // SQL_PREPARE_H