pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: cgm-aw (@cgm-aw) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] PR #3606: fix: add support for multiple schemas via PgConnection.setSchema
Date: Wed, 16 Apr 2025 06:15:01 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<[email protected]>
(on pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java:1706)
`Utils.escapeLiteral` requires a StringBuilder and throws a checked exception, so I kept it "old school" since I didn't find it more readable with streams. I could refactor it like this to use streams:
```
public void setSchema(@Nullable String schema) throws SQLException {
checkClosed();
try (Statement stmt = createStatement()) {
if (schema == null) {
stmt.executeUpdate("SET SESSION search_path TO DEFAULT");
} else {
// We allow a space after the comma
String encodedSchemas = Arrays.stream(schema.split(", ?"))
.map(s -> {
try {
return Utils.escapeLiteral(new StringBuilder(), s, getStandardConformingStrings());
} catch (SQLException e) {
throw new RuntimeException(e);
}
}).map(sb -> "'" + sb + "'")
.collect(Collectors.joining(","));
String sql = "SET SESSION search_path TO " + encodedSchemas;
stmt.executeUpdate(sql);
LOGGER.log(Level.FINE, " setSchema = {0}", encodedSchemas);
}
}
}
```
Let me know what you prefer.
view thread (19+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: github://pgjdbc/pgjdbc
Cc: [email protected], [email protected]
Subject: Re: [pgjdbc/pgjdbc] PR #3606: fix: add support for multiple schemas via PgConnection.setSchema
In-Reply-To: <<[email protected]>>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox