public AbstractBlobClob(BaseConnection conn, long oid) throws SQLException { this.conn = conn; this.oid = oid; this.currentLo = null; this.currentLoIsWriteable = false; support64bit = conn.haveMinimumServerVersion(90300); subLOs = new ArrayList<LargeObject>(); }
/** * Create a new Array. * * @param connection a database connection * @param oid the oid of the array datatype * @param fieldString the array data in string form */ public AbstractJdbc2Array(BaseConnection connection, int oid, String fieldString) throws SQLException { this.connection = connection; this.oid = oid; this.fieldString = fieldString; this.useObjects = connection.haveMinimumCompatibleVersion("8.3"); this.haveMinServer82 = connection.haveMinimumServerVersion("8.2"); }
public void setObject(int parameterIndex, Object x) throws SQLException { if (x instanceof UUID && connection.haveMinimumServerVersion("8.3")) { setString(parameterIndex, x.toString(), Oid.UUID); } else { super.setObject(parameterIndex, x); } }
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException { if (targetSqlType == Types.OTHER && x instanceof UUID && connection.haveMinimumServerVersion("8.3")) { setString(parameterIndex, x.toString(), Oid.UUID); } else { super.setObject(parameterIndex, x, targetSqlType, scale); } } }
static String addReturning(BaseConnection connection, String sql, String columns[], boolean escape) throws SQLException { if (!connection.haveMinimumServerVersion("8.2")) throw new PSQLException(GT.tr("Returning autogenerated keys is only supported for 8.2 and later servers."), PSQLState.NOT_IMPLEMENTED); sql = sql.trim(); if (sql.endsWith(";")) sql = sql.substring(0, sql.length()-1); StringBuffer sb = new StringBuffer(sql); sb.append(" RETURNING "); for (int i=0; i<columns.length; i++) { if (i != 0) sb.append(", "); // If given user provided column names, quote and escape them. // This isn't likely to be popular as it enforces case sensitivity, // but it does match up with our handling of things like // DatabaseMetaData.getColumns and is necessary for the same // reasons. if (escape) Utils.appendEscapedIdentifier(sb, columns[i]); else sb.append(columns[i]); } return sb.toString(); }
public synchronized String getPGType(int oid) throws SQLException { if (oid == Oid.UNSPECIFIED) return null; String pgTypeName = (String)_oidToPgName.get(new Integer(oid)); if (pgTypeName != null) return pgTypeName; if (_getNameStatement == null) { String sql; if (_conn.haveMinimumServerVersion("7.3")) { sql = "SELECT typname FROM pg_catalog.pg_type WHERE oid = ?"; } else { sql = "SELECT typname FROM pg_type WHERE oid = ?"; } _getNameStatement = _conn.prepareStatement(sql); } _getNameStatement.setInt(1, oid); // Go through BaseStatement to avoid transaction start. if (!((BaseStatement)_getNameStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN)) throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA); ResultSet rs = _getNameStatement.getResultSet(); if (rs.next()) { pgTypeName = rs.getString(1); _pgNameToOid.put(pgTypeName, new Integer(oid)); _oidToPgName.put(new Integer(oid), pgTypeName); } rs.close(); return pgTypeName; }
public synchronized int getPGType(String pgTypeName) throws SQLException { Integer oid = (Integer)_pgNameToOid.get(pgTypeName); if (oid != null) return oid.intValue(); if (_getOidStatement == null) { String sql; if (_conn.haveMinimumServerVersion("7.3")) { sql = "SELECT oid FROM pg_catalog.pg_type WHERE typname = ?"; } else { sql = "SELECT oid FROM pg_type WHERE typname = ?"; } _getOidStatement = _conn.prepareStatement(sql); } _getOidStatement.setString(1, pgTypeName); // Go through BaseStatement to avoid transaction start. if (!((BaseStatement)_getOidStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN)) throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA); oid = new Integer(Oid.UNSPECIFIED); ResultSet rs = _getOidStatement.getResultSet(); if (rs.next()) { oid = new Integer((int)rs.getLong(1)); _oidToPgName.put(oid, pgTypeName); } _pgNameToOid.put(pgTypeName, oid); rs.close(); return oid.intValue(); }
if (_conn.haveMinimumServerVersion("7.3")) { sql += "pg_catalog.";
public synchronized char getArrayDelimiter(int oid) throws SQLException { if (oid == Oid.UNSPECIFIED) return ','; Character delim = (Character) _arrayOidToDelimiter.get(new Integer(oid)); if (delim != null) return delim.charValue(); if (_getArrayDelimiterStatement == null) { String sql; if (_conn.haveMinimumServerVersion("7.3")) { sql = "SELECT e.typdelim FROM pg_catalog.pg_type t, pg_catalog.pg_type e WHERE t.oid = ? and t.typelem = e.oid"; } else { sql = "SELECT e.typdelim FROM pg_type t, pg_type e WHERE t.oid = ? and t.typelem = e.oid"; } _getArrayDelimiterStatement = _conn.prepareStatement(sql); } _getArrayDelimiterStatement.setInt(1, oid); // Go through BaseStatement to avoid transaction start. if (!((BaseStatement) _getArrayDelimiterStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN)) throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA); ResultSet rs = _getArrayDelimiterStatement.getResultSet(); if (!rs.next()) throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA); String s = rs.getString(1); delim = new Character(s.charAt(0)); _arrayOidToDelimiter.put(new Integer(oid), delim); rs.close(); return delim.charValue(); }
public synchronized int getPGArrayElement (int oid) throws SQLException { if (oid == Oid.UNSPECIFIED) return Oid.UNSPECIFIED; Integer pgType = (Integer) _pgArrayToPgType.get(new Integer(oid)); if (pgType != null) return pgType.intValue(); if (_getArrayElementOidStatement == null) { String sql; if (_conn.haveMinimumServerVersion("7.3")) { sql = "SELECT e.oid, e.typname FROM pg_catalog.pg_type t, pg_catalog.pg_type e WHERE t.oid = ? and t.typelem = e.oid"; } else { sql = "SELECT e.oid, e.typname FROM pg_type t, pg_type e WHERE t.oid = ? and t.typelem = e.oid"; } _getArrayElementOidStatement = _conn.prepareStatement(sql); } _getArrayElementOidStatement.setInt(1, oid); // Go through BaseStatement to avoid transaction start. if (!((BaseStatement) _getArrayElementOidStatement).executeWithFlags(QueryExecutor.QUERY_SUPPRESS_BEGIN)) throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA); ResultSet rs = _getArrayElementOidStatement.getResultSet(); if (!rs.next()) throw new PSQLException(GT.tr("No results were returned by the query."), PSQLState.NO_DATA); pgType = new Integer((int)rs.getLong(1)); _pgArrayToPgType.put(new Integer(oid), pgType); _pgNameToOid.put(rs.getString(2), pgType); _oidToPgName.put(pgType, rs.getString(2)); rs.close(); return pgType.intValue(); }
if (_getOidStatementComplexArray == null) { String sql; if (_conn.haveMinimumServerVersion(ServerVersion.v8_3)) { sql = "SELECT t.typarray, arr.typname " + " FROM pg_catalog.pg_type t"
PSQLState.STATEMENT_NOT_ALLOWED_IN_FUNCTION_CALL); if (connection.haveMinimumServerVersion("8.1") && ((AbstractJdbc2Connection)connection).getProtocolVersion() == 3)
+ "a.attnotnull OR (t.typtype = 'd' AND t.typnotnull), "); if ( connection.haveMinimumServerVersion(ServerVersion.v10)) { sql.append("a.attidentity != '' OR pg_catalog.pg_get_expr(d.adbin, d.adrelid) LIKE '%nextval(%' "); } else {
/** * For Blobs this should be in bytes while for Clobs it should be * in characters. Since we really haven't figured out how to handle * character sets for Clobs the current implementation uses bytes for * both Blobs and Clobs. */ public synchronized void truncate(long len) throws SQLException { checkFreed(); if (!conn.haveMinimumServerVersion("8.3")) throw new PSQLException(GT.tr("Truncation of large objects is only implemented in 8.3 and later servers."), PSQLState.NOT_IMPLEMENTED); if (len < 0) { throw new PSQLException(GT.tr("Cannot truncate LOB to a negative length."), PSQLState.INVALID_PARAMETER_VALUE); } if (len > Integer.MAX_VALUE) { throw new PSQLException(GT.tr("PostgreSQL LOBs can only index to: {0}", new Integer(Integer.MAX_VALUE)), PSQLState.INVALID_PARAMETER_VALUE); } lo.truncate((int)len); }
if (connection.haveMinimumServerVersion("7.2")) { setNull(i, Types.VARCHAR); } else {
currentXid = null; if (!conn.haveMinimumServerVersion("8.1")) throw new PGXAException(GT.tr("Server versions prior to 8.1 do not support two-phase commit."), XAException.XAER_RMERR);
/** * For Blobs this should be in bytes while for Clobs it should be in characters. Since we really * haven't figured out how to handle character sets for Clobs the current implementation uses * bytes for both Blobs and Clobs. * * @param len maximum length * @throws SQLException if operation fails */ public synchronized void truncate(long len) throws SQLException { checkFreed(); if (!conn.haveMinimumServerVersion(ServerVersion.v8_3)) { throw new PSQLException( GT.tr("Truncation of large objects is only implemented in 8.3 and later servers."), PSQLState.NOT_IMPLEMENTED); } if (len < 0) { throw new PSQLException(GT.tr("Cannot truncate LOB to a negative length."), PSQLState.INVALID_PARAMETER_VALUE); } if (len > Integer.MAX_VALUE) { if (support64bit) { getLo(true).truncate64(len); } else { throw new PSQLException(GT.tr("PostgreSQL LOBs can only index to: {0}", Integer.MAX_VALUE), PSQLState.INVALID_PARAMETER_VALUE); } } else { getLo(true).truncate((int) len); } }
&& connection.haveMinimumServerVersion(ServerVersion.v8_3)) { setUuid(parameterIndex, (UUID) in); return;
if (x == null) { setNull(parameterIndex, Types.OTHER); } else if (x instanceof UUID && connection.haveMinimumServerVersion(ServerVersion.v8_3)) { setUuid(parameterIndex, (UUID) x); } else if (x instanceof SQLXML) {
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException { if (targetSqlType == Types.OTHER && x instanceof UUID && connection.haveMinimumServerVersion("8.3")) { setString(parameterIndex, x.toString(), Oid.UUID); } else { super.setObject(parameterIndex, x, targetSqlType, scale); } } }