~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.h

  • Committer: Monty Taylor
  • Date: 2009-08-12 06:25:19 UTC
  • mto: (1114.1.1 innodb-plugin-merge)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: mordred@inaugust.com-20090812062519-cij02mrrunvnxblt
Tags: innodb-plugin-1.0.4
InnoDB Plugin 1.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <jaypipes@gmail.com>
6
 
 *
7
 
 *  Authors:
8
 
 *
9
 
 *    Jay Pipes <jaypipes@gmail.com>
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
 
 
25
 
/**
26
 
 * @file
27
 
 *
28
 
 * Declarations of various routines that can be used to convert
29
 
 * Transaction messages to other formats, including SQL statements.
30
 
 */
31
 
 
32
 
#ifndef DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
33
 
#define DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
34
 
 
35
 
#include <drizzled/message/table.pb.h>
36
 
#include <string>
37
 
#include <vector>
38
 
 
39
 
#include "drizzled/common.h"
40
 
 
41
 
namespace drizzled
42
 
{
43
 
namespace message
44
 
{
45
 
/* some forward declarations */
46
 
class Transaction;
47
 
class Statement;
48
 
class InsertHeader;
49
 
class InsertData;
50
 
class InsertRecord;
51
 
class UpdateHeader;
52
 
class UpdateData;
53
 
class UpdateRecord;
54
 
class DeleteHeader;
55
 
class DeleteData;
56
 
class DeleteRecord;
57
 
class DropTableStatement;
58
 
class CreateTableStatement;
59
 
class TruncateTableStatement;
60
 
class CreateSchemaStatement;
61
 
class DropSchemaStatement;
62
 
class AlterSchemaStatement;
63
 
class SetVariableStatement;
64
 
 
65
 
/** A Variation of SQL to be output during transformation */
66
 
enum TransformSqlVariant
67
 
{
68
 
  ANSI,
69
 
  MYSQL_4,
70
 
  MYSQL_5,
71
 
  DRIZZLE
72
 
};
73
 
 
74
 
/** Error codes which can happen during tranformations */
75
 
enum TransformSqlError
76
 
{
77
 
  NONE= 0,
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 */
80
 
  UUID_MISMATCH= 3
81
 
};
82
 
 
83
 
/**
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.
87
 
 *
88
 
 * @param Statement message to transform
89
 
 * @param Vector of strings to append SQL statements to
90
 
 * @param Variation of SQL to generate
91
 
 *
92
 
 * @retval
93
 
 *  NONE if successful transformation
94
 
 * @retval
95
 
 *  Error code (see enum TransformSqlError definition) if failure
96
 
 */
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);
102
 
 
103
 
/**
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.
107
 
 *
108
 
 * @note
109
 
 *
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.
114
 
 *
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
119
 
 *
120
 
 * @retval
121
 
 *  NONE if successful transformation
122
 
 * @retval
123
 
 *  Error code (see enum TransformSqlError definition) if failure
124
 
 */
125
 
enum TransformSqlError
126
 
transformInsertStatementToSql(const InsertHeader &header,
127
 
                              const InsertData &data,
128
 
                              std::string &destination,
129
 
                              enum TransformSqlVariant sql_variant= DRIZZLE);
130
 
 
131
 
/**
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.
135
 
 *
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
140
 
 *
141
 
 * @retval
142
 
 *  NONE if successful transformation
143
 
 * @retval
144
 
 *  Error code (see enum TransformSqlError definition) if failure
145
 
 */
146
 
enum TransformSqlError
147
 
transformInsertRecordToSql(const InsertHeader &header,
148
 
                           const InsertRecord &record,
149
 
                           std::string &destination,
150
 
                           enum TransformSqlVariant sql_variant= DRIZZLE);
151
 
 
152
 
/**
153
 
 * Helper function to construct the header portion of an INSERT
154
 
 * SQL statement from an InsertHeader message.
155
 
 *
156
 
 * @param InsertHeader message to transform
157
 
 * @param Destination string to append SQL to
158
 
 * @param Variation of SQL to generate
159
 
 *
160
 
 * @retval
161
 
 *  NONE if successful transformation
162
 
 * @retval
163
 
 *  Error code (see enum TransformSqlError definition) if failure
164
 
 */
165
 
enum TransformSqlError
166
 
transformInsertHeaderToSql(const InsertHeader &header,
167
 
                           std::string &destination,
168
 
                           enum TransformSqlVariant sql_variant= DRIZZLE);
169
 
 
170
 
/**
171
 
 * Helper function to construct the header portion of an UPDATE
172
 
 * SQL statement from an UpdateHeader message.
173
 
 *
174
 
 * @param UpdateHeader message to transform
175
 
 * @param Destination string to append SQL to
176
 
 * @param Variation of SQL to generate
177
 
 *
178
 
 * @retval
179
 
 *  NONE if successful transformation
180
 
 * @retval
181
 
 *  Error code (see enum TransformSqlError definition) if failure
182
 
 */
183
 
enum TransformSqlError
184
 
transformUpdateHeaderToSql(const UpdateHeader &header,
185
 
                           std::string &destination,
186
 
                           enum TransformSqlVariant sql_variant= DRIZZLE);
187
 
 
188
 
/**
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.
192
 
 *
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
197
 
 *
198
 
 * @retval
199
 
 *  NONE if successful transformation
200
 
 * @retval
201
 
 *  Error code (see enum TransformSqlError definition) if failure
202
 
 */
203
 
enum TransformSqlError
204
 
transformUpdateRecordToSql(const UpdateHeader &header,
205
 
                           const UpdateRecord &record,
206
 
                           std::string &destination,
207
 
                           enum TransformSqlVariant sql_variant= DRIZZLE);
208
 
 
209
 
/**
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.
213
 
 *
214
 
 * @note
215
 
 *
216
 
 * This function constructs a <strong>single SQL statement</strong>
217
 
 * for all keys in the DeleteData message.
218
 
 *
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
223
 
 *
224
 
 * @retval
225
 
 *  NONE if successful transformation
226
 
 * @retval
227
 
 *  Error code (see enum TransformSqlError definition) if failure
228
 
 */
229
 
enum TransformSqlError
230
 
transformDeleteStatementToSql(const DeleteHeader &header,
231
 
                              const DeleteData &data,
232
 
                              std::string &destination,
233
 
                              enum TransformSqlVariant sql_variant= DRIZZLE);
234
 
 
235
 
/**
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.
239
 
 *
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
244
 
 *
245
 
 * @retval
246
 
 *  NONE if successful transformation
247
 
 * @retval
248
 
 *  Error code (see enum TransformSqlError definition) if failure
249
 
 */
250
 
enum TransformSqlError
251
 
transformDeleteRecordToSql(const DeleteHeader &header,
252
 
                           const DeleteRecord &record,
253
 
                           std::string &destination,
254
 
                           enum TransformSqlVariant sql_variant= DRIZZLE);
255
 
 
256
 
/**
257
 
 * Helper function to construct the header portion of a DELETE
258
 
 * SQL statement from an DeleteHeader message.
259
 
 *
260
 
 * @param DeleteHeader message to transform
261
 
 * @param Destination string to append SQL to
262
 
 * @param Variation of SQL to generate
263
 
 *
264
 
 * @retval
265
 
 *  NONE if successful transformation
266
 
 * @retval
267
 
 *  Error code (see enum TransformSqlError definition) if failure
268
 
 */
269
 
enum TransformSqlError
270
 
transformDeleteHeaderToSql(const DeleteHeader &header,
271
 
                           std::string &destination,
272
 
                           enum TransformSqlVariant sql_variant= DRIZZLE);
273
 
 
274
 
/**
275
 
 * This function looks at a supplied DropTableStatement
276
 
 * and constructs a correctly-formatted SQL
277
 
 * statement to the supplied destination string.
278
 
 *
279
 
 * @param DropTableStatement message to transform
280
 
 * @param Destination string to append SQL to
281
 
 * @param Variation of SQL to generate
282
 
 *
283
 
 * @retval
284
 
 *  NONE if successful transformation
285
 
 * @retval
286
 
 *  Error code (see enum TransformSqlError definition) if failure
287
 
 */
288
 
enum TransformSqlError
289
 
transformDropTableStatementToSql(const DropTableStatement &statement,
290
 
                                  std::string &destination,
291
 
                                  enum TransformSqlVariant sql_variant= DRIZZLE);
292
 
 
293
 
/**
294
 
 * This function looks at a supplied TruncateTableStatement
295
 
 * and constructs a correctly-formatted SQL
296
 
 * statement to the supplied destination string.
297
 
 *
298
 
 * @param TruncateTableStatement message to transform
299
 
 * @param Destination string to append SQL to
300
 
 * @param Variation of SQL to generate
301
 
 *
302
 
 * @retval
303
 
 *  NONE if successful transformation
304
 
 * @retval
305
 
 *  Error code (see enum TransformSqlError definition) if failure
306
 
 */
307
 
enum TransformSqlError
308
 
transformTruncateTableStatementToSql(const TruncateTableStatement &statement,
309
 
                                     std::string &destination,
310
 
                                     enum TransformSqlVariant sql_variant= DRIZZLE);
311
 
 
312
 
/**
313
 
 * This function looks at a supplied CreateSchemaStatement
314
 
 * and constructs a correctly-formatted SQL
315
 
 * statement to the supplied destination string.
316
 
 *
317
 
 * @param CreateSchemaStatement message to transform
318
 
 * @param Destination string to append SQL to
319
 
 * @param Variation of SQL to generate
320
 
 *
321
 
 * @retval
322
 
 *  NONE if successful transformation
323
 
 * @retval
324
 
 *  Error code (see enum TransformSqlError definition) if failure
325
 
 */
326
 
enum TransformSqlError
327
 
transformCreateSchemaStatementToSql(const CreateSchemaStatement &statement,
328
 
                                    std::string &destination,
329
 
                                    enum TransformSqlVariant sql_variant= DRIZZLE);
330
 
 
331
 
/**
332
 
 * This function looks at a supplied DropSchemaStatement
333
 
 * and constructs a correctly-formatted SQL
334
 
 * statement to the supplied destination string.
335
 
 *
336
 
 * @param DropSchemaStatement message to transform
337
 
 * @param Destination string to append SQL to
338
 
 * @param Variation of SQL to generate
339
 
 *
340
 
 * @retval
341
 
 *  NONE if successful transformation
342
 
 * @retval
343
 
 *  Error code (see enum TransformSqlError definition) if failure
344
 
 */
345
 
enum TransformSqlError
346
 
transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
347
 
                                  std::string &destination,
348
 
                                  enum TransformSqlVariant sql_variant= DRIZZLE);
