drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
statement_transform.cc
Go to the documentation of this file.
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2009 Sun Microsystems, Inc.
5 * Copyright (C) 2010 Jay Pipes
6 *
7 * Authors:
8 *
9 * Jay Pipes <[email protected]>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
31
32#include <config.h>
33
34#include <boost/lexical_cast.hpp>
35
36#include <drizzled/charset.h>
37#include <drizzled/message.h>
39#include <drizzled/message/transaction.pb.h>
40#include <drizzled/message/access.h>
41
42#include <string>
43#include <vector>
44#include <sstream>
45#include <cstdio>
46
47using namespace std;
48
49namespace drizzled
50{
51
52namespace message
53{
54
55static void escapeEmbeddedQuotes(string &s, const char quote='\'')
56{
57 string::iterator it;
58
59 for (it= s.begin(); it != s.end(); ++it)
60 {
61 if (*it == quote)
62 {
63 it= s.insert(it, quote);
64 ++it; // advance back to the quote
65 }
66 }
67}
68
69/* Incredibly similar to append_unescaped() in table.cc, but for std::string */
70static void append_escaped_string(std::string *res, const std::string &input, const char quote='\'')
71{
72 const char *pos= input.c_str();
73 const char *end= input.c_str()+input.length();
74 res->push_back(quote);
75
76 for (; pos != end ; pos++)
77 {
78 uint32_t mblen;
79 if (use_mb(default_charset_info) &&
80 (mblen= my_ismbchar(default_charset_info, pos, end)))
81 {
82 res->append(pos, mblen);
83 pos+= mblen - 1;
84 if (pos >= end)
85 break;
86 continue;
87 }
88
89 switch (*pos) {
90 case 0: /* Must be escaped for 'mysql' */
91 res->push_back('\\');
92 res->push_back('0');
93 break;
94 case '\n': /* Must be escaped for logs */
95 res->push_back('\\');
96 res->push_back('n');
97 break;
98 case '\r':
99 res->push_back('\\'); /* This gives better readability */
100 res->push_back('r');
101 break;
102 case '\\':
103 res->push_back('\\'); /* Because of the sql syntax */
104 res->push_back('\\');
105 break;
106 default:
107 if (*pos == quote) /* SQL syntax for quoting a quote */
108 {
109 res->push_back(quote);
110 res->push_back(quote);
111 }
112 else
113 res->push_back(*pos);
114 break;
115 }
116 }
117 res->push_back(quote);
118}
119
121transformStatementToSql(const Statement &source,
122 vector<string> &sql_strings,
123 enum TransformSqlVariant sql_variant,
124 bool already_in_transaction)
125{
126 TransformSqlError error= NONE;
127
128 switch (source.type())
129 {
130 case Statement::ROLLBACK_STATEMENT:
131 {
132 break;
133 }
134 case Statement::ROLLBACK:
135 {
136 sql_strings.push_back("ROLLBACK");
137 break;
138 }
139 case Statement::INSERT:
140 {
141 if (! source.has_insert_header())
142 {
143 error= MISSING_HEADER;
144 return error;
145 }
146 if (! source.has_insert_data())
147 {
148 error= MISSING_DATA;
149 return error;
150 }
151
152 const InsertHeader &insert_header= source.insert_header();
153 const InsertData &insert_data= source.insert_data();
154 size_t num_keys= insert_data.record_size();
155
156 if (num_keys > 1 && ! already_in_transaction)
157 sql_strings.push_back("START TRANSACTION");
158
159 for (size_t x= 0; x < num_keys; ++x)
160 {
161 string destination;
162
163 error= transformInsertRecordToSql(insert_header,
164 insert_data.record(x),
165 destination,
166 sql_variant);
167 if (error != NONE)
168 break;
169
170 sql_strings.push_back(destination);
171 }
172
173 if (num_keys > 1 && ! already_in_transaction)
174 {
175 if (error == NONE)
176 sql_strings.push_back("COMMIT");
177 else
178 sql_strings.push_back("ROLLBACK");
179 }
180 }
181 break;
182 case Statement::UPDATE:
183 {
184 if (! source.has_update_header())
185 {
186 error= MISSING_HEADER;
187 return error;
188 }
189 if (! source.has_update_data())
190 {
191 error= MISSING_DATA;
192 return error;
193 }
194
195 const UpdateHeader &update_header= source.update_header();
196 const UpdateData &update_data= source.update_data();
197 size_t num_keys= update_data.record_size();
198 size_t x;
199
200 if (num_keys > 1 && ! already_in_transaction)
201 sql_strings.push_back("START TRANSACTION");
202
203 for (x= 0; x < num_keys; ++x)
204 {
205 string destination;
206
207 error= transformUpdateRecordToSql(update_header,
208 update_data.record(x),
209 destination,
210 sql_variant);
211 if (error != NONE)
212 break;
213
214 sql_strings.push_back(destination);
215 }
216
217 if (num_keys > 1 && ! already_in_transaction)
218 {
219 if (error == NONE)
220 sql_strings.push_back("COMMIT");
221 else
222 sql_strings.push_back("ROLLBACK");
223 }
224 }
225 break;
226 case Statement::DELETE:
227 {
228 if (! source.has_delete_header())
229 {
230 error= MISSING_HEADER;
231 return error;
232 }
233 if (! source.has_delete_data())
234 {
235 error= MISSING_DATA;
236 return error;
237 }
238
239 const DeleteHeader &delete_header= source.delete_header();
240 const DeleteData &delete_data= source.delete_data();
241 size_t num_keys= delete_data.record_size();
242 size_t x;
243
244 if (num_keys > 1 && ! already_in_transaction)
245 sql_strings.push_back("START TRANSACTION");
246
247 for (x= 0; x < num_keys; ++x)
248 {
249 string destination;
250
251 error= transformDeleteRecordToSql(delete_header,
252 delete_data.record(x),
253 destination,
254 sql_variant);
255 if (error != NONE)
256 break;
257
258 sql_strings.push_back(destination);
259 }
260
261 if (num_keys > 1 && ! already_in_transaction)
262 {
263 if (error == NONE)
264 sql_strings.push_back("COMMIT");
265 else
266 sql_strings.push_back("ROLLBACK");
267 }
268 }
269 break;
270 case Statement::CREATE_TABLE:
271 {
272 assert(source.has_create_table_statement());
273 string destination;
274 error= transformCreateTableStatementToSql(source.create_table_statement(),
275 destination,
276 sql_variant);
277 sql_strings.push_back(destination);
278 }
279 break;
280 case Statement::TRUNCATE_TABLE:
281 {
282 assert(source.has_truncate_table_statement());
283 string destination;
284 error= transformTruncateTableStatementToSql(source.truncate_table_statement(),
285 destination,
286 sql_variant);
287 sql_strings.push_back(destination);
288 }
289 break;
290 case Statement::DROP_TABLE:
291 {
292 assert(source.has_drop_table_statement());
293 string destination;
294 error= transformDropTableStatementToSql(source.drop_table_statement(),
295 destination,
296 sql_variant);
297 sql_strings.push_back(destination);
298 }
299 break;
300 case Statement::CREATE_SCHEMA:
301 {
302 assert(source.has_create_schema_statement());
303 string destination;
304 error= transformCreateSchemaStatementToSql(source.create_schema_statement(),
305 destination,
306 sql_variant);
307 sql_strings.push_back(destination);
308 }
309 break;
310 case Statement::DROP_SCHEMA:
311 {
312 assert(source.has_drop_schema_statement());
313 string destination;
314 error= transformDropSchemaStatementToSql(source.drop_schema_statement(),
315 destination,
316 sql_variant);
317 sql_strings.push_back(destination);
318 }
319 break;
320 case Statement::ALTER_SCHEMA:
321 {
322 assert(source.has_alter_schema_statement());
323 string destination;
324 error= transformAlterSchemaStatementToSql(source.alter_schema_statement(),
325 destination,
326 sql_variant);
327 sql_strings.push_back(destination);
328 }
329 break;
330 case Statement::SET_VARIABLE:
331 {
332 assert(source.has_set_variable_statement());
333 string destination;
334 error= transformSetVariableStatementToSql(source.set_variable_statement(),
335 destination,
336 sql_variant);
337 sql_strings.push_back(destination);
338 }
339 break;
340 case Statement::RAW_SQL:
341 {
342 if (source.has_raw_sql_schema())
343 {
344 string destination("USE ");
345 destination.append(source.raw_sql_schema());
346 sql_strings.push_back(destination);
347 }
348 sql_strings.push_back(source.sql());
349 }
350 break;
351 default:
352 sql_strings.push_back(source.sql());
353 break;
354 }
355 return error;
356}
357
358enum TransformSqlError
359transformInsertHeaderToSql(const InsertHeader &header,
360 string &destination,
361 enum TransformSqlVariant sql_variant)
362{
363 char quoted_identifier= '`';
364 if (sql_variant == ANSI)
365 quoted_identifier= '"';
366
367 destination.assign("INSERT INTO ", 12);
368 destination.push_back(quoted_identifier);
369 destination.append(header.table_metadata().schema_name());
370 destination.push_back(quoted_identifier);
371 destination.push_back('.');
372 destination.push_back(quoted_identifier);
373 destination.append(header.table_metadata().table_name());
374 destination.push_back(quoted_identifier);
375 destination.append(" (", 2);
376
377 /* Add field list to SQL string... */
378 size_t num_fields= header.field_metadata_size();
379 size_t x;
380
381 for (x= 0; x < num_fields; ++x)
382 {
383 const FieldMetadata &field_metadata= header.field_metadata(x);
384 if (x != 0)
385 destination.push_back(',');
386
387 destination.push_back(quoted_identifier);
388 destination.append(field_metadata.name());
389 destination.push_back(quoted_identifier);
390 }
391
392 return NONE;
393}
394
395enum TransformSqlError
396transformInsertRecordToSql(const InsertHeader &header,
397 const InsertRecord &record,
398 string &destination,
399 enum TransformSqlVariant sql_variant)
400{
402 destination,
403 sql_variant);
404
405 destination.append(") VALUES (");
406
407 /* Add insert values */
408 size_t num_fields= header.field_metadata_size();
409 size_t x;
410 bool should_quote_field_value= false;
411
412 for (x= 0; x < num_fields; ++x)
413 {
414 if (x != 0)
415 destination.push_back(',');
416
417 const FieldMetadata &field_metadata= header.field_metadata(x);
418
419 if (record.is_null(x))
420 {
421 should_quote_field_value= false;
422 }
423 else
424 {
425 should_quote_field_value= shouldQuoteFieldValue(field_metadata.type());
426 }
427
428 if (should_quote_field_value)
429 destination.push_back('\'');
430
431 if (record.is_null(x))
432 {
433 destination.append("NULL");
434 }
435 else
436 {
437 if (field_metadata.type() == Table::Field::BLOB)
438 {
439 /*
440 * We do this here because BLOB data is returned
441 * in a string correctly, but calling append()
442 * without a length will result in only the string
443 * up to a \0 being output here.
444 */
445 string raw_data(record.insert_value(x));
446 destination.append(raw_data.c_str(), raw_data.size());
447 }
448 else
449 {
450 string tmp(record.insert_value(x));
451 escapeEmbeddedQuotes(tmp);
452 destination.append(tmp);
453 }
454 }
455
456 if (should_quote_field_value)
457 destination.push_back('\'');
458 }
459 destination.push_back(')');
460
461 return error;
462}
463
464enum TransformSqlError
465transformInsertStatementToSql(const InsertHeader &header,
466 const InsertData &data,
467 string &destination,
468 enum TransformSqlVariant sql_variant)
469{
471 destination,
472 sql_variant);
473
474 destination.append(") VALUES (", 10);
475
476 /* Add insert values */
477 size_t num_records= data.record_size();
478 size_t num_fields= header.field_metadata_size();
479 size_t x, y;
480 bool should_quote_field_value= false;
481
482 for (x= 0; x < num_records; ++x)
483 {
484 if (x != 0)
485 destination.append("),(", 3);
486
487 for (y= 0; y < num_fields; ++y)
488 {
489 if (y != 0)
490 destination.push_back(',');
491
492 const FieldMetadata &field_metadata= header.field_metadata(y);
493
494 should_quote_field_value= shouldQuoteFieldValue(field_metadata.type());
495
496 if (should_quote_field_value)
497 destination.push_back('\'');
498
499 if (field_metadata.type() == Table::Field::BLOB)
500 {
501 /*
502 * We do this here because BLOB data is returned
503 * in a string correctly, but calling append()
504 * without a length will result in only the string
505 * up to a \0 being output here.
506 */
507 string raw_data(data.record(x).insert_value(y));
508 destination.append(raw_data.c_str(), raw_data.size());
509 }
510 else
511 {
512 string tmp(data.record(x).insert_value(y));
513 escapeEmbeddedQuotes(tmp);
514 destination.append(tmp);
515 }
516
517 if (should_quote_field_value)
518 destination.push_back('\'');
519 }
520 }
521 destination.push_back(')');
522
523 return error;
524}
525
526enum TransformSqlError
527transformUpdateHeaderToSql(const UpdateHeader &header,
528 string &destination,
529 enum TransformSqlVariant sql_variant)
530{
531 char quoted_identifier= '`';
532 if (sql_variant == ANSI)
533 quoted_identifier= '"';
534
535 destination.assign("UPDATE ", 7);
536 destination.push_back(quoted_identifier);
537 destination.append(header.table_metadata().schema_name());
538 destination.push_back(quoted_identifier);
539 destination.push_back('.');
540 destination.push_back(quoted_identifier);
541 destination.append(header.table_metadata().table_name());
542 destination.push_back(quoted_identifier);
543 destination.append(" SET ", 5);
544
545 return NONE;
546}
547
548enum TransformSqlError
549transformUpdateRecordToSql(const UpdateHeader &header,
550 const UpdateRecord &record,
551 string &destination,
552 enum TransformSqlVariant sql_variant)
553{
555 destination,
556 sql_variant);
557
558 char quoted_identifier= '`';
559 if (sql_variant == ANSI)
560 quoted_identifier= '"';
561
562 /* Add field SET list to SQL string... */
563 size_t num_set_fields= header.set_field_metadata_size();
564 size_t x;
565 bool should_quote_field_value= false;
566
567 for (x= 0; x < num_set_fields; ++x)
568 {
569 const FieldMetadata &field_metadata= header.set_field_metadata(x);
570 if (x != 0)
571 destination.push_back(',');
572
573 destination.push_back(quoted_identifier);
574 destination.append(field_metadata.name());
575 destination.push_back(quoted_identifier);
576 destination.push_back('=');
577
578 if (record.is_null(x))
579 {
580 should_quote_field_value= false;
581 }
582 else
583 {
584 should_quote_field_value= shouldQuoteFieldValue(field_metadata.type());
585 }
586
587 if (should_quote_field_value)
588 destination.push_back('\'');
589
590 if (record.is_null(x))
591 {
592 destination.append("NULL");
593 }
594 else
595 {
596 if (field_metadata.type() == Table::Field::BLOB)
597 {
598 /*
599 * We do this here because BLOB data is returned
600 * in a string correctly, but calling append()
601 * without a length will result in only the string
602 * up to a \0 being output here.
603 */
604 string raw_data(record.after_value(x));
605 destination.append(raw_data.c_str(), raw_data.size());
606 }
607 else
608 {
609 string tmp(record.after_value(x));
610 escapeEmbeddedQuotes(tmp);
611 destination.append(tmp);
612 }
613 }
614
615 if (should_quote_field_value)
616 destination.push_back('\'');
617 }
618
619 size_t num_key_fields= header.key_field_metadata_size();
620
621 destination.append(" WHERE ", 7);
622 for (x= 0; x < num_key_fields; ++x)
623 {
624 const FieldMetadata &field_metadata= header.key_field_metadata(x);
625
626 if (x != 0)
627 destination.append(" AND ", 5); /* Always AND condition with a multi-column PK */
628
629 destination.push_back(quoted_identifier);
630 destination.append(field_metadata.name());
631 destination.push_back(quoted_identifier);
632
633 destination.push_back('=');
634
635 should_quote_field_value= shouldQuoteFieldValue(field_metadata.type());
636
637 if (should_quote_field_value)
638 destination.push_back('\'');
639
640 if (field_metadata.type() == Table::Field::BLOB)
641 {
642 /*
643 * We do this here because BLOB data is returned
644 * in a string correctly, but calling append()
645 * without a length will result in only the string
646 * up to a \0 being output here.
647 */
648 string raw_data(record.key_value(x));
649 destination.append(raw_data.c_str(), raw_data.size());
650 }
651 else
652 {
653 destination.append(record.key_value(x));
654 }
655
656 if (should_quote_field_value)
657 destination.push_back('\'');
658 }
659
660 return error;
661}
662
663enum TransformSqlError
664transformDeleteHeaderToSql(const DeleteHeader &header,
665 string &destination,
666 enum TransformSqlVariant sql_variant)
667{
668 char quoted_identifier= '`';
669 if (sql_variant == ANSI)
670 quoted_identifier= '"';
671
672 destination.assign("DELETE FROM ", 12);
673 destination.push_back(quoted_identifier);
674 destination.append(header.table_metadata().schema_name());
675 destination.push_back(quoted_identifier);
676 destination.push_back('.');
677 destination.push_back(quoted_identifier);
678 destination.append(header.table_metadata().table_name());
679 destination.push_back(quoted_identifier);
680
681 return NONE;
682}
683
684enum TransformSqlError
685transformDeleteRecordToSql(const DeleteHeader &header,
686 const DeleteRecord &record,
687 string &destination,
688 enum TransformSqlVariant sql_variant)
689{
691 destination,
692 sql_variant);
693 char quoted_identifier= '`';
694 if (sql_variant == ANSI)
695 quoted_identifier= '"';
696
697 /* Add WHERE clause to SQL string... */
698 uint32_t num_key_fields= header.key_field_metadata_size();
699 uint32_t x;
700 bool should_quote_field_value= false;
701
702 destination.append(" WHERE ", 7);
703 for (x= 0; x < num_key_fields; ++x)
704 {
705 const FieldMetadata &field_metadata= header.key_field_metadata(x);
706
707 if (x != 0)
708 destination.append(" AND ", 5); /* Always AND condition with a multi-column PK */
709
710 destination.push_back(quoted_identifier);
711 destination.append(field_metadata.name());
712 destination.push_back(quoted_identifier);
713
714 destination.push_back('=');
715
716 should_quote_field_value= shouldQuoteFieldValue(field_metadata.type());
717
718 if (should_quote_field_value)
719 destination.push_back('\'');
720
721 if (field_metadata.type() == Table::Field::BLOB)
722 {
723 /*
724 * We do this here because BLOB data is returned
725 * in a string correctly, but calling append()
726 * without a length will result in only the string
727 * up to a \0 being output here.
728 */
729 string raw_data(record.key_value(x));
730 destination.append(raw_data.c_str(), raw_data.size());
731 }
732 else
733 {
734 string tmp(record.key_value(x));
735 escapeEmbeddedQuotes(tmp);
736 destination.append(tmp);
737 }
738
739 if (should_quote_field_value)
740 destination.push_back('\'');
741 }
742
743 return error;
744}
745
746enum TransformSqlError
747transformDeleteStatementToSql(const DeleteHeader &header,
748 const DeleteData &data,
749 string &destination,
750 enum TransformSqlVariant sql_variant)
751{
753 destination,
754 sql_variant);
755 char quoted_identifier= '`';
756 if (sql_variant == ANSI)
757 quoted_identifier= '"';
758
759 /* Add WHERE clause to SQL string... */
760 uint32_t num_key_fields= header.key_field_metadata_size();
761 uint32_t num_key_records= data.record_size();
762 uint32_t x, y;
763 bool should_quote_field_value= false;
764
765 destination.append(" WHERE ", 7);
766 for (x= 0; x < num_key_records; ++x)
767 {
768 if (x != 0)
769 destination.append(" OR ", 4); /* Always OR condition for multiple key records */
770
771 if (num_key_fields > 1)
772 destination.push_back('(');
773
774 for (y= 0; y < num_key_fields; ++y)
775 {
776 const FieldMetadata &field_metadata= header.key_field_metadata(y);
777
778 if (y != 0)
779 destination.append(" AND ", 5); /* Always AND condition with a multi-column PK */
780
781 destination.push_back(quoted_identifier);
782 destination.append(field_metadata.name());
783 destination.push_back(quoted_identifier);
784
785 destination.push_back('=');
786
787 should_quote_field_value= shouldQuoteFieldValue(field_metadata.type());
788
789 if (should_quote_field_value)
790 destination.push_back('\'');
791
792 if (field_metadata.type() == Table::Field::BLOB)
793 {
794 /*
795 * We do this here because BLOB data is returned
796 * in a string correctly, but calling append()
797 * without a length will result in only the string
798 * up to a \0 being output here.
799 */
800 string raw_data(data.record(x).key_value(y));
801 destination.append(raw_data.c_str(), raw_data.size());
802 }
803 else
804 {
805 string tmp(data.record(x).key_value(y));
806 escapeEmbeddedQuotes(tmp);
807 destination.append(tmp);
808 }
809
810 if (should_quote_field_value)
811 destination.push_back('\'');
812 }
813 if (num_key_fields > 1)
814 destination.push_back(')');
815 }
816 return error;
817}
818
819enum TransformSqlError
820transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement,
821 string &destination,
822 enum TransformSqlVariant sql_variant)
823{
824 const Schema &before= statement.before();
825 const Schema &after= statement.after();
826
827 /* Make sure we are given the before and after for the same object */
828 if (before.uuid() != after.uuid())
829 return UUID_MISMATCH;
830
831 char quoted_identifier= '`';
832 if (sql_variant == ANSI)
833 quoted_identifier= '"';
834
835 destination.append("ALTER SCHEMA ");
836 destination.push_back(quoted_identifier);
837 destination.append(before.name());
838 destination.push_back(quoted_identifier);
839
840 /*
841 * Diff our schemas. Currently, only collation can change so a
842 * diff of the two structures is not really necessary.
843 */
844 destination.append(" COLLATE = ");
845 destination.append(after.collation());
846
847 return NONE;
848}
849
850enum TransformSqlError
851transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
852 string &destination,
853 enum TransformSqlVariant sql_variant)
854{
855 char quoted_identifier= '`';
856 if (sql_variant == ANSI)
857 quoted_identifier= '"';
858
859 destination.append("DROP SCHEMA ", 12);
860 destination.push_back(quoted_identifier);
861 destination.append(statement.schema_name());
862 destination.push_back(quoted_identifier);
863
864 return NONE;
865}
866
867enum TransformSqlError
868transformCreateSchemaStatementToSql(const CreateSchemaStatement &statement,
869 string &destination,
870 enum TransformSqlVariant sql_variant)
871{
872 char quoted_identifier= '`';
873 if (sql_variant == ANSI)
874 quoted_identifier= '"';
875
876 const Schema &schema= statement.schema();
877
878 destination.append("CREATE SCHEMA ");
879 destination.push_back(quoted_identifier);
880 destination.append(schema.name());
881 destination.push_back(quoted_identifier);
882
883 if (schema.has_collation())
884 {
885 destination.append(" COLLATE ");
886 destination.append(schema.collation());
887 }
888
889 if (not message::is_replicated(schema))
890 {
891 destination.append(" REPLICATE = FALSE");
892 }
893
894 if (message::has_definer(schema))
895 {
896 destination.append(" DEFINER ");
897 destination.push_back('\'');
898 destination.append(message::definer(schema));
899 destination.push_back('\'');
900 }
901
902 return NONE;
903}
904
905enum TransformSqlError
906transformDropTableStatementToSql(const DropTableStatement &statement,
907 string &destination,
908 enum TransformSqlVariant sql_variant)
909{
910 char quoted_identifier= '`';
911 if (sql_variant == ANSI)
912 quoted_identifier= '"';
913
914 const TableMetadata &table_metadata= statement.table_metadata();
915
916 destination.append("DROP TABLE ");
917
918 /* Add the IF EXISTS clause if necessary */
919 if (statement.has_if_exists_clause() &&
920 statement.if_exists_clause() == true)
921 {
922 destination.append("IF EXISTS ");
923 }
924
925 destination.push_back(quoted_identifier);
926 destination.append(table_metadata.schema_name());
927 destination.push_back(quoted_identifier);
928 destination.push_back('.');
929 destination.push_back(quoted_identifier);
930 destination.append(table_metadata.table_name());
931 destination.push_back(quoted_identifier);
932
933 return NONE;
934}
935
936enum TransformSqlError
937transformTruncateTableStatementToSql(const TruncateTableStatement &statement,
938 string &destination,
939 enum TransformSqlVariant sql_variant)
940{
941 char quoted_identifier= '`';
942 if (sql_variant == ANSI)
943 quoted_identifier= '"';
944
945 const TableMetadata &table_metadata= statement.table_metadata();
946
947 destination.append("TRUNCATE TABLE ");
948 destination.push_back(quoted_identifier);
949 destination.append(table_metadata.schema_name());
950 destination.push_back(quoted_identifier);
951 destination.push_back('.');
952 destination.push_back(quoted_identifier);
953 destination.append(table_metadata.table_name());
954 destination.push_back(quoted_identifier);
955
956 return NONE;
957}
958
959enum TransformSqlError
960transformSetVariableStatementToSql(const SetVariableStatement &statement,
961 string &destination,
962 enum TransformSqlVariant sql_variant)
963{
964 (void) sql_variant;
965 const FieldMetadata &variable_metadata= statement.variable_metadata();
966 bool should_quote_field_value= shouldQuoteFieldValue(variable_metadata.type());
967
968 destination.append("SET GLOBAL "); /* Only global variables are replicated */
969 destination.append(variable_metadata.name());
970 destination.push_back('=');
971
972 if (should_quote_field_value)
973 destination.push_back('\'');
974
975 destination.append(statement.variable_value());
976
977 if (should_quote_field_value)
978 destination.push_back('\'');
979
980 return NONE;
981}
982
983enum TransformSqlError
984transformCreateTableStatementToSql(const CreateTableStatement &statement,
985 string &destination,
986 enum TransformSqlVariant sql_variant)
987{
988 return transformTableDefinitionToSql(statement.table(), destination, sql_variant);
989}
990
991enum TransformSqlError
993 string &destination,
994 enum TransformSqlVariant sql_variant, bool with_schema)
995{
996 char quoted_identifier= '`';
997 if (sql_variant == ANSI)
998 quoted_identifier= '"';
999
1000 destination.append("CREATE ");
1001
1002 if (table.type() == Table::TEMPORARY)
1003 destination.append("TEMPORARY ");
1004
1005 destination.append("TABLE ");
1006 if (with_schema)
1007 {
1008 append_escaped_string(&destination, table.schema(), quoted_identifier);
1009 destination.push_back('.');
1010 }
1011 append_escaped_string(&destination, table.name(), quoted_identifier);
1012 destination.append(" (\n");
1013
1014 enum TransformSqlError result= NONE;
1015 size_t num_fields= table.field_size();
1016 for (size_t x= 0; x < num_fields; ++x)
1017 {
1018 const Table::Field &field= table.field(x);
1019
1020 if (x != 0)
1021 destination.append(",\n");
1022
1023 destination.append(" ");
1024
1025 result= transformFieldDefinitionToSql(field, destination, sql_variant);
1026
1027 if (result != NONE)
1028 return result;
1029 }
1030
1031 size_t num_indexes= table.indexes_size();
1032
1033 if (num_indexes > 0)
1034 destination.append(",\n");
1035
1036 for (size_t x= 0; x < num_indexes; ++x)
1037 {
1038 const message::Table::Index &index= table.indexes(x);
1039
1040 if (x != 0)
1041 destination.append(",\n");
1042
1043 result= transformIndexDefinitionToSql(index, table, destination, sql_variant);
1044
1045 if (result != NONE)
1046 return result;
1047 }
1048
1049 size_t num_foreign_keys= table.fk_constraint_size();
1050
1051 if (num_foreign_keys > 0)
1052 destination.append(",\n");
1053
1054 for (size_t x= 0; x < num_foreign_keys; ++x)
1055 {
1056 const message::Table::ForeignKeyConstraint &fkey= table.fk_constraint(x);
1057
1058 if (x != 0)
1059 destination.append(",\n");
1060
1061 result= transformForeignKeyConstraintDefinitionToSql(fkey, table, destination, sql_variant);
1062
1063 if (result != NONE)
1064 return result;
1065 }
1066
1067 destination.append("\n)");
1068
1069 /* Add ENGINE = " clause */
1070 if (table.has_engine())
1071 {
1072 destination.append(" ENGINE=");
1073 destination.append(table.engine().name());
1074
1075 size_t num_engine_options= table.engine().options_size();
1076 if (num_engine_options > 0)
1077 destination.append(" ", 1);
1078 for (size_t x= 0; x < num_engine_options; ++x)
1079 {
1080 const Engine::Option &option= table.engine().options(x);
1081 destination.append(option.name());
1082 destination.append("='");
1083 destination.append(option.state());
1084 destination.append("'");
1085 if (x != num_engine_options-1)
1086 {
1087 destination.append(", ");
1088 }
1089 }
1090 }
1091
1092 if (table.has_options())
1093 (void) transformTableOptionsToSql(table.options(), destination, sql_variant);
1094
1095 if (not message::is_replicated(table))
1096 {
1097 destination.append(" REPLICATE = FALSE");
1098 }
1099
1100 if (message::has_definer(table))
1101 {
1102 destination.append(" DEFINER ");
1103 destination.push_back('\'');
1104 destination.append(message::definer(table));
1105 destination.push_back('\'');
1106 }
1107
1108 return NONE;
1109}
1110
1111enum TransformSqlError
1112transformTableOptionsToSql(const Table::TableOptions &options,
1113 string &destination,
1114 enum TransformSqlVariant sql_variant)
1115{
1116 if (sql_variant == ANSI)
1117 return NONE; /* ANSI does not support table options... */
1118
1119 if (options.has_comment())
1120 {
1121 destination.append(" COMMENT=");
1122 append_escaped_string(&destination, options.comment());
1123 }
1124
1125 if (options.has_collation())
1126 {
1127 destination.append(" COLLATE = ");
1128 destination.append(options.collation());
1129 }
1130
1131 if (options.has_data_file_name())
1132 {
1133 destination.append("\nDATA_FILE_NAME = '");
1134 destination.append(options.data_file_name());
1135 destination.push_back('\'');
1136 }
1137
1138 if (options.has_index_file_name())
1139 {
1140 destination.append("\nINDEX_FILE_NAME = '");
1141 destination.append(options.index_file_name());
1142 destination.push_back('\'');
1143 }
1144
1145 if (options.has_max_rows())
1146 {
1147 destination.append("\nMAX_ROWS = ");
1148 destination.append(boost::lexical_cast<string>(options.max_rows()));
1149 }
1150
1151 if (options.has_min_rows())
1152 {
1153 destination.append("\nMIN_ROWS = ");
1154 destination.append(boost::lexical_cast<string>(options.min_rows()));
1155 }
1156
1157 if (options.has_user_set_auto_increment_value()
1158 && options.has_auto_increment_value())
1159 {
1160 destination.append(" AUTO_INCREMENT=");
1161 destination.append(boost::lexical_cast<string>(options.auto_increment_value()));
1162 }
1163
1164 if (options.has_avg_row_length())
1165 {
1166 destination.append("\nAVG_ROW_LENGTH = ");
1167 destination.append(boost::lexical_cast<string>(options.avg_row_length()));
1168 }
1169
1170 if (options.has_checksum() && options.checksum())
1171 destination.append("\nCHECKSUM = TRUE");
1172
1173 if (options.has_page_checksum() && options.page_checksum())
1174 destination.append("\nPAGE_CHECKSUM = TRUE");
1175
1176 return NONE;
1177}
1178
1179enum TransformSqlError
1180transformIndexDefinitionToSql(const Table::Index &index,
1181 const Table &table,
1182 string &destination,
1183 enum TransformSqlVariant sql_variant)
1184{
1185 char quoted_identifier= '`';
1186 if (sql_variant == ANSI)
1187 quoted_identifier= '"';
1188
1189 destination.append(" ", 2);
1190
1191 if (index.is_primary())
1192 destination.append("PRIMARY ");
1193 else if (index.is_unique())
1194 destination.append("UNIQUE ");
1195
1196 destination.append("KEY ", 4);
1197 if (! (index.is_primary() && index.name().compare("PRIMARY")==0))
1198 {
1199 destination.push_back(quoted_identifier);
1200 destination.append(index.name());
1201 destination.push_back(quoted_identifier);
1202 destination.append(" (", 2);
1203 }
1204 else
1205 destination.append("(", 1);
1206
1207 size_t num_parts= index.index_part_size();
1208 for (size_t x= 0; x < num_parts; ++x)
1209 {
1210 const Table::Index::IndexPart &part= index.index_part(x);
1211 const Table::Field &field= table.field(part.fieldnr());
1212
1213 if (x != 0)
1214 destination.push_back(',');
1215
1216 destination.push_back(quoted_identifier);
1217 destination.append(field.name());
1218 destination.push_back(quoted_identifier);
1219
1220 /*
1221 * If the index part's field type is VARCHAR or TEXT
1222 * then check for a prefix length then is different
1223 * from the field's full length...
1224 */
1225 if (field.type() == Table::Field::VARCHAR ||
1226 field.type() == Table::Field::BLOB)
1227 {
1228 if (part.has_compare_length())
1229 {
1230 if (part.compare_length() != field.string_options().length())
1231 {
1232 destination.push_back('(');
1233 destination.append(boost::lexical_cast<string>(part.compare_length()));
1234 destination.push_back(')');
1235 }
1236 }
1237 }
1238 }
1239 destination.push_back(')');
1240
1241 switch (index.type())
1242 {
1243 case Table::Index::UNKNOWN_INDEX:
1244 break;
1245 case Table::Index::BTREE:
1246 destination.append(" USING BTREE");
1247 break;
1248 case Table::Index::RTREE:
1249 destination.append(" USING RTREE");
1250 break;
1251 case Table::Index::HASH:
1252 destination.append(" USING HASH");
1253 break;
1254 case Table::Index::FULLTEXT:
1255 destination.append(" USING FULLTEXT");
1256 break;
1257 case Table::Index::LSMTREE:
1258 destination.append(" USING LSMTREE");
1259 break;
1260 }
1261
1262 if (index.has_comment())
1263 {
1264 destination.append(" COMMENT ");
1265 append_escaped_string(&destination, index.comment());
1266 }
1267
1268 return NONE;
1269}
1270
1271static void transformForeignKeyOptionToSql(Table::ForeignKeyConstraint::ForeignKeyOption opt, string &destination)
1272{
1273 switch (opt)
1274 {
1275 case Table::ForeignKeyConstraint::OPTION_RESTRICT:
1276 destination.append("RESTRICT");
1277 break;
1278 case Table::ForeignKeyConstraint::OPTION_CASCADE:
1279 destination.append("CASCADE");
1280 break;
1281 case Table::ForeignKeyConstraint::OPTION_SET_NULL:
1282 destination.append("SET NULL");
1283 break;
1284 case Table::ForeignKeyConstraint::OPTION_UNDEF:
1285 case Table::ForeignKeyConstraint::OPTION_NO_ACTION:
1286 destination.append("NO ACTION");
1287 break;
1288 case Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
1289 destination.append("SET DEFAULT");
1290 break;
1291 }
1292}
1293
1295transformForeignKeyConstraintDefinitionToSql(const Table::ForeignKeyConstraint &fkey,
1296 const Table &,
1297 string &destination,
1298 enum TransformSqlVariant sql_variant)
1299{
1300 char quoted_identifier= '`';
1301 if (sql_variant == ANSI)
1302 quoted_identifier= '"';
1303
1304 destination.append(" ");
1305
1306 if (fkey.has_name())
1307 {
1308 destination.append("CONSTRAINT ");
1309 append_escaped_string(&destination, fkey.name(), quoted_identifier);
1310 destination.append(" ", 1);
1311 }
1312
1313 destination.append("FOREIGN KEY (");
1314
1315 for (ssize_t x= 0; x < fkey.column_names_size(); ++x)
1316 {
1317 if (x != 0)
1318 destination.append(", ");
1319
1320 append_escaped_string(&destination, fkey.column_names(x),
1321 quoted_identifier);
1322 }
1323
1324 destination.append(") REFERENCES ");
1325
1326 append_escaped_string(&destination, fkey.references_table_name(),
1327 quoted_identifier);
1328 destination.append(" (");
1329
1330 for (ssize_t x= 0; x < fkey.references_columns_size(); ++x)
1331 {
1332 if (x != 0)
1333 destination.append(", ");
1334
1335 append_escaped_string(&destination, fkey.references_columns(x),
1336 quoted_identifier);
1337 }
1338
1339 destination.push_back(')');
1340
1341 if (fkey.has_update_option() and fkey.update_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1342 {
1343 destination.append(" ON UPDATE ");
1344 transformForeignKeyOptionToSql(fkey.update_option(), destination);
1345 }
1346
1347 if (fkey.has_delete_option() and fkey.delete_option() != Table::ForeignKeyConstraint::OPTION_UNDEF)
1348 {
1349 destination.append(" ON DELETE ");
1350 transformForeignKeyOptionToSql(fkey.delete_option(), destination);
1351 }
1352
1353 return NONE;
1354}
1355
1356enum TransformSqlError
1357transformFieldDefinitionToSql(const Table::Field &field,
1358 string &destination,
1359 enum TransformSqlVariant sql_variant)
1360{
1361 char quoted_identifier= '`';
1362 char quoted_default;
1363
1364 if (sql_variant == ANSI)
1365 quoted_identifier= '"';
1366
1367 if (sql_variant == DRIZZLE)
1368 quoted_default= '\'';
1369 else
1370 quoted_default= quoted_identifier;
1371
1372 append_escaped_string(&destination, field.name(), quoted_identifier);
1373
1374 Table::Field::FieldType field_type= field.type();
1375
1376 switch (field_type)
1377 {
1378 case Table::Field::DOUBLE:
1379 destination.append(" DOUBLE");
1380 if (field.has_numeric_options()
1381 && field.numeric_options().has_precision())
1382 {
1383 stringstream ss;
1384 ss << "(" << field.numeric_options().precision() << ",";
1385 ss << field.numeric_options().scale() << ")";
1386 destination.append(ss.str());
1387 }
1388 break;
1389 case Table::Field::VARCHAR:
1390 {
1391 if (field.string_options().has_collation()
1392 && field.string_options().collation().compare("binary") == 0)
1393 destination.append(" VARBINARY(");
1394 else
1395 destination.append(" VARCHAR(");
1396
1397 destination.append(boost::lexical_cast<string>(field.string_options().length()));
1398 destination.append(")");
1399 }
1400 break;
1401 case Table::Field::BLOB:
1402 {
1403 if (field.string_options().has_collation()
1404 && field.string_options().collation().compare("binary") == 0)
1405 destination.append(" BLOB");
1406 else
1407 destination.append(" TEXT");
1408 }
1409 break;
1410 case Table::Field::ENUM:
1411 {
1412 size_t num_field_values= field.enumeration_values().field_value_size();
1413 destination.append(" ENUM(");
1414 for (size_t x= 0; x < num_field_values; ++x)
1415 {
1416 const string &type= field.enumeration_values().field_value(x);
1417
1418 if (x != 0)
1419 destination.push_back(',');
1420
1421 destination.push_back('\'');
1422 destination.append(type);
1423 destination.push_back('\'');
1424 }
1425 destination.push_back(')');
1426 break;
1427 }
1428 case Table::Field::UUID:
1429 destination.append(" UUID");
1430 break;
1431 case Table::Field::IPV6:
1432 destination.append(" IPV6");
1433 break;
1434 case Table::Field::BOOLEAN:
1435 destination.append(" BOOLEAN");
1436 break;
1437 case Table::Field::INTEGER:
1438 destination.append(" INT");
1439 break;
1440 case Table::Field::BIGINT:
1441 if (field.has_constraints() and
1442 field.constraints().is_unsigned())
1443 {
1444 destination.append(" BIGINT UNSIGNED");
1445 }
1446 else
1447 {
1448 destination.append(" BIGINT");
1449 }
1450 break;
1451 case Table::Field::DECIMAL:
1452 {
1453 destination.append(" DECIMAL(");
1454 stringstream ss;
1455 ss << field.numeric_options().precision() << ",";
1456 ss << field.numeric_options().scale() << ")";
1457 destination.append(ss.str());
1458 }
1459 break;
1460 case Table::Field::DATE:
1461 destination.append(" DATE");
1462 break;
1463
1464 case Table::Field::EPOCH:
1465 if (field.time_options().microseconds())
1466 {
1467 destination.append(" TIMESTAMP(6)");
1468 }
1469 else
1470 {
1471 destination.append(" TIMESTAMP");
1472 }
1473 break;
1474
1475 case Table::Field::DATETIME:
1476 destination.append(" DATETIME");
1477 break;
1478 case Table::Field::TIME:
1479 destination.append(" TIME");
1480 break;
1481 }
1482
1483 if (field.type() == Table::Field::BLOB ||
1484 field.type() == Table::Field::VARCHAR)
1485 {
1486 if (field.string_options().has_collation()
1487 && field.string_options().collation().compare("binary"))
1488 {
1489 destination.append(" COLLATE ");
1490 destination.append(field.string_options().collation());
1491 }
1492 }
1493
1494 if (field.has_constraints() and field.constraints().is_unique())
1495 {
1496 destination.append(" UNIQUE");
1497 }
1498
1499 if (field.has_constraints() && field.constraints().is_notnull())
1500 {
1501 destination.append(" NOT NULL");
1502 }
1503 else if (field.type() == Table::Field::EPOCH)
1504 {
1505 destination.append(" NULL");
1506 }
1507
1508 if (field.type() == Table::Field::INTEGER ||
1509 field.type() == Table::Field::BIGINT)
1510 {
1511 /* AUTO_INCREMENT must be after NOT NULL */
1512 if (field.has_numeric_options() &&
1513 field.numeric_options().is_autoincrement())
1514 {
1515 destination.append(" AUTO_INCREMENT");
1516 }
1517 }
1518
1519 if (field.options().has_default_value())
1520 {
1521 destination.append(" DEFAULT ");
1522 append_escaped_string(&destination, field.options().default_value());
1523 }
1524 else if (field.options().has_default_expression())
1525 {
1526 destination.append(" DEFAULT ");
1527 destination.append(field.options().default_expression());
1528 }
1529 else if (field.options().has_default_bin_value())
1530 {
1531 const string &v= field.options().default_bin_value();
1532 if (v.length() == 0)
1533 {
1534 destination.append(" DEFAULT ''");
1535 }
1536 else
1537 {
1538 destination.append(" DEFAULT 0x");
1539 for (size_t x= 0; x < v.length(); x++)
1540 {
1541 char hex[3];
1542 snprintf(hex, sizeof(hex), "%.2X", *(v.c_str() + x));
1543 destination.append(hex, 2);
1544 }
1545 }
1546 }
1547 else if (field.options().has_default_null()
1548 && field.options().default_null()
1549 && field.type() != Table::Field::BLOB)
1550 {
1551 destination.append(" DEFAULT NULL");
1552 }
1553
1554 if (field.has_options() && field.options().has_update_expression())
1555 {
1556 destination.append(" ON UPDATE ");
1557 destination.append(field.options().update_expression());
1558 }
1559
1560 if (field.has_comment())
1561 {
1562 destination.append(" COMMENT ");
1563 append_escaped_string(&destination, field.comment(), quoted_default);
1564 }
1565 return NONE;
1566}
1567
1568bool shouldQuoteFieldValue(Table::Field::FieldType in_type)
1569{
1570 switch (in_type)
1571 {
1572 case Table::Field::DOUBLE:
1573 case Table::Field::DECIMAL:
1574 case Table::Field::INTEGER:
1575 case Table::Field::BIGINT:
1576 return false;
1577 default:
1578 return true;
1579 }
1580}
1581
1582Table::Field::FieldType internalFieldTypeToFieldProtoType(enum enum_field_types type)
1583{
1584 switch (type) {
1585 case DRIZZLE_TYPE_LONG:
1586 return Table::Field::INTEGER;
1587 case DRIZZLE_TYPE_DOUBLE:
1588 return Table::Field::DOUBLE;
1589 case DRIZZLE_TYPE_NULL:
1590 assert(false); /* Not a user definable type */
1591 return Table::Field::INTEGER; /* unreachable */
1592 case DRIZZLE_TYPE_MICROTIME:
1593 case DRIZZLE_TYPE_TIMESTAMP:
1594 return Table::Field::EPOCH;
1595 case DRIZZLE_TYPE_LONGLONG:
1596 return Table::Field::BIGINT;
1597 case DRIZZLE_TYPE_DATETIME:
1598 return Table::Field::DATETIME;
1599 case DRIZZLE_TYPE_TIME:
1600 return Table::Field::TIME;
1601 case DRIZZLE_TYPE_DATE:
1602 return Table::Field::DATE;
1603 case DRIZZLE_TYPE_VARCHAR:
1604 return Table::Field::VARCHAR;
1605 case DRIZZLE_TYPE_DECIMAL:
1606 return Table::Field::DECIMAL;
1607 case DRIZZLE_TYPE_ENUM:
1608 return Table::Field::ENUM;
1609 case DRIZZLE_TYPE_BLOB:
1610 return Table::Field::BLOB;
1611 case DRIZZLE_TYPE_UUID:
1612 return Table::Field::UUID;
1613 case DRIZZLE_TYPE_BOOLEAN:
1614 return Table::Field::BOOLEAN;
1615 case DRIZZLE_TYPE_IPV6:
1616 return Table::Field::IPV6;
1617 }
1618
1619 assert(false);
1620 return Table::Field::INTEGER; /* unreachable */
1621}
1622
1623bool transactionContainsBulkSegment(const Transaction &transaction)
1624{
1625 size_t num_statements= transaction.statement_size();
1626 if (num_statements == 0)
1627 return false;
1628
1629 /*
1630 * Only INSERT, UPDATE, and DELETE statements can possibly
1631 * have bulk segments. So, we loop through the statements
1632 * checking for segment_id > 1 in those specific submessages.
1633 */
1634 size_t x;
1635 for (x= 0; x < num_statements; ++x)
1636 {
1637 const Statement &statement= transaction.statement(x);
1638 Statement::Type type= statement.type();
1639
1640 switch (type)
1641 {
1642 case Statement::INSERT:
1643 if (statement.insert_data().segment_id() > 1)
1644 return true;
1645 break;
1646 case Statement::UPDATE:
1647 if (statement.update_data().segment_id() > 1)
1648 return true;
1649 break;
1650 case Statement::DELETE:
1651 if (statement.delete_data().segment_id() > 1)
1652 return true;
1653 break;
1654 default:
1655 break;
1656 }
1657 }
1658 return false;
1659}
1660
1661} /* namespace message */
1662} /* namespace drizzled */
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.
STL namespace.
enum TransformSqlError transformSetVariableStatementToSql(const SetVariableStatement &statement, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformTableDefinitionToSql(const Table &table, string &destination, enum TransformSqlVariant sql_variant, bool with_schema)
enum TransformSqlError transformDeleteHeaderToSql(const DeleteHeader &header, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformForeignKeyConstraintDefinitionToSql(const Table::ForeignKeyConstraint &fkey, const Table &, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformTableOptionsToSql(const Table::TableOptions &options, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformFieldDefinitionToSql(const Table::Field &field, string &destination, enum TransformSqlVariant sql_variant)
bool transactionContainsBulkSegment(const Transaction &transaction)
enum TransformSqlError transformInsertHeaderToSql(const InsertHeader &header, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformUpdateHeaderToSql(const UpdateHeader &header, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformTruncateTableStatementToSql(const TruncateTableStatement &statement, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformCreateTableStatementToSql(const CreateTableStatement &statement, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformInsertStatementToSql(const InsertHeader &header, const InsertData &data, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformCreateSchemaStatementToSql(const CreateSchemaStatement &statement, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformDeleteStatementToSql(const DeleteHeader &header, const DeleteData &data, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformDeleteRecordToSql(const DeleteHeader &header, const DeleteRecord &record, string &destination, enum TransformSqlVariant sql_variant)
bool shouldQuoteFieldValue(Table::Field::FieldType in_type)
enum TransformSqlError transformIndexDefinitionToSql(const Table::Index &index, const Table &table, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformDropTableStatementToSql(const DropTableStatement &statement, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformUpdateRecordToSql(const UpdateHeader &header, const UpdateRecord &record, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformInsertRecordToSql(const InsertHeader &header, const InsertRecord &record, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformDropSchemaStatementToSql(const DropSchemaStatement &statement, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement, string &destination, enum TransformSqlVariant sql_variant)
enum TransformSqlError transformStatementToSql(const Statement &source, vector< string > &sql_strings, enum TransformSqlVariant sql_variant, bool already_in_transaction)