21 #include "sql_bootstrap.h"
23 int read_bootstrap_query(
char *
query,
int *query_length,
24 fgets_input_t input, fgets_fn_t fgets_fn,
int *error)
26 char line_buffer[MAX_BOOTSTRAP_LINE_SIZE];
35 line= (*fgets_fn)(line_buffer,
sizeof(line_buffer), input, &fgets_error);
41 return READ_BOOTSTRAP_ERROR;
44 return (query_len == 0) ? READ_BOOTSTRAP_EOF : READ_BOOTSTRAP_ERROR;
56 while (len && (isspace(line[len - 1])))
62 line_buffer[len]=
'\0';
73 if ((line[0] ==
'-') && (line[1] ==
'-'))
77 if (strncmp(line,
"delimiter", 9) == 0)
84 if (query_len + len + 1 >= MAX_BOOTSTRAP_QUERY_SIZE)
86 int new_len= MAX_BOOTSTRAP_QUERY_SIZE - query_len - 1;
87 if ((new_len > 0) && (query_len < MAX_BOOTSTRAP_QUERY_SIZE))
89 memcpy(query + query_len, line, new_len);
92 query[query_len]=
'\0';
93 *query_length= query_len;
94 return READ_BOOTSTRAP_QUERY_SIZE;
103 query[query_len++]=
'\n';
105 memcpy(query + query_len, line, len);
108 if (line[len - 1] ==
';')
114 query[query_len]=
'\0';
115 *query_length= query_len;
116 return READ_BOOTSTRAP_SUCCESS;