MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rpl_gtid_specification.cc
1 /* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or
4  modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation; version 2 of the
6  License.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16  02110-1301 USA */
17 
18 #include "rpl_gtid.h"
19 
20 #ifndef MYSQL_CLIENT
21 #include "mysqld.h"
22 #endif
23 
24 //const int Gtid_specification::MAX_TEXT_LENGTH;
25 
26 
27 #ifndef MYSQL_CLIENT
28 
29 enum_return_status Gtid_specification::parse(Sid_map *sid_map, const char *text)
30 {
31  DBUG_ENTER("Gtid_specification::parse");
32  DBUG_ASSERT(text != NULL);
33  if (my_strcasecmp(&my_charset_latin1, text, "AUTOMATIC") == 0)
34  {
35  type= AUTOMATIC_GROUP;
36  gtid.sidno= 0;
37  gtid.gno= 0;
38  }
39  else if (my_strcasecmp(&my_charset_latin1, text, "ANONYMOUS") == 0)
40  {
41  type= ANONYMOUS_GROUP;
42  gtid.sidno= 0;
43  gtid.gno= 0;
44  }
45  else
46  {
47  PROPAGATE_REPORTED_ERROR(gtid.parse(sid_map, text));
48  type= GTID_GROUP;
49  }
50  RETURN_OK;
51 };
52 
53 
54 enum_group_type Gtid_specification::get_type(const char *text)
55 {
56  DBUG_ENTER("Gtid_specification::get_type");
57  DBUG_ASSERT(text != NULL);
58  if (my_strcasecmp(&my_charset_latin1, text, "AUTOMATIC") == 0)
59  DBUG_RETURN(AUTOMATIC_GROUP);
60  else if (my_strcasecmp(&my_charset_latin1, text, "ANONYMOUS") == 0)
61  DBUG_RETURN(ANONYMOUS_GROUP);
62  else
63  DBUG_RETURN(Gtid::is_valid(text) ? GTID_GROUP : INVALID_GROUP);
64 }
65 
66 #endif // ifndef MYSQL_CLIENT
67 
68 
69 int Gtid_specification::to_string(const rpl_sid *sid, char *buf) const
70 {
71  DBUG_ENTER("Gtid_specification::to_string(char*)");
72  switch (type)
73  {
74  case AUTOMATIC_GROUP:
75  strcpy(buf, "AUTOMATIC");
76  DBUG_RETURN(9);
77  case ANONYMOUS_GROUP:
78  strcpy(buf, "ANONYMOUS");
79  DBUG_RETURN(9);
80  /*
81  UNDEFINED_GROUP must be printed like GTID_GROUP because of
82  SELECT @@SESSION.GTID_NEXT.
83  */
84  case UNDEFINED_GROUP:
85  case GTID_GROUP:
86  DBUG_RETURN(gtid.to_string(*sid, buf));
87  case INVALID_GROUP:
88  DBUG_ASSERT(0);
89  }
90  DBUG_ASSERT(0);
91  DBUG_RETURN(0);
92 }
93 
94 
95 int Gtid_specification::to_string(const Sid_map *sid_map, char *buf) const
96 {
97  return to_string(type == GTID_GROUP || type == UNDEFINED_GROUP ?
98  &sid_map->sidno_to_sid(gtid.sidno) : NULL,
99  buf);
100 }