Java Code Examples for net.sf.jsqlparser.JSQLParserException#printStackTrace()

The following examples show how to use net.sf.jsqlparser.JSQLParserException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaExtractor.java    From evosql with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, TableSchema> getTablesFromQuery(String pathToBeTested) {
    Map<String, TableSchema> tableSchemas = new HashMap<>();

    // Get a list of table names from the query
    Statement stmt;
    try {
        stmt = CCJSqlParserUtil.parse(pathToBeTested);
    } catch (JSQLParserException e) {
        e.printStackTrace();
        return null;
    }

    if (!(stmt instanceof Select)) {
        return null;
    }
    List<String> tableList = new TablesNamesFinder().getTableList(stmt);

    for (String tableName : tableList) {
        tableName = tableName.replaceAll("^\"|\"$", ""); // Remove quotes around tablenames
        tableSchemas.put(tableName, this.extract(tableName));
    }

    return tableSchemas;
}
 
Example 2
Source File: MockedSchemaExtractor.java    From evosql with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, TableSchema> getTablesFromQuery(String pathToBeTested) {
    Map<String, TableSchema> tableSchemas = new HashMap<String, TableSchema>();

    // Get a list of table names from the query
    Statement stmt;
    try {
        stmt = CCJSqlParserUtil.parse(pathToBeTested);
    } catch (JSQLParserException e) {
        e.printStackTrace();
        return null;
    }

    if (!(stmt instanceof Select)) {
        return null;
    }
    List<String> tableList = new TablesNamesFinder().getTableList(stmt);

    for (String tableName : tableList) {
        tableName = tableName.replaceAll("^\"|\"$", ""); // Remove quotes around tablenames
        tableSchemas.put(tableName,	this.extract(tableName));
    }

    return tableSchemas;
}
 
Example 3
Source File: SqlUtils.java    From sql-to-mongo-db-query-converter with Apache License 2.0 5 votes vote down vote up
public static Expression cloneExpression(Expression expression) {
	if(expression == null) {
		return null;
	}
	try {
		return CCJSqlParserUtil.parseCondExpression(expression.toString());
	} catch (JSQLParserException e) {
		// Never exception because clone
		e.printStackTrace();
		return null;
	}
}
 
Example 4
Source File: TableNameReplacerTests.java    From DDF with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnion() {
    TableNameReplacer tableNameReplacer = new TableNameReplacer(manager);
    String sqlcmd = "select * from ddf://adatao/a union select * from " +
            "ddf://adatao/b";
    try {
        Statement statement = parser.parse(new StringReader(sqlcmd));
        // System.out.println(statement.toString());
        int a = 2;
    } catch (JSQLParserException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: StatementAnalyzer.java    From aceql-http with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
    * Constructor.
    *
    * @param sql             the string content of the SQL parsedStatement.
    * @param parameterValues the parameter values of a prepared parsedStatement in
    *                        the natural order, empty list for a (non prepared)
    *                        parsedStatement
    * @throws SQLException if the parsed Statement can not be parsed
    */
   public StatementAnalyzer(String sql, List<Object> parameterValues) throws SQLException {

if (sql == null) {
    throw new IllegalArgumentException(Tag.PRODUCT_PRODUCT_FAIL + "sql can not be null!");
}

if (parameterValues == null) {
    throw new IllegalArgumentException(Tag.PRODUCT_PRODUCT_FAIL + "parameterValues can not be null!");
}

sql = trimAndremoveTrailingSemicolons(sql);
this.sql = sql;

this.tables = new ArrayList<>();
String theStatementName = StringUtils.substringBefore(sql, BLANK);

// Can not treat GRANT, REVOKE or ROLLBACK here, not supported by
// CCJSqlParserUtil
if (theStatementName.equalsIgnoreCase("GRANT")) {
    this.statementName = "GRANT";
    this.isDCL = true;
    this.tables = new ArrayList<>();
} else if (theStatementName.equalsIgnoreCase("REVOKE")) {
    this.statementName = "REVOKE";
    this.isDCL = true;
    this.tables = new ArrayList<>();
} else if (theStatementName.equalsIgnoreCase("ROLLBACK")) {
    this.statementName = "ROLLBACK";
    this.isTCL = true;
    this.tables = new ArrayList<>();
} else if (theStatementName.equalsIgnoreCase("DROP")) {
    this.statementName = "DROP";
    this.isDDL = true;
    this.tables = new ArrayList<>();
} else {
    parsedStatement = null;
    try {
	parsedStatement = CCJSqlParserUtil.parse(sql);
	JsqlParserWrapper jsqlParserWrapper = new JsqlParserWrapper(parsedStatement);
	this.isDCL = jsqlParserWrapper.isDCL();
	this.isDDL = jsqlParserWrapper.isDDL();
	this.isDML = jsqlParserWrapper.isDML();
	this.isTCL = jsqlParserWrapper.isTCL();

	this.tables = jsqlParserWrapper.getTables();
	this.statementName = jsqlParserWrapper.getStatementName();

    } catch (JSQLParserException e) {
	if (DEBUG) {
	    e.printStackTrace(System.err);
	}
	this.parseException = new SQLException(e);
    }
}

// If returned parsedStatement is null, let's assume it was not parsed
if (parsedStatement == null) {
    this.statementTypeNotParsed = true;
}

if (this.statementName == null) {
    this.statementName = StringUtils.substringBefore(sql, BLANK);
}

this.parameterValues = parameterValues;
   }