SHA256
Сервер: исправить автоинициализацию PostgreSQL schema v1
This commit is contained in:
@@ -787,33 +787,88 @@ public final class DatabaseInitializer {
|
|||||||
List<String> statements = new ArrayList<>();
|
List<String> statements = new ArrayList<>();
|
||||||
StringBuilder current = new StringBuilder();
|
StringBuilder current = new StringBuilder();
|
||||||
boolean inSingleQuote = false;
|
boolean inSingleQuote = false;
|
||||||
|
boolean inLineComment = false;
|
||||||
|
boolean inBlockComment = false;
|
||||||
String dollarQuoteTag = null;
|
String dollarQuoteTag = null;
|
||||||
|
|
||||||
for (int i = 0; i < sqlScript.length(); i++) {
|
for (int i = 0; i < sqlScript.length(); i++) {
|
||||||
char ch = sqlScript.charAt(i);
|
char ch = sqlScript.charAt(i);
|
||||||
|
|
||||||
if (dollarQuoteTag == null && ch == '\'' && !isEscapedSingleQuote(sqlScript, i)) {
|
if (inLineComment) {
|
||||||
inSingleQuote = !inSingleQuote;
|
current.append(ch);
|
||||||
|
if (ch == '\n') {
|
||||||
|
inLineComment = false;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inBlockComment) {
|
||||||
|
current.append(ch);
|
||||||
|
if (ch == '*' && i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '/') {
|
||||||
|
current.append('/');
|
||||||
|
i += 1;
|
||||||
|
inBlockComment = false;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dollarQuoteTag != null) {
|
||||||
|
if (startsWithAt(sqlScript, i, dollarQuoteTag)) {
|
||||||
|
current.append(dollarQuoteTag);
|
||||||
|
i += dollarQuoteTag.length() - 1;
|
||||||
|
dollarQuoteTag = null;
|
||||||
|
} else {
|
||||||
|
current.append(ch);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inSingleQuote) {
|
||||||
|
current.append(ch);
|
||||||
|
if (ch == '\'') {
|
||||||
|
if (i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '\'') {
|
||||||
|
current.append('\'');
|
||||||
|
i += 1;
|
||||||
|
} else {
|
||||||
|
inSingleQuote = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch == '-' && i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '-') {
|
||||||
|
current.append("--");
|
||||||
|
i += 1;
|
||||||
|
inLineComment = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch == '/' && i + 1 < sqlScript.length() && sqlScript.charAt(i + 1) == '*') {
|
||||||
|
current.append("/*");
|
||||||
|
i += 1;
|
||||||
|
inBlockComment = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ch == '\'') {
|
||||||
|
inSingleQuote = true;
|
||||||
current.append(ch);
|
current.append(ch);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inSingleQuote) {
|
|
||||||
String tag = readDollarQuoteTag(sqlScript, i);
|
String tag = readDollarQuoteTag(sqlScript, i);
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
current.append(tag);
|
current.append(tag);
|
||||||
i += tag.length() - 1;
|
i += tag.length() - 1;
|
||||||
if (dollarQuoteTag == null) {
|
|
||||||
dollarQuoteTag = tag;
|
dollarQuoteTag = tag;
|
||||||
} else if (dollarQuoteTag.equals(tag)) {
|
|
||||||
dollarQuoteTag = null;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (ch == ';' && !inSingleQuote && dollarQuoteTag == null) {
|
if (ch == ';') {
|
||||||
|
String statement = current.toString().trim();
|
||||||
|
if (!statement.isEmpty()) {
|
||||||
statements.add(current.toString());
|
statements.add(current.toString());
|
||||||
|
}
|
||||||
current.setLength(0);
|
current.setLength(0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -822,13 +877,16 @@ public final class DatabaseInitializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!current.isEmpty()) {
|
if (!current.isEmpty()) {
|
||||||
|
String statement = current.toString().trim();
|
||||||
|
if (!statement.isEmpty()) {
|
||||||
statements.add(current.toString());
|
statements.add(current.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return statements;
|
return statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isEscapedSingleQuote(String sqlScript, int index) {
|
private static boolean startsWithAt(String sqlScript, int index, String token) {
|
||||||
return index + 1 < sqlScript.length() && sqlScript.charAt(index + 1) == '\'';
|
return sqlScript.regionMatches(index, token, 0, token.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readDollarQuoteTag(String sqlScript, int index) {
|
private static String readDollarQuoteTag(String sqlScript, int index) {
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
client.version=1.2.354
|
client.version=1.2.354
|
||||||
server.version=1.2.320
|
server.version=1.2.321
|
||||||
|
|||||||
Reference in New Issue
Block a user