mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
MDEV-9077 - sys schema preparation
- increase MAX_BOOTSTRAP_QUERY_SIZE (sys.schema has SP over 50K large) don't allocate bootstrap query on heap anymore. - support DELIMITER in bootstrap
This commit is contained in:
@ -18,9 +18,20 @@
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "sql_bootstrap.h"
|
||||
#include <string>
|
||||
|
||||
int read_bootstrap_query(char *query, int *query_length,
|
||||
fgets_input_t input, fgets_fn_t fgets_fn, int *error)
|
||||
static bool is_end_of_query(const char *line, size_t len,
|
||||
const std::string& delimiter)
|
||||
{
|
||||
if (delimiter.length() > len)
|
||||
return false;
|
||||
return !strcmp(line + len-delimiter.length(),delimiter.c_str());
|
||||
}
|
||||
|
||||
static std::string delimiter= ";";
|
||||
extern "C" int read_bootstrap_query(char *query, int *query_length,
|
||||
fgets_input_t input, fgets_fn_t fgets_fn,
|
||||
int preserve_delimiter, int *error)
|
||||
{
|
||||
char line_buffer[MAX_BOOTSTRAP_LINE_SIZE];
|
||||
const char *line;
|
||||
@ -73,10 +84,33 @@ int read_bootstrap_query(char *query, int *query_length,
|
||||
if ((line[0] == '-') && (line[1] == '-'))
|
||||
continue;
|
||||
|
||||
/* Skip delimiter, ignored. */
|
||||
if (strncmp(line, "delimiter", 9) == 0)
|
||||
size_t i=0;
|
||||
while (line[i] == ' ')
|
||||
i++;
|
||||
|
||||
/* Skip -- comments */
|
||||
if (line[i] == '-' && line[i+1] == '-')
|
||||
continue;
|
||||
|
||||
if (strncmp(line, "DELIMITER", 9) == 0)
|
||||
{
|
||||
const char *p= strrchr(line,' ');
|
||||
if (!p || !p[1])
|
||||
{
|
||||
/* Invalid DELIMITER specifier */
|
||||
return READ_BOOTSTRAP_ERROR;
|
||||
}
|
||||
delimiter.assign(p+1);
|
||||
if (preserve_delimiter)
|
||||
{
|
||||
memcpy(query,line,len);
|
||||
query[len]=0;
|
||||
*query_length = (int)len;
|
||||
return READ_BOOTSTRAP_SUCCESS;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Append the current line to a multi line query. If the new line will make
|
||||
the query too long, preserve the partial line to provide context for the
|
||||
error message.
|
||||
@ -105,13 +139,18 @@ int read_bootstrap_query(char *query, int *query_length,
|
||||
memcpy(query + query_len, line, len);
|
||||
query_len+= len;
|
||||
|
||||
if (line[len - 1] == ';')
|
||||
if (is_end_of_query(line, len, delimiter))
|
||||
{
|
||||
/*
|
||||
The last line is terminated by ';'.
|
||||
The last line is terminated by delimiter
|
||||
Return the query found.
|
||||
*/
|
||||
query[query_len]= '\0';
|
||||
if (!preserve_delimiter)
|
||||
{
|
||||
query_len-= delimiter.length();
|
||||
query[query_len++]= ';';
|
||||
}
|
||||
query[query_len]= 0;
|
||||
*query_length= (int)query_len;
|
||||
return READ_BOOTSTRAP_SUCCESS;
|
||||
}
|
||||
|
Reference in New Issue
Block a user