Get DB2-specific parser instance

112 Views Asked by At

I'm trying to create a simple plugin where I can paste in an sql query from our logs and have it display the column names and inserted values in a table. I've got it working, except for dates and times, because our DB2 database uses special values like {d: '2014-07-03'} rather than '2014-07-03'.

How do I figure out what values I need to pass to SQLQueryParserManagerProvider.getInstance().getParserManager(dbProduct, dbVersion);

to get the right parser that can handle these values?

1

There are 1 best solutions below

1
On BEST ANSWER

Set up a connection in the Database Development view (I called mine QA), double click to open a connection, then run:

IConnectionProfile profile = ProfileManager.getInstance().getProfileByName("QA");
Database db = getDatabase(profile);
if (db != null) {
    System.out.println("DB Vendor: " + db.getVendor());
    System.out.println("DB Version: " + db.getVersion());
}

getDatabase method was taken from the end of this page:

private Database getDatabase(IConnectionProfile profile) {
    IManagedConnection managedConnection = ((IConnectionProfile) profile)
            .getManagedConnection("org.eclipse.datatools.connectivity.sqm.core.connection.ConnectionInfo");
    if (managedConnection != null) {
        try {
            ConnectionInfo connectionInfo = (ConnectionInfo) managedConnection.getConnection().getRawConnection();
            if (connectionInfo != null) {
                Database database = connectionInfo.getSharedDatabase();
                return database;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}