use of org.postgresql.util.PSQLException in project questdb by bluestreak01.
the class PGJobContextTest method testPreparedStatementInsertSelectNullDesignatedColumn.
@Test
public void testPreparedStatementInsertSelectNullDesignatedColumn() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (final PGWireServer ignored = createPGServer(2);
final Connection connection = getConnection(false, false);
final Statement statement = connection.createStatement();
final PreparedStatement insert = connection.prepareStatement("insert into tab(ts, value) values(?, ?)")) {
statement.execute("create table tab(ts timestamp, value double) timestamp(ts) partition by MONTH");
// Null is not allowed
insert.setNull(1, Types.NULL);
insert.setNull(2, Types.NULL);
try {
insert.executeUpdate();
fail("cannot insert null when the column is designated");
} catch (PSQLException expected) {
Assert.assertEquals("ERROR: timestamp before 1970-01-01 is not allowed", expected.getMessage());
}
// Insert a dud
insert.setString(1, "1970-01-01 00:11:22.334455");
insert.setNull(2, Types.NULL);
insert.executeUpdate();
try (ResultSet rs = statement.executeQuery("select null, ts, value from tab where value = null")) {
StringSink sink = new StringSink();
String expected = "null[VARCHAR],ts[TIMESTAMP],value[DOUBLE]\n" + "null,1970-01-01 00:11:22.334455,null\n";
assertResultSet(expected, sink, rs);
}
statement.execute("drop table tab");
}
});
}
use of org.postgresql.util.PSQLException in project questdb by bluestreak01.
the class PGJobContextTest method testBlobOverLimit.
@Test
public void testBlobOverLimit() throws Exception {
PGWireConfiguration configuration = new DefaultPGWireConfiguration() {
@Override
public int getMaxBlobSizeOnQuery() {
return 150;
}
};
TestUtils.assertMemoryLeak(() -> {
try (final PGWireServer ignored = createPGServer(configuration);
final Connection connection = getConnection(false, true)) {
Statement statement = connection.createStatement();
statement.executeQuery("select " + "rnd_str(4,4,4) s, " + "rnd_int(0, 256, 4) i, " + "rnd_double(4) d, " + "timestamp_sequence(0,10000) t, " + "rnd_float(4) f, " + "rnd_short() _short, " + "rnd_long(0, 10000000, 5) l, " + "rnd_timestamp(to_timestamp('2015','yyyy'),to_timestamp('2016','yyyy'),2) ts2, " + "rnd_byte(0,127) bb, " + "rnd_boolean() b, " + "rnd_symbol(4,4,4,2), " + "rnd_date(to_date('2015', 'yyyy'), to_date('2016', 'yyyy'), 2)," + "rnd_bin(1024,2048,2) " + "from long_sequence(50)");
Assert.fail();
} catch (PSQLException e) {
TestUtils.assertContains(e.getServerErrorMessage().getMessage(), "blob is too large");
}
});
}
use of org.postgresql.util.PSQLException in project cloudbreak by hortonworks.
the class RdsConnectionBuilder method createDb.
private void createDb(Connection conn, String clusterName, String service) {
String createSQL = "CREATE DATABASE ?";
try (PreparedStatement preparedStatement = conn.prepareStatement(createSQL)) {
preparedStatement.setString(1, clusterName + service);
preparedStatement.executeUpdate(createSQL);
} catch (PSQLException ex) {
if ("42P04".equals(ex.getSQLState())) {
LOGGER.warn("The expected database already exist");
} else {
throw new BadRequestException("Failed to create database in RDS: " + ex.getMessage(), ex);
}
} catch (SQLException e) {
throw new BadRequestException("Failed to connect to RDS: " + e.getMessage(), e);
}
}
use of org.postgresql.util.PSQLException in project cloudbreak by hortonworks.
the class SqlUtil method getProperSqlErrorMessage.
public static String getProperSqlErrorMessage(DataIntegrityViolationException ex) {
Throwable cause = ex.getCause();
while (cause.getCause() != null || cause instanceof PSQLException) {
if (cause instanceof PSQLException && !((SQLException) cause).getSQLState().isEmpty()) {
PSQLException e = (PSQLException) cause;
String[] split = e.getLocalizedMessage().split("\\n");
if (split.length > 0) {
return split[0];
}
}
cause = cause.getCause();
}
return ex.getLocalizedMessage();
}
use of org.postgresql.util.PSQLException in project midpoint by Evolveum.
the class SqaleServiceBase method recordFatalError.
protected void recordFatalError(@NotNull OperationResult operationResult, @NotNull Throwable t) {
String exceptionMessage = t.toString();
if (t instanceof com.querydsl.core.QueryException) {
PSQLException psqlException = ExceptionUtil.findCause(t, PSQLException.class);
// PSQLException message is lost in QueryException and it may be handy
if (psqlException != null) {
exceptionMessage += "\n" + psqlException.getMessage();
}
}
logger.debug("Unexpected exception (will be rethrown and handled higher): {}\n" + " OPERATION RESULT: {}", exceptionMessage, operationResult.debugDump());
operationResult.recordFatalError(t);
}
Aggregations