Skip to content

Commit 04a2df3

Browse files
committed
refactor(odbc): enhance statement caching with improved logging
- Updated the statement caching logic in StatementManager to use match statements for better clarity and handling of prepared statements. - Improved logging to trace both preparation and usage of SQL statements, aiding in debugging and performance monitoring.
1 parent aa8fc4f commit 04a2df3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sqlx-core/src/odbc/connection/worker.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::hash_map::Entry;
12
use std::collections::HashMap;
23
use std::thread;
34

@@ -256,12 +257,17 @@ impl<'conn> StatementManager<'conn> {
256257
sql.hash(&mut hasher);
257258
let sql_hash = hasher.finish();
258259

259-
if let std::collections::hash_map::Entry::Vacant(e) = self.prepared_cache.entry(sql_hash) {
260-
log::debug!("Preparing statement for SQL hash: {}", sql_hash);
261-
let prepared = self.conn.prepare(sql).map_err(Error::from)?;
262-
e.insert(prepared);
260+
match self.prepared_cache.entry(sql_hash) {
261+
Entry::Vacant(e) => {
262+
log::trace!("Preparing statement for SQL: {}", sql);
263+
let prepared = self.conn.prepare(sql)?;
264+
Ok(e.insert(prepared))
265+
}
266+
Entry::Occupied(e) => {
267+
log::trace!("Using prepared statement for SQL: {}", sql);
268+
Ok(e.into_mut())
269+
}
263270
}
264-
Ok(self.prepared_cache.get_mut(&sql_hash).unwrap())
265271
}
266272
}
267273
// Utility functions for channel operations (deprecated - use send_result_safe)

0 commit comments

Comments
 (0)