~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/statement_transform.h

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

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
 *
 
6
 *  Authors:
 
7
 *
 
8
 *    Jay Pipes <joinfu@sun.com>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; version 2 of the License.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
22
 */
 
23
 
 
24
/**
 
25
 * @file
 
26
 *
 
27
 * Declarations of various routines that can be used to convert
 
28
 * Transaction messages to other formats, including SQL statements.
 
29
 */
 
30
 
 
31
#ifndef DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
 
32
#define DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
 
33
 
 
34
#include <drizzled/message/table.pb.h>
 
35
#include <string>
 
36
#include <vector>
 
37
 
 
38
namespace drizzled
 
39
{
 
40
namespace message
 
41
{
 
42
/* some forward declarations */
 
43
class Statement;
 
44
class InsertHeader;
 
45
class InsertData;
 
46
class InsertRecord;
 
47
class UpdateHeader;
 
48
class UpdateData;
 
49
class UpdateRecord;
 
50
class DeleteHeader;
 
51
class DeleteData;
 
52
class DeleteRecord;
 
53
class TruncateTableStatement;
 
54
class SetVariableStatement;
 
55
 
 
56
/** A Variation of SQL to be output during transformation */
 
57
enum TransformSqlVariant
 
58
{
 
59
  ANSI,
 
60
  MYSQL_4,
 
61
  MYSQL_5,
 
62
  DRIZZLE
 
63
};
 
64
 
 
65
/** Error codes which can happen during tranformations */
 
66
enum TransformSqlError
 
67
{
 
68
  NONE= 0,
 
69
  MISSING_HEADER= 1, /* A data segment without a header segment was found */
 
70
  MISSING_DATA= 2 /* A header segment without a data segment was found */
 
71
};
 
72
 
 
73
/**
 
74
 * This function looks at the Statement
 
75
 * message and appends one or more correctly-formatted SQL
 
76
 * strings to the supplied vector of strings.
 
77
 *
 
78
 * @param Statement message to transform
 
79
 * @param Vector of strings to append SQL statements to
 
80
 * @param Variation of SQL to generate
 
81
 *
 
82
 * @retval
 
83
 *  NONE if successful transformation
 
84
 * @retval
 
85
 *  Error code (see enum TransformSqlError definition) if failure
 
86
 */
 
87
enum TransformSqlError
 
88
transformStatementToSql(const Statement &source,
 
89
                        std::vector<std::string> &sql_strings,
 
90
                        enum TransformSqlVariant sql_variant= DRIZZLE,
 
91
                        bool already_in_transaction= false);
 
92
 
 
93
/**
 
94
 * This function looks at a supplied InsertHeader
 
95
 * and InsertData message and constructs a correctly-formatted SQL
 
96
 * statement to the supplied destination string.
 
97
 *
 
98
 * @note
 
99
 *
 
100
 * This function is used when you want to construct a <strong>
 
101
 * single SQL statement</strong> from an entire InsertHeader and
 
102
 * InsertData message.  If there are many records in the InsertData
 
103
 * message, the SQL statement will be a multi-value INSERT statement.
 
104
 *
 
105
 * @param InsertHeader message to transform
 
106
 * @param InsertData message to transform
 
107
 * @param Destination string to append SQL to
 
108
 * @param Variation of SQL to generate
 
109
 *
 
110
 * @retval
 
111
 *  NONE if successful transformation
 
112
 * @retval
 
113
 *  Error code (see enum TransformSqlError definition) if failure
 
114
 */
 
115
enum TransformSqlError
 
116
transformInsertStatementToSql(const InsertHeader &header,
 
117
                              const InsertData &data,
 
118
                              std::string *destination,
 
119
                              enum TransformSqlVariant sql_variant= DRIZZLE);
 
120
 
 
121
/**
 
122
 * This function looks at a supplied InsertHeader
 
123
 * and a single InsertRecord message and constructs a correctly-formatted
 
124
 * SQL statement to the supplied destination string.
 
125
 *
 
126
 * @param InsertHeader message to transform
 
127
 * @param InsertRecord message to transform
 
128
 * @param Destination string to append SQL to
 
129
 * @param Variation of SQL to generate
 
130
 *
 
131
 * @retval
 
132
 *  NONE if successful transformation
 
133
 * @retval
 
134
 *  Error code (see enum TransformSqlError definition) if failure
 
135
 */
 
136
enum TransformSqlError
 
137
transformInsertRecordToSql(const InsertHeader &header,
 
138
                           const InsertRecord &record,
 
139
                           std::string *destination,
 
140
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
141
 
 
142
/**
 
143
 * Helper function to construct the header portion of an INSERT
 
144
 * SQL statement from an InsertHeader message.
 
145
 *
 
146
 * @param InsertHeader message to transform
 
147
 * @param Destination string to append SQL to
 
148
 * @param Variation of SQL to generate
 
149
 *
 
150
 * @retval
 
151
 *  NONE if successful transformation
 
152
 * @retval
 
153
 *  Error code (see enum TransformSqlError definition) if failure
 
154
 */
 
155
enum TransformSqlError
 
156
transformInsertHeaderToSql(const InsertHeader &header,
 
157
                           std::string *destination,
 
158
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
159
 
 
160
/**
 
161
 * Helper function to construct the header portion of an UPDATE
 
162
 * SQL statement from an UpdateHeader message.
 
163
 *
 
164
 * @param UpdateHeader message to transform
 
165
 * @param Destination string to append SQL to
 
166
 * @param Variation of SQL to generate
 
167
 *
 
168
 * @retval
 
169
 *  NONE if successful transformation
 
170
 * @retval
 
171
 *  Error code (see enum TransformSqlError definition) if failure
 
172
 */
 
173
enum TransformSqlError
 
174
transformUpdateHeaderToSql(const UpdateHeader &header,
 
175
                           std::string *destination,
 
176
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
177
 
 
178
/**
 
179
 * This function looks at a supplied UpdateHeader
 
180
 * and a single UpdateRecord message and constructs a correctly-formatted
 
181
 * SQL statement to the supplied destination string.
 
182
 *
 
183
 * @param UpdateHeader message to transform
 
184
 * @param UpdateRecord message to transform
 
185
 * @param Destination string to append SQL to
 
186
 * @param Variation of SQL to generate
 
187
 *
 
188
 * @retval
 
189
 *  NONE if successful transformation
 
190
 * @retval
 
191
 *  Error code (see enum TransformSqlError definition) if failure
 
192
 */
 
193
enum TransformSqlError
 
194
transformUpdateRecordToSql(const UpdateHeader &header,
 
195
                           const UpdateRecord &record,
 
196
                           std::string *destination,
 
197
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
198
 
 
199
/**
 
200
 * This function looks at a supplied DeleteHeader
 
201
 * and DeleteData message and constructs a correctly-formatted SQL
 
202
 * statement to the supplied destination string.
 
203
 *
 
204
 * @note
 
205
 *
 
206
 * This function constructs a <strong>single SQL statement</strong>
 
207
 * for all keys in the DeleteData message.
 
208
 *
 
209
 * @param DeleteHeader message to transform
 
210
 * @param DeleteData message to transform
 
211
 * @param Destination string to append SQL to
 
212
 * @param Variation of SQL to generate
 
213
 *
 
214
 * @retval
 
215
 *  NONE if successful transformation
 
216
 * @retval
 
217
 *  Error code (see enum TransformSqlError definition) if failure
 
218
 */
 
219
enum TransformSqlError
 
220
transformDeleteStatementToSql(const DeleteHeader &header,
 
221
                              const DeleteData &data,
 
222
                              std::string *destination,
 
223
                              enum TransformSqlVariant sql_variant= DRIZZLE);
 
224
 
 
225
/**
 
226
 * This function looks at a supplied DeleteHeader
 
227
 * and a single DeleteRecord message and constructs a correctly-formatted
 
228
 * SQL statement to the supplied destination string.
 
229
 *
 
230
 * @param DeleteHeader message to transform
 
231
 * @param DeleteRecord message to transform
 
232
 * @param Destination string to append SQL to
 
233
 * @param Variation of SQL to generate
 
234
 *
 
235
 * @retval
 
236
 *  NONE if successful transformation
 
237
 * @retval
 
238
 *  Error code (see enum TransformSqlError definition) if failure
 
239
 */
 
240
enum TransformSqlError
 
241
transformDeleteRecordToSql(const DeleteHeader &header,
 
242
                           const DeleteRecord &record,
 
243
                           std::string *destination,
 
244
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
245
 
 
246
/**
 
247
 * Helper function to construct the header portion of a DELETE
 
248
 * SQL statement from an DeleteHeader message.
 
249
 *
 
250
 * @param DeleteHeader message to transform
 
251
 * @param Destination string to append SQL to
 
252
 * @param Variation of SQL to generate
 
253
 *
 
254
 * @retval
 
255
 *  NONE if successful transformation
 
256
 * @retval
 
257
 *  Error code (see enum TransformSqlError definition) if failure
 
258
 */
 
259
enum TransformSqlError
 
260
transformDeleteHeaderToSql(const DeleteHeader &header,
 
261
                           std::string *destination,
 
262
                           enum TransformSqlVariant sql_variant= DRIZZLE);
 
263
 
 
264
/**
 
265
 * This function looks at a supplied TruncateTableStatement
 
266
 * and constructs a correctly-formatted SQL
 
267
 * statement to the supplied destination string.
 
268
 *
 
269
 * @param TruncateTableStatement message to transform
 
270
 * @param Destination string to append SQL to
 
271
 * @param Variation of SQL to generate
 
272
 *
 
273
 * @retval
 
274
 *  NONE if successful transformation
 
275
 * @retval
 
276
 *  Error code (see enum TransformSqlError definition) if failure
 
277
 */
 
278
enum TransformSqlError
 
279
transformTruncateTableStatementToSql(const TruncateTableStatement &statement,
 
280
                                     std::string *destination,
 
281
                                     enum TransformSqlVariant sql_variant= DRIZZLE);
 
282
 
 
283
/**
 
284
 * This function looks at a supplied SetVariableStatement
 
285
 * and constructs a correctly-formatted SQL
 
286
 * statement to the supplied destination string.
 
287
 *
 
288
 * @param SetVariableStatement message to transform
 
289
 * @param Destination string to append SQL to
 
290
 * @param Variation of SQL to generate
 
291
 *
 
292
 * @retval
 
293
 *  NONE if successful transformation
 
294
 * @retval
 
295
 *  Error code (see enum TransformSqlError definition) if failure
 
296
 */
 
297
enum TransformSqlError
 
298
transformSetVariableStatementToSql(const SetVariableStatement &statement,
 
299
                                   std::string *destination,
 
300
                                   enum TransformSqlVariant sql_variant= DRIZZLE);
 
301
 
 
302
 
 
303
/**
 
304
 * Returns true if the supplied message::Table::Field::FieldType
 
305
 * should have its values quoted when modifying values.
 
306
 *
 
307
 * @param[in] type of field
 
308
 */
 
309
bool shouldQuoteFieldValue(Table::Field::FieldType in_type);
 
310
 
 
311
} /* namespace message */
 
312
} /* namespace drizzled */
 
313
 
 
314
#endif /* DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H */