summaryrefslogtreecommitdiff
path: root/sql/parse_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/parse_file.cc')
-rw-r--r--sql/parse_file.cc395
1 files changed, 199 insertions, 196 deletions
diff --git a/sql/parse_file.cc b/sql/parse_file.cc
index 03e0d25b885..f2dbeba1bbf 100644
--- a/sql/parse_file.cc
+++ b/sql/parse_file.cc
@@ -13,7 +13,12 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-// Text .frm files management routines
+/**
+ @file
+
+ @brief
+ Text .frm files management routines
+*/
#include "mysql_priv.h"
#include <errno.h>
@@ -25,17 +30,16 @@
extern long mysql_rm_arc_files(THD *thd, MY_DIR *dirp, const char *org_path);
-/*
- write string with escaping
+/**
+ Write string with escaping.
- SYNOPSIS
- write_escaped_string()
- file - IO_CACHE for record
- val_s - string for writing
+ @param file IO_CACHE for record
+ @param val_s string for writing
- RETURN
- FALSE - OK
- TRUE - error
+ @retval
+ FALSE OK
+ @retval
+ TRUE error
*/
static my_bool
@@ -52,27 +56,27 @@ write_escaped_string(IO_CACHE *file, LEX_STRING *val_s)
*/
switch(*ptr) {
case '\\': // escape character
- if (my_b_append(file, (const byte *)STRING_WITH_LEN("\\\\")))
+ if (my_b_append(file, (const uchar *)STRING_WITH_LEN("\\\\")))
return TRUE;
break;
case '\n': // parameter value delimiter
- if (my_b_append(file, (const byte *)STRING_WITH_LEN("\\n")))
+ if (my_b_append(file, (const uchar *)STRING_WITH_LEN("\\n")))
return TRUE;
break;
case '\0': // problem for some string processing utilities
- if (my_b_append(file, (const byte *)STRING_WITH_LEN("\\0")))
+ if (my_b_append(file, (const uchar *)STRING_WITH_LEN("\\0")))
return TRUE;
break;
case 26: // problem for windows utilities (Ctrl-Z)
- if (my_b_append(file, (const byte *)STRING_WITH_LEN("\\z")))
+ if (my_b_append(file, (const uchar *)STRING_WITH_LEN("\\z")))
return TRUE;
break;
case '\'': // list of string delimiter
- if (my_b_append(file, (const byte *)STRING_WITH_LEN("\\\'")))
+ if (my_b_append(file, (const uchar *)STRING_WITH_LEN("\\\'")))
return TRUE;
break;
default:
- if (my_b_append(file, (const byte *)ptr, 1))
+ if (my_b_append(file, (const uchar *)ptr, 1))
return TRUE;
}
}
@@ -80,22 +84,22 @@ write_escaped_string(IO_CACHE *file, LEX_STRING *val_s)
}
-/*
- write parameter value to IO_CACHE
+/**
+ Write parameter value to IO_CACHE.
- SYNOPSIS
- write_parameter()
- file pointer to IO_CACHE structure for writing
- base pointer to data structure
- parameter pointer to parameter descriptor
+ @param file pointer to IO_CACHE structure for writing
+ @param base pointer to data structure
+ @param parameter pointer to parameter descriptor
- RETURN
- FALSE - OK
- TRUE - error
+ @retval
+ FALSE OK
+ @retval
+ TRUE error
*/
+
static my_bool
-write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
+write_parameter(IO_CACHE *file, uchar* base, File_option *parameter)
{
char num_buf[20]; // buffer for numeric operations
// string for numeric operations
@@ -106,7 +110,7 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
case FILE_OPTIONS_STRING:
{
LEX_STRING *val_s= (LEX_STRING *)(base + parameter->offset);
- if (my_b_append(file, (const byte *)val_s->str, val_s->length))
+ if (my_b_append(file, (const uchar *)val_s->str, val_s->length))
DBUG_RETURN(TRUE);
break;
}
@@ -119,7 +123,7 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
case FILE_OPTIONS_ULONGLONG:
{
num.set(*((ulonglong *)(base + parameter->offset)), &my_charset_bin);
- if (my_b_append(file, (const byte *)num.ptr(), num.length()))
+ if (my_b_append(file, (const uchar *)num.ptr(), num.length()))
DBUG_RETURN(TRUE);
break;
}
@@ -127,12 +131,12 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
{
/* string have to be allocated already */
LEX_STRING *val_s= (LEX_STRING *)(base + parameter->offset);
- time_t tm= time(NULL);
+ time_t tm= my_time(0);
get_date(val_s->str, GETDATE_DATE_TIME|GETDATE_GMT|GETDATE_FIXEDLENGTH,
tm);
val_s->length= PARSE_FILE_TIMESTAMPLENGTH;
- if (my_b_append(file, (const byte *)val_s->str,
+ if (my_b_append(file, (const uchar *)val_s->str,
PARSE_FILE_TIMESTAMPLENGTH))
DBUG_RETURN(TRUE);
break;
@@ -146,10 +150,10 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
while ((str= it++))
{
// We need ' ' after string to detect list continuation
- if ((!first && my_b_append(file, (const byte *)STRING_WITH_LEN(" "))) ||
- my_b_append(file, (const byte *)STRING_WITH_LEN("\'")) ||
+ if ((!first && my_b_append(file, (const uchar *)STRING_WITH_LEN(" "))) ||
+ my_b_append(file, (const uchar *)STRING_WITH_LEN("\'")) ||
write_escaped_string(file, str) ||
- my_b_append(file, (const byte *)STRING_WITH_LEN("\'")))
+ my_b_append(file, (const uchar *)STRING_WITH_LEN("\'")))
{
DBUG_RETURN(TRUE);
}
@@ -167,8 +171,8 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
{
num.set(*val, &my_charset_bin);
// We need ' ' after string to detect list continuation
- if ((!first && my_b_append(file, (const byte *)STRING_WITH_LEN(" "))) ||
- my_b_append(file, (const byte *)num.ptr(), num.length()))
+ if ((!first && my_b_append(file, (const uchar *)STRING_WITH_LEN(" "))) ||
+ my_b_append(file, (const uchar *)num.ptr(), num.length()))
{
DBUG_RETURN(TRUE);
}
@@ -183,27 +187,27 @@ write_parameter(IO_CACHE *file, gptr base, File_option *parameter)
}
-/*
- write new .frm
+/**
+ Write new .frm.
- SYNOPSIS
- sql_create_definition_file()
- dir directory where put .frm
- file .frm file name
- type .frm type string (VIEW, TABLE)
- base base address for parameter reading (structure like
- TABLE)
- parameters parameters description
+ @param dir directory where put .frm
+ @param file_name .frm file name
+ @param type .frm type string (VIEW, TABLE)
+ @param base base address for parameter reading (structure like
+ TABLE)
+ @param parameters parameters description
- RETURN
- FALSE - OK
- TRUE - error
+ @retval
+ FALSE OK
+ @retval
+ TRUE error
*/
+
my_bool
sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
const LEX_STRING *type,
- gptr base, File_option *parameters)
+ uchar* base, File_option *parameters)
{
File handler;
IO_CACHE file;
@@ -212,10 +216,23 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
File_option *param;
DBUG_ENTER("sql_create_definition_file");
DBUG_PRINT("enter", ("Dir: %s, file: %s, base 0x%lx",
- dir->str, file_name->str, (ulong) base));
+ dir ? dir->str : "(null)",
+ file_name->str, (ulong) base));
- fn_format(path, file_name->str, dir->str, 0, MY_UNPACK_FILENAME);
- path_end= (uint) strlen(path);
+ if (dir)
+ {
+ fn_format(path, file_name->str, dir->str, "", MY_UNPACK_FILENAME);
+ path_end= strlen(path);
+ }
+ else
+ {
+ /*
+ if not dir is passed, it means file_name is a full path,
+ including dir name, file name itself, and an extension,
+ and with unpack_filename() executed over it.
+ */
+ path_end= strxnmov(path, FN_REFLEN, file_name->str, NullS) - path;
+ }
// temporary file name
path[path_end]='~';
@@ -230,19 +247,19 @@ sql_create_definition_file(const LEX_STRING *dir, const LEX_STRING *file_name,
goto err_w_file;
// write header (file signature)
- if (my_b_append(&file, (const byte *)STRING_WITH_LEN("TYPE=")) ||
- my_b_append(&file, (const byte *)type->str, type->length) ||
- my_b_append(&file, (const byte *)STRING_WITH_LEN("\n")))
+ if (my_b_append(&file, (const uchar *)STRING_WITH_LEN("TYPE=")) ||
+ my_b_append(&file, (const uchar *)type->str, type->length) ||
+ my_b_append(&file, (const uchar *)STRING_WITH_LEN("\n")))
goto err_w_file;
// write parameters to temporary file
for (param= parameters; param->name.str; param++)
{
- if (my_b_append(&file, (const byte *)param->name.str,
+ if (my_b_append(&file, (const uchar *)param->name.str,
param->name.length) ||
- my_b_append(&file, (const byte *)STRING_WITH_LEN("=")) ||
+ my_b_append(&file, (const uchar *)STRING_WITH_LEN("=")) ||
write_parameter(&file, base, param) ||
- my_b_append(&file, (const byte *)STRING_WITH_LEN("\n")))
+ my_b_append(&file, (const uchar *)STRING_WITH_LEN("\n")))
goto err_w_cache;
}
@@ -279,41 +296,36 @@ err_w_file:
DBUG_RETURN(TRUE);
}
-/*
- Renames a frm file (including backups) in same schema
+/**
+ Renames a frm file (including backups) in same schema.
- SYNOPSIS
- rename_in_schema_file
- thd thread handler
- schema name of given schema
- old_name original file name
- new_name new file name
-
- RETURN
- 0 - OK
- 1 - Error (only if renaming of frm failed)
+ @thd thread handler
+ @param schema name of given schema
+ @param old_name original file name
+ @param new_db new schema
+ @param new_name new file name
+ @retval
+ 0 OK
+ @retval
+ 1 Error (only if renaming of frm failed)
*/
my_bool rename_in_schema_file(THD *thd,
const char *schema, const char *old_name,
- const char *new_name)
+ const char *new_db, const char *new_name)
{
char old_path[FN_REFLEN], new_path[FN_REFLEN], arc_path[FN_REFLEN];
- strxnmov(old_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
- old_name, reg_ext, NullS);
- (void) unpack_filename(old_path, old_path);
-
- strxnmov(new_path, FN_REFLEN, mysql_data_home, "/", schema, "/",
- new_name, reg_ext, NullS);
- (void) unpack_filename(new_path, new_path);
+ build_table_filename(old_path, sizeof(old_path) - 1,
+ schema, old_name, reg_ext, 0);
+ build_table_filename(new_path, sizeof(new_path) - 1,
+ new_db, new_name, reg_ext, 0);
if (my_rename(old_path, new_path, MYF(MY_WME)))
return 1;
/* check if arc_dir exists: disabled unused feature (see bug #17823). */
- strxnmov(arc_path, FN_REFLEN, mysql_data_home, "/", schema, "/arc", NullS);
- (void) unpack_filename(arc_path, arc_path);
+ build_table_filename(arc_path, sizeof(arc_path) - 1, schema, "arc", "", 0);
{ // remove obsolete 'arc' directory and files if any
MY_DIR *new_dirp;
@@ -326,21 +338,20 @@ my_bool rename_in_schema_file(THD *thd,
return 0;
}
-/*
- Prepare frm to parse (read to memory)
+/**
+ Prepare frm to parse (read to memory).
- SYNOPSIS
- sql_parse_prepare()
- file_name - path & filename to .frm file
- mem_root - MEM_ROOT for buffer allocation
- bad_format_errors - send errors on bad content
+ @param file_name path & filename to .frm file
+ @param mem_root MEM_ROOT for buffer allocation
+ @param bad_format_errors send errors on bad content
- RETURN
+ @note
+ returned pointer + 1 will be type of .frm
+
+ @return
0 - error
+ @return
parser object
-
- NOTE
- returned pointer + 1 will be type of .frm
*/
File_parser *
@@ -348,11 +359,11 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root,
bool bad_format_errors)
{
MY_STAT stat_info;
- uint len;
+ size_t len;
char *end, *sign;
File_parser *parser;
File file;
- DBUG_ENTER("sql__parse_prepare");
+ DBUG_ENTER("sql_parse_prepare");
if (!my_stat(file_name->str, &stat_info, MYF(MY_WME)))
{
@@ -370,7 +381,7 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root,
DBUG_RETURN(0);
}
- if (!(parser->buff= alloc_root(mem_root, stat_info.st_size+1)))
+ if (!(parser->buff= (char*) alloc_root(mem_root, stat_info.st_size+1)))
{
DBUG_RETURN(0);
}
@@ -380,7 +391,7 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root,
DBUG_RETURN(0);
}
- if ((len= my_read(file, (byte *)parser->buff,
+ if ((len= my_read(file, (uchar *)parser->buff,
stat_info.st_size, MYF(MY_WME))) ==
MY_FILE_ERROR)
{
@@ -411,7 +422,7 @@ sql_parse_prepare(const LEX_STRING *file_name, MEM_ROOT *mem_root,
sign++;
if (*sign != '\n')
goto frm_error;
- parser->file_type.length= (uint) (sign - parser->file_type.str);
+ parser->file_type.length= sign - parser->file_type.str;
// EOS for file signature just for safety
*sign= '\0';
@@ -431,22 +442,22 @@ frm_error:
}
-/*
- parse LEX_STRING
+/**
+ parse LEX_STRING.
- SYNOPSIS
- parse_string()
- ptr - pointer on string beginning
- end - pointer on symbol after parsed string end (still owned
- by buffer and can be accessed
- mem_root - MEM_ROOT for parameter allocation
- str - pointer on string, where results should be stored
+ @param ptr pointer on string beginning
+ @param end pointer on symbol after parsed string end (still owned
+ by buffer and can be accessed
+ @param mem_root MEM_ROOT for parameter allocation
+ @param str pointer on string, where results should be stored
- RETURN
- 0 - error
- # - pointer on symbol after string
+ @retval
+ 0 error
+ @retval
+ \# pointer on symbol after string
*/
+
static char *
parse_string(char *ptr, char *end, MEM_ROOT *mem_root, LEX_STRING *str)
{
@@ -456,29 +467,25 @@ parse_string(char *ptr, char *end, MEM_ROOT *mem_root, LEX_STRING *str)
if (eol >= end)
return 0;
- str->length= (uint) (eol - ptr);
+ str->length= eol - ptr;
- if (!(str->str= alloc_root(mem_root, str->length+1)))
+ if (!(str->str= strmake_root(mem_root, ptr, str->length)))
return 0;
-
- memcpy(str->str, ptr, str->length);
- str->str[str->length]= '\0'; // just for safety
return eol+1;
}
-/*
- read escaped string from ptr to eol in already allocated str
+/**
+ read escaped string from ptr to eol in already allocated str.
- SYNOPSIS
- read_escaped_string()
- ptr - pointer on string beginning
- eol - pointer on character after end of string
- str - target string
+ @param ptr pointer on string beginning
+ @param eol pointer on character after end of string
+ @param str target string
- RETURN
- FALSE - OK
- TRUE - error
+ @retval
+ FALSE OK
+ @retval
+ TRUE error
*/
my_bool
@@ -521,34 +528,34 @@ read_escaped_string(char *ptr, char *eol, LEX_STRING *str)
else
*write_pos= c;
}
- str->str[str->length= (uint) (write_pos - str->str)]= '\0'; // just for safety
+ str->str[str->length= write_pos-str->str]= '\0'; // just for safety
return FALSE;
}
-/*
- parse \n delimited escaped string
+/**
+ parse \\n delimited escaped string.
- SYNOPSIS
- parse_escaped_string()
- ptr - pointer on string beginning
- end - pointer on symbol after parsed string end (still owned
- by buffer and can be accessed
- mem_root - MEM_ROOT for parameter allocation
- str - pointer on string, where results should be stored
+ @param ptr pointer on string beginning
+ @param end pointer on symbol after parsed string end (still owned
+ by buffer and can be accessed
+ @param mem_root MEM_ROOT for parameter allocation
+ @param str pointer on string, where results should be stored
- RETURN
- 0 - error
- # - pointer on symbol after string
+ @retval
+ 0 error
+ @retval
+ \# pointer on symbol after string
*/
+
char *
parse_escaped_string(char *ptr, char *end, MEM_ROOT *mem_root, LEX_STRING *str)
{
char *eol= strchr(ptr, '\n');
if (eol == 0 || eol >= end ||
- !(str->str= alloc_root(mem_root, (uint) ((eol - ptr) + 1))) ||
+ !(str->str= (char*) alloc_root(mem_root, (eol - ptr) + 1)) ||
read_escaped_string(ptr, eol, str))
return 0;
@@ -556,20 +563,19 @@ parse_escaped_string(char *ptr, char *end, MEM_ROOT *mem_root, LEX_STRING *str)
}
-/*
- parse '' delimited escaped string
+/**
+ parse '' delimited escaped string.
- SYNOPSIS
- parse_quoted_escaped_string()
- ptr - pointer on string beginning
- end - pointer on symbol after parsed string end (still owned
- by buffer and can be accessed
- mem_root - MEM_ROOT for parameter allocation
- str - pointer on string, where results should be stored
+ @param ptr pointer on string beginning
+ @param end pointer on symbol after parsed string end (still owned
+ by buffer and can be accessed
+ @param mem_root MEM_ROOT for parameter allocation
+ @param str pointer on string, where results should be stored
- RETURN
- 0 - error
- # - pointer on symbol after string
+ @retval
+ 0 error
+ @retval
+ \# pointer on symbol after string
*/
static char *
@@ -593,7 +599,7 @@ parse_quoted_escaped_string(char *ptr, char *end,
// process string
if (eol >= end ||
- !(str->str= alloc_root(mem_root, result_len + 1)) ||
+ !(str->str= (char*) alloc_root(mem_root, result_len + 1)) ||
read_escaped_string(ptr, eol, str))
return 0;
@@ -601,22 +607,20 @@ parse_quoted_escaped_string(char *ptr, char *end,
}
-/*
+/**
Parser for FILE_OPTIONS_ULLLIST type value.
- SYNOPSIS
- get_file_options_ulllist()
- ptr [in/out] pointer to parameter
- end [in] end of the configuration
- line [in] pointer to the line begining
- base [in] base address for parameter writing (structure
- like TABLE)
- parameter [in] description
- mem_root [in] MEM_ROOT for parameters allocation
+ @param[in,out] ptr pointer to parameter
+ @param[in] end end of the configuration
+ @param[in] line pointer to the line begining
+ @param[in] base base address for parameter writing (structure
+ like TABLE)
+ @param[in] parameter description
+ @param[in] mem_root MEM_ROOT for parameters allocation
*/
bool get_file_options_ulllist(char *&ptr, char *end, char *line,
- gptr base, File_option *parameter,
+ uchar* base, File_option *parameter,
MEM_ROOT *mem_root)
{
List<ulonglong> *nlist= (List<ulonglong>*)(base + parameter->offset);
@@ -656,30 +660,30 @@ nlist_err:
}
-/*
- parse parameters
-
- SYNOPSIS
- File_parser::parse()
- base base address for parameter writing (structure like
- TABLE)
- mem_root MEM_ROOT for parameters allocation
- parameters parameters description
- required number of parameters in the above list. If the file
- contains more parameters than "required", they will
- be ignored. If the file contains less parameters
- then "required", non-existing parameters will
- remain their values.
- hook hook called for unknown keys
- hook_data some data specific for the hook
-
- RETURN
- FALSE - OK
- TRUE - error
+/**
+ parse parameters.
+
+ @param base base address for parameter writing (structure like
+ TABLE)
+ @param mem_root MEM_ROOT for parameters allocation
+ @param parameters parameters description
+ @param required number of required parameters in above list. If the file
+ contains more parameters than "required", they will
+ be ignored. If the file contains less parameters
+ then "required", non-existing parameters will
+ remain their values.
+ @param hook hook called for unknown keys
+ @param hook_data some data specific for the hook
+
+ @retval
+ FALSE OK
+ @retval
+ TRUE error
*/
+
my_bool
-File_parser::parse(gptr base, MEM_ROOT *mem_root,
+File_parser::parse(uchar* base, MEM_ROOT *mem_root,
struct File_option *parameters, uint required,
Unknown_key_hook *hook)
{
@@ -862,32 +866,31 @@ list_err:
}
-/*
- Dummy unknown key hook
+/**
+ Dummy unknown key hook.
- SYNOPSIS
- File_parser_dummy_hook::process_unknown_string()
- unknown_key [in/out] reference on the line with unknown
- parameter and the parsing point
- base [in] base address for parameter writing (structure like
- TABLE)
- mem_root [in] MEM_ROOT for parameters allocation
- end [in] the end of the configuration
+ @param[in,out] unknown_key reference on the line with unknown
+ parameter and the parsing point
+ @param[in] base base address for parameter writing
+ (structure like TABLE)
+ @param[in] mem_root MEM_ROOT for parameters allocation
+ @param[in] end the end of the configuration
- NOTE
+ @note
This hook used to catch no longer supported keys and process them for
backward compatibility, but it will not slow down processing of modern
format files.
This hook does nothing except debug output.
- RETURN
+ @retval
FALSE OK
+ @retval
TRUE Error
*/
bool
File_parser_dummy_hook::process_unknown_string(char *&unknown_key,
- gptr base, MEM_ROOT *mem_root,
+ uchar* base, MEM_ROOT *mem_root,
char *end)
{
DBUG_ENTER("file_parser_dummy_hook::process_unknown_string");