(
framed: &mut Framed<T, crate::protocol::PostgresCodec>,
db: &Arc<DbHandler>,
query: &str,
portal_name: &str,
session: &Arc<SessionState>,
)
| 5070 | } |
| 5071 | |
| 5072 | async fn execute_dml<T>( |
| 5073 | framed: &mut Framed<T, crate::protocol::PostgresCodec>, |
| 5074 | db: &Arc<DbHandler>, |
| 5075 | query: &str, |
| 5076 | portal_name: &str, |
| 5077 | session: &Arc<SessionState>, |
| 5078 | ) -> Result<(), PgSqliteError> |
| 5079 | where |
| 5080 | T: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin, |
| 5081 | { |
| 5082 | // Check for RETURNING clause |
| 5083 | if ReturningTranslator::has_returning_clause(query) { |
| 5084 | debug!("Extended protocol: Query has RETURNING clause, using execute_dml_with_returning: {}", query); |
| 5085 | // Get result formats from portal |
| 5086 | let result_formats = { |
| 5087 | let portals = session.portals.read().await; |
| 5088 | let portal = portals.get(portal_name).unwrap(); |
| 5089 | portal.result_formats.clone() |
| 5090 | }; |
| 5091 | return Self::execute_dml_with_returning(framed, db, session, query, &result_formats).await; |
| 5092 | } |
| 5093 | |
| 5094 | // Validation is now done in handle_execute before parameter substitution |
| 5095 | |
| 5096 | debug!("Extended protocol: Executing DML query without RETURNING: {}", query); |
| 5097 | let cached_conn = Self::get_or_cache_connection(session, db).await; |
| 5098 | let response = db.execute_with_session_cached(query, &session.id, cached_conn.as_ref()).await?; |
| 5099 | |
| 5100 | let tag = if query_starts_with_ignore_case(query, "INSERT") { |
| 5101 | format!("INSERT 0 {}", response.rows_affected) |
| 5102 | } else if query_starts_with_ignore_case(query, "UPDATE") { |
| 5103 | format!("UPDATE {}", response.rows_affected) |
| 5104 | } else if query_starts_with_ignore_case(query, "DELETE") { |
| 5105 | format!("DELETE {}", response.rows_affected) |
| 5106 | } else { |
| 5107 | format!("OK {}", response.rows_affected) |
| 5108 | }; |
| 5109 | |
| 5110 | framed.send(BackendMessage::CommandComplete { tag }).await |
| 5111 | .map_err(PgSqliteError::Io)?; |
| 5112 | |
| 5113 | Ok(()) |
| 5114 | } |
| 5115 | |
| 5116 | /// Helper function to build field descriptions for RETURNING clause with proper type detection |
| 5117 | async fn build_returning_field_descriptions( |
nothing calls this directly
no test coverage detected