(&self, client: &mut C, query: &str)
| 303 | #[async_trait] |
| 304 | impl SimpleQueryHandler for NodeDbPgHandler { |
| 305 | async fn do_query<C>(&self, client: &mut C, query: &str) -> PgWireResult<Vec<Response>> |
| 306 | where |
| 307 | C: ClientInfo + ClientPortalStore + Sink<PgWireBackendMessage> + Unpin + Send + Sync, |
| 308 | C::Error: Debug, |
| 309 | PgWireError: From<<C as Sink<PgWireBackendMessage>>::Error>, |
| 310 | { |
| 311 | let addr = client.socket_addr(); |
| 312 | self.sessions.ensure_session(addr); |
| 313 | |
| 314 | let identity = self.resolve_identity(client, &addr)?; |
| 315 | self.enforce_database_access(&identity, &addr)?; |
| 316 | |
| 317 | // Emit db.id / db.name trace fields at session bind so that any |
| 318 | // downstream spans inherit the database context. |
| 319 | let current_db = self |
| 320 | .sessions |
| 321 | .get_current_database(&addr) |
| 322 | .unwrap_or(crate::types::DatabaseId::DEFAULT); |
| 323 | let db_name: String = self |
| 324 | .state |
| 325 | .credentials |
| 326 | .catalog() |
| 327 | .as_ref() |
| 328 | .and_then(|cat| cat.get_database(current_db).ok().flatten()) |
| 329 | .map(|d| d.name.clone()) |
| 330 | .unwrap_or_else(|| "default".to_string()); |
| 331 | tracing::debug!( |
| 332 | db.id = current_db.as_u64(), |
| 333 | db.name = %db_name, |
| 334 | user = %identity.username, |
| 335 | "session query dispatch", |
| 336 | ); |
| 337 | |
| 338 | // Send notice if BEGIN is called (advisory transactions). |
| 339 | let upper = query.trim().to_uppercase(); |
| 340 | if (upper == "BEGIN" || upper == "BEGIN TRANSACTION" || upper == "START TRANSACTION") |
| 341 | && self.sessions.transaction_state(&addr) == TransactionState::InBlock |
| 342 | { |
| 343 | let notice = notice_warning("there is already a transaction in progress"); |
| 344 | let _ = client |
| 345 | .send(PgWireBackendMessage::NoticeResponse(notice)) |
| 346 | .await; |
| 347 | } |
| 348 | |
| 349 | if (upper == "COMMIT" || upper == "END") |
| 350 | && self.sessions.transaction_state(&addr) == TransactionState::Idle |
| 351 | { |
| 352 | let notice = notice_warning("there is no transaction in progress"); |
| 353 | let _ = client |
| 354 | .send(PgWireBackendMessage::NoticeResponse(notice)) |
| 355 | .await; |
| 356 | } |
| 357 | |
| 358 | // J.4: install the DDL audit context for this statement. Any |
| 359 | // `propose_catalog_entry` call reached from `execute_sql` |
| 360 | // picks up the identity + raw SQL so the applier can emit a |
| 361 | // full audit record on every replica. The guard auto-clears |
| 362 | // on scope exit. |
nothing calls this directly
no test coverage detected