349
 
 
350
 
/**
351
 
 * This function looks at a supplied AlterSchemaStatement
352
 
 * and constructs a correctly-formatted SQL
353
 
 * statement to the supplied destination string.
354
 
 *
355
 
 * @param AlterSchemaStatement message to transform
356
 
 * @param Destination string to append SQL to
357
 
 * @param Variation of SQL to generate
358
 
 *
359
 
 * @retval
360
 
 *  NONE if successful transformation
361
 
 * @retval
362
 
 *  Error code (see enum TransformSqlError definition) if failure
363
 
 */
364
 
enum TransformSqlError
365
 
transformAlterSchemaStatementToSql(const AlterSchemaStatement &statement,
366
 
                                   std::string &destination,
367
 
                                   enum TransformSqlVariant sql_variant= DRIZZLE);
368
 
 
369
 
/**
370
 
 * This function looks at a supplied SetVariableStatement
371
 
 * and constructs a correctly-formatted SQL
372
 
 * statement to the supplied destination string.
373
 
 *
374
 
 * @param SetVariableStatement message to transform
375
 
 * @param Destination string to append SQL to
376
 
 * @param Variation of SQL to generate
377
 
 *
378
 
 * @retval
379
 
 *  NONE if successful transformation
380
 
 * @retval
381
 
 *  Error code (see enum TransformSqlError definition) if failure
382
 
 */
