~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.h

  • Committer: Brian Aker
  • Date: 2010-05-27 01:25:56 UTC
  • mfrom: (1567.1.4 new-staging)
  • Revision ID: brian@gaz-20100527012556-5zgkirkl7swbigd6
Merge of Brian, Paul. PBXT compile issue, and test framework cleanup. 

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
 
5
 *  Copyright (c) 2010 Jay Pipes <jayjpipes@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 SetVariableStatement;
 
63
 
 
64
/** A Variation of SQL to be output during transformation */
 
65
enum TransformSqlVariant
 
66
{
 
67
  ANSI,
 
68
  MYSQL_4,
 
69
  MYSQL_5,
 
70
  DRIZZLE
 
71
};
 
72
 
 
73
/** Error codes which can happen during tranformations */
 
74
enum TransformSqlError
 
75
{
 
76
  NONE= 0,
 
77
  MISSING_HEADER= 1, /* A data segment without a header segment was found */
 
78
  MISSING_DATA= 2 /* A header segment without a data segment was found */
 
79
};
 
80
 
 
81
/**
 
82
 * This function looks at the Statement
 
83
 * message and appends one or more correctly-formatted SQL
 
84
 * strings to the supplied vector of strings.
 
85
 *
 
86
 * @param Statement message to transform
 
87
 * @param Vector of strings to append SQL statements to
 
88
 * @param Variation of SQL to generate
 
89
 *
 
90
 * @retval
 
91
 *  NONE if successful transformation
 
92
 * @retval
 
93
 *  Error code (see enum TransformSqlError definition) if failure
 
94
 */
 
95
enum TransformSqlError
 
96
transformStatementToSql(const Statement &source,
 
97
                        std::vector<std::string> &sql_strings,
 
98
                        enum TransformSqlVariant sql_variant= DRIZZLE,
 
99
                        bool already_in_transaction= false);
 
100
 
 
101
/**
 
102
 * This function looks at a supplied InsertHeader
 
103
 * and InsertData message and constructs a correctly-formatted SQL
 
104
 * statement to the supplied destination string.
 
105
 *
 
106
 * @note
 
107
 *
 
108
 * This function is used when you want to construct a <strong>
 
109
 * single SQL statement</strong> from an entire InsertHeader and
 
110
 * InsertData message.  If there are many records in the InsertData
 
111
 * message, the SQL statement will be a multi-value INSERT statement.
 
112
 *
 
113
 * @param InsertHeader message to transform
 
114
 * @param InsertData message to transform
 
115
 * @param Destination string to append SQL to
 
116
 * @param Variation of SQL to generate
 
117
 *
 
118
 * @retval
 
119
 *  NONE if successful transformation
 
120
 * @retval
 
121
 *  Error code (see enum TransformSqlError definition) if failure
 
122
 */
 
123
enum TransformSqlError
 
124
transformInsertStatementToSql(const InsertHeader &header,
 
125
                              const InsertData &data,
 
126
                              std::string &destination,
 
127
                              enum TransformSqlVariant sql_variant= DRIZZLE);
 
128
 
 
129
/**
 
130
 * This function looks at a supplied InsertHeader
 
131
 * and a single InsertRecord message and constructs a correctly-formatted
 
132
 * SQL statement to the supplied destination string.
 
133
 *
 
134
 * @param InsertHeader message to transform
 
135
 * @param InsertRecord message to transform
 
136
 * @param Destination string to append SQL to
 
137
 * @param Variation of SQL to generate
 
138
 *
 
139
 * @retval
 
140
 *  NONE if successful transformation
 
141
 * @retval
 
142
 *  Error code (see enum TransformSqlError definition) if failure
 
143
 */
 
144
enum TransformSqlError
 
