MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_setup_timers.cc
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
21 #include "my_global.h"
22 #include "my_pthread.h"
23 #include "table_setup_timers.h"
24 #include "pfs_column_values.h"
25 #include "pfs_timer.h"
26 
27 #define COUNT_SETUP_TIMERS 4
28 
29 static row_setup_timers all_setup_timers_data[COUNT_SETUP_TIMERS]=
30 {
31  {
32  { C_STRING_WITH_LEN("idle") },
33  &idle_timer
34  },
35  {
36  { C_STRING_WITH_LEN("wait") },
37  &wait_timer
38  },
39  {
40  { C_STRING_WITH_LEN("stage") },
42  },
43  {
44  { C_STRING_WITH_LEN("statement") },
46  }
47 };
48 
49 THR_LOCK table_setup_timers::m_table_lock;
50 
51 static const TABLE_FIELD_TYPE field_types[]=
52 {
53  {
54  { C_STRING_WITH_LEN("NAME") },
55  { C_STRING_WITH_LEN("varchar(64)") },
56  { NULL, 0}
57  },
58  {
59  { C_STRING_WITH_LEN("TIMER_NAME") },
60  { C_STRING_WITH_LEN("enum(\'CYCLE\',\'NANOSECOND\',\'MICROSECOND\',"
61  "\'MILLISECOND\',\'TICK\')") },
62  { NULL, 0}
63  }
64 };
65 
67 table_setup_timers::m_field_def=
68 { 2, field_types };
69 
72 {
73  { C_STRING_WITH_LEN("setup_timers") },
75  &table_setup_timers::create,
76  NULL, /* write_row */
77  NULL, /* delete_all_rows */
78  NULL, /* get_row_count */
79  COUNT_SETUP_TIMERS,
80  sizeof(PFS_simple_index),
81  &m_table_lock,
82  &m_field_def,
83  false /* checked */
84 };
85 
86 PFS_engine_table* table_setup_timers::create(void)
87 {
88  return new table_setup_timers();
89 }
90 
91 table_setup_timers::table_setup_timers()
92  : PFS_engine_table(&m_share, &m_pos),
93  m_row(NULL), m_pos(0), m_next_pos(0)
94 {}
95 
97 {
98  m_pos.m_index= 0;
99  m_next_pos.m_index= 0;
100 }
101 
103 {
104  int result;
105 
106  m_pos.set_at(&m_next_pos);
107 
108  if (m_pos.m_index < COUNT_SETUP_TIMERS)
109  {
110  m_row= &all_setup_timers_data[m_pos.m_index];
111  m_next_pos.set_after(&m_pos);
112  result= 0;
113  }
114  else
115  {
116  m_row= NULL;
117  result= HA_ERR_END_OF_FILE;
118  }
119 
120  return result;
121 }
122 
123 int table_setup_timers::rnd_pos(const void *pos)
124 {
125  set_position(pos);
126  DBUG_ASSERT(m_pos.m_index < COUNT_SETUP_TIMERS);
127  m_row= &all_setup_timers_data[m_pos.m_index];
128  return 0;
129 }
130 
132  unsigned char *,
133  Field **fields,
134  bool read_all)
135 {
136  Field *f;
137 
138  DBUG_ASSERT(m_row);
139 
140  /* Set the null bits */
141  DBUG_ASSERT(table->s->null_bytes == 0);
142 
143  for (; (f= *fields) ; fields++)
144  {
145  if (read_all || bitmap_is_set(table->read_set, f->field_index))
146  {
147  switch(f->field_index)
148  {
149  case 0: /* NAME */
150  set_field_varchar_utf8(f, m_row->m_name.str, m_row->m_name.length);
151  break;
152  case 1: /* TIMER_NAME */
153  set_field_enum(f, *(m_row->m_timer_name_ptr));
154  break;
155  default:
156  DBUG_ASSERT(false);
157  }
158  }
159  }
160 
161  return 0;
162 }
163 
165  const unsigned char *,
166  unsigned char *,
167  Field **fields)
168 {
169  Field *f;
170  longlong value;
171 
172  DBUG_ASSERT(m_row);
173 
174  for (; (f= *fields) ; fields++)
175  {
176  if (bitmap_is_set(table->write_set, f->field_index))
177  {
178  switch(f->field_index)
179  {
180  case 0: /* NAME */
181  return HA_ERR_WRONG_COMMAND;
182  case 1: /* TIMER_NAME */
183  value= get_field_enum(f);
184  if ((value >= FIRST_TIMER_NAME) && (value <= LAST_TIMER_NAME))
185  *(m_row->m_timer_name_ptr)= (enum_timer_name) value;
186  else
187  return HA_ERR_WRONG_COMMAND;
188  break;
189  default:
190  DBUG_ASSERT(false);
191  }
192  }
193  }
194 
195  return 0;
196 }
197