summaryrefslogtreecommitdiff
path: root/sql/sql_partition.cc
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2013-06-27 14:01:03 +0300
committerMichael Widenius <monty@askmonty.org>2013-06-27 14:01:03 +0300
commit94d722b6a43b86ee760f07915921cf58f9869a5d (patch)
tree9e750187a900b393c5cb3139c306f16c2cf07fca /sql/sql_partition.cc
parente7606294b2bbd70be118cc81c5818dc643a770bf (diff)
downloadmariadb-git-94d722b6a43b86ee760f07915921cf58f9869a5d.tar.gz
ha_partition.cc and ha_partition.h are now completely merged
Added sql_mode_t to simplify merges
Diffstat (limited to 'sql/sql_partition.cc')
-rw-r--r--sql/sql_partition.cc79
1 files changed, 75 insertions, 4 deletions
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc
index bb94e2392c5..05ce5bdb4ce 100644
--- a/sql/sql_partition.cc
+++ b/sql/sql_partition.cc
@@ -1995,6 +1995,79 @@ static int add_quoted_string(File fptr, const char *quotestr)
return err + add_string(fptr, "'");
}
+/**
+ @brief Truncate the partition file name from a path it it exists.
+
+ @note A partition file name will contian one or more '#' characters.
+One of the occurances of '#' will be either "#P#" or "#p#" depending
+on whether the storage engine has converted the filename to lower case.
+*/
+void truncate_partition_filename(char *path)
+{
+ if (path)
+ {
+ char* last_slash= strrchr(path, FN_LIBCHAR);
+
+ if (!last_slash)
+ last_slash= strrchr(path, FN_LIBCHAR2);
+
+ if (last_slash)
+ {
+ /* Look for a partition-type filename */
+ for (char* pound= strchr(last_slash, '#');
+ pound; pound = strchr(pound + 1, '#'))
+ {
+ if ((pound[1] == 'P' || pound[1] == 'p') && pound[2] == '#')
+ {
+ last_slash[0] = '\0'; /* truncate the file name */
+ break;
+ }
+ }
+ }
+ }
+}
+
+
+/**
+ @brief Output a filepath. Similar to add_keyword_string except it
+ also converts \ to / on Windows and skips the partition file name at
+ the end if found.
+
+ @note
+
+ When Mysql sends a DATA DIRECTORY from SQL for partitions it does
+ not use a file name, but it does for DATA DIRECTORY on a non-partitioned
+ table. So when the storage engine is asked for the DATA DIRECTORY string
+ after a restart through Handler::update_create_options(), the storage
+ engine may include the filename.
+*/
+
+static int add_keyword_path(File fptr, const char *keyword,
+ const char *path)
+{
+ char temp_path[FN_REFLEN];
+ int err= add_string(fptr, keyword);
+
+ err+= add_space(fptr);
+ err+= add_equal(fptr);
+ err+= add_space(fptr);
+
+ strmake(temp_path, path, sizeof(temp_path)-1);
+ /* Convert \ to / to be able to create table on unix */
+ to_unix_path(temp_path);
+
+ /*
+ If the partition file name with its "#P#" identifier
+ is found after the last slash, truncate that filename.
+ */
+ truncate_partition_filename(temp_path);
+
+ err+= add_quoted_string(fptr, temp_path);
+
+ return err + add_space(fptr);
+}
+
+
static int add_keyword_string(File fptr, const char *keyword,
bool should_use_quotes,
const char *keystr)
@@ -2047,11 +2120,9 @@ static int add_partition_options(File fptr, partition_element *p_elem)
if (!(current_thd->variables.sql_mode & MODE_NO_DIR_IN_CREATE))
{
if (p_elem->data_file_name)
- err+= add_keyword_string(fptr, "DATA DIRECTORY", TRUE,
- p_elem->data_file_name);
+ err+= add_keyword_path(fptr, "DATA DIRECTORY", p_elem->data_file_name);
if (p_elem->index_file_name)
- err+= add_keyword_string(fptr, "INDEX DIRECTORY", TRUE,
- p_elem->index_file_name);
+ err+= add_keyword_path(fptr, "INDEX DIRECTORY", p_elem->index_file_name);
}
if (p_elem->part_comment)
err+= add_keyword_string(fptr, "COMMENT", TRUE, p_elem->part_comment);