MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_data_change.h
Go to the documentation of this file.
1 #ifndef SQL_DATA_CHANGE_INCLUDED
2 #define SQL_DATA_CHANGE_INCLUDED
3 /* Copyright (c) 2000, 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 
26 #include "sql_list.h"
27 #include "my_base.h"
28 #include "my_bitmap.h"
29 #include "table.h"
30 
31 enum enum_duplicates { DUP_ERROR, DUP_REPLACE, DUP_UPDATE };
32 
57 class COPY_INFO: public Sql_alloc
58 {
59 public:
60  class Statistics
61  {
62  public:
63  Statistics() :
64  records(0), deleted(0), updated(0), copied(0), error_count(0), touched(0)
65  {}
66 
67  ha_rows records;
68  ha_rows deleted;
69  ha_rows updated;
70  ha_rows copied;
71  ha_rows error_count;
72  ha_rows touched; /* Number of touched records */
73  };
74 
75  enum operation_type { INSERT_OPERATION, UPDATE_OPERATION };
76 
77 private:
78  COPY_INFO(const COPY_INFO &other);
79  void operator=(COPY_INFO &);
80 
82  const operation_type m_optype;
83 
89  List<Item> *m_changed_columns;
90 
95  List<Item> *m_changed_columns2;
96 
97 
99  const bool m_manage_defaults;
101  MY_BITMAP *m_function_default_columns;
102 
103 protected:
104 
111  enum enum_duplicates handle_duplicates;
112 
119  bool ignore;
120 
138 
145  MY_BITMAP *get_cached_bitmap() const { return m_function_default_columns; }
146 
147 public:
148  Statistics stats;
149  int escape_char, last_errno;
152 
188  COPY_INFO(operation_type optype,
189  List<Item> *inserted_columns,
190  bool manage_defaults,
191  enum_duplicates duplicate_handling,
192  bool ignore_errors) :
193  m_optype(optype),
194  m_changed_columns(inserted_columns),
195  m_changed_columns2(NULL),
196  m_manage_defaults(manage_defaults),
197  m_function_default_columns(NULL),
198  handle_duplicates(duplicate_handling),
199  ignore(ignore_errors),
200  stats(),
201  escape_char(0),
202  last_errno(0),
203  update_values(NULL)
204  {
205  DBUG_ASSERT(optype == INSERT_OPERATION);
206  }
207 
231  COPY_INFO(operation_type optype,
232  List<Item> *inserted_columns,
233  List<Item> *inserted_columns2,
234  bool manage_defaults,
235  enum_duplicates duplicates_handling,
236  bool ignore_duplicates,
237  int escape_character) :
238  m_optype(optype),
239  m_changed_columns(inserted_columns),
240  m_changed_columns2(inserted_columns2),
241  m_manage_defaults(manage_defaults),
242  m_function_default_columns(NULL),
243  handle_duplicates(duplicates_handling),
244  ignore(ignore_duplicates),
245  stats(),
246  escape_char(escape_character),
247  last_errno(0),
248  update_values(NULL)
249  {
250  DBUG_ASSERT(optype == INSERT_OPERATION);
251  }
252 
262  COPY_INFO(operation_type optype, List<Item> *fields, List<Item> *values) :
263  m_optype(optype),
264  m_changed_columns(fields),
265  m_changed_columns2(NULL),
266  m_manage_defaults(true),
267  m_function_default_columns(NULL),
268  handle_duplicates(DUP_ERROR),
269  ignore(false),
270  stats(),
271  escape_char(0),
272  last_errno(0),
273  update_values(values)
274  {
275  DBUG_ASSERT(optype == UPDATE_OPERATION);
276  }
277 
278  operation_type get_operation_type() const { return m_optype; }
279 
280  List<Item> *get_changed_columns() const { return m_changed_columns; }
281 
282  const List<Item> *get_changed_columns2() const { return m_changed_columns2; }
283 
284  bool get_manage_defaults() const { return m_manage_defaults; }
285 
286  enum_duplicates get_duplicate_handling() const { return handle_duplicates; }
287 
288  bool get_ignore_errors() const { return ignore; }
289 
303  virtual void set_function_defaults(TABLE *table);
304 
317  {
318  if (get_function_default_columns(table))
319  return true;
320  bitmap_union(columns, m_function_default_columns);
321  return false;
322  }
323 
332  {
333  DBUG_ASSERT(m_function_default_columns != NULL);
334  return !bitmap_is_clear_all(m_function_default_columns);
335  }
336 
342  {
343  DBUG_ASSERT(m_function_default_columns != NULL);
344  return bitmap_is_overlapping(m_function_default_columns, map);
345  }
346 
352  bool ignore_last_columns(TABLE *table, uint count);
353 
358  virtual ~COPY_INFO() {}
359 };
360 
361 
362 #endif // SQL_DATA_CHANGE_INCLUDED