My Project
sql_get_diagnostics.h
00001 /* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 #ifndef SQL_GET_DIAGNOSTICS_H
00017 #define SQL_GET_DIAGNOSTICS_H
00018 
00020 class Diagnostics_information;
00021 
00022 
00030 class Sql_cmd_get_diagnostics : public Sql_cmd
00031 {
00032 public:
00038   Sql_cmd_get_diagnostics(Diagnostics_information *info)
00039     : m_info(info)
00040   {}
00041 
00042   virtual enum_sql_command sql_command_code() const
00043   {
00044     return SQLCOM_GET_DIAGNOSTICS;
00045   }
00046 
00047   virtual bool execute(THD *thd);
00048 
00049 private:
00051   Diagnostics_information *m_info;
00052 };
00053 
00054 
00061 class Diagnostics_information : public Sql_alloc
00062 {
00063 public:
00068   enum Which_area
00069   {
00071     CURRENT_AREA
00072   };
00073 
00075   void set_which_da(Which_area area)
00076   { m_area= area; }
00077 
00079   Which_area get_which_da(void) const
00080   { return m_area; }
00081 
00091   virtual bool aggregate(THD *thd, const Diagnostics_area *da) = 0;
00092 
00093 protected:
00098   virtual ~Diagnostics_information()
00099   {
00100     DBUG_ASSERT(false);
00101   }
00102 
00113   template <typename Diag_item, typename Context>
00114   bool evaluate(THD *thd, Diag_item *diag_item, Context ctx)
00115   {
00116     Item *value;
00117 
00118     /* Get this item's value. */
00119     if (! (value= diag_item->get_value(thd, ctx)))
00120       return true;
00121 
00122     /* Set variable/parameter value. */
00123     return diag_item->set_value(thd, &value);
00124   }
00125 
00126 private:
00128   Which_area m_area;
00129 };
00130 
00131 
00136 class Diagnostics_information_item : public Sql_alloc
00137 {
00138 public:
00148   bool set_value(THD *thd, Item **value);
00149 
00150 protected:
00156   Diagnostics_information_item(Item *target)
00157     : m_target(target)
00158   {}
00159 
00164   virtual ~Diagnostics_information_item()
00165   {
00166     DBUG_ASSERT(false);
00167   }
00168 
00169 private:
00171   Item *m_target;
00172 };
00173 
00174 
00178 class Statement_information_item : public Diagnostics_information_item
00179 {
00180 public:
00182   enum Name
00183   {
00184     NUMBER,
00185     ROW_COUNT
00186   };
00187 
00194   Statement_information_item(Name name, Item *target)
00195     : Diagnostics_information_item(target), m_name(name)
00196   {}
00197 
00199   Item *get_value(THD *thd, const Diagnostics_area *da);
00200 
00201 private:
00203   Name m_name;
00204 };
00205 
00206 
00212 class Statement_information : public Diagnostics_information
00213 {
00214 public:
00221   Statement_information(List<Statement_information_item> *items)
00222     : m_items(items)
00223   {}
00224 
00226   bool aggregate(THD *thd, const Diagnostics_area *da);
00227 
00228 private:
00229   /* List of statement information items. */
00230   List<Statement_information_item> *m_items;
00231 };
00232 
00233 
00237 class Condition_information_item : public Diagnostics_information_item
00238 {
00239 public:
00243   enum Name
00244   {
00245     CLASS_ORIGIN,
00246     SUBCLASS_ORIGIN,
00247     CONSTRAINT_CATALOG,
00248     CONSTRAINT_SCHEMA,
00249     CONSTRAINT_NAME,
00250     CATALOG_NAME,
00251     SCHEMA_NAME,
00252     TABLE_NAME,
00253     COLUMN_NAME,
00254     CURSOR_NAME,
00255     MESSAGE_TEXT,
00256     MYSQL_ERRNO,
00257     RETURNED_SQLSTATE
00258   };
00259 
00266   Condition_information_item(Name name, Item *target)
00267     : Diagnostics_information_item(target), m_name(name)
00268   {}
00269 
00271   Item *get_value(THD *thd, const Sql_condition *cond);
00272 
00273 private:
00275   Name m_name;
00276 
00278   Item *make_utf8_string_item(THD *thd, const String *str);
00279 };
00280 
00281 
00288 class Condition_information : public Diagnostics_information
00289 {
00290 public:
00298   Condition_information(Item *cond_number_expr,
00299                         List<Condition_information_item> *items)
00300     : m_cond_number_expr(cond_number_expr), m_items(items)
00301   {}
00302 
00304   bool aggregate(THD *thd, const Diagnostics_area *da);
00305 
00306 private:
00311   Item *m_cond_number_expr;
00312 
00314   List<Condition_information_item> *m_items;
00315 };
00316 
00317 #endif
00318 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines