@@ -278,22 +278,43 @@ async fn complex_sql_with_question_marks() {
278278 assert_eq ! ( row. answer, "Yes?" ) ;
279279}
280280
281- #[ tokio:: test]
282- async fn query_raw_preserves_exact_sql ( ) {
283- let client = prepare_database ! ( ) ;
284- //check client
281+ #[ tokio:: test]
282+ async fn query_matches_log ( ) {
283+ use uuid:: Uuid ;
285284
286- // Test that raw query preserves the exact SQL including whitespace and formatting
287- let sql = "SELECT 1 WHERE 'test?' = 'test?' " ;
285+ // setup
286+ let client = prepare_database ! ( ) ;
287+ let query_id = Uuid :: new_v4 ( ) . to_string ( ) ; // unique per run
288+ let sql = "SELECT 1 WHERE 'x?' = 'x?'" ; // raw statement to verify
288289
289- let result = client. query_raw ( sql) . fetch_bytes ( "TSV" ) . unwrap ( ) ;
290+ // execute with explicit query_id
291+ client
292+ . query_raw ( sql)
293+ . with_option ( "query_id" , & query_id)
294+ . execute ( )
295+ . await
296+ . expect ( "executing raw SQL failed" ) ;
290297
291- let mut data = Vec :: new ( ) ;
292- let mut cursor = result;
293- while let Some ( chunk) = cursor. next ( ) . await . unwrap ( ) {
294- data. extend_from_slice ( & chunk) ;
295- }
296- let response = String :: from_utf8 ( data) . unwrap ( ) ;
298+ crate :: flush_query_log ( & client) . await ;
297299
298- assert_eq ! ( response. trim( ) , "1" ) ;
299- }
300+ // read log row *inline*
301+ let log_sql = format ! (
302+ "SELECT query \
303+ FROM system.query_log \
304+ WHERE query_id = '{}' LIMIT 1",
305+ query_id
306+ ) ;
307+
308+ let logged_sql: String = client
309+ . query_raw ( & log_sql)
310+ . fetch_one ( )
311+ . await
312+ . expect ( "log entry not found" ) ;
313+
314+ // assertion
315+ assert_eq ! (
316+ logged_sql. trim( ) ,
317+ sql. trim( ) ,
318+ "Logged SQL differs from the statement sent"
319+ ) ;
320+ }
0 commit comments