Debian Codegraph @

src/bnetd/sql_dbcreator.cpp

raw symbols SCIP
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */
16
17 #include "common/setup_before.h"
18 #ifdef WITH_SQL
19 #define SQL_DBCREATOR_INTERNAL_ACCESS
20 #include "sql_dbcreator.h"
21 #undef SQL_DBCREATOR_INTERNAL_ACCESS
22
23 #include <cstdio>
24 #include <cstring>
25
26 #include "common/eventlog.h"
27 #include "common/xstr.h"
28 #include "common/util.h"
29
30 #include "prefs.h"
31 #include "common/setup_after.h"
32
33 namespace pvpgn
34 {
35
36 namespace bnetd
37 {
38
39 t_elem * curr_table = NULL;
40 t_elem * curr_column = NULL;
41 t_elem * curr_cmd = NULL;
42
43 t_db_layout * db_layout;
44
45 static void sql_escape_command(char *escape, const char *from, int len);
46
47 t_column * create_column(char * name, char * value, char * mode, char * extra_cmd)
48 {
49 t_column * column;
50
51 if (!(name))
52 {
53 eventlog(eventlog_level_error, __FUNCTION__, "got NULL column name");
54 return NULL;
55 }
56
57 if (!(value))
58 {
59 eventlog(eventlog_level_error, __FUNCTION__, "got NULL column value");
60 return NULL;
61 }
62
63 column = (t_column *)xmalloc(sizeof(t_column));
64 column->name = xstrdup(name);
65 column->value = xstrdup(value);
66
67 if (mode && extra_cmd)
68 {
69 column->mode = xstrdup(mode);
70 column->extra_cmd = xstrdup(extra_cmd);
71 }
72 else
73 {
74 column->mode = NULL;
75 column->extra_cmd = NULL;
76 }
77
78 return column;
79 }
80
81 void dispose_column(t_column * column)
82 {
83 if (column)
84 {
85 if (column->name) xfree((void *)column->name);
86 if (column->value) xfree((void *)column->value);
87 if (column->mode) xfree((void *)column->mode);
88 if (column->extra_cmd) xfree((void *)column->extra_cmd);
89 xfree((void *)column);
90 }
91 }
92
93 t_sqlcommand * create_sqlcommand(char * sql_command, char * mode, char * extra_cmd)
94 {
95 t_sqlcommand * sqlcommand;
96
97 if (!(sql_command))
98 {
99 eventlog(eventlog_level_error, __FUNCTION__, "got NULL sql_command");
100 return NULL;
101 }
102
103 sqlcommand = (t_sqlcommand *)xmalloc(sizeof(t_sqlcommand));
104 sqlcommand->sql_command = xstrdup(sql_command);
105 if (mode && extra_cmd)
106 {
107 sqlcommand->mode = xstrdup(mode);
108 sqlcommand->extra_cmd = xstrdup(extra_cmd);
109 }
110 else
111 {
112 sqlcommand->mode = NULL;
113 sqlcommand->extra_cmd = NULL;
114 }
115
116 return sqlcommand;
117 }
118
119 void dispose_sqlcommand(t_sqlcommand * sqlcommand)
120 {
121 if (sqlcommand)
122 {
123 if (sqlcommand->sql_command) xfree((void *)sqlcommand->sql_command);
124 if (sqlcommand->mode) xfree((void *)sqlcommand->mode);
125 if (sqlcommand->extra_cmd) xfree((void *)sqlcommand->extra_cmd);
126 xfree(sqlcommand);
127 }
128 }
129
130 t_table * create_table(char * name)
131 {
132 t_table * table;
133
134 if (!(name))
135 {
136 eventlog(eventlog_level_error, __FUNCTION__, "got NULL table name");
137 return NULL;
138 }
139
140 table = (t_table *)xmalloc(sizeof(t_table));
141 table->name = xstrdup(name);
142
143 table->columns = list_create();
144 table->sql_commands = list_create();
145
146 return table;
147 }
148
149 void dispose_table(t_table * table)
150 {
151 t_elem * curr;
152 t_column * column;
153 t_sqlcommand * sql_command;
154
155 if (table)
156 {
157 if (table->name) xfree((void *)table->name);
158 // free list
159 if (table->columns)
160 {
161 LIST_TRAVERSE(table->columns, curr)
162 {
163 if (!(column = (t_column *)elem_get_data(curr)))
164 {
165 eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
166 continue;
167 }
168 dispose_column(column);
169 list_remove_elem(table->columns, &curr);
170 }
171
172 list_destroy(table->columns);
173 }
174
175 if (table->sql_commands)
176 {
177 LIST_TRAVERSE(table->sql_commands, curr)
178 {
179 if (!(sql_command = (t_sqlcommand *)elem_get_data(curr)))
180 {
181 eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
182 continue;
183 }
184 dispose_sqlcommand(sql_command);
185 list_remove_elem(table->sql_commands, &curr);
186 }
187
188 list_destroy(table->sql_commands);
189 }
190
191
192 xfree((void *)table);
193 }
194 }
195
196 void table_add_column(t_table * table, t_column * column)
197 {
198 if ((table) && (column))
199 {
200 list_append_data(table->columns, column);
201 }
202 }
203
204 void table_add_sql_command(t_table * table, t_sqlcommand * sql_command)
205 {
206 if ((table) && (sql_command))
207 {
208 list_append_data(table->sql_commands, sql_command);
209 }
210 }
211
212 t_db_layout * create_db_layout()
213 {
214 t_db_layout * db_layout;
215
216 db_layout = (t_db_layout *)xmalloc(sizeof(t_db_layout));
217
218 db_layout->tables = list_create();
219
220 return db_layout;
221 }
222
223 void dispose_db_layout(t_db_layout * db_layout)
224 {
225 t_elem * curr;
226 t_table * table;
227
228
229 if (db_layout)
230 {
231 if (db_layout->tables)
232 {
233 LIST_TRAVERSE(db_layout->tables, curr)
234 {
235 if (!(table = (t_table *)elem_get_data(curr)))
236 {
237 eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list");
238 continue;
239 }
240 dispose_table(table);
241 list_remove_elem(db_layout->tables, &curr);
242 }
243 list_destroy(db_layout->tables);
244 }
245 xfree((void *)db_layout);
246 }
247
248 }
249
250 void db_layout_add_table(t_db_layout * db_layout, t_table * table)
251 {
252 if ((db_layout) && (table))
253 {
254 list_append_data(db_layout->tables, table);
255 }
256 }
257
258 t_table * db_layout_get_first_table(t_db_layout * db_layout)
259 {
260 t_table * table;
261
262 curr_column = NULL;
263
264 if (!(db_layout))
265 {
266 eventlog(eventlog_level_error, __FUNCTION__, "got NULL db_layout");
267 return NULL;
268 }
269
270 if (!(db_layout->tables))
271 {
272 eventlog(eventlog_level_error, __FUNCTION__, "found NULL db_layout->tables");
273 return NULL;
274 }
275
276 if (!(curr_table = list_get_first(db_layout->tables)))
277 {
278 eventlog(eventlog_level_error, __FUNCTION__, "db_layout has no tables");
279 return NULL;
280 }
281
282 if (!(table = (t_table *)elem_get_data(curr_table)))
283 {
284 eventlog(eventlog_level_error, __FUNCTION__, "got NULL elem in list");
285 return NULL;
286 }
287
288 return table;
289 }
290
291 t_table * db_layout_get_next_table(t_db_layout * db_layout)
292 {
293 t_table * table;
294
295 curr_column = NULL;
296
297 if (!(curr_table))
298 {
299 eventlog(eventlog_level_error, __FUNCTION__, "got NULL curr_table");
300 return NULL;
301 }
302
303 if (!(curr_table = elem_get_next(db_layout->tables, curr_table))) return NULL;
304
305 if (!(table = (t_table *)elem_get_data(curr_table)))
306 {
307 eventlog(eventlog_level_error, __FUNCTION__, "got NULL elem in list");
308 return NULL;
309 }
310
311 return table;
312 }
313
314 t_column * table_get_first_column(t_table * table)
315 {
316 t_column * column;
317
318 if (!(table))
319 {
320 eventlog(eventlog_level_error, __FUNCTION__, "got NULL table");
321 return NULL;
322 }
323
324 if (!(table->columns))
325 {
326 eventlog(eventlog_level_error, __FUNCTION__, "got NULL table->columns");
327 return NULL;
328 }
329
330 if (!(curr_column = list_get_first(table->columns)))
331 {
332 eventlog(eventlog_level_error, __FUNCTION__, "table has no columns");
333 return NULL;
334 }
335
336 if (!(column = (t_column *)elem_get_data(curr_column)))
337 {
338 eventlog(eventlog_level_error, __FUNCTION__, "got NULL elem in list");
339 return NULL;
340 }
341
342 return column;
343 }
344
345 t_column * table_get_next_column(t_table * table)
346 {
347 t_column * column;
348
349 if (!(curr_column))
350 {
351 eventlog(eventlog_level_error, __FUNCTION__, "got NULL curr_column");
352 return NULL;
353 }
354
355 if (!(curr_column = elem_get_next(table->columns, curr_column))) return NULL;
356
357 if (!(column = (t_column *)elem_get_data(curr_column)))
358 {
359 eventlog(eventlog_level_error, __FUNCTION__, "got NULL elem in list");
360 return NULL;
361 }
362
363 return column;
364 }
365
366 t_sqlcommand * table_get_first_sql_command(t_table * table)
367 {
368 t_sqlcommand * sql_command;
369
370 if (!(table))
371 {
372 eventlog(eventlog_level_error, __FUNCTION__, "got NULL table");
373 return NULL;
374 }
375
376 if (!(table->sql_commands))
377 {
378 eventlog(eventlog_level_error, __FUNCTION__, "got NULL table->sql_commands");
379 return NULL;
380 }
381
382 if (!(curr_cmd = list_get_first(table->sql_commands)))
383 {
384 return NULL;
385 }
386
387 if (!(sql_command = (t_sqlcommand *)elem_get_data(curr_cmd)))
388 {
389 eventlog(eventlog_level_error, __FUNCTION__, "got NULL elem in list");
390 return NULL;
391 }
392
393 return sql_command;
394 }
395
396 t_sqlcommand * table_get_next_sql_command(t_table * table)
397 {
398 t_sqlcommand * sql_command;
399
400 if (!(curr_cmd))
401 {
402 eventlog(eventlog_level_error, __FUNCTION__, "got NULL curr_cmd");
403 return NULL;
404 }
405
406 if (!(curr_cmd = elem_get_next(table->sql_commands, curr_cmd))) return NULL;
407
408 if (!(sql_command = (t_sqlcommand *)elem_get_data(curr_cmd)))
409 {
410 eventlog(eventlog_level_error, __FUNCTION__, "got NULL elem in list");
411 return NULL;
412 }
413
414 return sql_command;
415 }
416
417 int load_db_layout(char const * filename)
418 {
419 std::FILE * fp;
420 int lineno;
421 char * line = NULL;
422 char * tmp = NULL;
423 char * table = NULL;
424 char * column = NULL;
425 char * value = NULL;
426 char * sqlcmd = NULL;
427 char * sqlcmd_escaped = NULL;
428 char * mode = NULL;
429 char * extra_cmd = NULL;
430 char * extra_cmd_escaped = NULL;
431 t_table * _table = NULL;
432 t_column * _column = NULL;
433 t_sqlcommand * _sqlcommand = NULL;
434 t_xstr * xstr = NULL;
435 int prefix;
436
437 if (!(filename))
438 {
439 eventlog(eventlog_level_error, __FUNCTION__, "got NULL filename");
440 return -1;
441 }
442
443 if (!(fp = std::fopen(filename, "r")))
444 {
445 eventlog(eventlog_level_error, __FUNCTION__, "can't open sql_DB_layout file");
446 return -1;
447 }
448
449 if (!(db_layout = create_db_layout()))
450 {
451 eventlog(eventlog_level_error, __FUNCTION__, "failed to create db_layout");
452 std::fclose(fp);
453 return -1;
454 }
455
456 for (lineno = 1; (line = file_get_line(fp)); lineno++)
457 {
458 /* convert ${prefix} replacement variable */
459 prefix = 0;
460 for (tmp = line; (tmp = std::strstr(line, "${prefix}")); line = tmp + 9 /* std::strlen("${prefix}") */)
461 {
462 *tmp = '\0';
463
464 if (!prefix) {
465 prefix = 1;
466
467 if (!xstr) xstr = xstr_alloc();
468
469 xstr_clear(xstr);
470 }
471
472 xstr_cat_str(xstr, line);
473 xstr_cat_str(xstr, tab_prefix);
474 }
475 if (prefix) {
476 /* append any reminder of the original string */
477 xstr_cat_str(xstr, line);
478 line = (char*)xstr_get_str(xstr);
479 }
480
481 switch (line[0])
482 {
483 case '[':
484 table = &line[1];
485 if (!(tmp = std::strchr(table, ']')))
486 {
487 eventlog(eventlog_level_error, __FUNCTION__, "missing ']' in line {}", lineno);
488 continue;
489 }
490 tmp[0] = '\0';
491 if (_table) db_layout_add_table(db_layout, _table);
492
493 _table = create_table(table);
494
495 break;
496 case '"':
497 if (!(_table))
498 {
499 eventlog(eventlog_level_error, __FUNCTION__, "found a column without previous table in line {}", lineno);
500 continue;
501 }
502 column = &line[1];
503 if (!(tmp = std::strchr(column, '"')))
504 {
505 eventlog(eventlog_level_error, __FUNCTION__, "missing '\"' at the end of column definition in line {}", lineno);
506 continue;
507 }
508 tmp[0] = '\0';
509 tmp++;
510 if (!(tmp = std::strchr(tmp, '"')))
511 {
512 eventlog(eventlog_level_error, __FUNCTION__, "missing default value in line {}", lineno);
513 continue;
514 }
515 value = ++tmp;
516 if (!(tmp = std::strchr(value, '"')))
517 {
518 eventlog(eventlog_level_error, __FUNCTION__, "missing '\"' at the end of default value in line {}", lineno);
519 continue;
520 }
521 tmp[0] = '\0';
522 tmp++;
523 mode = NULL;
524 extra_cmd = NULL;
525 extra_cmd_escaped = NULL;
526 if ((mode = std::strchr(tmp, '&')) || (mode = std::strchr(tmp, '|')))
527 {
528 if (mode[0] == mode[1])
529 {
530 mode[2] = '\0';
531 tmp = mode + 3;
532 if (!(tmp = std::strchr(tmp, '"')))
533 {
534 eventlog(eventlog_level_error, __FUNCTION__, "missing starting '\"' in extra sql_command on line {}", lineno);
535 continue;
536 }
537 extra_cmd = ++tmp;
538 if (!(tmp = std::strchr(extra_cmd, '"')))
539 {
540 eventlog(eventlog_level_error, __FUNCTION__, "missing ending '\"' in extra sql_command on line {}", lineno);
541 continue;
542 }
543 tmp[0] = '\0';
544 }
545 else
546 {
547 eventlog(eventlog_level_error, __FUNCTION__, "missing or non-matching secondary character in combination logic on line {}", lineno);
548 continue;
549 }
550 }
551 if (extra_cmd)
552 {
553 extra_cmd_escaped = (char *)xmalloc(std::strlen(extra_cmd) * 2);
554 sql_escape_command(extra_cmd_escaped, extra_cmd, std::strlen(extra_cmd));
555 }
556 _column = create_column(column, value, mode, extra_cmd_escaped);
557 if (extra_cmd_escaped) xfree(extra_cmd_escaped);
558 table_add_column(_table, _column);
559 _column = NULL;
560 break;
561 case ':':
562 if (!(_table))
563 {
564 eventlog(eventlog_level_error, __FUNCTION__, "found a sql_command without previous table in line {}", lineno);
565 continue;
566 }
567 if (line[1] != '"')
568 {
569 eventlog(eventlog_level_error, __FUNCTION__, "missing starting '\"' in sql_command definition on line {}", lineno);
570 continue;
571 }
572 sqlcmd = &line[2];
573 if (!(tmp = std::strchr(sqlcmd, '"')))
574 {
575 eventlog(eventlog_level_error, __FUNCTION__, "missing ending '\"' in sql_command definition on line {}", lineno);
576 continue;
577 }
578 tmp[0] = '\0';
579 tmp++;
580 mode = NULL;
581 extra_cmd = NULL;
582 extra_cmd_escaped = NULL;
583 if ((mode = std::strchr(tmp, '&')) || (mode = std::strchr(tmp, '|')))
584 {
585 if (mode[0] == mode[1])
586 {
587 mode[2] = '\0';
588 tmp = mode + 3;
589 if (!(tmp = std::strchr(tmp, '"')))
590 {
591 eventlog(eventlog_level_error, __FUNCTION__, "missing starting '\"' in extra sql_command on line {}", lineno);
592 continue;
593 }
594 extra_cmd = ++tmp;
595 if (!(tmp = std::strchr(extra_cmd, '"')))
596 {
597 eventlog(eventlog_level_error, __FUNCTION__, "missing ending '\"' in extra sql_command on line {}", lineno);
598 continue;
599 }
600 tmp[0] = '\0';
601 }
602 else
603 {
604 eventlog(eventlog_level_error, __FUNCTION__, "missing or non-matching secondary character in combination logic on line {}", lineno);
605 continue;
606 }
607 }
608 sqlcmd_escaped = (char *)xmalloc(std::strlen(sqlcmd) * 2);
609 sql_escape_command(sqlcmd_escaped, sqlcmd, std::strlen(sqlcmd));
610 if (extra_cmd)
611 {
612 extra_cmd_escaped = (char *)xmalloc(std::strlen(extra_cmd) * 2);
613 sql_escape_command(extra_cmd_escaped, extra_cmd, std::strlen(extra_cmd));
614 }
615 _sqlcommand = create_sqlcommand(sqlcmd_escaped, mode, extra_cmd_escaped);
616 xfree(sqlcmd_escaped);
617 if (extra_cmd_escaped) xfree(extra_cmd_escaped);
618 table_add_sql_command(_table, _sqlcommand);
619 _sqlcommand = NULL;
620
621 break;
622 case '#':
623 break;
624 default:
625 eventlog(eventlog_level_error, __FUNCTION__, "illegal starting symbol at line {}", lineno);
626 }
627 }
628 if (_table) db_layout_add_table(db_layout, _table);
629
630 if (xstr) xstr_free(xstr);
631 file_get_line(NULL); // clear file_get_line buffer
632 std::fclose(fp);
633 return 0;
634 }
635
636 int sql_dbcreator(t_sql_engine * sql)
637 {
638 t_table * table;
639 t_column * column;
640 char _column[1024];
641 char query[1024];
642 t_sqlcommand * sqlcmd;
643
644 load_db_layout(prefs_get_DBlayoutfile());
645
646 eventlog(eventlog_level_info, __FUNCTION__, "Creating missing tables and columns (if any)");
647
648 for (table = db_layout_get_first_table(db_layout); table; table = db_layout_get_next_table(db_layout))
649 {
650 column = table_get_first_column(table);
651 std::sprintf(query, "CREATE TABLE %s (%s default %s)", table->name, column->name, column->value);
652 //create table if missing
653 if (!(sql->query(query)))
654 {
655 eventlog(eventlog_level_info, __FUNCTION__, "added missing table {} to DB", table->name);
656 eventlog(eventlog_level_info, __FUNCTION__, "added missing column {} to table {}", column->name, table->name);
657 }
658
659 for (; column; column = table_get_next_column(table))
660 {
661 std::sprintf(query, "ALTER TABLE %s ADD %s DEFAULT %s", table->name, column->name, column->value);
662 if (!(sql->query(query)))
663 {
664 eventlog(eventlog_level_info, __FUNCTION__, "added missing column {} to table {}", column->name, table->name);
665 if ((column->mode != NULL) && (std::strcmp(column->mode, "&&") == 0))
666 {
667 if (!(sql->query(column->extra_cmd)))
668 {
669 eventlog(eventlog_level_info, __FUNCTION__, "sucessfully issued: {} {}", column->mode, column->extra_cmd);
670 }
671 }
672 /*
673 std::sscanf(column->name,"%s",_column);
674 std::sprintf(query,"ALTER TABLE %s ALTER %s SET DEFAULT %s",table->name,_column,column->value);
675
676 // If failed, try alternate language. (From ZSoft for sql_odbc.)
677 if(sql->query(query)) {
678 std::sprintf(query,"ALTER TABLE %s ADD DEFAULT %s FOR %s",table->name,column->value,_column);
679 sql->query(query);
680 }
681 // ALTER TABLE BNET add default 'false' for auth_admin;
682 */
683 }
684 else
685 {
686 if ((column->mode != NULL) && (std::strcmp(column->mode, "||") == 0))
687 {
688 if (!(sql->query(column->extra_cmd)))
689 {
690 eventlog(eventlog_level_info, __FUNCTION__, "sucessfully issued: {} {}", column->mode, column->extra_cmd);
691 }
692 }
693
694 }
695 }
696
697 for (sqlcmd = table_get_first_sql_command(table); sqlcmd; sqlcmd = table_get_next_sql_command(table))
698 {
699 if (!(sql->query(sqlcmd->sql_command)))
700 {
701 eventlog(eventlog_level_info, __FUNCTION__, "sucessfully issued: {}", sqlcmd->sql_command);
702 if ((sqlcmd->mode != NULL) && (std::strcmp(sqlcmd->mode, "&&") == 0))
703 {
704 if (!(sql->query(sqlcmd->extra_cmd)))
705 {
706 eventlog(eventlog_level_info, __FUNCTION__, "sucessfully issued: {} {}", sqlcmd->mode, sqlcmd->extra_cmd);
707 }
708 }
709 }
710 else
711 {
712 if ((sqlcmd->mode != NULL) && (std::strcmp(sqlcmd->mode, "||") == 0))
713 {
714 if (!(sql->query(sqlcmd->extra_cmd)))
715 {
716 eventlog(eventlog_level_info, __FUNCTION__, "sucessfully issued: {} {}", sqlcmd->mode, sqlcmd->extra_cmd);
717 }
718 }
719
720 }
721 }
722
723 column = table_get_first_column(table);
724 std::sscanf(column->name, "%s", _column); //get column name without format infos
725 std::sprintf(query, "INSERT INTO %s (%s) VALUES (%s)", table->name, _column, column->value);
726 if (!(sql->query(query)))
727 {
728 eventlog(eventlog_level_info, __FUNCTION__, "added missing default account to table {}", table->name);
729 }
730
731 }
732
733 dispose_db_layout(db_layout);
734
735 eventlog(eventlog_level_info, __FUNCTION__, "finished adding missing tables and columns");
736 return 0;
737 }
738
739 static void sql_escape_command(char *escape, const char *from, int len)
740 {
741 if (from != NULL && len != 0) /* make sure we have a command */
742 {
743 char * tmp1 = xstrdup(from); /* copy of 'from' */
744 char * tmp2 = escape;
745 char * tmp3 = NULL; /* begining of string to be escaped */
746 char * tmp4 = (char *)xmalloc(std::strlen(tmp1) * 2); /* escaped string */
747 unsigned int i, j;
748
749 /* eventlog(eventlog_level_trace,__FUNCTION__,"COMMAND: {}",tmp1); */
750
751 for (i = 0; tmp1[i] && i < len; i++, tmp2++)
752 {
753 *tmp2 = tmp1[i]; /* copy 'from' to 'escape' */
754
755 if (tmp1[i] == '\'') /* check if we find a string by checking for a single quote (') */
756 {
757 tmp3 = &tmp1[++i]; /* set tmp3 to the begining of the string to be escaped */
758
759 for (; tmp1[i] && tmp1[i] != '\'' && i < len; i++); /* find the end of the string to be escaped */
760
761 tmp1[i] = '\0'; /* set end of string with null terminator */
762 /* eventlog(eventlog_level_trace,__FUNCTION__,"STRING: {}",tmp3); */
763
764 sql->escape_string(tmp4, tmp3, std::strlen(tmp3)); /* escape the string */
765 /* eventlog(eventlog_level_trace,__FUNCTION__,"ESCAPE STRING: {}",tmp4); */
766
767 for (j = 0, tmp2++; tmp4[j]; j++, tmp2++) *tmp2 = tmp4[j]; /* add 'escaped string' to 'escape' */
768
769 *tmp2 = '\''; /* add single quote to end after adding 'escaped string' */
770 }
771 }
772 *tmp2 = '\0';
773 /* eventlog(eventlog_level_trace,__FUNCTION__,"ESCAPED COMMAND: {}",escape); */
774
775 xfree(tmp1);
776 xfree(tmp4);
777 }
778 }
779
780 }
781
782 }
783
784 #endif /* WITH_SQL */