24 #include "parse_file.h"
26 #include "sql_table.h"
33 extern long mysql_rm_arc_files(THD *thd,
MY_DIR *dirp,
const char *org_path);
51 char *eos= val_s->str + val_s->length;
52 char *ptr= val_s->str;
54 for (; ptr < eos; ptr++)
62 if (my_b_append(file, (
const uchar *)STRING_WITH_LEN(
"\\\\")))
66 if (my_b_append(file, (
const uchar *)STRING_WITH_LEN(
"\\n")))
70 if (my_b_append(file, (
const uchar *)STRING_WITH_LEN(
"\\0")))
74 if (my_b_append(file, (
const uchar *)STRING_WITH_LEN(
"\\z")))
78 if (my_b_append(file, (
const uchar *)STRING_WITH_LEN(
"\\\'")))
82 if (my_b_append(file, (
const uchar *)ptr, 1))
109 String num(num_buf,
sizeof(num_buf), &my_charset_bin);
110 DBUG_ENTER(
"write_parameter");
112 switch (parameter->
type) {
113 case FILE_OPTIONS_STRING:
116 if (my_b_append(file, (
const uchar *)val_s->str, val_s->length))
120 case FILE_OPTIONS_ESTRING:
126 case FILE_OPTIONS_ULONGLONG:
128 num.set(*((ulonglong *)(base + parameter->
offset)), &my_charset_bin);
129 if (my_b_append(file, (
const uchar *)num.ptr(), num.length()))
133 case FILE_OPTIONS_TIMESTAMP:
137 time_t tm= my_time(0);
139 get_date(val_s->str, GETDATE_DATE_TIME|GETDATE_GMT|GETDATE_FIXEDLENGTH,
141 val_s->length= PARSE_FILE_TIMESTAMPLENGTH;
142 if (my_b_append(file, (
const uchar *)val_s->str,
143 PARSE_FILE_TIMESTAMPLENGTH))
147 case FILE_OPTIONS_STRLIST:
150 (base + parameter->
offset)));
156 if ((!first && my_b_append(file, (
const uchar *)STRING_WITH_LEN(
" "))) ||
157 my_b_append(file, (
const uchar *)STRING_WITH_LEN(
"\'")) ||
158 write_escaped_string(file, str) ||
159 my_b_append(file, (
const uchar *)STRING_WITH_LEN(
"\'")))
167 case FILE_OPTIONS_ULLLIST:
170 (base + parameter->
offset)));
175 num.set(*val, &my_charset_bin);
177 if ((!first && my_b_append(file, (
const uchar *)STRING_WITH_LEN(
" "))) ||
178 my_b_append(file, (
const uchar *)num.ptr(), num.length()))
217 char path[FN_REFLEN+1];
220 DBUG_ENTER(
"sql_create_definition_file");
221 DBUG_PRINT(
"enter", (
"Dir: %s, file: %s, base 0x%lx",
222 dir ? dir->str :
"(null)",
223 file_name->str, (ulong) base));
227 fn_format(path, file_name->str, dir->str,
"", MY_UNPACK_FILENAME);
228 path_end= strlen(path);
237 path_end= strxnmov(path,
sizeof(path) - 1, file_name->str, NullS) - path;
242 path[path_end+1]=
'\0';
244 path, CREATE_MODE, O_RDWR | O_TRUNC,
250 if (init_io_cache(&file, handler, 0, SEQ_READ_APPEND, 0L, 0, MYF(MY_WME)))
254 if (my_b_append(&file, (
const uchar *)STRING_WITH_LEN(
"TYPE=")) ||
255 my_b_append(&file, (
const uchar *)type->str, type->length) ||
256 my_b_append(&file, (
const uchar *)STRING_WITH_LEN(
"\n")))
260 for (param= parameters; param->
name.str; param++)
262 if (my_b_append(&file, (
const uchar *)param->
name.str,
263 param->
name.length) ||
264 my_b_append(&file, (
const uchar *)STRING_WITH_LEN(
"=")) ||
265 write_parameter(&file, base, param) ||
266 my_b_append(&file, (
const uchar *)STRING_WITH_LEN(
"\n")))
270 if (end_io_cache(&file))
287 char path_to[FN_REFLEN];
288 memcpy(path_to, path, path_end+1);
318 const char *schema,
const char *old_name,
319 const char *new_db,
const char *new_name)
321 char old_path[FN_REFLEN + 1], new_path[FN_REFLEN + 1], arc_path[FN_REFLEN + 1];
323 build_table_filename(old_path,
sizeof(old_path) - 1,
324 schema, old_name, reg_ext, 0);
325 build_table_filename(new_path,
sizeof(new_path) - 1,
326 new_db, new_name, reg_ext, 0);
332 build_table_filename(arc_path,
sizeof(arc_path) - 1, schema,
"arc",
"", 0);
336 if ((new_dirp = my_dir(arc_path, MYF(MY_DONT_SORT))))
338 DBUG_PRINT(
"my",(
"Archive subdir found: %s", arc_path));
339 (void) mysql_rm_arc_files(thd, new_dirp, arc_path);
363 bool bad_format_errors)
367 char *buff, *end, *sign;
370 DBUG_ENTER(
"sql_parse_prepare");
373 file_name->str, &stat_info, MYF(MY_WME)))
378 if (stat_info.st_size > INT_MAX-1)
380 my_error(ER_FPARSER_TOO_BIG_FILE, MYF(0), file_name->str);
389 if (!(buff= (
char*) alloc_root(mem_root, stat_info.st_size+1)))
395 O_RDONLY | O_SHARE, MYF(MY_WME))) < 0)
401 MYF(MY_WME))) == MY_FILE_ERROR)
425 parser->file_type.str= sign= buff + 5;
426 while (*sign >=
'A' && *sign <=
'Z' && sign < end)
430 parser->file_type.length= sign - parser->file_type.str;
435 parser->start= sign + 1;
436 parser->content_ok= 1;
441 if (bad_format_errors)
443 my_error(ER_FPARSER_BAD_HEADER, MYF(0), file_name->str);
468 parse_string(
const char *ptr,
const char *end,
MEM_ROOT *mem_root,
472 const char *eol= strchr(ptr,
'\n');
477 str->length= eol - ptr;
479 if (!(str->str= strmake_root(mem_root, ptr, str->length)))
501 char *write_pos= str->str;
503 for (; ptr < eol; ptr++, write_pos++)
538 str->str[str->length= write_pos-str->str]=
'\0';
563 const char *eol= strchr(ptr,
'\n');
565 if (eol == 0 || eol >= end ||
566 !(str->str= (
char*) alloc_root(mem_root, (eol - ptr) + 1)) ||
590 parse_quoted_escaped_string(
const char *ptr,
const char *end,
598 if (*(ptr++) !=
'\'')
602 for (eol= ptr; (*eol !=
'\'' || escaped) && eol < end; eol++)
604 if (!(escaped= (*eol ==
'\\' && !escaped)))
610 !(str->str= (
char*) alloc_root(mem_root, result_len + 1)) ||
641 char *num_end=
const_cast<char *
>(end);
642 if (!(num= (ulonglong*)alloc_root(mem_root,
sizeof(ulonglong))) ||
643 nlist->push_back(num, mem_root))
645 *num= my_strtoll10(ptr, &num_end, ¬_used);
655 goto nlist_err_w_message;
660 if (*(ptr++) !=
'\n')
665 my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0), parameter->
name.str, line);
698 uint first_param= 0, found= 0;
699 const char *ptr= start;
703 DBUG_ENTER(
"File_parser::parse");
705 while (ptr < end && found < required)
707 const char *line= ptr;
711 if (!(ptr= strchr(ptr,
'\n')))
713 my_error(ER_FPARSER_EOF_IN_COMMENT, MYF(0), line);
721 *parameters_end= parameters+required;
723 for (; parameter < parameters_end; parameter++)
725 len= parameter->
name.length;
727 if (len < (end-ptr) && ptr[len] !=
'=')
730 if (memcmp(parameter->
name.str, ptr, len) == 0)
734 if (parameter < parameters_end)
743 if (parameter == parameters+first_param)
748 switch (parameter->
type) {
749 case FILE_OPTIONS_STRING:
751 if (!(ptr= parse_string(ptr, end, mem_root,
755 my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
756 parameter->
name.str, line);
761 case FILE_OPTIONS_ESTRING:
765 (base + parameter->
offset))))
767 my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
768 parameter->
name.str, line);
773 case FILE_OPTIONS_ULONGLONG:
774 if (!(eol= strchr(ptr,
'\n')))
776 my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
777 parameter->
name.str, line);
782 *((ulonglong*)(base + parameter->
offset))=
783 my_strtoll10(ptr, 0, ¬_used);
787 case FILE_OPTIONS_TIMESTAMP:
792 if (ptr[PARSE_FILE_TIMESTAMPLENGTH] !=
'\n')
794 my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
795 parameter->
name.str, line);
798 memcpy(val->str, ptr, PARSE_FILE_TIMESTAMPLENGTH);
799 val->str[val->length= PARSE_FILE_TIMESTAMPLENGTH]=
'\0';
800 ptr+= (PARSE_FILE_TIMESTAMPLENGTH+1);
803 case FILE_OPTIONS_STRLIST:
813 list->push_back(str, mem_root))
815 if (!(ptr= parse_quoted_escaped_string(ptr, end, mem_root, str)))
816 goto list_err_w_message;
825 goto list_err_w_message;
830 if (*(ptr++) !=
'\n')
835 my_error(ER_FPARSER_ERROR_IN_PARAMETER, MYF(0),
836 parameter->
name.str, line);
840 case FILE_OPTIONS_ULLLIST:
842 parameter, mem_root))
852 if (hook->process_unknown_string(ptr, base, mem_root, end))
857 if (!(ptr= strchr(ptr,
'\n')))
859 my_error(ER_FPARSER_EOF_IN_UNKNOWN_PARAMETER, MYF(0), line);
904 DBUG_ENTER(
"file_parser_dummy_hook::process_unknown_string");
905 DBUG_PRINT(
"info", (
"Unknown key: '%60s'", unknown_key));