MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_prepare.h
1 #ifndef SQL_PREPARE_H
2 #define SQL_PREPARE_H
3 /* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software Foundation,
16  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
17 
18 #include "sql_error.h"
19 
20 class THD;
21 struct LEX;
22 
52 {
53 public:
60  bool report_error(THD *thd);
61  bool is_invalidated() const { return m_invalidated; }
62  void reset_reprepare_observer() { m_invalidated= FALSE; }
63 private:
64  bool m_invalidated;
65 };
66 
67 
68 void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length);
69 void mysqld_stmt_execute(THD *thd, char *packet, uint packet_length);
70 void mysqld_stmt_close(THD *thd, char *packet, uint packet_length);
71 void mysql_sql_stmt_prepare(THD *thd);
72 void mysql_sql_stmt_execute(THD *thd);
73 void mysql_sql_stmt_close(THD *thd);
74 void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length);
75 void mysqld_stmt_reset(THD *thd, char *packet, uint packet_length);
76 void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length);
77 void reinit_stmt_before_use(THD *thd, LEX *lex);
78 
87 {
88 public:
89  virtual bool execute_server_code(THD *thd)= 0;
90  virtual ~Server_runnable();
91 };
92 
93 
100 class Ed_row;
101 
109 {
110 public:
111  operator List<Ed_row>&() { return *m_rows; }
112  unsigned int size() const { return m_rows->elements; }
113 
114  Ed_result_set(List<Ed_row> *rows_arg, size_t column_count,
115  MEM_ROOT *mem_root_arg);
116 
119 
120  size_t get_field_count() const { return m_column_count; }
121 
122  static void operator delete(void *ptr, size_t size) throw ();
123 private:
124  Ed_result_set(const Ed_result_set &); /* not implemented */
125  Ed_result_set &operator=(Ed_result_set &); /* not implemented */
126 private:
127  MEM_ROOT m_mem_root;
128  size_t m_column_count;
129  List<Ed_row> *m_rows;
130  Ed_result_set *m_next_rset;
131  friend class Ed_connection;
132 };
133 
134 
136 {
137 public:
153  Ed_connection(THD *thd);
154 
192  bool execute_direct(LEX_STRING sql_text);
193 
205  bool execute_direct(Server_runnable *server_runnable);
206 
217  ulong get_field_count() const
218  {
219  return m_current_rset ? m_current_rset->get_field_count() : 0;
220  }
221 
230  ulonglong get_affected_rows() const
231  {
232  return m_diagnostics_area.affected_rows();
233  }
234 
240  ulonglong get_last_insert_id() const
241  {
242  return m_diagnostics_area.last_insert_id();
243  }
244 
253  ulong get_warn_count() const
254  {
255  return m_diagnostics_area.warn_count();
256  }
257 
264  const char *get_last_error() const { return m_diagnostics_area.message(); }
265  unsigned int get_last_errno() const { return m_diagnostics_area.sql_errno(); }
266  const char *get_last_sqlstate() const { return m_diagnostics_area.get_sqlstate(); }
267 
276  Ed_result_set *use_result_set() { return m_current_rset; }
285 
292  bool has_next_result() const { return test(m_current_rset->m_next_rset); }
298  {
299  m_current_rset= m_current_rset->m_next_rset;
300  return test(m_current_rset);
301  }
302 
303  ~Ed_connection() { free_old_result(); }
304 private:
305  Diagnostics_area m_diagnostics_area;
313  THD *m_thd;
314  Ed_result_set *m_rsets;
315  Ed_result_set *m_current_rset;
316  friend class Protocol_local;
317 private:
318  void free_old_result();
319  void add_result_set(Ed_result_set *ed_result_set);
320 private:
321  Ed_connection(const Ed_connection &); /* not implemented */
322  Ed_connection &operator=(Ed_connection &); /* not implemented */
323 };
324 
325 
328 struct Ed_column: public LEX_STRING
329 {
331 };
332 
333 
336 class Ed_row: public Sql_alloc
337 {
338 public:
339  const Ed_column &operator[](const unsigned int column_index) const
340  {
341  return *get_column(column_index);
342  }
343  const Ed_column *get_column(const unsigned int column_index) const
344  {
345  DBUG_ASSERT(column_index < size());
346  return m_column_array + column_index;
347  }
348  size_t size() const { return m_column_count; }
349 
350  Ed_row(Ed_column *column_array_arg, size_t column_count_arg)
351  :m_column_array(column_array_arg),
352  m_column_count(column_count_arg)
353  {}
354 private:
355  Ed_column *m_column_array;
356  size_t m_column_count; /* TODO: change to point to metadata */
357 };
358 
359 #endif // SQL_PREPARE_H