Skip to content

Commit

Permalink
Add padding around "SET" check to avoid potential problems with classes
Browse files Browse the repository at this point in the history
containing those letters. Fixes datanucleus#274
  • Loading branch information
andyjefferson committed Jan 12, 2018
1 parent ca31d3f commit 0d44b87
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/java/org/datanucleus/query/JPQLSingleStringParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ public void parse()
}

/**
* Compiler to process keywords contents. In the query the keywords often have
* content values following them that represent the constituent parts of the query. This takes the keyword
* and sets the constituent part accordingly.
* Compiler to process keywords contents.
* In the query the keywords often have content values following them that represent the constituent parts of the query.
* This takes the keyword and sets the constituent part accordingly.
*/
private class Compiler
{
Expand Down Expand Up @@ -294,27 +294,28 @@ private void compileUpdate()
{
// Subquery (or subqueries) present so split them out and just apply the filter for this query
String substitutedContent = processContentWithSubqueries(content);

String contentUpper = substitutedContent.toUpperCase();
int setIndex = contentUpper.indexOf("SET");
int setIndex = contentUpper.indexOf(" SET ");
if (setIndex < 0)
{
// UPDATE clause has no "SET ..." !
// UPDATE clause has no " SET ..." !
throw new NucleusUserException(Localiser.msg("043011"));
}
query.setFrom(substitutedContent.substring(0, setIndex).trim());
query.setUpdate(substitutedContent.substring(setIndex+3).trim());
query.setFrom(substitutedContent.substring(0, setIndex+1).trim());
query.setUpdate(substitutedContent.substring(setIndex+4).trim());
}
else
{
String contentUpper = content.toUpperCase();
int setIndex = contentUpper.indexOf("SET");
int setIndex = contentUpper.indexOf(" SET ");
if (setIndex < 0)
{
// UPDATE clause has no "SET ..." !
// UPDATE clause has no " SET ..." !
throw new NucleusUserException(Localiser.msg("043011"));
}
query.setFrom(content.substring(0, setIndex).trim());
query.setUpdate(content.substring(setIndex+3).trim());
query.setFrom(content.substring(0, setIndex+1).trim());
query.setUpdate(content.substring(setIndex+4).trim());
}
}

Expand Down

0 comments on commit 0d44b87

Please sign in to comment.