void setStatementName(String statementName, short deallocateEpoch) { assert statementName != null : "statement name should not be null"; this.statementName = statementName; this.encodedStatementName = Utils.encodeUTF8(statementName); this.deallocateEpoch = deallocateEpoch; }
public String getPGName() throws SQLException { if (!_isValid) throw new PSQLException(GT.tr("Cannot reference a savepoint after it has been released."), PSQLState.INVALID_SAVEPOINT_SPECIFICATION); if (_isNamed) { // We need to quote and escape the name in case it // contains spaces/quotes/etc. // return Utils.appendEscapedIdentifier(null, _name).toString(); } return "JDBC_SAVEPOINT_" + _id; }
public void setStringParameter(int index, String value, int oid) throws SQLException { StringBuffer sbuf = new StringBuffer(2 + value.length() * 11 / 10); // Add 10% for escaping. if (useEStringSyntax) sbuf.append(' ').append('E'); sbuf.append('\''); Utils.appendEscapedLiteral(sbuf, value, false); sbuf.append('\''); setLiteralParameter(index, sbuf.toString(), oid); }
private void runInitialQueries(QueryExecutor queryExecutor, Properties info) throws SQLException { String assumeMinServerVersion = PGProperty.ASSUME_MIN_SERVER_VERSION.get(info); if (Utils.parseServerVersionStr(assumeMinServerVersion) >= ServerVersion.v9_0.getVersionNum()) { // We already sent the parameter values in the StartupMessage so skip this return; } final int dbVersion = queryExecutor.getServerVersionNum(); if (dbVersion >= ServerVersion.v9_0.getVersionNum()) { SetupQueryRunner.run(queryExecutor, "SET extra_float_digits = 3", false); } String appName = PGProperty.APPLICATION_NAME.get(info); if (appName != null && dbVersion >= ServerVersion.v9_0.getVersionNum()) { StringBuilder sql = new StringBuilder(); sql.append("SET application_name = '"); Utils.escapeLiteral(sql, appName, queryExecutor.getStandardConformingStrings()); sql.append("'"); SetupQueryRunner.run(queryExecutor, sql.toString(), false); } }
byte[] md5Salt = pgStream.receive(4); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.log(Level.FINEST, " <=BE AuthenticationReqMD5(salt={0})", Utils.toHexString(md5Salt));
@Override public String escapeIdentifier(String identifier) throws SQLException { return Utils.escapeIdentifier(null, identifier).toString(); }
@Override public String escapeLiteral(String literal) throws SQLException { return Utils.escapeLiteral(null, literal, queryExecutor.getStandardConformingStrings()) .toString(); }
/** * Escape the given identifier <tt>value</tt> and append it to the string builder <tt>sbuf</tt>. * If <tt>sbuf</tt> is <tt>null</tt>, a new StringBuilder will be returned. This method is * different from appendEscapedLiteral in that it includes the quoting required for the identifier * while {@link #escapeLiteral(StringBuilder, String, boolean)} does not. * * @param sbuf the string builder to append to; or <tt>null</tt> * @param value the string value * @return the sbuf argument; or a new string builder for sbuf == null * @throws SQLException if the string contains a <tt>\0</tt> character */ public static StringBuilder escapeIdentifier(StringBuilder sbuf, String value) throws SQLException { if (sbuf == null) { sbuf = new StringBuilder(2 + (value.length() + 10) / 10 * 11); // Add 10% for escaping. } doAppendEscapedIdentifier(sbuf, value); return sbuf; }
logger.debug(" <=BE AuthenticationReqMD5(salt=" + Utils.toHexString(md5Salt) + ")");
private static boolean addReturning(StringBuilder nativeSql, SqlCommandType currentCommandType, String[] returningColumnNames, boolean isReturningPresent) throws SQLException { if (isReturningPresent || returningColumnNames.length == 0) { return false; } if (currentCommandType != SqlCommandType.INSERT && currentCommandType != SqlCommandType.UPDATE && currentCommandType != SqlCommandType.DELETE && currentCommandType != SqlCommandType.WITH) { return false; } nativeSql.append("\nRETURNING "); if (returningColumnNames.length == 1 && returningColumnNames[0].charAt(0) == '*') { nativeSql.append('*'); return true; } for (int col = 0; col < returningColumnNames.length; col++) { String columnName = returningColumnNames[col]; if (col > 0) { nativeSql.append(", "); } Utils.escapeIdentifier(nativeSql, columnName); } return true; }
@Override public String escapeString(String str) throws SQLException { return Utils.escapeLiteral(null, str, queryExecutor.getStandardConformingStrings()) .toString(); }
Portal(SimpleQuery query, String portalName) { this.query = query; this.portalName = portalName; this.encodedName = Utils.encodeUTF8(portalName); }
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 String escapeString(String str) throws SQLException { return Utils.appendEscapedLiteral(null, str, protoConnection.getStandardConformingStrings()).toString(); }
if (logger.logDebug()) logger.debug(" <=BE AuthenticationReqMD5(salt=" + Utils.toHexString(md5Salt) + ")");
public String getPGName() throws SQLException { if (!_isValid) { throw new PSQLException(GT.tr("Cannot reference a savepoint after it has been released."), PSQLState.INVALID_SAVEPOINT_SPECIFICATION); } if (_isNamed) { // We need to quote and escape the name in case it // contains spaces/quotes/etc. // return Utils.escapeIdentifier(null, _name).toString(); } return "JDBC_SAVEPOINT_" + _id; } }
public void setSchema(String schema) throws SQLException { checkClosed(); Statement stmt = createStatement(); try { if (schema == null) { stmt.executeUpdate("SET SESSION search_path TO DEFAULT"); } else { StringBuilder sb = new StringBuilder(); sb.append("SET SESSION search_path TO '"); Utils.escapeLiteral(sb, schema, getStandardConformingStrings()); sb.append("'"); stmt.executeUpdate(sb.toString()); LOGGER.log(Level.FINE, " setSchema = {0}", schema); } } finally { stmt.close(); } }
Portal(SimpleQuery query, String portalName) { this.query = query; this.portalName = portalName; this.encodedName = Utils.encodeUTF8(portalName); }
Utils.appendEscapedIdentifier(insertSQL, columnName); if ( i < numColumns - 1 )
private void runInitialQueries(ProtocolConnection protoConnection, Properties info, Logger logger) throws SQLException { String dbVersion = protoConnection.getServerVersion(); if (dbVersion.compareTo("9.0") >= 0) { SetupQueryRunner.run(protoConnection, "SET extra_float_digits = 3", false); } String appName = info.getProperty("ApplicationName"); if (appName != null && dbVersion.compareTo("9.0") >= 0) { StringBuffer sql = new StringBuffer(); sql.append("SET application_name = '"); Utils.appendEscapedLiteral(sql, appName, protoConnection.getStandardConformingStrings()); sql.append("'"); SetupQueryRunner.run(protoConnection, sql.toString(), false); } }