383
 
enum TransformSqlError
384
 
transformSetVariableStatementToSql(const SetVariableStatement &statement,
385
 
                                   std::string &destination,
386
 
                                   enum TransformSqlVariant sql_variant= DRIZZLE);
387
 
 
388
 
/**
389
 
 * Appends to supplied string an SQL expression
390
 
 * containing the supplied CreateTableStatement's
391
 
 * appropriate CREATE TABLE SQL statement.
392
 
 */
393
 
enum TransformSqlError
394
 
transformCreateTableStatementToSql(const CreateTableStatement &statement,
395
 
                                   std::string &destination,
396
 
                                   enum TransformSqlVariant sql_variant= DRIZZLE);
397
 
 
398
 
/**
399
 
 * Appends to the supplied string an SQL expression
400
 
 * representing the table for a CREATE TABLE expression.
401
 
 *
402
 
 * @param[in]   Table message
403
 
 * @param[out]  String to append to
404
 
 *
405
 
 * @retval
406
 
 *  NONE if successful transformation
407
 
 * @retval
408
 
 *  Error code (see enum TransformSqlError definition) if failure
409
 
 */
410
 
enum TransformSqlError
411
 
transformTableDefinitionToSql(const Table &table,
412
 
                              std::string &destination,
413
 
                              enum TransformSqlVariant sql_variant= DRIZZLE,
414
 
                              bool with_schema= true);
