Skip to content

Commit

Permalink
Partial parser validate comparison incorrect. Fixed agentgt#26
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed May 7, 2013
1 parent c5ec3bb commit 9ef549c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ protected ExpandedSql _expand(DeclarationSql f, Set<String> seenPaths) {
r.getStartIndex();

DeclarationSql ds = e.getDeclaration();
boolean validate = ! r.isSame() || ds.getDeclaredSql().equals(r.getDeclaredSql());
boolean validate = ! r.isSame() || ds.inner().equals(r.inner());
check.state(validate,
"Reference '> {}' in {} at line: {}" +
" does" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ public void testExpand() throws Exception {
}

@Test(expected=JirmIllegalStateException.class)
public void testValidate() throws Exception {
public void testValidateInvalid() throws Exception {
Parser p = SqlPartialParser.Parser.create();
p.expand("/co/jirm/core/sql/partial-test-validate.sql#other");
}

@Test
public void testIssue26ValidateValid() throws Exception {
SqlPartialParser.parseFromPath("/co/jirm/core/sql/issue26-partial-test-validate.sql#other");
}

@Test
public void testIssue25ValidateErrorMessage() throws Exception {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
SELECT
-- {#stuff}
c.id, c.name, c.tags, c.category, c.description,
c.division, c.experience_level as "experienceLevel",
c.locations, c.type, c.parent_id as "parentId",
g.latitude as "latitude", g.longitude as "longitude"
-- {/stuff}
FROM campaign c
LEFT OUTER JOIN
(SELECT DISTINCT cg.campaign, geo.latitude, geo.longitude from campaign_geo cg
INNER JOIN geo geo on geo.id = cg.geo
WHERE geo.latitude IS NOT NULL AND geo.longitude IS NOT NULL AND cg.createts < now() -- {}
) g on g.campaign = c.id
WHERE
-- {> #blah}
c.type = 'JOBPAGE' AND c.createts < now() -- {}
-- {<}
ORDER BY c.createts ASC, c.id, g.latitude, g.longitude
LIMIT 100 -- {}
OFFSET 1 -- {}

SELECT
-- {> #stuff}
c.id, c.name, c.tags, c.category, c.description,
c.division, c.experience_level as "experienceLevel",
c.locations, c.type, c.parent_id as "parentId",
g.latitude as "latitude", g.longitude as "longitude"
-- {<}
FROM campaign c
LEFT OUTER JOIN
(SELECT DISTINCT cg.campaign, geo.latitude, geo.longitude from campaign_geo cg
INNER JOIN geo geo on geo.id = cg.geo
WHERE geo.latitude IS NOT NULL AND geo.longitude IS NOT NULL AND cg.createts < now() -- {}
) g on g.campaign = c.id
WHERE
-- {#blah}
c.type = 'JOBPAGE' AND c.createts < now() -- {}
-- {/blah}
ORDER BY c.createts ASC, c.id, g.latitude, g.longitude
LIMIT 100 -- {}
OFFSET 1 -- {}

-- {#other}
SELECT
-- {> #stuff same }
c.id, c.name, c.tags, c.category, c.description,
c.division, c.experience_level as "experienceLevel",
c.locations, c.type, c.parent_id as "parentId",
g.latitude as "latitude", g.longitude as "longitude"
-- {<}
FROM campaign c
LEFT OUTER JOIN
(SELECT DISTINCT cg.campaign, geo.latitude, geo.longitude from campaign_geo cg
INNER JOIN geo geo on geo.id = cg.geo
WHERE geo.latitude IS NOT NULL AND geo.longitude IS NOT NULL AND cg.createts < now() -- {}
) g on g.campaign = c.id
ORDER BY c.createts ASC, c.id, g.latitude, g.longitude
LIMIT 100 -- {}
OFFSET 1 -- {}
-- {/other}

0 comments on commit 9ef549c

Please sign in to comment.