use of org.jooq.impl.ParserException in project jOOQ by jOOQ.
the class SQLiteDatabase method loadCheckConstraints.
@Override
protected void loadCheckConstraints(DefaultRelations r) throws SQLException {
DSLContext ctx = create().configuration().deriveSettings(s -> s.withInterpreterDelayForeignKeyDeclarations(true)).dsl();
SchemaDefinition schema = getSchemata().get(0);
for (Record record : ctx.select(SQLiteMaster.TBL_NAME, SQLiteMaster.SQL).from(SQLITE_MASTER).where(SQLiteMaster.SQL.likeIgnoreCase("%CHECK%")).orderBy(SQLiteMaster.TBL_NAME)) {
TableDefinition table = getTable(schema, record.get(SQLiteMaster.TBL_NAME));
if (table != null) {
String sql = record.get(SQLiteMaster.SQL);
try {
Query query = ctx.parser().parseQuery(sql);
for (Table<?> t : ctx.meta(query).getTables(table.getName())) {
for (Check<?> check : t.getChecks()) {
r.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, check.getName(), ctx.renderInlined(check.condition()), check.enforced()));
}
}
} catch (ParserException e) {
log.info("Cannot parse SQL: " + sql, e);
} catch (DataDefinitionException e) {
log.info("Cannot interpret SQL: " + sql, e);
}
}
}
}
use of org.jooq.impl.ParserException in project jOOQ by jOOQ.
the class SQLiteTableDefinition method interpretedTable.
Table<?> interpretedTable() {
if (interpretedTable == null) {
try {
Configuration c = create().configuration().derive();
c.settings().withParseWithMetaLookups(THROW_ON_FAILURE);
Query query = create().parser().parseQuery(getSource());
for (Table<?> t : create().meta(query).getTables(getInputName())) return interpretedTable = t;
} catch (ParserException e) {
log.info("Cannot parse SQL: " + getSource(), e);
} catch (DataDefinitionException e) {
log.info("Cannot interpret SQL: " + getSource(), e);
}
}
return interpretedTable;
}
use of org.jooq.impl.ParserException in project jOOQ by jOOQ.
the class DDLDatabase method export.
@Override
protected void export() throws Exception {
Settings defaultSettings = new Settings();
String scripts = getProperties().getProperty("scripts");
String encoding = getProperties().getProperty("encoding", "UTF-8");
String sort = getProperties().getProperty("sort", "semantic").toLowerCase();
final String defaultNameCase = getProperties().getProperty("defaultNameCase", "as_is").toUpperCase();
boolean parseIgnoreComments = !"false".equalsIgnoreCase(getProperties().getProperty("parseIgnoreComments"));
String parseIgnoreCommentStart = getProperties().getProperty("parseIgnoreCommentStart", defaultSettings.getParseIgnoreCommentStart());
String parseIgnoreCommentStop = getProperties().getProperty("parseIgnoreCommentStop", defaultSettings.getParseIgnoreCommentStop());
logExecutedQueries = !"false".equalsIgnoreCase(getProperties().getProperty("logExecutedQueries"));
logExecutionResults = !"false".equalsIgnoreCase(getProperties().getProperty("logExecutionResults"));
if (isBlank(scripts)) {
scripts = "";
log.warn("No scripts defined", "It is recommended that you provide an explicit script directory to scan");
}
try {
final DSLContext ctx = DSL.using(connection(), new Settings().withParseIgnoreComments(parseIgnoreComments).withParseIgnoreCommentStart(parseIgnoreCommentStart).withParseIgnoreCommentStop(parseIgnoreCommentStop).withParseUnknownFunctions(ParseUnknownFunctions.IGNORE));
// [#7771] [#8011] Ignore all parsed storage clauses when executing the statements
ctx.data("org.jooq.ddl.ignore-storage-clauses", true);
// [#8910] Parse things a bit differently for use with the DDLDatabase
ctx.data("org.jooq.ddl.parse-for-ddldatabase", true);
if (!"AS_IS".equals(defaultNameCase)) {
ctx.configuration().set(new DefaultVisitListener() {
@Override
public void visitStart(VisitContext vc) {
if (vc.queryPart() instanceof Name) {
Name n = (Name) vc.queryPart();
Name[] parts = n.parts();
boolean changed = false;
for (int i = 0; i < parts.length; i++) {
// flag for DSL.systemName() names
if (parts[i].quoted() == Quoted.UNQUOTED) {
parts[i] = DSL.quotedName("UPPER".equals(defaultNameCase) ? parts[i].first().toUpperCase(renderLocale(ctx.settings())) : parts[i].first().toLowerCase(renderLocale(ctx.settings())));
changed = true;
}
}
if (changed)
vc.queryPart(DSL.name(parts));
}
}
});
}
new FilePattern().encoding(encoding).basedir(new File(getBasedir())).pattern(scripts).sort(Sort.of(sort)).load(source -> DDLDatabase.this.load(ctx, source));
} catch (ParserException e) {
log.error("An exception occurred while parsing script source : " + scripts + ". Please report this error to https://github.com/jOOQ/jOOQ/issues/new", e);
throw e;
}
}
Aggregations