forked from h2database/h2database
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue#479 Made column names optional
- Loading branch information
Showing
3 changed files
with
40 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
package org.h2.command.dml; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class RecursiveQuery { | ||
|
||
// A query is recursive if it references it's own name in its definition | ||
public static boolean isRecursive(String tempViewName, String querySQL) { | ||
return Pattern.matches("\\b"+tempViewName+"\\b",querySQL); | ||
// ?i is case insensitive | ||
// ?m is multi-line search | ||
// ?d is Unix line endings | ||
String pattern = "(?i)(?m)(?d).*\\b("+tempViewName+")\\b"; | ||
System.out.println("pattern="+pattern); | ||
boolean stringContains = querySQL.contains(tempViewName); | ||
System.out.println("stringContains="+stringContains); | ||
boolean foundAny = RecursiveQuery.foundAny(tempViewName,querySQL); | ||
System.out.println("foundAny="+foundAny); | ||
boolean patternMatch = Pattern.matches(pattern,querySQL); | ||
System.out.println("patternMatch="+patternMatch); | ||
return patternMatch||stringContains|| foundAny; | ||
} | ||
|
||
private static boolean foundAny(String tempViewName, String querySQL){ | ||
Pattern p = Pattern.compile("(?i)(?m)(?d)\\b("+tempViewName+")\\b"); | ||
Matcher m = p.matcher(querySQL); | ||
while (m.find()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters