Skip to content

Commit 622c886

Browse files
committed
[DB] Use Postgres startup encoding without SET NAMES
1 parent ea500bf commit 622c886

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

‎GITAR.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ System roots and PEM roots supplied with `sslcert` remain supported. `sslidentit
88

99
Consumers must repeat both Cargo patch tables from this manifest at their workspace root. Cargo ignores patches in dependencies. The registry patch makes `tokio-postgres-rustls` use the same driver source as Quaint.
1010

11+
PostgreSQL text encoding comes from tokio-postgres's UTF8 startup parameter. Connection initialization retains an explicit schema's search path and omits redundant `SET NAMES`, as that command pins sessions in RDS Proxy.
12+
1113
Run `python3 tests/rustls/run.py` with Docker and OpenSSL 3 to exercise certificate verification and SCRAM channel binding. The runner also covers client identities and TLS negotiation. Set `OPENSSL_BIN` if OpenSSL 3 is not the default executable.
1214

1315
Release tested source with immutable tags and pin consumers by commit. CLI binaries and checksums belong to the compatible `gitarcode/prisma-client-rust` release, which consumes this fork. Downloaded Prisma engine executables are separate artifacts and do not inherit this source change.

‎src/connector/postgres.rs‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -461,19 +461,12 @@ impl PostgreSql {
461461
}
462462
}));
463463

464-
// SET NAMES sets the client text encoding. It needs to be explicitly set for automatic
465-
// conversion to and from UTF-8 to happen server-side.
466-
//
467-
// Relevant docs: https://www.postgresql.org/docs/current/multibyte.html
468-
let session_variables = format!(
469-
r##"
470-
{set_search_path}
471-
SET NAMES 'UTF8';
472-
"##,
473-
set_search_path = SetSearchPath(url.query_params.schema.as_deref())
474-
);
475-
476-
client.simple_query(session_variables.as_str()).await?;
464+
// tokio-postgres requests UTF8 in the startup packet. Repeating it with
465+
// SET NAMES pins every RDS Proxy session to one database connection.
466+
let session_variables = SetSearchPath(url.query_params.schema.as_deref()).to_string();
467+
if !session_variables.is_empty() {
468+
client.simple_query(session_variables.as_str()).await?;
469+
}
477470

478471
Ok(Self {
479472
client: PostgresClient(client),
@@ -833,6 +826,23 @@ mod tests {
833826
assert_eq!(Some("\"musti-test\""), row[0].as_str());
834827
}
835828

829+
#[tokio::test]
830+
async fn startup_encoding_preserves_unicode_round_trips() -> crate::Result<()> {
831+
let client = Quaint::new(&CONN_STR).await?;
832+
let encoding = client.query_raw("SHOW client_encoding", &[]).await?;
833+
assert_eq!(
834+
encoding.first().and_then(|row| row[0].as_str().map(str::to_owned)),
835+
Some("UTF8".to_string())
836+
);
837+
let text = "caf\u{00e9} \u{65e5}\u{672c}\u{8a9e}";
838+
let result = client.query_raw("SELECT $1::text", &[text.into()]).await?;
839+
assert_eq!(
840+
result.first().and_then(|row| row[0].as_str().map(str::to_owned)),
841+
Some(text.to_string())
842+
);
843+
Ok(())
844+
}
845+
836846
#[tokio::test]
837847
async fn should_map_nonexisting_database_error() {
838848
let mut url = Url::parse(&CONN_STR).unwrap();

0 commit comments

Comments
 (0)