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
8
* Jay Pipes <joinfu@sun.com>
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.
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.
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
27
* Declarations of various routines that can be used to convert
28
* Transaction messages to other formats, including SQL statements.
31
#ifndef DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
32
#define DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H
34
#include <drizzled/message/table.pb.h>
42
/* some forward declarations */
53
class SetVariableStatement;
55
/** A Variation of SQL to be output during transformation */
56
enum TransformSqlVariant
64
/** Error codes which can happen during tranformations */
65
enum TransformSqlError
68
MISSING_HEADER= 1, /* A data segment without a header segment was found */
69
MISSING_DATA= 2 /* A header segment without a data segment was found */
73
* This function looks at the Statement
74
* message and appends one or more correctly-formatted SQL
75
* strings to the supplied vector of strings.
77
* @param Statement message to transform
78
* @param Vector of strings to append SQL statements to
79
* @param Variation of SQL to generate
82
* NONE if successful transformation
84
* Error code (see enum TransformSqlError definition) if failure
86
enum TransformSqlError
87
transformStatementToSql(const Statement &source,
88
std::vector<std::string> &sql_strings,
89
enum TransformSqlVariant sql_variant= DRIZZLE);
92
* This function looks at a supplied InsertHeader
93
* and InsertData message and constructs a correctly-formatted SQL
94
* statement to the supplied destination string.
98
* This function is used when you want to construct a <strong>
99
* single SQL statement</strong> from an entire InsertHeader and
100
* InsertData message. If there are many records in the InsertData
101
* message, the SQL statement will be a multi-value INSERT statement.
103
* @param InsertHeader message to transform
104
* @param InsertData message to transform
105
* @param Destination string to append SQL to
106
* @param Variation of SQL to generate
109
* NONE if successful transformation
111
* Error code (see enum TransformSqlError definition) if failure
113
enum TransformSqlError
114
transformInsertStatementToSql(const InsertHeader &header,
115
const InsertData &data,
116
std::string *destination,
117
enum TransformSqlVariant sql_variant= DRIZZLE);
120
* This function looks at a supplied InsertHeader
121
* and a single InsertRecord message and constructs a correctly-formatted
122
* SQL statement to the supplied destination string.
124
* @param InsertHeader message to transform
125
* @param InsertRecord message to transform
126
* @param Destination string to append SQL to
127
* @param Variation of SQL to generate
130
* NONE if successful transformation
132
* Error code (see enum TransformSqlError definition) if failure
134
enum TransformSqlError
135
transformInsertRecordToSql(const InsertHeader &header,
136
const InsertRecord &record,
137
std::string *destination,
138
enum TransformSqlVariant sql_variant= DRIZZLE);
141
* Helper function to construct the header portion of an INSERT
142
* SQL statement from an InsertHeader message.
144
* @param InsertHeader message to transform
145
* @param Destination string to append SQL to
146
* @param Variation of SQL to generate
149
* NONE if successful transformation
151
* Error code (see enum TransformSqlError definition) if failure
153
enum TransformSqlError
154
transformInsertHeaderToSql(const InsertHeader &header,
155
std::string *destination,
156
enum TransformSqlVariant sql_variant= DRIZZLE);
158
* This function looks at a supplied UpdateHeader
159
* and UpdateData message and constructs a correctly-formatted SQL
160
* statement to the supplied destination string.
164
* This function constructs a <strong>single SQL statement</strong>
165
* that contains all the update keys represented in all records in
166
* the UpdateData message.
168
* @param UpdateHeader message to transform
169
* @param UpdateData message to transform
170
* @param Destination string to append SQL to
171
* @param Variation of SQL to generate
174
* NONE if successful transformation
176
* Error code (see enum TransformSqlError definition) if failure
178
enum TransformSqlError
179
transformUpdateStatementToSql(const UpdateHeader &header,
180
const UpdateData &data,
181
std::string *destination,
182
enum TransformSqlVariant sql_variant= DRIZZLE);
185
* Helper function to construct the header portion of an UPDATE
186
* SQL statement from an UpdateHeader message.
188
* @param UpdateHeader message to transform
189
* @param Destination string to append SQL to
190
* @param Variation of SQL to generate
193
* NONE if successful transformation
195
* Error code (see enum TransformSqlError definition) if failure
197
enum TransformSqlError
198
transformUpdateHeaderToSql(const UpdateHeader &header,
199
std::string *destination,
200
enum TransformSqlVariant sql_variant= DRIZZLE);
203
* This function looks at a supplied UpdateHeader
204
* and a single UpdateRecord message and constructs a correctly-formatted
205
* SQL statement to the supplied destination string.
207
* @param UpdateHeader message to transform
208
* @param UpdateRecord message to transform
209
* @param Destination string to append SQL to
210
* @param Variation of SQL to generate
213
* NONE if successful transformation
215
* Error code (see enum TransformSqlError definition) if failure
217
enum TransformSqlError
218
transformUpdateRecordToSql(const UpdateHeader &header,
219
const UpdateRecord &record,
220
std::string *destination,
221
enum TransformSqlVariant sql_variant= DRIZZLE);
224
* This function looks at a supplied DeleteHeader
225
* and DeleteData message and constructs a correctly-formatted SQL
226
* statement to the supplied destination string.
230
* This function constructs a <strong>single SQL statement</strong>
231
* for all keys in the DeleteData message.
233
* @param DeleteHeader message to transform
234
* @param DeleteData message to transform
235
* @param Destination string to append SQL to
236
* @param Variation of SQL to generate
239
* NONE if successful transformation
241
* Error code (see enum TransformSqlError definition) if failure
243
enum TransformSqlError
244
transformDeleteStatementToSql(const DeleteHeader &header,
245
const DeleteData &data,
246
std::string *destination,
247
enum TransformSqlVariant sql_variant= DRIZZLE);
250
* This function looks at a supplied DeleteHeader
251
* and a single DeleteRecord message and constructs a correctly-formatted
252
* SQL statement to the supplied destination string.
254
* @param DeleteHeader message to transform
255
* @param DeleteRecord message to transform
256
* @param Destination string to append SQL to
257
* @param Variation of SQL to generate
260
* NONE if successful transformation
262
* Error code (see enum TransformSqlError definition) if failure
264
enum TransformSqlError
265
transformDeleteRecordToSql(const DeleteHeader &header,
266
const DeleteRecord &record,
267
std::string *destination,
268
enum TransformSqlVariant sql_variant= DRIZZLE);
271
* Helper function to construct the header portion of a DELETE
272
* SQL statement from an DeleteHeader message.
274
* @param DeleteHeader message to transform
275
* @param Destination string to append SQL to
276
* @param Variation of SQL to generate
279
* NONE if successful transformation
281
* Error code (see enum TransformSqlError definition) if failure
283
enum TransformSqlError
284
transformDeleteHeaderToSql(const DeleteHeader &header,
285
std::string *destination,
286
enum TransformSqlVariant sql_variant= DRIZZLE);
289
* This function looks at a supplied SetVariableStatement
290
* and constructs a correctly-formatted SQL
291
* statement to the supplied destination string.
293
* @param SetVariableStatement message to transform
294
* @param Destination string to append SQL to
295
* @param Variation of SQL to generate
298
* NONE if successful transformation
300
* Error code (see enum TransformSqlError definition) if failure
302
enum TransformSqlError
303
transformSetVariableStatementToSql(const SetVariableStatement &statement,
304
std::string *destination,
305
enum TransformSqlVariant sql_variant= DRIZZLE);
309
* Returns true if the supplied message::Table::Field::FieldType
310
* should have its values quoted when modifying values.
312
* @param[in] type of field
314
bool shouldQuoteFieldValue(Table::Field::FieldType in_type);
316
} /* end namespace drizzled::message */
317
} /* end namespace drizzled */
319
#endif /* DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H */