1415
by Brian Aker
Mass overhaul to use schema_identifier. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2009 Sun Microsystems, Inc.
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
#include "config.h" |
|
22 |
||
23 |
#include <assert.h> |
|
24 |
||
1660.1.1
by Brian Aker
Merge in move identifier work. |
25 |
#include "drizzled/identifier.h" |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
26 |
#include "drizzled/session.h" |
27 |
#include "drizzled/current_session.h" |
|
28 |
#include "drizzled/internal/my_sys.h" |
|
29 |
||
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
30 |
#include "drizzled/util/tablename_to_filename.h" |
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
31 |
#include "drizzled/util/backtrace.h" |
32 |
||
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
33 |
#include <algorithm> |
34 |
#include <sstream> |
|
35 |
#include <cstdio> |
|
36 |
||
1685.2.11
by Brian Aker
First pass around removing need for lower case version of DB in the |
37 |
#include <boost/algorithm/string/compare.hpp> |
38 |
||
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
39 |
using namespace std; |
40 |
||
41 |
namespace drizzled |
|
42 |
{
|
|
43 |
||
1627.2.4
by Monty Taylor
Fixed the valgrind error that crept in in schema_identifier. Score one for std:string over char*. |
44 |
extern string drizzle_tmpdir; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
45 |
extern pid_t current_pid; |
46 |
||
1627.2.4
by Monty Taylor
Fixed the valgrind error that crept in in schema_identifier. Score one for std:string over char*. |
47 |
static size_t build_schema_filename(string &path, const string &db) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
48 |
{
|
1864.3.10
by Brian Aker
Restore so that local is not added to schema for path. |
49 |
path.append(""); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
50 |
bool conversion_error= false; |
51 |
||
1904.1.1
by Brian Aker
Merge in change to have just a single function for both |
52 |
conversion_error= util::tablename_to_filename(db, path); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
53 |
if (conversion_error) |
54 |
{
|
|
55 |
errmsg_printf(ERRMSG_LVL_ERROR, |
|
56 |
_("Schema name cannot be encoded and fit within filesystem " |
|
57 |
"name length restrictions.")); |
|
58 |
return 0; |
|
59 |
}
|
|
60 |
||
61 |
return path.length(); |
|
62 |
}
|
|
63 |
||
1613
by Brian Aker
Fix solaris warning. |
64 |
SchemaIdentifier::SchemaIdentifier(const std::string &db_arg) : |
65 |
db(db_arg), |
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
66 |
db_path(""), |
67 |
catalog("LOCAL") |
|
1613
by Brian Aker
Fix solaris warning. |
68 |
{
|
1861.5.1
by Brian Aker
This just fixes our current catalog to be displayed properly. |
69 |
#if 0
|
70 |
string::size_type lastPos= db.find_first_of('/', 0);
|
|
71 |
||
72 |
if (lastPos != std::string::npos)
|
|
73 |
{
|
|
74 |
catalog= db.substr(0, lastPos);
|
|
75 |
db.erase(0, lastPos + 1);
|
|
76 |
}
|
|
77 |
#endif
|
|
78 |
||
1685.2.12
by Brian Aker
This fixes the lower casing of names from Schema even when we should not. |
79 |
if (not db_arg.empty()) |
1613
by Brian Aker
Fix solaris warning. |
80 |
{
|
1685.2.12
by Brian Aker
This fixes the lower casing of names from Schema even when we should not. |
81 |
drizzled::build_schema_filename(db_path, db); |
1613
by Brian Aker
Fix solaris warning. |
82 |
assert(db_path.length()); // TODO throw exception, this is a possibility |
83 |
}
|
|
84 |
}
|
|
85 |
||
1954.2.1
by Brian Aker
getSQLPath() modified to take a string so that we can const the table |
86 |
void SchemaIdentifier::getSQLPath(std::string &arg) const |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
87 |
{
|
1954.2.1
by Brian Aker
getSQLPath() modified to take a string so that we can const the table |
88 |
arg.append(getSchemaName()); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
89 |
}
|
90 |
||
1613
by Brian Aker
Fix solaris warning. |
91 |
const std::string &SchemaIdentifier::getPath() const |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
92 |
{
|
93 |
return db_path; |
|
94 |
}
|
|
95 |
||
1685.2.11
by Brian Aker
First pass around removing need for lower case version of DB in the |
96 |
bool SchemaIdentifier::compare(const std::string &arg) const |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
97 |
{
|
1685.2.11
by Brian Aker
First pass around removing need for lower case version of DB in the |
98 |
return boost::iequals(arg, db); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
99 |
}
|
100 |
||
1992.4.1
by Brian Aker
Update code for testing identifiers/table/schema name correctness. |
101 |
bool SchemaIdentifier::compare(SchemaIdentifier::const_reference arg) const |
102 |
{
|
|
103 |
return boost::iequals(arg.getSchemaName(), db); |
|
104 |
}
|
|
105 |
||
1613
by Brian Aker
Fix solaris warning. |
106 |
bool SchemaIdentifier::isValid() const |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
107 |
{
|
1992.4.1
by Brian Aker
Update code for testing identifiers/table/schema name correctness. |
108 |
bool error= false; |
109 |
||
110 |
do
|
|
111 |
{
|
|
112 |
if (db.empty()) |
|
113 |
{
|
|
114 |
error= true; |
|
115 |
break; |
|
116 |
}
|
|
117 |
||
118 |
if (db.size() > NAME_LEN) |
|
119 |
{
|
|
120 |
error= true; |
|
121 |
break; |
|
122 |
}
|
|
123 |
||
124 |
if (db.at(db.length() -1) == ' ') |
|
125 |
{
|
|
126 |
error= true; |
|
127 |
break; |
|
128 |
}
|
|
129 |
||
130 |
if (db.at(0) == '.') |
|
131 |
{
|
|
132 |
error= true; |
|
133 |
break; |
|
134 |
}
|
|
135 |
||
136 |
{
|
|
137 |
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci; |
|
138 |
||
139 |
int well_formed_error; |
|
140 |
uint32_t res= cs->cset->well_formed_len(cs, db.c_str(), db.c_str() + db.length(), |
|
141 |
NAME_CHAR_LEN, &well_formed_error); |
|
142 |
if (well_formed_error or db.length() != res) |
|
143 |
{
|
|
144 |
error= true; |
|
145 |
break; |
|
146 |
}
|
|
147 |
}
|
|
148 |
} while (0); |
|
149 |
||
150 |
if (error) |
|
151 |
{
|
|
152 |
std::string name; |
|
153 |
||
154 |
getSQLPath(name); |
|
155 |
my_error(ER_WRONG_DB_NAME, MYF(0), name.c_str()); |
|
156 |
||
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
157 |
return false; |
158 |
}
|
|
159 |
||
160 |
return true; |
|
161 |
}
|
|
162 |
||
163 |
} /* namespace drizzled */ |