41 static void close_file (FILE * infp, FILE * outfp);
42 static int log_bind_value (
char *str,
int bind_len,
int lineno, FILE * outfp);
52 char *outfilename =
NULL;
56 if ((start_arg =
get_args (argc, argv)) < 0)
60 if (start_arg + 1 <= argc)
61 outfilename = argv[start_arg + 1];
88 if (linebuf_tstr ==
NULL)
90 fprintf (stderr,
"malloc error\n");
98 fprintf (stderr,
"malloc error\n");
106 if (linebuf[
strlen (linebuf) - 1] ==
'\n')
107 linebuf[
strlen (linebuf) - 1] =
'\0';
113 fprintf (outfp,
"\n");
114 fprintf (outfp,
"P %d %d\n", exec_h_id, prepare_flag);
119 if (strncmp (msg_p,
"execute", 7) == 0)
127 if (strncmp (msg_p,
"srv_h_id ", 9) == 0)
143 fprintf (outfp,
"Q ");
150 fprintf (outfp,
"/* QUERY_ID %d */ ", query_id++);
160 fprintf (outfp,
"E %d %d\n", exec_h_id, execute_flag);
161 fprintf (outfp,
"C %d\n", exec_h_id);
162 fprintf (outfp,
"T\n");
167 else if (strncmp (msg_p,
"bind ", 5) == 0)
191 if (strcmp (infilename,
"-") == 0)
197 *infp = fopen (infilename,
"r");
200 fprintf (stderr,
"fopen error[%s]\n", infilename);
205 if (outfilename ==
NULL)
211 *outfp = fopen (outfilename,
"w");
214 fprintf (stderr,
"fopen error[%s]\n", outfilename);
240 p = strchr (str,
':');
243 fprintf (stderr,
"log error [line:%d]\n", lineno);
250 if (strcmp (p,
"NULL") == 0)
252 value_p = (
char *)
"";
256 fprintf (stderr,
"log error [line:%d]\n", lineno);
267 fprintf (stderr,
"log error [line:%d]\n", lineno);
281 if (strcmp (p,
"NULL") == 0)
283 type = CCI_U_TYPE_NULL;
285 else if (strcmp (p,
"CHAR") == 0)
287 type = CCI_U_TYPE_CHAR;
289 else if (strcmp (p,
"VARCHAR") == 0)
291 type = CCI_U_TYPE_STRING;
293 else if (strcmp (p,
"NCHAR") == 0)
295 type = CCI_U_TYPE_NCHAR;
297 else if (strcmp (p,
"VARNCHAR") == 0)
299 type = CCI_U_TYPE_VARNCHAR;
301 else if (strcmp (p,
"BIT") == 0)
303 type = CCI_U_TYPE_BIT;
305 else if (strcmp (p,
"VARBIT") == 0)
307 type = CCI_U_TYPE_VARBIT;
309 else if (strcmp (p,
"NUMERIC") == 0)
311 type = CCI_U_TYPE_NUMERIC;
313 else if (strcmp (p,
"UBIGINT") == 0)
315 type = CCI_U_TYPE_UBIGINT;
317 else if (strcmp (p,
"BIGINT") == 0)
319 type = CCI_U_TYPE_BIGINT;
321 else if (strcmp (p,
"UINT") == 0)
323 type = CCI_U_TYPE_UINT;
325 else if (strcmp (p,
"INT") == 0)
327 type = CCI_U_TYPE_INT;
329 else if (strcmp (p,
"USHORT") == 0)
331 type = CCI_U_TYPE_USHORT;
333 else if (strcmp (p,
"SHORT") == 0)
335 type = CCI_U_TYPE_SHORT;
337 else if (strcmp (p,
"MONETARY") == 0)
339 type = CCI_U_TYPE_MONETARY;
341 else if (strcmp (p,
"FLOAT") == 0)
343 type = CCI_U_TYPE_FLOAT;
345 else if (strcmp (p,
"DOUBLE") == 0)
347 type = CCI_U_TYPE_DOUBLE;
349 else if (strcmp (p,
"DATE") == 0)
351 type = CCI_U_TYPE_DATE;
353 else if (strcmp (p,
"TIME") == 0)
355 type = CCI_U_TYPE_TIME;
357 else if (strcmp (p,
"TIMESTAMP") == 0)
359 type = CCI_U_TYPE_TIMESTAMP;
361 else if (strcmp (p,
"DATETIME") == 0)
363 type = CCI_U_TYPE_DATETIME;
365 else if (strcmp (p,
"TIMESTAMPTZ") == 0)
367 type = CCI_U_TYPE_TIMESTAMPTZ;
369 else if (strcmp (p,
"DATETIMETZ") == 0)
371 type = CCI_U_TYPE_DATETIMETZ;
373 else if (strcmp (p,
"OBJECT") == 0)
375 type = CCI_U_TYPE_OBJECT;
377 else if (strcmp (p,
"BLOB") == 0)
379 type = CCI_U_TYPE_NULL;
380 fprintf (stderr,
"%s\nBLOB type is not implemented. Replaced with NULL\n", value_p);
381 value_p = (
char *)
"";
385 else if (strcmp (p,
"CLOB") == 0)
387 type = CCI_U_TYPE_NULL;
388 fprintf (stderr,
"%s\nCLOB type is not implemented. Replaced with NULL\n", value_p);
389 value_p = (
char *)
"";
393 else if (strcmp (p,
"ENUM") == 0)
395 type = CCI_U_TYPE_ENUM;
397 else if (strcmp (p,
"JSON") == 0)
399 type = CCI_U_TYPE_JSON;
403 fprintf (stderr,
"log error [line:%d]\n", lineno);
409 fprintf (outfp,
"B %d %d %s\n", type, bind_len, value_p);
413 fprintf (outfp,
"B %d %s\n", type, value_p);
423 while ((c =
getopt (argc, argv,
"iq")) != EOF)
445 "usage : %s [OPTION] infile outfile\n" "\n" "valid options:\n" 446 " -i add a unique id to each query as a comment.\n", argv[0]);
static void close_file(FILE *infp, FILE *outfp)
char * get_msg_start_ptr(char *linebuf)
int getopt(int, char *const *, const char *)
static int log_converter(FILE *infp, FILE *outfp)
int t_string_len(T_STRING *t_str)
char * t_string_str(T_STRING *t_str)
int main(int argc, char *argv[])
int is_cas_log(char *str)
int str_to_int32(int *ret_p, char **end_p, const char *str_p, int base)
int t_string_bind_len(T_STRING *t_str)
static char add_query_info
static void error(const char *msg)
T_STRING * t_string_make(int init_size)
char * ut_get_execute_type(char *msg_p, int *prepare_flag, int *execute_flag)
static int get_args(int argc, char *argv[])
static int open_file(char *infilename, char *outfilename, FILE **infp, FILE **outfp)
#define CAS_RUN_NEW_LINE_CHAR
int ut_get_line(FILE *fp, T_STRING *t_str, char **out_str, int *lineno)
static int log_bind_value(char *str, int bind_len, int lineno, FILE *outfp)