415
 
 
416
 
/**
417
 
 * Appends to the supplied string an SQL expression
418
 
 * representing the table's optional attributes.
419
 
 *
420
 
 * @note
421
 
 *
422
 
 * This function will eventually be a much simpler
423
 
 * listing of key/value pairs.
424
 
 *
425
 
 * @param[in]   TableOptions message
426
 
 * @param[out]  String to append to
427
 
 *
428
 
 * @retval
429
 
 *  NONE if successful transformation
430
 
 * @retval
431
 
 *  Error code (see enum TransformSqlError definition) if failure
432
 
 */
433
 
enum TransformSqlError
434
 
transformTableOptionsToSql(const Table::TableOptions &table_options,
435
 
                           std::string &destination,
436
 
                           enum TransformSqlVariant sql_variant= DRIZZLE);
437
 
 
438
 
/**
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.
442
 
 *
443
 
 * @param[in]   Index message
444
 
 * @param[in]   Table containing this index (used to get field names...)
445
 
 * @param[out]  String to append to
446
 
 *
447
 
 * @retval
448
 
 *  NONE if successful transformation
449
 
 * @retval
450
 
 *  Error code (see enum TransformSqlError definition) if failure
451
 
 */
452
 
enum TransformSqlError
453
 
transformIndexDefinitionToSql(const Table::Index &index,
454
 
                              const Table &table,
455
 
                              std::string &destination,
456
 
                              enum TransformSqlVariant sql_variant= DRIZZLE);
457
 
 
458
 
/**
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.
462
 
 *
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
466
 
 *
467
 
 * @retval
468
 
 *  NONE if successful transformation
469
 
 * @retval
470
 
 *  Error code (see enum TransformSqlError definition) if failure
471
 
 */
472
 
enum TransformSqlError
473
 
transformForeignKeyConstraintDefinitionToSql(const Table::ForeignKeyConstraint &fkey,
474
 
                                             const Table &table,
475
 
                                             std::string &destination,
476
 
                                             enum TransformSqlVariant sql_variant = DRIZZLE);
477
 
 
478
 
/**
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.
482
 
 *
483
 
 * @param[in]   Field message
484
 
 * @param[out]  String to append to
485
 
 *
486
 
 * @retval
487
 
 *  NONE if successful transformation
488
 
 * @retval
489
 
 *  Error code (see enum TransformSqlError definition) if failure
490
 
 */
491
 
enum TransformSqlError
492
 
transformFieldDefinitionToSql(const Table::Field &field,
493
 
                              std::string &destination,
494
 
                              enum TransformSqlVariant sql_variant= DRIZZLE);
495
 
 
496
 
/**
497
 
 * Returns true if the supplied message::Table::Field::FieldType
498
 
 * should have its values quoted when modifying values.
499
 
 *
500
 
 * @param[in] type of field
501
 
 */
502
 
bool shouldQuoteFieldValue(Table::Field::FieldType in_type);
503
 
 
504
 
drizzled::message::Table::Field::FieldType internalFieldTypeToFieldProtoType(enum enum_field_types type);
505
 
 
506
 
/**
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).
510
 
 *
511
 
 * @param The transaction to check
512
 
 */
513
 
bool transactionContainsBulkSegment(const Transaction &transaction);
514
 
 
515
 
} /* namespace message */
516
 
} /* namespace drizzled */
517
 
 
518
 
#endif /* DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H */