Skip to content

Commit

Permalink
first try to fix .group with .offset with .count (unsuccessful :( )
Browse files Browse the repository at this point in the history
  • Loading branch information
arkadiyk committed Jan 17, 2011
1 parent 80b05a2 commit 3f1602e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/java/arjdbc/sybase/SybaseRubyJdbcConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private boolean executeQueryWithOffset(Statement stmt, String query, String limi
}

private static Pattern COUNT_PATTERN = Pattern.compile("\\sCOUNT\\s*\\(.+\\)", Pattern.CASE_INSENSITIVE);
// private static Pattern COUNT_AS_MATCHER = Pattern.compile("\\sCOUNT\\s*\\(.+\\)\\s+AS count_(.+),", Pattern.CASE_INSENSITIVE);
private static Pattern LIMIT_PATTERN = Pattern.compile("\\sLIMIT\\s+(\\d+)", Pattern.CASE_INSENSITIVE);
private static Pattern OFFSET_PATTERN = Pattern.compile("\\sOFFSET\\s+(\\d+)", Pattern.CASE_INSENSITIVE);
/**
Expand All @@ -146,6 +147,19 @@ private static Map<String, String> extractLimitOffsetAndCount(String queryString
queryString = countMatcher.replaceAll(" 'F' as f ");
}

/**
* Not 100% sure if we need something like "User.group(:name).limit(10).offset(10).count"
* without "offset" it works fine as it is.
* If we do need it, it should be matched here and implemented in <code>executeQueryWithOffset</code>
*/
/*
Matcher countAsMatcher = COUNT_AS_MATCHER.matcher(queryString);
if(countAsMatcher.find()) {
parsedQuery.put("count","Y");
queryString = countMatcher.replaceAll(" 'F' as f ");
}
*/

Matcher limitMatcher = LIMIT_PATTERN.matcher(queryString);
if(limitMatcher.find()) {
parsedQuery.put("limit",limitMatcher.group(1));
Expand Down

0 comments on commit 3f1602e

Please sign in to comment.