I am using Eclipse 4.5.1 Mars and the Data Tools Project is already integrated in this distribution. I am trying to use the SQL Query Parser of the Data Tools Project to parse a SQL-file. I created a new Java project, a package and a class and I used the code example given here: http://dev.eclipse.org/mhonarc/lists/dtp-sqldevtools-dev/msg00074.html
But I have trouble to resolve the required classes to use the parser. E.g. at the very beginning of the code you find this statement: SQLQueryParserManager parserManager = SQLQueryParserManagerProvider SQLQueryParserManager shows an error and asks to "Import 'SQLQueryParserManager ' (org.eclipse.datatools.sqltools.parsers.sql.query)" - which I do. At the import-statement section at the top of the java file "import org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager;" is the relevant reference. However, it keep on telling me that 'The import org.eclipse' can not be resolved.
I do not know anymore how to solve it. I tried to download the DTP and copied the plugins in the the plugin Folder of Mars but there was no change either.
Here is the .java-File that I try to run. It is pretty simple but still the required classes can not be resolved for some reasons. The classes should be part of eclipse Mars imo. I tried different Eclipse downloads and for all its the same. Please help
// imports needed
import java.util.Iterator;
import java.util.List;
import org.eclipse.datatools.sqltools.parsers.sql.query.src.org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParseResult;
import org.eclipse.datatools.sqltools.parsers.sql.query.src.org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager;
import org.eclipse.datatools.sqltools.parsers.sql.query.src.org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManagerProvider;
import org.eclipse.datatools.sqltools.parsers.sql.src.org.eclipse.datatools.sqltools.parsers.sql.SQLParseErrorInfo;
import org.eclipse.datatools.sqltools.parsers.sql.src.org.eclipse.datatools.sqltools.parsers.sql.SQLParserException;
import org.eclipse.datatools.sqltools.parsers.sql.src.org.eclipse.datatools.sqltools.parsers.sql.SQLParserInternalException;
class LPGParserExample {
public static void main(String args[]) {
try {
// Create an instance the Parser Manager
// SQLQueryParserManagerProvider.getInstance().getParserManager
// returns the best compliant SQLQueryParserManager
// supporting the SQL dialect of the database described by the given
// database product information. In the code below null is passed
// for both the database and version
// in which case a generic parser is returned
SQLQueryParserManager parserManager = SQLQueryParserManagerProvider
.getInstance().getParserManager(null, null);
// Sample query
String sql = "SELECT * FROM TABLE1";
// Parse
SQLQueryParseResult parseResult = parserManager.parseQuery(sql);
// Get the Query Model object from the result
QueryStatement resultObject = parseResult.getQueryStatement();
// Get the SQL text
String parsedSQL = resultObject.getSQL();
System.out.println(parsedSQL);
} catch (SQLParserException spe) {
// handle the syntax error
System.out.println(spe.getMessage());
List syntacticErrors = spe.getErrorInfoList();
Iterator itr = syntacticErrors.iterator();
while (itr.hasNext()) {
SQLParseErrorInfo errorInfo = (SQLParseErrorInfo) itr.next();
// Example usage of the SQLParseErrorInfo object
// the error message
String errorMessage = errorInfo.getParserErrorMessage();
// the line numbers of error
int errorLine = errorInfo.getLineNumberStart();
int errorColumn = errorInfo.getColumnNumberStart();
}
} catch (SQLParserInternalException spie) {
// handle the exception
System.out.println(spie.getMessage());
}
}
}