use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class OracleDataSource method getErrorPosition.
@Nullable
@Override
public ErrorPosition[] getErrorPosition(@NotNull DBRProgressMonitor monitor, @NotNull DBCExecutionContext context, @NotNull String query, @NotNull Throwable error) {
while (error instanceof DBException) {
if (error.getCause() == null) {
break;
}
error = error.getCause();
}
String message = error.getMessage();
if (!CommonUtils.isEmpty(message)) {
Matcher matcher = ERROR_POSITION_PATTERN.matcher(message);
List<ErrorPosition> positions = new ArrayList<>();
while (matcher.find()) {
DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
pos.info = matcher.group(1);
pos.line = Integer.parseInt(matcher.group(1)) - 1;
pos.position = Integer.parseInt(matcher.group(2)) - 1;
positions.add(pos);
}
if (!positions.isEmpty()) {
return positions.toArray(new ErrorPosition[positions.size()]);
}
}
if (error instanceof SQLException && SQLState.SQL_42000.getCode().equals(((SQLException) error).getSQLState())) {
try (JDBCSession session = (JDBCSession) context.openSession(monitor, DBCExecutionPurpose.UTIL, "Extract last error position")) {
try (CallableStatement stat = session.prepareCall("declare\n" + " l_cursor integer default dbms_sql.open_cursor; \n" + "begin \n" + " begin \n" + " dbms_sql.parse( l_cursor, ?, dbms_sql.native ); \n" + " exception \n" + " when others then ? := dbms_sql.last_error_position; \n" + " end; \n" + " dbms_sql.close_cursor( l_cursor );\n" + "end;")) {
stat.setString(1, query);
stat.registerOutParameter(2, Types.INTEGER);
stat.execute();
int errorPos = stat.getInt(2);
if (errorPos <= 0) {
return null;
}
DBPErrorAssistant.ErrorPosition pos = new DBPErrorAssistant.ErrorPosition();
pos.position = errorPos;
return new ErrorPosition[] { pos };
} catch (SQLException e) {
// Something went wrong
log.debug("Can't extract parse error info: " + e.getMessage());
}
}
}
return null;
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class OracleTablePhysical method getPartitionInfo.
@PropertyGroup
@LazyProperty(cacheValidator = PartitionInfoValidator.class)
public PartitionInfo getPartitionInfo(DBRProgressMonitor monitor) throws DBException {
if (partitionInfo == null && partitioned) {
try (final JDBCSession session = DBUtils.openMetaSession(monitor, getDataSource(), "Load partitioning info")) {
try (JDBCPreparedStatement dbStat = session.prepareStatement("SELECT * FROM ALL_PART_TABLES WHERE OWNER=? AND TABLE_NAME=?")) {
dbStat.setString(1, getContainer().getName());
dbStat.setString(2, getName());
try (JDBCResultSet dbResult = dbStat.executeQuery()) {
if (dbResult.next()) {
partitionInfo = new PartitionInfo(monitor, this.getDataSource(), dbResult);
}
}
}
} catch (SQLException e) {
throw new DBException(e, getDataSource());
}
}
return partitionInfo;
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class FireBirdUtils method getProcedureSource.
public static String getProcedureSource(DBRProgressMonitor monitor, GenericProcedure procedure) throws DBException {
try (JDBCSession session = DBUtils.openMetaSession(monitor, procedure.getDataSource(), "Load procedure source code")) {
DatabaseMetaData fbMetaData = session.getOriginal().getMetaData();
String source = (String) fbMetaData.getClass().getMethod("getProcedureSourceCode", String.class).invoke(fbMetaData, procedure.getName());
if (CommonUtils.isEmpty(source)) {
return null;
}
return getProcedureSourceWithHeader(monitor, procedure, source);
} catch (SQLException e) {
throw new DBException("Can't read source code of procedure '" + procedure.getName() + "'", e);
} catch (Exception e) {
log.debug(e);
return null;
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class SSHTunnelImpl method closeTunnel.
@Override
public void closeTunnel(DBRProgressMonitor monitor) throws DBException, IOException {
if (session != null) {
RuntimeUtils.runTask(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
session.disconnect();
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
}, "Close SSH session", 1000);
session = null;
}
}
use of org.jkiss.dbeaver.DBException in project dbeaver by serge-rider.
the class SQLQueryTransformerCount method transformQuery.
@Override
public SQLQuery transformQuery(SQLDataSource dataSource, SQLQuery query) throws DBException {
try {
Statement statement = CCJSqlParserUtil.parse(query.getQuery());
if (statement instanceof Select && ((Select) statement).getSelectBody() instanceof PlainSelect) {
PlainSelect select = (PlainSelect) ((Select) statement).getSelectBody();
List<SelectItem> selectItems = new ArrayList<>();
Function countFunc = new Function();
countFunc.setName("count");
countFunc.setParameters(new ExpressionList(Collections.<Expression>singletonList(new Column("*"))));
SelectItem countItem = new SelectExpressionItem(countFunc);
selectItems.add(countItem);
select.setSelectItems(selectItems);
return new SQLQuery(dataSource, select.toString(), query, false);
} else {
throw new DBException("Query [" + query.getQuery() + "] can't be modified");
}
} catch (JSQLParserException e) {
throw new DBException("Can't transform query to SELECT count(*)", e);
}
}
Aggregations