Skip to content

Commit 1ba154c

Browse files
committed
Fix TODOs for addError (via protected block)
1 parent 29e54da commit 1ba154c

File tree

1 file changed

+35
-11
lines changed

1 file changed

+35
-11
lines changed

src/wsjcpp_sql_builder.h

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ class WsjcppSqlBuilderHelpers {
3939

4040
enum class WsjcppSqlQueryType { SELECT, INSERT, UPDATE, DELETE };
4141

42+
43+
class WsjcppSqlQuery;
44+
class WsjcppSqlInsert;
45+
class WsjcppSqlUpdate;
46+
class WsjcppSqlSelect;
47+
class WsjcppSqlDelete;
48+
template<class T> class WsjcppSqlWhere;
49+
50+
51+
class IWsjcppSqlBuilder {
52+
public:
53+
54+
virtual bool hasErrors() = 0;
55+
virtual std::string sql() = 0;
56+
57+
protected:
58+
friend WsjcppSqlWhere<WsjcppSqlInsert>;
59+
friend WsjcppSqlWhere<WsjcppSqlUpdate>;
60+
friend WsjcppSqlWhere<WsjcppSqlDelete>;
61+
friend WsjcppSqlWhere<WsjcppSqlSelect>;
62+
friend WsjcppSqlQuery;
63+
virtual void addError(const std::string &err) = 0;
64+
};
65+
4266
class WsjcppSqlBuilder;
4367

4468
class WsjcppSqlQuery {
@@ -140,8 +164,7 @@ class WsjcppSqlWhere : public WsjcppSqlWhereBase {
140164
m_conditions.size() > 0
141165
&& m_conditions[m_conditions.size()-1]->type() == WsjcppSqlWhereType::LOGICAL_OPERATOR
142166
) {
143-
// TODO
144-
// m_builder->addError("[WARNING] WsjcppSqlWhere. Last item alredy defined as logical_operator. current will be skipped.");
167+
addError("[WARNING] WsjcppSqlWhere. Last item alredy defined as logical_operator. current will be skipped.");
145168
return *this;
146169
}
147170

@@ -154,8 +177,7 @@ class WsjcppSqlWhere : public WsjcppSqlWhereBase {
154177
m_conditions.size() > 0
155178
&& m_conditions[m_conditions.size()-1]->type() == WsjcppSqlWhereType::LOGICAL_OPERATOR
156179
) {
157-
// TODO
158-
// m_builder->addError("[WARNING] WsjcppSqlWhere. Last item alredy defined as logical_operator. current will be skipped.");
180+
addError("[WARNING] WsjcppSqlWhere. Last item alredy defined as logical_operator. current will be skipped.");
159181
return *this;
160182
}
161183
m_conditions.push_back(std::make_shared<WsjcppSqlWhereAnd>());
@@ -213,6 +235,10 @@ class WsjcppSqlWhere : public WsjcppSqlWhereBase {
213235
return *this;
214236
}
215237

238+
void addError(const std::string &err) {
239+
((IWsjcppSqlBuilder *)m_builder)->addError(err);
240+
}
241+
216242
WsjcppSqlBuilder *m_builder;
217243
T *m_query;
218244
WsjcppSqlWhere<T> *m_parent;
@@ -279,16 +305,13 @@ class WsjcppSqlUpdate : public WsjcppSqlQuery {
279305
class WsjcppSqlDelete : public WsjcppSqlQuery {
280306
public:
281307
WsjcppSqlDelete(const std::string &tableName, WsjcppSqlBuilder *builder);
282-
283308
WsjcppSqlWhere<WsjcppSqlDelete> &where();
284-
285309
virtual std::string sql() override;
286-
287310
private:
288311
std::shared_ptr<WsjcppSqlWhere<WsjcppSqlDelete>> m_where;
289312
};
290313

291-
class WsjcppSqlBuilder {
314+
class WsjcppSqlBuilder : public IWsjcppSqlBuilder {
292315
public:
293316
// TODO begin / end transaction can be added here
294317

@@ -300,16 +323,17 @@ class WsjcppSqlBuilder {
300323
WsjcppSqlDelete &deleteFrom(const std::string &sSqlTable);
301324
WsjcppSqlDelete &findDeleteOrCreate(const std::string &tableName);
302325

303-
bool hasErrors();
304-
std::string sql();
305326
void clear();
306327

328+
virtual bool hasErrors() override;
329+
virtual std::string sql() override;
330+
307331
protected:
308332
friend WsjcppSqlSelect;
309333
friend WsjcppSqlInsert;
310334
friend WsjcppSqlUpdate;
311335
friend WsjcppSqlWhere<WsjcppSqlSelect>;
312-
void addError(const std::string &err);
336+
virtual void addError(const std::string &err) override;
313337

314338
private:
315339
std::vector<std::string> m_errors;

0 commit comments

Comments
 (0)