Skip to content

Commit

Permalink
fix:bugs with parse
Browse files Browse the repository at this point in the history
  • Loading branch information
davecramer committed Apr 15, 2016
1 parent 2032836 commit 72945b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
32 changes: 16 additions & 16 deletions pgjdbc/src/main/java/org/postgresql/core/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,12 @@ public static boolean parseDeleteKeyword(final char[] query, int offset) {
return false;
}

return Character.toUpperCase(query[offset + 1]) == 'd'
&& Character.toUpperCase(query[offset + 1]) == 'e'
&& Character.toUpperCase(query[offset + 2]) == 'l'
&& Character.toUpperCase(query[offset + 3]) == 'e'
&& Character.toUpperCase(query[offset + 4]) == 't'
&& Character.toUpperCase(query[offset + 5]) == 'e';
return (query[offset ] | 32) == 'd'
&& (query[offset + 1] | 32) == 'e'
&& (query[offset + 2] | 32) == 'l'
&& (query[offset + 3] | 32) == 'e'
&& (query[offset + 4] | 32) == 't'
&& (query[offset + 5] | 32) == 'e';
}

/**
Expand Down Expand Up @@ -465,10 +465,10 @@ public static boolean parseMoveKeyword(final char[] query, int offset) {
return false;
}

return Character.toUpperCase(query[offset + 1]) == 'm'
&& Character.toUpperCase(query[offset + 1]) == 'o'
&& Character.toUpperCase(query[offset + 2]) == 'v'
&& Character.toUpperCase(query[offset + 3]) == 'e';
return (query[offset] | 32) == 'm'
&& (query[offset + 1] | 32) == 'o'
&& (query[offset + 2] | 32) == 'v'
&& (query[offset + 3] | 32) == 'e';
}

/**
Expand Down Expand Up @@ -504,12 +504,12 @@ public static boolean parseUpdateKeyword(final char[] query, int offset) {
return false;
}

return Character.toUpperCase(query[offset + 1]) == 'u'
&& Character.toUpperCase(query[offset + 1]) == 'p'
&& Character.toUpperCase(query[offset + 2]) == 'd'
&& Character.toUpperCase(query[offset + 3]) == 'a'
&& Character.toUpperCase(query[offset + 4]) == 't'
&& Character.toUpperCase(query[offset + 5]) == 'e';
return (query[offset] | 32) == 'u'
&& (query[offset + 1] | 32) == 'p'
&& (query[offset + 2] | 32) == 'd'
&& (query[offset + 3] | 32) == 'a'
&& (query[offset + 4] | 32) == 't'
&& (query[offset + 5] | 32) == 'e';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ public void testHasReturning() {

}

public void testHasDelete()
{
List<NativeQuery> queries = Parser.parseJdbcSql("delete from foo where a=1", true, true, false, true, true);
NativeQuery query = queries.get(0);
assertTrue("This is a delete command", query.command.getType() == DMLCommandType.DELETE);

queries = Parser.parseJdbcSql("update foo set (a=?,b=?,c=?)", true, true, false, true, true);
query = queries.get(0);
assertFalse("This is not a delete command", query.command.getType() == DMLCommandType.DELETE);

}
public void testIsInsert() {

List<NativeQuery> queries = Parser.parseJdbcSql("insert into foo (a,b,c) values (?,?,?) returning a", true, true, false, true, true);
Expand All @@ -97,7 +108,7 @@ public void testIsInsert() {

queries = Parser.parseJdbcSql("update foo set (a=?,b=?,c=?)", true, true, false, true, true);
query = queries.get(0);
assertFalse("This is an insert command", query.command.getType() == DMLCommandType.INSERT);
assertFalse("This is not insert command", query.command.getType() == DMLCommandType.INSERT);

queries = Parser.parseJdbcSql("select 1 as insert", true, true, false, true, true);
query = queries.get(0);
Expand Down

0 comments on commit 72945b0

Please sign in to comment.