public void handleCommandStatus(String status) throws PSQLException { if (status.startsWith("COPY")) { int i = status.lastIndexOf(' '); handledRowCount = i > 3 ? Long.parseLong(status.substring(i + 1)) : -1; } else { throw new PSQLException(GT.tr("CommandComplete expected COPY but got: " + status), PSQLState.COMMUNICATION_ERROR); } }
private static PSQLException cannotCastException(final String fromType, final String toType, final Exception cause) { return new PSQLException( GT.tr("Cannot convert an instance of {0} to type {1}", fromType, toType), PSQLState.INVALID_PARAMETER_TYPE, cause); }
public static double toDouble(String s) throws SQLException { if (s != null) { try { s = s.trim(); return Double.parseDouble(s); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Bad value for type {0} : {1}", "double", s), PSQLState.NUMERIC_VALUE_OUT_OF_RANGE); } } return 0; // SQL NULL }
protected void handleCopydata(byte[] data) throws PSQLException { throw new PSQLException(GT.tr("CopyIn copy direction can't receive data"), PSQLState.PROTOCOL_VIOLATION); } }
protected void checkColumnIndex(int column) throws SQLException { if (column < 1 || column > fields.length) { throw new PSQLException( GT.tr("The column index is out of range: {0}, number of columns: {1}.", column, fields.length), PSQLState.INVALID_PARAMETER_VALUE); } }
public static BigDecimal toBigDecimal(String s) throws SQLException { if (s == null) { return null; } try { s = s.trim(); return new BigDecimal(s); } catch (NumberFormatException e) { throw new PSQLException(GT.tr("Bad value for type {0} : {1}", "BigDecimal", s), PSQLState.NUMERIC_VALUE_OUT_OF_RANGE); } }
private BigDecimal scaleBigDecimal(BigDecimal val, int scale) throws PSQLException { if (scale == -1) { return val; } try { return val.setScale(scale); } catch (ArithmeticException e) { throw new PSQLException( GT.tr("Bad value for type {0} : {1}", "BigDecimal", val), PSQLState.NUMERIC_VALUE_OUT_OF_RANGE); } }
public <T> T getObject(int parameterIndex, Class<T> type) throws SQLException { if (type == ResultSet.class) { return type.cast(getObject(parameterIndex)); } throw new PSQLException(GT.tr("Unsupported type conversion to {1}.", type), PSQLState.INVALID_PARAMETER_VALUE); }
private static void twoArgumentsFunctionCall(StringBuilder buf, String call, String functionName, List<? extends CharSequence> parsedArgs) throws PSQLException { if (parsedArgs.size() != 2) { throw new PSQLException(GT.tr("{0} function takes two and only two arguments.", functionName), PSQLState.SYNTAX_ERROR); } appendCall(buf, call, ",", ")", parsedArgs); }
public void setMaxFieldSize(int max) throws SQLException { checkClosed(); if (max < 0) { throw new PSQLException( GT.tr("The maximum field size must be a value greater than or equal to 0."), PSQLState.INVALID_PARAMETER_VALUE); } maxfieldSize = max; }
public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { if (columnIndexes == null || columnIndexes.length == 0) { return executeUpdate(sql); } throw new PSQLException(GT.tr("Returning autogenerated keys by column index is not supported."), PSQLState.NOT_IMPLEMENTED); }
public void setFetchSize(int rows) throws SQLException { checkClosed(); if (rows < 0) { throw new PSQLException(GT.tr("Fetch size must be a value greater to or equal to 0."), PSQLState.INVALID_PARAMETER_VALUE); } fetchSize = rows; }
@Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { if (columnIndexes != null && columnIndexes.length == 0) { return prepareStatement(sql); } checkClosed(); throw new PSQLException(GT.tr("Returning autogenerated keys is not supported."), PSQLState.NOT_IMPLEMENTED); }
public void setProperty(String name, String value) throws SQLException { PGProperty pgProperty = PGProperty.forName(name); if (pgProperty != null) { setProperty(pgProperty, value); } else { throw new PSQLException(GT.tr("Unsupported property name: {0}", name), PSQLState.INVALID_PARAMETER_VALUE); } }
public boolean relative(int rows) throws SQLException { checkScrollable(); if (onInsertRow) { throw new PSQLException(GT.tr("Can''t use relative move methods while on the insert row."), PSQLState.INVALID_CURSOR_STATE); } // have to add 1 since absolute expects a 1-based index return absolute(current_row + 1 + rows); }
public synchronized void cancelRowUpdates() throws SQLException { checkClosed(); if (onInsertRow) { throw new PSQLException(GT.tr("Cannot call cancelRowUpdates() when on the insert row."), PSQLState.INVALID_CURSOR_STATE); } if (doingUpdates) { doingUpdates = false; clearRowBuffer(true); } }
public int findColumn(String columnName) throws SQLException { checkClosed(); int col = findColumnIndex(columnName); if (col == 0) { throw new PSQLException( GT.tr("The column name {0} was not found in this ResultSet.", columnName), PSQLState.UNDEFINED_COLUMN); } return col; }
public java.sql.ResultSet executeQuery(String p_sql) throws SQLException { if (!executeWithFlags(p_sql, 0)) { throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA); } return getSingleResultSet(); }
@Override public void commit() throws SQLException { checkClosed(); if (autoCommit) { throw new PSQLException(GT.tr("Cannot commit when autoCommit is enabled."), PSQLState.NO_ACTIVE_SQL_TRANSACTION); } if (queryExecutor.getTransactionState() != TransactionState.IDLE) { executeTransactionCommand(commitQuery); } }
private String makeSPN() throws PSQLException { final HostSpec hs = pgStream.getHostSpec(); try { return NTDSAPIWrapper.instance.DsMakeSpn(spnServiceClass, hs.getHost(), null, (short) hs.getPort(), null); } catch (LastErrorException ex) { throw new PSQLException("SSPI setup failed to determine SPN", PSQLState.CONNECTION_UNABLE_TO_CONNECT, ex); } }