SOLR-8652: Check if second to last token is limit to test for limit clause

This commit is contained in:
jbernste 2016-02-06 21:25:05 -05:00
parent ba20faa955
commit 75a81795b8
1 changed files with 8 additions and 1 deletions

View File

@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random; import java.util.Random;
@ -59,7 +60,7 @@ class StatementImpl implements Statement {
this.currentResultSet = null; this.currentResultSet = null;
} }
if(maxRows > 0 && !(sql.toLowerCase()).contains("limit")) { if(maxRows > 0 && !containsLimit(sql)) {
sql = sql + " limit "+Integer.toString(maxRows); sql = sql + " limit "+Integer.toString(maxRows);
} }
@ -356,4 +357,10 @@ class StatementImpl implements Statement {
public boolean isWrapperFor(Class<?> iface) throws SQLException { public boolean isWrapperFor(Class<?> iface) throws SQLException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
private boolean containsLimit(String sql) {
String[] tokens = sql.split("\\s+");
String secondToLastToken = tokens[tokens.length-2];
return ("limit").equals(secondToLastToken);
}
} }