Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add an ability to read metadata for attached databases #829

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
45 changes: 45 additions & 0 deletions src/main/java/org/sqlite/core/CoreDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ protected static String quote(String tableName) {
}
}

/**
* Escapes all wildcards, to prevent pattern matching for functions which should not support it
*
* @param val The string to escape
* @return The string with escaped wildcards
*/
protected static String escapeWildcards(final String val) {
if (val == null) {
return null;
}
String replacement = val.replace("%", "\\%");
replacement = replacement.replace("_", "\\_");
return replacement;
}

/**
* Applies SQL escapes for special characters in a given string.
*
Expand All @@ -184,6 +199,36 @@ protected String escape(final String val) {
return buf.toString();
}

/**
* Returns line without changes or with escaped schema prefix
*
* @param schema schema name
* @param line of text to prepend to
* @return The SQL escaped schema name with dot or empty string
*/
protected String prependSchemaPrefix(String schema, String line) {
if (schema == null) {
return line;
} else {
return escape(schema) + "." + line;
}
}

/**
* Adds line without changes or with escaped schema prefix
*
* @param sql String builder for sql request
* @param schema schema name
* @param line line to prepend schema prefix to
*/
protected void prependSchemaPrefix(StringBuilder sql, String schema, String line) {
if (schema == null) {
sql.append(line);
} else {
sql.append(schema).append('.').append(line);
}
}

// inner classes

/** Pattern used to extract column order for an unnamed primary key. */
Expand Down
Loading