92
Translate a cursor name to a table name (WL #1324).
95
filename_to_tablename()
98
to_length The size of the table name buffer.
103
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length)
107
if (!memcmp(from, TMP_FILE_PREFIX, TMP_FILE_PREFIX_LENGTH))
109
/* Temporary table name. */
110
length= strlen(strncpy(to, from, to_length));
114
for (; *from && length < to_length; length++, from++)
121
/* We've found an escaped char - skip the @ */
124
/* There will be a two-position hex-char version of the char */
125
for (int x=1; x >= 0; x--)
127
if (*from >= '0' && *from <= '9')
128
to[length] += ((*from++ - '0') << (4 * x));
129
else if (*from >= 'a' && *from <= 'f')
130
to[length] += ((*from++ - 'a' + 10) << (4 * x));
132
/* Backup because we advanced extra in the inner loop */
142
Translate a table name to a cursor name (WL #1324).
145
tablename_to_filename()
147
to OUT The cursor name
148
to_length The size of the cursor name buffer.
151
true if errors happen. false on success.
153
bool tablename_to_filename(const char *from, char *to, size_t to_length)
157
for (; *from && length < to_length; length++, from++)
159
if ((*from >= '0' && *from <= '9') ||
160
(*from >= 'A' && *from <= 'Z') ||
161
(*from >= 'a' && *from <= 'z') ||
162
/* OSX defines an extra set of high-bit and multi-byte characters
163
that cannot be used on the filesystem. Instead of trying to sort
164
those out, we'll just escape encode all high-bit-set chars on OSX.
165
It won't really hurt anything - it'll just make some filenames ugly. */
166
#if !defined(TARGET_OS_OSX)
167
((unsigned char)*from >= 128) ||
177
if (length + 3 >= to_length)
180
/* We need to escape this char in a way that can be reversed */
182
to[length++]= hexchars[(*from >> 4) & 15];
183
to[length]= hexchars[(*from) & 15];
186
if (internal::check_if_legal_tablename(to) &&
187
length + 4 < to_length)
189
memcpy(to + length, "@@@", 4);
197
Creates path to a cursor: drizzle_data_dir/db/table.ext
200
build_table_filename()
201
buff Where to write result
202
This may be the same as table_name.
205
table_name Table name
207
flags FN_FROM_IS_TMP or FN_TO_IS_TMP
208
table_name is temporary, do not change.
212
Uses database and table name, and extension to create
213
a cursor name in drizzle_data_dir. Database and table
214
names are converted from system_charset_info into "fscs".
215
Unless flags indicate a temporary table name.
216
'db' is always converted.
217
'ext' is not converted.
219
The conversion suppression is required for ALTER Table. This
220
statement creates intermediate tables. These are regular
221
(non-temporary) tables with a temporary name. Their path names must
222
be derivable from the table name. So we cannot use
223
build_tmptable_filename() for them.
226
path length on success, 0 on failure
229
size_t build_table_filename(char *buff, size_t bufflen, const char *db, const char *table_name, bool is_tmp)
231
char dbbuff[FN_REFLEN];
232
char tbbuff[FN_REFLEN];
233
bool conversion_error= false;
235
memset(tbbuff, 0, sizeof(tbbuff));
236
if (is_tmp) // FN_FROM_IS_TMP | FN_TO_IS_TMP
237
strncpy(tbbuff, table_name, sizeof(tbbuff));
240
conversion_error= tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
241
if (conversion_error)
243
errmsg_printf(ERRMSG_LVL_ERROR,
244
_("Table name cannot be encoded and fit within filesystem "
245
"name length restrictions."));
249
memset(dbbuff, 0, sizeof(dbbuff));
250
conversion_error= tablename_to_filename(db, dbbuff, sizeof(dbbuff));
251
if (conversion_error)
253
errmsg_printf(ERRMSG_LVL_ERROR,
254
_("Schema name cannot be encoded and fit within filesystem "
255
"name length restrictions."));
260
int rootdir_len= strlen(FN_ROOTDIR);
261
string table_path(drizzle_data_home);
262
int without_rootdir= table_path.length()-rootdir_len;
264
/* Don't add FN_ROOTDIR if dirzzle_data_home already includes it */
265
if (without_rootdir >= 0)
267
const char *tmp= table_path.c_str()+without_rootdir;
268
if (memcmp(tmp, FN_ROOTDIR, rootdir_len) != 0)
269
table_path.append(FN_ROOTDIR);
272
table_path.append(dbbuff);
273
table_path.append(FN_ROOTDIR);
274
table_path.append(tbbuff);
276
if (bufflen < table_path.length())
279
strcpy(buff, table_path.c_str());
281
return table_path.length();
286
Creates path to a cursor: drizzle_tmpdir/#sql1234_12_1.ext
289
build_tmptable_filename()
290
session The thread handle.
291
buff Where to write result
296
Uses current_pid, thread_id, and tmp_table counter to create
297
a cursor name in drizzle_tmpdir.
300
path length on success, 0 on failure
303
size_t build_tmptable_filename(char *buff, size_t bufflen)
306
ostringstream path_str, post_tmpdir_str;
309
Session *session= current_session;
311
path_str << drizzle_tmpdir;
312
post_tmpdir_str << "/" << TMP_FILE_PREFIX << current_pid;
313
post_tmpdir_str << session->thread_id << session->tmp_table++;
314
tmp= post_tmpdir_str.str();
316
transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
320
if (bufflen < path_str.str().length())
323
length= internal::unpack_filename(buff, path_str.str().c_str());
331
93
session Thread object