My Project
sql_data_change.h
Go to the documentation of this file.
00001 #ifndef SQL_DATA_CHANGE_INCLUDED
00002 #define SQL_DATA_CHANGE_INCLUDED
00003 /* Copyright (c) 2000, 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 
00026 #include "sql_list.h"
00027 #include "my_base.h"
00028 #include "my_bitmap.h"
00029 #include "table.h"
00030 
00031 enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
00032 
00057 class COPY_INFO: public Sql_alloc
00058 {
00059 public:
00060   class Statistics
00061   {
00062   public:
00063     Statistics() :
00064       records(0), deleted(0), updated(0), copied(0), error_count(0), touched(0)
00065     {}
00066 
00067     ha_rows records; 
00068     ha_rows deleted; 
00069     ha_rows updated; 
00070     ha_rows copied;  
00071     ha_rows error_count;
00072     ha_rows touched; /* Number of touched records */
00073   };
00074 
00075   enum operation_type { INSERT_OPERATION, UPDATE_OPERATION };
00076 
00077 private:
00078   COPY_INFO(const COPY_INFO &other);            
00079   void operator=(COPY_INFO &);                  
00080 
00082   const operation_type m_optype;
00083 
00089   List<Item> *m_changed_columns;
00090 
00095   List<Item> *m_changed_columns2;
00096 
00097 
00099   const bool m_manage_defaults;
00101   MY_BITMAP *m_function_default_columns;
00102 
00103 protected:
00104 
00111   enum enum_duplicates handle_duplicates;
00112 
00119   bool ignore;
00120 
00137   bool get_function_default_columns(TABLE *table);
00138 
00145   MY_BITMAP *get_cached_bitmap() const { return m_function_default_columns; }
00146 
00147 public:
00148   Statistics stats;
00149   int escape_char, last_errno;
00151   List<Item> *update_values;
00152 
00188   COPY_INFO(operation_type optype,
00189             List<Item> *inserted_columns,
00190             bool manage_defaults,
00191             enum_duplicates duplicate_handling,
00192             bool ignore_errors) :
00193     m_optype(optype),
00194     m_changed_columns(inserted_columns),
00195     m_changed_columns2(NULL),
00196     m_manage_defaults(manage_defaults),
00197     m_function_default_columns(NULL),
00198     handle_duplicates(duplicate_handling),
00199     ignore(ignore_errors),
00200     stats(),
00201     escape_char(0),
00202     last_errno(0),
00203     update_values(NULL)
00204   {
00205     DBUG_ASSERT(optype == INSERT_OPERATION);
00206   }
00207 
00231   COPY_INFO(operation_type optype,
00232             List<Item> *inserted_columns,
00233             List<Item> *inserted_columns2,
00234             bool manage_defaults,
00235             enum_duplicates duplicates_handling,
00236             bool ignore_duplicates,
00237             int escape_character) :
00238     m_optype(optype),
00239     m_changed_columns(inserted_columns),
00240     m_changed_columns2(inserted_columns2),
00241     m_manage_defaults(manage_defaults),
00242     m_function_default_columns(NULL),
00243     handle_duplicates(duplicates_handling),
00244     ignore(ignore_duplicates),
00245     stats(),
00246     escape_char(escape_character),
00247     last_errno(0),
00248     update_values(NULL)
00249   {
00250     DBUG_ASSERT(optype == INSERT_OPERATION);
00251   }
00252 
00262   COPY_INFO(operation_type optype, List<Item> *fields, List<Item> *values) :
00263     m_optype(optype),
00264     m_changed_columns(fields),
00265     m_changed_columns2(NULL),
00266     m_manage_defaults(true),
00267     m_function_default_columns(NULL),
00268     handle_duplicates(DUP_ERROR),
00269     ignore(false),
00270     stats(),
00271     escape_char(0),
00272     last_errno(0),
00273     update_values(values)
00274   {
00275     DBUG_ASSERT(optype == UPDATE_OPERATION);
00276   }
00277 
00278   operation_type get_operation_type() const { return m_optype; }
00279 
00280   List<Item> *get_changed_columns() const { return m_changed_columns; }
00281 
00282   const List<Item> *get_changed_columns2() const { return m_changed_columns2; }
00283 
00284   bool get_manage_defaults() const { return m_manage_defaults; }
00285 
00286   enum_duplicates get_duplicate_handling() const { return handle_duplicates; }
00287 
00288   bool get_ignore_errors() const { return ignore; }
00289 
00303   virtual void set_function_defaults(TABLE *table);
00304 
00316   bool add_function_default_columns(TABLE *table, MY_BITMAP *columns)
00317   {
00318     if (get_function_default_columns(table))
00319       return true;
00320     bitmap_union(columns, m_function_default_columns);
00321     return false;
00322   }
00323 
00331   bool function_defaults_apply(const TABLE *table) const
00332   {
00333     DBUG_ASSERT(m_function_default_columns != NULL);
00334     return !bitmap_is_clear_all(m_function_default_columns);
00335   }
00336 
00341   bool function_defaults_apply_on_columns(MY_BITMAP *map)
00342   {
00343     DBUG_ASSERT(m_function_default_columns != NULL);
00344     return bitmap_is_overlapping(m_function_default_columns, map);
00345   }
00346 
00352   bool ignore_last_columns(TABLE *table, uint count);
00353 
00358   virtual ~COPY_INFO() {}
00359 };
00360 
00361 
00362 #endif // SQL_DATA_CHANGE_INCLUDED
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines