1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
5
* Copyright (C) 2010 Jay Pipes <jaypipes@gmail.com>
9
* Jay Pipes <jaypipes@gmail.com>
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.
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.
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
28
* Declarations of various routines that can be used to convert
29
* Transaction messages to other formats, including SQL statements.
32
#ifndef DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
33
#define DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
35
#include <drizzled/message/table.pb.h>
39
#include "drizzled/common.h"
45
/* some forward declarations */
57
class DropTableStatement;
58
class CreateTableStatement;
59
class TruncateTableStatement;
60
class CreateSchemaStatement;
61
class DropSchemaStatement;
62
class AlterSchemaStatement;
63
class SetVariableStatement;
65
/** A Variation of SQL to be output during transformation */
66
enum TransformSqlVariant
74
/** Error codes which can happen during tranformations */
75
enum TransformSqlError
78
MISSING_HEADER= 1, /* A data segment without a header segment was found */
79
MISSING_DATA= 2, /* A header segment without a data segment was found */
84
* This function looks at the Statement
85
* message and appends one or more correctly-formatted SQL
86
* strings to the supplied vector of strings.
88
* @param Statement message to transform
89
* @param Vector of strings to append SQL statements to
90
* @param Variation of SQL to generate
93
* NONE if successful transformation
95
* Error code (see enum TransformSqlError definition) if failure
97
enum TransformSqlError
98
transformStatementToSql(const Statement &source,
99
std::vector<std::string> &sql_strings,
100
enum TransformSqlVariant sql_variant= DRIZZLE,
101
bool already_in_transaction= false);
104
* This function looks at a supplied InsertHeader
105
* and InsertData message and constructs a correctly-formatted SQL
106
* statement to the supplied destination string.
110
* This function is used when you want to construct a <strong>
111
* single SQL statement</strong> from an entire InsertHeader and
112
* InsertData message. If there are many records in the InsertData
113
* message, the SQL statement will be a multi-value INSERT statement.
115
* @param InsertHeader message to transform
116
* @param InsertData message to transform
117
* @param Destination string to append SQL to
118
* @param Variation of SQL to generate
121
* NONE if successful transformation
123
* Error code (see enum TransformSqlError definition) if failure
125
enum TransformSqlError
126
transformInsertStatementToSql(const InsertHeader &header,
127
const InsertData &data,
128
std::string &destination,
129
enum TransformSqlVariant sql_variant= DRIZZLE);
132
* This function looks at a supplied InsertHeader
133
* and a single InsertRecord message and constructs a correctly-formatted
134
* SQL statement to the supplied destination string.
136
* @param InsertHeader message to transform
137
* @param InsertRecord message to transform
138
* @param Destination string to append SQL to
139
* @param Variation of SQL to generate
142
* NONE if successful transformation
144
* Error code (see enum TransformSqlError definition) if failure
146
enum TransformSqlError
147
transformInsertRecordToSql(const InsertHeader &header,
148
const InsertRecord &record,
149
std::string &destination,
150
enum TransformSqlVariant sql_variant= DRIZZLE);
153
* Helper function to construct the header portion of an INSERT
154
* SQL statement from an InsertHeader message.
156
* @param InsertHeader message to transform
157
* @param Destination string to append SQL to
158
* @param Variation of SQL to generate
161
* NONE if successful transformation
163
* Error code (see enum TransformSqlError definition) if failure
165
enum TransformSqlError
166
transformInsertHeaderToSql(const InsertHeader &header,
167
std::string &destination,
168
enum TransformSqlVariant sql_variant= DRIZZLE);
171
* Helper function to construct the header portion of an UPDATE
172
* SQL statement from an UpdateHeader message.
174
* @param UpdateHeader message to transform
175
* @param Destination string to append SQL to
176
* @param Variation of SQL to generate
179
* NONE if successful transformation
181
* Error code (see enum TransformSqlError definition) if failure
183
enum TransformSqlError
184
transformUpdateHeaderToSql(const UpdateHeader &header,
185
std::string &destination,
186
enum TransformSqlVariant sql_variant= DRIZZLE);
189
* This function looks at a supplied UpdateHeader
190
* and a single UpdateRecord message and constructs a correctly-formatted
191
* SQL statement to the supplied destination string.
193
* @param UpdateHeader message to transform
194
* @param UpdateRecord message to transform
195
* @param Destination string to append SQL to
196
* @param Variation of SQL to generate
199
* NONE if successful transformation
201
* Error code (see enum TransformSqlError definition) if failure
203
enum TransformSqlError
204
transformUpdateRecordToSql(const UpdateHeader &header,
205
const UpdateRecord &record,
206
std::string &destination,
207
enum TransformSqlVariant sql_variant= DRIZZLE);
210
* This function looks at a supplied DeleteHeader
211
* and DeleteData message and constructs a correctly-formatted SQL
212
* statement to the supplied destination string.
216
* This function constructs a <strong>single SQL statement</strong>
217
* for all keys in the DeleteData message.
219
* @param DeleteHeader message to transform
220
* @param DeleteData message to transform
221
* @param Destination string to append SQL to
222
* @param Variation of SQL to generate
225
* NONE if successful transformation
227
* Error code (see enum TransformSqlError definition) if failure
229
enum TransformSqlError
230
transformDeleteStatementToSql(const DeleteHeader &header,
231
const DeleteData &data,
232
std::string &destination,
233
enum TransformSqlVariant sql_variant= DRIZZLE);
236
* This function looks at a supplied DeleteHeader
237
* and a single DeleteRecord message and constructs a correctly-formatted
238
* SQL statement to the supplied destination string.
240
* @param DeleteHeader message to transform
241
* @param DeleteRecord message to transform
242
* @param Destination string to append SQL to
243
* @param Variation of SQL to generate
246
* NONE if successful transformation
248
* Error code (see enum TransformSqlError definition) if failure
250
enum TransformSqlError
251
transformDeleteRecordToSql(const DeleteHeader &header,
252
const DeleteRecord &record,
253
std::string &destination,
254
enum TransformSqlVariant sql_variant= DRIZZLE);
257
* Helper function to construct the header portion of a DELETE
258
* SQL statement from an DeleteHeader message.
260
* @param DeleteHeader message to transform
261
* @param Destination string to append SQL to
262
* @param Variation of SQL to generate
265
* NONE if successful transformation
267
* Error code (see enum TransformSqlError definition) if failure
269
enum TransformSqlError
270
transformDeleteHeaderToSql(const DeleteHeader &header,
271
std::string &destination,
272
enum TransformSqlVariant sql_variant= DRIZZLE);
275
* This function looks at a supplied DropTableStatement
276
* and constructs a correctly-formatted SQL
277
* statement to the supplied destination string.
279
* @param DropTableStatement message to transform
280
* @param Destination string to append SQL to
281
* @param Variation of SQL to generate
284
* NONE if successful transformation
286
* Error code (see enum TransformSqlError definition) if failure
288
enum TransformSqlError
289
transformDropTableStatementToSql(const DropTableStatement &statement,
290
std::string &destination,
291
enum TransformSqlVariant sql_variant= DRIZZLE);
294
* This function looks at a supplied TruncateTableStatement
295
* and constructs a correctly-formatted SQL
296
* statement to the supplied destination string.
298
* @param TruncateTableStatement message to transform
299
* @param Destination string to append SQL to
300
* @param Variation of SQL to generate
303
* NONE if successful transformation
305
* Error code (see enum TransformSqlError definition) if failure
307
enum TransformSqlError
308
transformTruncateTableStatementToSql(const TruncateTableStatement &statement,
309
std::string &destination,
310
enum TransformSqlVariant sql_variant= DRIZZLE);
313
* This function looks at a supplied CreateSchemaStatement
314
* and constructs a correctly-formatted SQL
315
* statement to the supplied destination string.
317
* @param CreateSchemaStatement message to transform
318
* @param Destination string to append SQL to
319
* @param Variation of SQL to generate
322
* NONE if successful transformation
324
* Error code (see enum TransformSqlError definition) if failure
326
enum TransformSqlError
327
transformCreateSchemaStatementToSql(const CreateSchemaStatement &statement,
328
std::string &destination,
329
enum TransformSqlVariant sql_variant= DRIZZLE);
332
* This function looks at a supplied DropSchemaStatement
333
* and constructs a correctly-formatted SQL
334
* statement to the supplied destination string.
336
* @param DropSchemaStatement message to transform
337
* @param Destination string to append SQL to
338
* @param Variation of SQL to generate
341
* NONE if successful transformation
343
* Error code (see enum TransformSqlError definition) if failure
345
enum TransformSqlError
346
transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
347
std::string &destination,
348
enum TransformSqlVariant sql_variant= DRIZZLE);
351
* This function looks at a supplied AlterSchemaStatement
352
* and constructs a correctly-formatted SQL
353
* statement to the supplied destination string.
355
* @param AlterSchemaStatement message to transform
356
* @param Destination string to append SQL to
357
* @param Variation of SQL to generate
360
* NONE if successful transformation
362
* Error code (see enum TransformSqlError definition) if failure
364
enum TransformSqlError
365
transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement,
366
std::string &destination,
367
enum TransformSqlVariant sql_variant= DRIZZLE);
370
* This function looks at a supplied SetVariableStatement
371
* and constructs a correctly-formatted SQL
372
* statement to the supplied destination string.
374
* @param SetVariableStatement message to transform
375
* @param Destination string to append SQL to
376
* @param Variation of SQL to generate
379
* NONE if successful transformation
381
* Error code (see enum TransformSqlError definition) if failure
383
enum TransformSqlError
384
transformSetVariableStatementToSql(const SetVariableStatement &statement,
385
std::string &destination,
386
enum TransformSqlVariant sql_variant= DRIZZLE);
389
* Appends to supplied string an SQL expression
390
* containing the supplied CreateTableStatement's
391
* appropriate CREATE TABLE SQL statement.
393
enum TransformSqlError
394
transformCreateTableStatementToSql(const CreateTableStatement &statement,
395
std::string &destination,
396
enum TransformSqlVariant sql_variant= DRIZZLE);
399
* Appends to the supplied string an SQL expression
400
* representing the table for a CREATE TABLE expression.
402
* @param[in] Table message
403
* @param[out] String to append to
406
* NONE if successful transformation
408
* Error code (see enum TransformSqlError definition) if failure
410
enum TransformSqlError
411
transformTableDefinitionToSql(const Table &table,
412
std::string &destination,
413
enum TransformSqlVariant sql_variant= DRIZZLE,
414
bool with_schema= true);
417
* Appends to the supplied string an SQL expression
418
* representing the table's optional attributes.
422
* This function will eventually be a much simpler
423
* listing of key/value pairs.
425
* @param[in] TableOptions message
426
* @param[out] String to append to
429
* NONE if successful transformation
431
* Error code (see enum TransformSqlError definition) if failure
433
enum TransformSqlError
434
transformTableOptionsToSql(const Table::TableOptions &table_options,
435
std::string &destination,
436
enum TransformSqlVariant sql_variant= DRIZZLE);
439
* Appends to the supplied string an SQL expression
440
* representing the index's attributes. The built string
441
* corresponds to the SQL in a CREATE INDEX statement.
443
* @param[in] Index message
444
* @param[in] Table containing this index (used to get field names...)
445
* @param[out] String to append to
448
* NONE if successful transformation
450
* Error code (see enum TransformSqlError definition) if failure
452
enum TransformSqlError
453
transformIndexDefinitionToSql(const Table::Index &index,
455
std::string &destination,
456
enum TransformSqlVariant sql_variant= DRIZZLE);
459
* Appends to the supplied string an SQL expression
460
* representing the foreign key attributes. The built string
461
* corresponds to the SQL in a CREATE TABLE statement.
463
* @param[in] Foreign Key Constraint message
464
* @param[in] Table containing this foregin key (used to get field names...)
465
* @param[out] String to append to
468
* NONE if successful transformation
470
* Error code (see enum TransformSqlError definition) if failure
472
enum TransformSqlError
473
transformForeignKeyConstraintDefinitionToSql(const Table::ForeignKeyConstraint &fkey,
475
std::string &destination,
476
enum TransformSqlVariant sql_variant = DRIZZLE);
479
* Appends to the supplied string an SQL expression
480
* representing the field's attributes. The built string
481
* corresponds to the SQL in a CREATE TABLE statement.
483
* @param[in] Field message
484
* @param[out] String to append to
487
* NONE if successful transformation
489
* Error code (see enum TransformSqlError definition) if failure
491
enum TransformSqlError
492
transformFieldDefinitionToSql(const Table::Field &field,
493
std::string &destination,
494
enum TransformSqlVariant sql_variant= DRIZZLE);
497
* Returns true if the supplied message::Table::Field::FieldType
498
* should have its values quoted when modifying values.
500
* @param[in] type of field
502
bool shouldQuoteFieldValue(Table::Field::FieldType in_type);
504
drizzled::message::Table::Field::FieldType internalFieldTypeToFieldProtoType(enum enum_field_types type);
507
* Returns true if the transaction contains any Statement
508
* messages which are not end segments (i.e. a bulk statement has
509
* previously been sent to replicators).
511
* @param The transaction to check
513
bool transactionContainsBulkSegment(const Transaction &transaction);
515
} /* namespace message */
516
} /* namespace drizzled */
518
#endif /* DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H */