Skip to content

Commit b765785

Browse files
committed
Renamed WsjcppSqlBuilder2 to WsjcppSqlBuilder
1 parent 58ebc11 commit b765785

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Example main func:
2323
#include <wsjcpp_sql_builder.h>
2424

2525
int main(int argc, const char* argv[]) {
26-
WsjcppSqlBuilder2 builder;
26+
WsjcppSqlBuilder builder;
2727
builder.selectFrom("table1")
2828
.colum("col1")
2929
.colum("col2", "c3")

src/tests/test_insert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <wsjcpp_sql_builder.h>
3030

3131
int main() {
32-
WsjcppSqlBuilder2 builder;
32+
WsjcppSqlBuilder builder;
3333
builder.insertInto("table1");
3434

3535
if (builder.hasErrors()) {

src/tests/test_select.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <wsjcpp_sql_builder.h>
3030

3131
int main() {
32-
WsjcppSqlBuilder2 builder;
32+
WsjcppSqlBuilder builder;
3333
builder.selectFrom("table1")
3434
.colum("col1")
3535
.colum("col2", "c3")

src/wsjcpp_sql_builder.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ std::string WsjcppSqlWhereCondition::sql() {
177177
// ---------------------------------------------------------------------
178178
// WsjcppSqlBuilderUpdate
179179

180-
WsjcppSqlSelect::WsjcppSqlSelect(const std::string &tableName, WsjcppSqlBuilder2 *builder)
180+
WsjcppSqlSelect::WsjcppSqlSelect(const std::string &tableName, WsjcppSqlBuilder *builder)
181181
: WsjcppSqlQuery(WsjcppSqlBuilderType::SELECT, tableName) {
182182
// TODO multitype table names with AS
183183
m_tableName = tableName;
@@ -203,7 +203,7 @@ WsjcppSqlWhere<WsjcppSqlSelect> &WsjcppSqlSelect::where() {
203203
return *(m_where.get());
204204
}
205205

206-
WsjcppSqlBuilder2 &WsjcppSqlSelect::compile() {
206+
WsjcppSqlBuilder &WsjcppSqlSelect::compile() {
207207
return *m_builder;
208208
}
209209

@@ -240,43 +240,43 @@ std::string WsjcppSqlSelect::sql() {
240240
}
241241

242242
// ---------------------------------------------------------------------
243-
// WsjcppSqlBuilder2
243+
// WsjcppSqlBuilder
244244

245-
WsjcppSqlSelect &WsjcppSqlBuilder2::selectFrom(const std::string &tableName) {
245+
WsjcppSqlSelect &WsjcppSqlBuilder::selectFrom(const std::string &tableName) {
246246
m_tableName = tableName;
247247
m_nSqlType = WsjcppSqlBuilderType::SELECT;
248248
m_queries.push_back(std::make_shared<WsjcppSqlSelect>(m_tableName, this));
249249
// TODO check must be select last one;
250250
return *(WsjcppSqlSelect *)(m_queries[m_queries.size() -1].get());
251251
}
252252

253-
WsjcppSqlBuilder2 &WsjcppSqlBuilder2::insertInto(const std::string &tableName) {
253+
WsjcppSqlBuilder &WsjcppSqlBuilder::insertInto(const std::string &tableName) {
254254
m_tableName = tableName;
255255
m_nSqlType = WsjcppSqlBuilderType::INSERT;
256256
return *this;
257257
}
258258

259-
// WsjcppSqlBuilder2 &WsjcppSqlBuilder2::makeUpdate(const std::string &tableName) {
259+
// WsjcppSqlBuilder &WsjcppSqlBuilder::makeUpdate(const std::string &tableName) {
260260
// m_tableName = tableName;
261261
// m_nSqlType = WsjcppSqlBuilderType::UPDATE;
262262
// return *this;
263263
// }
264264

265-
// WsjcppSqlBuilder2 &WsjcppSqlBuilder2::makeDelete(const std::string &tableName) {
265+
// WsjcppSqlBuilder &WsjcppSqlBuilder::makeDelete(const std::string &tableName) {
266266
// m_tableName = tableName;
267267
// m_nSqlType = WsjcppSqlBuilderType::DELETE;
268268
// return *this;
269269
// }
270270

271-
bool WsjcppSqlBuilder2::hasErrors() {
271+
bool WsjcppSqlBuilder::hasErrors() {
272272
return m_errors.size() > 0;
273273
}
274274

275-
void WsjcppSqlBuilder2::addError(const std::string &err) {
275+
void WsjcppSqlBuilder::addError(const std::string &err) {
276276
m_errors.push_back(err);
277277
}
278278

279-
std::string WsjcppSqlBuilder2::sql() {
279+
std::string WsjcppSqlBuilder::sql() {
280280
std::string ret = "";
281281
for (auto query : m_queries) {
282282
if (ret.size() > 0) {
@@ -287,6 +287,6 @@ std::string WsjcppSqlBuilder2::sql() {
287287
return ret;
288288
}
289289

290-
void WsjcppSqlBuilder2::clear() {
290+
void WsjcppSqlBuilder::clear() {
291291
m_queries.clear();
292292
}

src/wsjcpp_sql_builder.h

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class WsjcppSqlQuery {
5151
std::string m_tableName;
5252
};
5353

54-
class WsjcppSqlBuilder2;
54+
class WsjcppSqlBuilder;
5555

5656
enum class WsjcppSqlWhereType { LOGICAL_OPERATOR, CONDITION, SUB_CONDITION };
5757

@@ -100,7 +100,7 @@ class WsjcppSqlSelect;
100100
template<class T>
101101
class WsjcppSqlWhere : public WsjcppSqlWhereBase {
102102
public:
103-
WsjcppSqlWhere(WsjcppSqlWhere<T> *parent, WsjcppSqlBuilder2 *builder, T *query)
103+
WsjcppSqlWhere(WsjcppSqlWhere<T> *parent, WsjcppSqlBuilder *builder, T *query)
104104
: WsjcppSqlWhereBase(WsjcppSqlWhereType::SUB_CONDITION), m_parent(parent), m_builder(builder), m_query(query) { }
105105

106106
template <typename TVal>
@@ -210,39 +210,59 @@ class WsjcppSqlWhere : public WsjcppSqlWhereBase {
210210
return *this;
211211
}
212212

213-
WsjcppSqlBuilder2 *m_builder;
213+
WsjcppSqlBuilder *m_builder;
214214
T *m_query;
215215
WsjcppSqlWhere<T> *m_parent;
216216
std::vector<std::shared_ptr<WsjcppSqlWhereBase>> m_conditions;
217217
};
218218

219219
class WsjcppSqlSelect : public WsjcppSqlQuery {
220220
public:
221-
WsjcppSqlSelect(const std::string &tableName, WsjcppSqlBuilder2 *builder);
221+
WsjcppSqlSelect(const std::string &tableName, WsjcppSqlBuilder *builder);
222222
WsjcppSqlSelect &colum(const std::string &col, const std::string &col_as = "");
223223

224224
WsjcppSqlWhere<WsjcppSqlSelect> &where();
225225
// TODO group by
226226
// TODO order by
227-
WsjcppSqlBuilder2 &compile();
227+
WsjcppSqlBuilder &compile();
228228
virtual std::string sql() override;
229229

230230
private:
231231
std::string m_tableName;
232-
WsjcppSqlBuilder2 *m_builder;
232+
WsjcppSqlBuilder *m_builder;
233233
std::shared_ptr<WsjcppSqlWhere<WsjcppSqlSelect>> m_where;
234234
std::vector<std::string> m_columns;
235235
std::map<std::string, std::string> m_columns_as;
236236
};
237237

238-
class WsjcppSqlBuilder2 {
238+
239+
// class WsjcppSqlInsert : public WsjcppSqlQuery {
240+
// public:
241+
// WsjcppSqlInsert(const std::string &tableName, WsjcppSqlBuilder *builder);
242+
// WsjcppSqlInsert &colum(const std::string &col, const std::string &col_as = "");
243+
244+
// WsjcppSqlWhere<WsjcppSqlInsert> &where();
245+
// // TODO group by
246+
// // TODO order by
247+
// WsjcppSqlBuilder &compile();
248+
// virtual std::string sql() override;
249+
250+
// private:
251+
// std::string m_tableName;
252+
// WsjcppSqlBuilder *m_builder;
253+
// std::shared_ptr<WsjcppSqlWhere<WsjcppSqlSelect>> m_where;
254+
// std::vector<std::string> m_columns;
255+
// std::map<std::string, std::string> m_columns_as;
256+
// };
257+
258+
class WsjcppSqlBuilder {
239259
public:
240260
// TODO begin / end transaction can be added here
241261

242262
WsjcppSqlSelect &selectFrom(const std::string &tableName);
243-
WsjcppSqlBuilder2 &insertInto(const std::string &tableName);
244-
// WsjcppSqlBuilder2 &makeUpdate(const std::string &sSqlTable);
245-
// WsjcppSqlBuilder2 &makeDelete(const std::string &sSqlTable);
263+
WsjcppSqlBuilder &insertInto(const std::string &tableName);
264+
// WsjcppSqlBuilder &makeUpdate(const std::string &sSqlTable);
265+
// WsjcppSqlBuilder &makeDelete(const std::string &sSqlTable);
246266

247267
bool hasErrors();
248268
std::string sql();

0 commit comments

Comments
 (0)