1 /*
2 Copyright (c) 2020, MariaDB Corporation.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU 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 02110-1335 USA */
16
17 #include "mariadb.h"
18 #include "sql_type.h"
19 #include "sql_schema.h"
20 #include "sql_class.h"
21
22 class Schema_oracle: public Schema
23 {
24 public:
Schema_oracle(const LEX_CSTRING & name)25 Schema_oracle(const LEX_CSTRING &name)
26 :Schema(name)
27 { }
map_data_type(THD * thd,const Type_handler * src) const28 const Type_handler *map_data_type(THD *thd, const Type_handler *src)
29 const
30 {
31 if (src == &type_handler_newdate)
32 return thd->type_handler_for_datetime();
33 return src;
34 }
35 };
36
37
38 class Schema_maxdb: public Schema
39 {
40 public:
Schema_maxdb(const LEX_CSTRING & name)41 Schema_maxdb(const LEX_CSTRING &name)
42 :Schema(name)
43 { }
map_data_type(THD * thd,const Type_handler * src) const44 const Type_handler *map_data_type(THD *thd, const Type_handler *src)
45 const
46 {
47 if (src == &type_handler_timestamp ||
48 src == &type_handler_timestamp2)
49 return thd->type_handler_for_datetime();
50 return src;
51 }
52 };
53
54
55 Schema mariadb_schema(Lex_cstring(STRING_WITH_LEN("mariadb_schema")));
56 Schema_oracle oracle_schema(Lex_cstring(STRING_WITH_LEN("oracle_schema")));
57 Schema_maxdb maxdb_schema(Lex_cstring(STRING_WITH_LEN("maxdb_schema")));
58
59
find_by_name(const LEX_CSTRING & name)60 Schema *Schema::find_by_name(const LEX_CSTRING &name)
61 {
62 DBUG_ASSERT(name.str);
63 if (mariadb_schema.eq_name(name))
64 return &mariadb_schema;
65 if (oracle_schema.eq_name(name))
66 return &oracle_schema;
67 if (maxdb_schema.eq_name(name))
68 return &maxdb_schema;
69 return NULL;
70 }
71
72
find_implied(THD * thd)73 Schema *Schema::find_implied(THD *thd)
74 {
75 if (thd->variables.sql_mode & MODE_ORACLE)
76 return &oracle_schema;
77 if (thd->variables.sql_mode & MODE_MAXDB)
78 return &maxdb_schema;
79 return &mariadb_schema;
80 }
81