MCPcopy Create free account
hub / github.com/MariaDB/server / main

Function main

scripts/comp_sql.c:126–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124static char query[MAX_BOOTSTRAP_QUERY_SIZE];
125
126int main(int argc, char *argv[])
127{
128 char* struct_name= argv[1];
129 char* infile_name= argv[2];
130 char* outfile_name= argv[3];
131 int rc;
132 int query_length;
133 int error= 0;
134 char *err_ptr;
135
136 if (argc != 4)
137 die("Usage: comp_sql <struct_name> <sql_filename> <c_filename>");
138
139 /* Open input and output file */
140 if (!(in= fopen(infile_name, "r")))
141 die("Failed to open SQL file '%s'", infile_name);
142 if (!(out= fopen(outfile_name, "w")))
143 die("Failed to open output file '%s'", outfile_name);
144
145 fprintf(out, "/*\n");
146 fprintf(out, " Do not edit this file, it is automatically generated from:\n");
147 fprintf(out, " <%s>\n", infile_name);
148 fprintf(out, "*/\n");
149 fprintf(out, "#include <stdlib.h>\n"); /* NULL */
150 fprintf(out, "const char* %s[]={\n", struct_name);
151
152 for ( ; ; )
153 {
154 rc= read_bootstrap_query(query, &query_length,
155 (fgets_input_t) in, fgets_fn, 1, &error);
156
157 if (rc == READ_BOOTSTRAP_EOF)
158 break;
159
160 if (rc != READ_BOOTSTRAP_SUCCESS)
161 {
162 /* Get the most recent query text for reference. */
163 err_ptr= query + (query_length <= MAX_BOOTSTRAP_ERROR_LEN ?
164 0 : (query_length - MAX_BOOTSTRAP_ERROR_LEN));
165 switch (rc)
166 {
167 case READ_BOOTSTRAP_ERROR:
168 die("Failed to read the bootstrap input file. Return code (%d).\n"
169 "Last query: '%s'\n", error, err_ptr);
170 break;
171
172 case READ_BOOTSTRAP_QUERY_SIZE:
173 die("Failed to read the boostrap input file. Query size exceeded %d bytes.\n"
174 "Last query: '%s'.\n", MAX_BOOTSTRAP_LINE_SIZE, err_ptr);
175 break;
176
177 default:
178 die("Failed to read the boostrap input file. Unknown error.\n");
179 break;
180 }
181 }
182
183 print_query(out, query);

Callers

nothing calls this directly

Calls 3

read_bootstrap_queryFunction · 0.85
dieFunction · 0.70
print_queryFunction · 0.70

Tested by

no test coverage detected