1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
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> |
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
36 |
#include <vector> |
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
37 |
|
38 |
namespace drizzled |
|
39 |
{
|
|
40 |
namespace message |
|
41 |
{
|
|
42 |
/* some forward declarations */
|
|
43 |
class Statement; |
|
44 |
class InsertHeader; |
|
45 |
class InsertData; |
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
46 |
class InsertRecord; |
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
47 |
class UpdateHeader; |
48 |
class UpdateData; |
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
49 |
class UpdateRecord; |
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
50 |
class DeleteHeader; |
51 |
class DeleteData; |
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
52 |
class DeleteRecord; |
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
53 |
class SetVariableStatement; |
54 |
||
55 |
/** A Variation of SQL to be output during transformation */
|
|
56 |
enum TransformSqlVariant |
|
57 |
{
|
|
58 |
ANSI, |
|
59 |
MYSQL_4, |
|
60 |
MYSQL_5, |
|
61 |
DRIZZLE
|
|
62 |
};
|
|
63 |
||
64 |
/** Error codes which can happen during tranformations */
|
|
65 |
enum TransformSqlError |
|
66 |
{
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
67 |
NONE= 0, |
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 */ |
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
70 |
};
|
71 |
||
72 |
/**
|
|
73 |
* This function looks at the Statement
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
74 |
* message and appends one or more correctly-formatted SQL
|
75 |
* strings to the supplied vector of strings.
|
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
76 |
*
|
77 |
* @param Statement message to transform
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
78 |
* @param Vector of strings to append SQL statements to
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
79 |
* @param Variation of SQL to generate
|
80 |
*
|
|
81 |
* @retval
|
|
82 |
* NONE if successful transformation
|
|
83 |
* @retval
|
|
84 |
* Error code (see enum TransformSqlError definition) if failure
|
|
85 |
*/
|
|
86 |
enum TransformSqlError |
|
87 |
transformStatementToSql(const Statement &source, |
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
88 |
std::vector<std::string> &sql_strings, |
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
89 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
90 |
||
91 |
/**
|
|
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.
|
|
95 |
*
|
|
96 |
* @note
|
|
97 |
*
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
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.
|
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
102 |
*
|
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
|
|
107 |
*
|
|
108 |
* @retval
|
|
109 |
* NONE if successful transformation
|
|
110 |
* @retval
|
|
111 |
* Error code (see enum TransformSqlError definition) if failure
|
|
112 |
*/
|
|
113 |
enum TransformSqlError |
|
114 |
transformInsertStatementToSql(const InsertHeader &header, |
|
115 |
const InsertData &data, |
|
116 |
std::string *destination, |
|
117 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
118 |
||
119 |
/**
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
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.
|
|
123 |
*
|
|
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
|
|
128 |
*
|
|
129 |
* @retval
|
|
130 |
* NONE if successful transformation
|
|
131 |
* @retval
|
|
132 |
* Error code (see enum TransformSqlError definition) if failure
|
|
133 |
*/
|
|
134 |
enum TransformSqlError |
|
135 |
transformInsertRecordToSql(const InsertHeader &header, |
|
136 |
const InsertRecord &record, |
|
137 |
std::string *destination, |
|
138 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
139 |
||
140 |
/**
|
|
141 |
* Helper function to construct the header portion of an INSERT
|
|
142 |
* SQL statement from an InsertHeader message.
|
|
143 |
*
|
|
144 |
* @param InsertHeader message to transform
|
|
145 |
* @param Destination string to append SQL to
|
|
146 |
* @param Variation of SQL to generate
|
|
147 |
*
|
|
148 |
* @retval
|
|
149 |
* NONE if successful transformation
|
|
150 |
* @retval
|
|
151 |
* Error code (see enum TransformSqlError definition) if failure
|
|
152 |
*/
|
|
153 |
enum TransformSqlError |
|
154 |
transformInsertHeaderToSql(const InsertHeader &header, |
|
155 |
std::string *destination, |
|
156 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
157 |
|
158 |
/**
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
159 |
* Helper function to construct the header portion of an UPDATE
|
160 |
* SQL statement from an UpdateHeader message.
|
|
161 |
*
|
|
162 |
* @param UpdateHeader message to transform
|
|
163 |
* @param Destination string to append SQL to
|
|
164 |
* @param Variation of SQL to generate
|
|
165 |
*
|
|
166 |
* @retval
|
|
167 |
* NONE if successful transformation
|
|
168 |
* @retval
|
|
169 |
* Error code (see enum TransformSqlError definition) if failure
|
|
170 |
*/
|
|
171 |
enum TransformSqlError |
|
172 |
transformUpdateHeaderToSql(const UpdateHeader &header, |
|
173 |
std::string *destination, |
|
174 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
175 |
||
176 |
/**
|
|
177 |
* This function looks at a supplied UpdateHeader
|
|
178 |
* and a single UpdateRecord message and constructs a correctly-formatted
|
|
179 |
* SQL statement to the supplied destination string.
|
|
180 |
*
|
|
181 |
* @param UpdateHeader message to transform
|
|
182 |
* @param UpdateRecord message to transform
|
|
183 |
* @param Destination string to append SQL to
|
|
184 |
* @param Variation of SQL to generate
|
|
185 |
*
|
|
186 |
* @retval
|
|
187 |
* NONE if successful transformation
|
|
188 |
* @retval
|
|
189 |
* Error code (see enum TransformSqlError definition) if failure
|
|
190 |
*/
|
|
191 |
enum TransformSqlError |
|
192 |
transformUpdateRecordToSql(const UpdateHeader &header, |
|
193 |
const UpdateRecord &record, |
|
194 |
std::string *destination, |
|
195 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
196 |
||
197 |
/**
|
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
198 |
* This function looks at a supplied DeleteHeader
|
199 |
* and DeleteData message and constructs a correctly-formatted SQL
|
|
200 |
* statement to the supplied destination string.
|
|
201 |
*
|
|
202 |
* @note
|
|
203 |
*
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
204 |
* This function constructs a <strong>single SQL statement</strong>
|
205 |
* for all keys in the DeleteData message.
|
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
206 |
*
|
207 |
* @param DeleteHeader message to transform
|
|
208 |
* @param DeleteData message to transform
|
|
209 |
* @param Destination string to append SQL to
|
|
210 |
* @param Variation of SQL to generate
|
|
211 |
*
|
|
212 |
* @retval
|
|
213 |
* NONE if successful transformation
|
|
214 |
* @retval
|
|
215 |
* Error code (see enum TransformSqlError definition) if failure
|
|
216 |
*/
|
|
217 |
enum TransformSqlError |
|
218 |
transformDeleteStatementToSql(const DeleteHeader &header, |
|
219 |
const DeleteData &data, |
|
220 |
std::string *destination, |
|
221 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
222 |
||
223 |
/**
|
|
1143.2.7
by Jay Pipes
Based on IRC discussions with Brian, this patch reworks the Statement |
224 |
* This function looks at a supplied DeleteHeader
|
225 |
* and a single DeleteRecord message and constructs a correctly-formatted
|
|
226 |
* SQL statement to the supplied destination string.
|
|
227 |
*
|
|
228 |
* @param DeleteHeader message to transform
|
|
229 |
* @param DeleteRecord message to transform
|
|
230 |
* @param Destination string to append SQL to
|
|
231 |
* @param Variation of SQL to generate
|
|
232 |
*
|
|
233 |
* @retval
|
|
234 |
* NONE if successful transformation
|
|
235 |
* @retval
|
|
236 |
* Error code (see enum TransformSqlError definition) if failure
|
|
237 |
*/
|
|
238 |
enum TransformSqlError |
|
239 |
transformDeleteRecordToSql(const DeleteHeader &header, |
|
240 |
const DeleteRecord &record, |
|
241 |
std::string *destination, |
|
242 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
243 |
||
244 |
/**
|
|
245 |
* Helper function to construct the header portion of a DELETE
|
|
246 |
* SQL statement from an DeleteHeader message.
|
|
247 |
*
|
|
248 |
* @param DeleteHeader message to transform
|
|
249 |
* @param Destination string to append SQL to
|
|
250 |
* @param Variation of SQL to generate
|
|
251 |
*
|
|
252 |
* @retval
|
|
253 |
* NONE if successful transformation
|
|
254 |
* @retval
|
|
255 |
* Error code (see enum TransformSqlError definition) if failure
|
|
256 |
*/
|
|
257 |
enum TransformSqlError |
|
258 |
transformDeleteHeaderToSql(const DeleteHeader &header, |
|
259 |
std::string *destination, |
|
260 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
261 |
||
262 |
/**
|
|
1143.2.4
by Jay Pipes
New transaction proto file containing message definitions to be |
263 |
* This function looks at a supplied SetVariableStatement
|
264 |
* and constructs a correctly-formatted SQL
|
|
265 |
* statement to the supplied destination string.
|
|
266 |
*
|
|
267 |
* @param SetVariableStatement message to transform
|
|
268 |
* @param Destination string to append SQL to
|
|
269 |
* @param Variation of SQL to generate
|
|
270 |
*
|
|
271 |
* @retval
|
|
272 |
* NONE if successful transformation
|
|
273 |
* @retval
|
|
274 |
* Error code (see enum TransformSqlError definition) if failure
|
|
275 |
*/
|
|
276 |
enum TransformSqlError |
|
277 |
transformSetVariableStatementToSql(const SetVariableStatement &statement, |
|
278 |
std::string *destination, |
|
279 |
enum TransformSqlVariant sql_variant= DRIZZLE); |
|
280 |
||
281 |
||
282 |
/**
|
|
283 |
* Returns true if the supplied message::Table::Field::FieldType
|
|
284 |
* should have its values quoted when modifying values.
|
|
285 |
*
|
|
286 |
* @param[in] type of field
|
|
287 |
*/
|
|
288 |
bool shouldQuoteFieldValue(Table::Field::FieldType in_type); |
|
289 |
||
290 |
} /* end namespace drizzled::message */ |
|
291 |
} /* end namespace drizzled */ |
|
292 |
||
293 |
#endif /* DRIZZLED_MESSAGE_STATEMENT_TRANSFORM_H */ |