145
transformInsertRecordToSql(const InsertHeader &header,
 
146
                           const InsertRecord &record,
 
147
                           std::string &destination,
 
148
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
149
 
 
150
/**
 
151
 * Helper function to construct the header portion of an INSERT
 
152
 * SQL statement from an InsertHeader message.
 
153
 *
 
154
 * @param InsertHeader message to transform
 
155
 * @param Destination string to append SQL to
 
156
 * @param Variation of SQL to generate
 
157
 *
 
158
 * @retval
 
159
 *  NONE if successful transformation
 
160
 * @retval
 
161
 *  Error code (see enum TransformSqlError definition) if failure
 
162
 */
 
163
enum TransformSqlError
 
164
transformInsertHeaderToSql(const InsertHeader &header,
 
165
                           std::string &destination,
 
166
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
167
 
 
168
/**
 
169
 * Helper function to construct the header portion of an UPDATE
 
170
 * SQL statement from an UpdateHeader message.
 
171
 *
 
172
 * @param UpdateHeader message to transform
 
173
 * @param Destination string to append SQL to
 
174
 * @param Variation of SQL to generate
 
175
 *
 
176
 * @retval
 
177
 *  NONE if successful transformation
 
178
 * @retval
 
179
 *  Error code (see enum TransformSqlError definition) if failure
 
180
 */
 
181
enum TransformSqlError
 
182
transformUpdateHeaderToSql(const UpdateHeader &header,
 
183
                           std::string &destination,
 
184
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
185
 
 
186
/**
 
187
 * This function looks at a supplied UpdateHeader
 
188
 * and a single UpdateRecord message and constructs a correctly-formatted
 
189
 * SQL statement to the supplied destination string.
 
190
 *
 
191
 * @param UpdateHeader message to transform
 
192
 * @param UpdateRecord message to transform
 
193
 * @param Destination string to append SQL to
 
194
 * @param Variation of SQL to generate
 
195
 *
 
196
 * @retval
 
197
 *  NONE if successful transformation
 
198
 * @retval
 
199
 *  Error code (see enum TransformSqlError definition) if failure
 
200
 */
 
201
enum TransformSqlError
 
202
transformUpdateRecordToSql(const UpdateHeader &header,
 
203
                           const UpdateRecord &record,
 
204
                           std::string &destination,
 
205
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
206
 
 
207
/**
 
208
 * This function looks at a supplied DeleteHeader
 
209
 * and DeleteData message and constructs a correctly-formatted SQL
 
210
 * statement to the supplied destination string.
 
211
 *
 
212
 * @note
 
213
 *
 
214
 * This function constructs a <strong>single SQL statement</strong>
 
215
 * for all keys in the DeleteData message.
 
216
 *
 
217
 * @param DeleteHeader message to transform
 
218
 * @param DeleteData message to transform
 
219
 * @param Destination string to append SQL to
 
220
 * @param Variation of SQL to generate
 
221
 *
 
222
 * @retval
 
223
 *  NONE if successful transformation
 
224
 * @retval
 
225
 *  Error code (see enum TransformSqlError definition) if failure
 
226
 */
 
227
enum TransformSqlError
 
228
transformDeleteStatementToSql(const DeleteHeader &header,
 
229
                              const DeleteData &data,
 
230
                              std::string &destination,
 
231
                              enum TransformSqlVariant sql_variant= DRIZZLE);
 
232
 
 
233
/**
 
234
 * This function looks at a supplied DeleteHeader
 
235
 * and a single DeleteRecord message and constructs a correctly-formatted
 
236
 * SQL statement to the supplied destination string.
 
237
 *
 
238
 * @param DeleteHeader message to transform
 
239
 * @param DeleteRecord message to transform
 
240
 * @param Destination string to append SQL to
 
241
 * @param Variation of SQL to generate
 
242
 *
 
243
 * @retval
 
244
 *  NONE if successful transformation
 
245
 * @retval
 
246
 *  Error code (see enum TransformSqlError definition) if failure
 
247
 */
 
248
enum TransformSqlError
 
249
transformDeleteRecordToSql(const DeleteHeader &header,
 
250
                           const DeleteRecord &record,
 
251
                           std::string &destination,
 
252
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
253
 
 
254
/**
 
255
 * Helper function to construct the header portion of a DELETE
 
256
 * SQL statement from an DeleteHeader message.
 
257
 *
 
258
 * @param DeleteHeader message to transform
 
259
 * @param Destination string to append SQL to
 
260
 * @param Variation of SQL to generate
 
261
 *
 
262
 * @retval
 
263
 *  NONE if successful transformation
 
264
 * @retval
 
265
 *  Error code (see enum TransformSqlError definition) if failure
 
266
 */
 
267
enum TransformSqlError
 
268
transformDeleteHeaderToSql(const DeleteHeader &header,
 
269
                           std::string &destination,
 
270
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
271
 
 
272
/**
 
273
 * This function looks at a supplied DropTableStatement
 
274
 * and constructs a correctly-formatted SQL
 
275
 * statement to the supplied destination string.
 
276
 *
 
277
 * @param DropTableStatement message to transform
 
278
 * @param Destination string to append SQL to
 
279
 * @param Variation of SQL to generate
 
280
 *
 
281
 * @retval
 
282
 *  NONE if successful transformation
 
283
 * @retval
 
284
 *  Error code (see enum TransformSqlError definition) if failure
 
285
 */
 
286
enum TransformSqlError
 
287
transformDropTableStatementToSql(const DropTableStatement &statement,
 
288
                                  std::string &destination,
 
289
                                  enum TransformSqlVariant sql_variant= DRIZZLE);
 
290
 
 
291
/**
 
292
 * This function looks at a supplied TruncateTableStatement
 
293
 * and constructs a correctly-formatted SQL
 
294
 * statement to the supplied destination string.
 
295
 *
 
296
 * @param TruncateTableStatement message to transform
 
297
 * @param Destination string to append SQL to
 
298
 * @param Variation of SQL to generate
 
299
 *
 
300
 * @retval
 
301
 *  NONE if successful transformation
 
302
 * @retval
 
303
 *  Error code (see enum TransformSqlError definition) if failure
 
304
 */
 
305
enum TransformSqlError
 
306
transformTruncateTableStatementToSql(const TruncateTableStatement &statement,
 
307
                                     std::string &destination,
 
308
                                     enum TransformSqlVariant sql_variant= DRIZZLE);
 
309
 
 
310
/**
 
311
 * This function looks at a supplied CreateSchemaStatement
 
312
 * and constructs a correctly-formatted SQL
 
313
 * statement to the supplied destination string.
 
314
 *
 
315
 * @param CreateSchemaStatement message to transform
 
316
 * @param Destination string to append SQL to
 
317
 * @param Variation of SQL to generate
 
318
 *
 
319
 * @retval
 
320
 *  NONE if successful transformation
 
321
 * @retval
 
322
 *  Error code (see enum TransformSqlError definition) if failure
 
323
 */
 
324
enum TransformSqlError
 
325
transformCreateSchemaStatementToSql(const CreateSchemaStatement &statement,
 
326
                                    std::string &destination,
 
327
                                    enum TransformSqlVariant sql_variant= DRIZZLE);
 
328
 
 
329
/**
 
330
 * This function looks at a supplied DropSchemaStatement
 
331
 * and constructs a correctly-formatted SQL
 
332
 * statement to the supplied destination string.
 
333
 *
 
334
 * @param DropSchemaStatement message to transform
 
335
 * @param Destination string to append SQL to
 
336
 * @param Variation of SQL to generate
 
337
 *
 
338
 * @retval
 
339
 *  NONE if successful transformation
 
340
 * @retval
 
341
 *  Error code (see enum TransformSqlError definition) if failure
 
342
 */
 
343
enum TransformSqlError
 
344
transformDropSchemaStatementToSql(const DropSchemaStatement &statement,
 
345
                                  std::string &destination,
 
346
                                  enum TransformSqlVariant sql_variant= DRIZZLE);
 
347
 
 
348
/**
 
349
 * This function looks at a supplied SetVariableStatement
 
350
 * and constructs a correctly-formatted SQL
 
351
 * statement to the supplied destination string.
 
352
 *
 
353
 * @param SetVariableStatement message to transform
 
354
 * @param Destination string to append SQL to
 
355
 * @param Variation of SQL to generate
 
356
 *
 
357
 * @retval
 
358
 *  NONE if successful transformation
 
359
 * @retval
 
360
 *  Error code (see enum TransformSqlError definition) if failure
 
361
 */
 
362
enum TransformSqlError
 
363
transformSetVariableStatementToSql(const SetVariableStatement &statement,
 
364
                                   std::string &destination,
 
365
                                   enum TransformSqlVariant sql_variant= DRIZZLE);
 
366
 
 
367
/**
 
368
 * Appends to supplied string an SQL expression
 
369
 * containing the supplied CreateTableStatement's
 
370
 * appropriate CREATE TABLE SQL statement.
 
371
 */
 
372
enum TransformSqlError
 
373
transformCreateTableStatementToSql(const CreateTableStatement &statement,
 
374
                                   std::string &destination,
 
375
                                   enum TransformSqlVariant sql_variant= DRIZZLE);
 
376
 
 
377
/**
 
378
 * Appends to the supplied string an SQL expression
 
379
 * representing the table for a CREATE TABLE expression.
 
380
 *
 
381
 * @param[in]   Table message
 
382
 * @param[out]  String to append to
 
383
 *
 
384
 * @retval
 
385
 *  NONE if successful transformation
 
386
 * @retval
 
387
 *  Error code (see enum TransformSqlError definition) if failure
 
388
 */
 
389
enum TransformSqlError
 
390
transformTableDefinitionToSql(const Table &table,
 
391
                              std::string &destination,
 
392
                              enum TransformSqlVariant sql_variant= DRIZZLE,
 
393
                              bool with_schema= true);
 
394
 
 
395
/**
 
396
 * Appends to the supplied string an SQL expression
 
397
 * representing the table's optional attributes.
 
398
 *
 
399
 * @note
 
400
 *
 
401
 * This function will eventually be a much simpler
 
402
 * listing of key/value pairs.
 
403
 *
 
404
 * @param[in]   TableOptions message
 
405
 * @param[out]  String to append to
 
406
 *
 
407
 * @retval
 
408
 *  NONE if successful transformation
 
409
 * @retval
 
410
 *  Error code (see enum TransformSqlError definition) if failure
 
411
 */
 
412
enum TransformSqlError
 
413
transformTableOptionsToSql(const Table::TableOptions &table_options,
 
414
                           std::string &destination,
 
415
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
416
 
 
417
/**
 
418
 * Appends to the supplied string an SQL expression
 
419
 * representing the index's attributes.  The built string
 
420
 * corresponds to the SQL in a CREATE INDEX statement.
 
421
 *
 
422
 * @param[in]   Index message
 
423
 * @param[in]   Table containing this index (used to get field names...)
 
424
 * @param[out]  String to append to
 
425
 *
 
426
 * @retval
 
427
 *  NONE if successful transformation
 
428
 * @retval
 
429
 *  Error code (see enum TransformSqlError definition) if failure
 
430
 */
 
431
enum TransformSqlError
 
432
transformIndexDefinitionToSql(const Table::Index &index,
 
433
                              const Table &table,
 
434
                              std::string &destination,
 
435
                              enum TransformSqlVariant sql_variant= DRIZZLE);
 
436
 
 
437
/**
 
438
 * Appends to the supplied string an SQL expression
 
439
 * representing the field's attributes.  The built string
 
440
 * corresponds to the SQL in a CREATE TABLE statement.
 
441
 *
 
442
 * @param[in]   Field message
 
443
 * @param[out]  String to append to
 
444
 *
 
445
 * @retval
 
446
 *  NONE if successful transformation
 
447
 * @retval
 
448
 *  Error code (see enum TransformSqlError definition) if failure
 
449
 */
 
450
enum TransformSqlError
 
451
transformFieldDefinitionToSql(const Table::Field &field,
 
452
                              std::string &destination,
 
453
                              enum TransformSqlVariant sql_variant= DRIZZLE);
 
454
 
 
455
/**
 
456
 * Returns true if the supplied message::Table::Field::FieldType
 
457
 * should have its values quoted when modifying values.
 
458
 *
 
459
 * @param[in] type of field
 
460
 */
 
461
bool shouldQuoteFieldValue(Table::Field::FieldType in_type);
 
462
 
 
463
drizzled::message::Table::Field::FieldType internalFieldTypeToFieldProtoType(enum enum_field_types type);
 
464
 
 
465
/**
 
466
 * Returns true if the transaction contains any Statement
 
467
 * messages which are not end segments (i.e. a bulk statement has
 
468
 * previously been sent to replicators).
 
469
 *
 
470
 * @param The transaction to check
 
471
 */
 
472
bool transactionContainsBulkSegment(const Transaction &transaction);
 
473
 
 
474
} /* namespace message */
 
475
} /* namespace drizzled */
 
476
 
 
477
#endif /* DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H */