diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-21 19:00:45 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-21 19:00:45 -0500 |
commit | 9423ab7f075afd3e1501a2d1438fc8330811e40e (patch) | |
tree | 71f1b207711907aad2e02643838eb2e479714526 /lib/statement.h | |
parent | 2a1f319b37dc3af45c136bfdc9226515c2fefaf2 (diff) | |
download | verbly-9423ab7f075afd3e1501a2d1438fc8330811e40e.tar.gz verbly-9423ab7f075afd3e1501a2d1438fc8330811e40e.tar.bz2 verbly-9423ab7f075afd3e1501a2d1438fc8330811e40e.zip |
Fixed statement generation involving negative subqueries
Previously, we generated negative subqueries by integrating them into the main statement normally, and then making the connecting join be a LEFT JOIN instead of an INNER JOIN, and by adding a condition that the join column be NULL. The problem with this is that if the top table of the subquery joins against any other table (which join throughs always do), then no rows will be returned. This was solved by putting the subquery into a CTE and then LEFT JOINing as before with the CTE.
Diffstat (limited to 'lib/statement.h')
-rw-r--r-- | lib/statement.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/statement.h b/lib/statement.h index a528d60..8188ec0 100644 --- a/lib/statement.h +++ b/lib/statement.h | |||
@@ -184,13 +184,15 @@ namespace verbly { | |||
184 | std::map<std::string, std::string> tables, | 184 | std::map<std::string, std::string> tables, |
185 | std::string topTable, | 185 | std::string topTable, |
186 | condition where, | 186 | condition where, |
187 | std::list<join> joins) : | 187 | std::list<join> joins, |
188 | bool recursive) : | ||
188 | identifier_(std::move(identifier)), | 189 | identifier_(std::move(identifier)), |
189 | field_(f), | 190 | field_(f), |
190 | tables_(std::move(tables)), | 191 | tables_(std::move(tables)), |
191 | topTable_(std::move(topTable)), | 192 | topTable_(std::move(topTable)), |
192 | topCondition_(std::move(where)), | 193 | topCondition_(std::move(where)), |
193 | joins_(std::move(joins)) | 194 | joins_(std::move(joins)), |
195 | recursive_(recursive) | ||
194 | { | 196 | { |
195 | } | 197 | } |
196 | 198 | ||
@@ -224,6 +226,11 @@ namespace verbly { | |||
224 | return joins_; | 226 | return joins_; |
225 | } | 227 | } |
226 | 228 | ||
229 | bool isRecursive() const | ||
230 | { | ||
231 | return recursive_; | ||
232 | } | ||
233 | |||
227 | private: | 234 | private: |
228 | std::string identifier_; | 235 | std::string identifier_; |
229 | field field_; | 236 | field field_; |
@@ -231,6 +238,7 @@ namespace verbly { | |||
231 | std::string topTable_; | 238 | std::string topTable_; |
232 | condition topCondition_; | 239 | condition topCondition_; |
233 | std::list<join> joins_; | 240 | std::list<join> joins_; |
241 | bool recursive_; | ||
234 | 242 | ||
235 | }; | 243 | }; |
236 | 244 | ||
@@ -254,7 +262,9 @@ namespace verbly { | |||
254 | 262 | ||
255 | std::string instantiateTable(std::string name); | 263 | std::string instantiateTable(std::string name); |
256 | 264 | ||
257 | condition integrate(statement subStmt); | 265 | std::string instantiateWith(std::string name); |
266 | |||
267 | condition integrate(statement subStmt, bool cte = false); | ||
258 | 268 | ||
259 | int nextTableId_; | 269 | int nextTableId_; |
260 | int nextWithId_; | 270 | int nextWithId_; |