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 TruncateTableStatement;
54
class SetVariableStatement;
56
/** A Variation of SQL to be output during transformation */
57
enum TransformSqlVariant
65
/** Error codes which can happen during tranformations */
66
enum TransformSqlError
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 */
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.
78
* @param Statement message to transform
79
* @param Vector of strings to append SQL statements to
80
* @param Variation of SQL to generate
83
* NONE if successful transformation
85
* Error code (see enum TransformSqlError definition) if failure
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);
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.
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.
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
111
* NONE if successful transformation
113
* Error code (see enum TransformSqlError definition) if failure
115
enum TransformSqlError
116
transformInsertStatementToSql(const InsertHeader &header,
117
const InsertData &data,
118
std::string *destination,
119
enum TransformSqlVariant sql_variant= DRIZZLE);
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.
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
132
* NONE if successful transformation
134
* Error code (see enum TransformSqlError definition) if failure
136
enum TransformSqlError
137
transformInsertRecordToSql(const InsertHeader &header,
138
const InsertRecord &record,
139
std::string *destination,
140
enum TransformSqlVariant sql_variant= DRIZZLE);
143
* Helper function to construct the header portion of an INSERT
144
* SQL statement from an InsertHeader message.
146
* @param InsertHeader message to transform
147
* @param Destination string to append SQL to
148
* @param Variation of SQL to generate
151
* NONE if successful transformation
153
* Error code (see enum TransformSqlError definition) if failure
155
enum TransformSqlError
156
transformInsertHeaderToSql(const InsertHeader &header,
157
std::string *destination,
158
enum TransformSqlVariant sql_variant= DRIZZLE);
161
* Helper function to construct the header portion of an UPDATE
162
* SQL statement from an UpdateHeader message.
164
* @param UpdateHeader message to transform
165
* @param Destination string to append SQL to
166
* @param Variation of SQL to generate
169
* NONE if successful transformation
171
* Error code (see enum TransformSqlError definition) if failure
173
enum TransformSqlError
174
transformUpdateHeaderToSql(const UpdateHeader &header,
175
std::string *destination,
176
enum TransformSqlVariant sql_variant= DRIZZLE);
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.
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
189
* NONE if successful transformation
191
* Error code (see enum TransformSqlError definition) if failure
193
enum TransformSqlError
194
transformUpdateRecordToSql(const UpdateHeader &header,
195
const UpdateRecord &record,
196
std::string *destination,
197
enum TransformSqlVariant sql_variant= DRIZZLE);
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.
206
* This function constructs a <strong>single SQL statement</strong>
207
* for all keys in the DeleteData message.
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
215
* NONE if successful transformation
217
* Error code (see enum TransformSqlError definition) if failure
219
enum TransformSqlError
220
transformDeleteStatementToSql(const DeleteHeader &header,
221
const DeleteData &data,
222
std::string *destination,
223
enum TransformSqlVariant sql_variant= DRIZZLE);
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.
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
236
* NONE if successful transformation
238
* Error code (see enum TransformSqlError definition) if failure
240
enum TransformSqlError
241
transformDeleteRecordToSql(const DeleteHeader &header,
242
const DeleteRecord &record,
243
std::string *destination,
244
enum TransformSqlVariant sql_variant= DRIZZLE);
247
* Helper function to construct the header portion of a DELETE
248
* SQL statement from an DeleteHeader message.
250
* @param DeleteHeader message to transform
251
* @param Destination string to append SQL to
252
* @param Variation of SQL to generate
255
* NONE if successful transformation
257
* Error code (see enum TransformSqlError definition) if failure
259
enum TransformSqlError
260
transformDeleteHeaderToSql(const DeleteHeader &header,
261
std::string *destination,
262
enum TransformSqlVariant sql_variant= DRIZZLE);
265
* This function looks at a supplied TruncateTableStatement
266
* and constructs a correctly-formatted SQL
267
* statement to the supplied destination string.
269
* @param TruncateTableStatement message to transform
270
* @param Destination string to append SQL to
271
* @param Variation of SQL to generate
274
* NONE if successful transformation
276
* Error code (see enum TransformSqlError definition) if failure
278
enum TransformSqlError
279
transformTruncateTableStatementToSql(const TruncateTableStatement &statement,
280
std::string *destination,
281
enum TransformSqlVariant sql_variant= DRIZZLE);
284
* This function looks at a supplied SetVariableStatement
285
* and constructs a correctly-formatted SQL
286
* statement to the supplied destination string.
288
* @param SetVariableStatement message to transform
289
* @param Destination string to append SQL to
290
* @param Variation of SQL to generate
293
* NONE if successful transformation
295
* Error code (see enum TransformSqlError definition) if failure
297
enum TransformSqlError
298
transformSetVariableStatementToSql(const SetVariableStatement &statement,
299
std::string *destination,
300
enum TransformSqlVariant sql_variant= DRIZZLE);
304
* Returns true if the supplied message::Table::Field::FieldType
305
* should have its values quoted when modifying values.
307
* @param[in] type of field
309
bool shouldQuoteFieldValue(Table::Field::FieldType in_type);
311
} /* namespace message */
312
} /* namespace drizzled */
314
#endif /* DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H */