MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / test_bind_params

Function test_bind_params

src/environmentd/tests/pgwire.rs:37–223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35#[mz_ore::test]
36#[allow(clippy::disallowed_methods)]
37fn test_bind_params() {
38 let server = test_util::TestHarness::default()
39 .unsafe_mode()
40 .start_blocking();
41 server.enable_feature_flags(&["enable_expressions_in_limit_syntax"]);
42 let mut client = server.connect(postgres::NoTls).unwrap();
43
44 match client.query("SELECT ROW(1, 2) = $1", &[&"(1,2)"]) {
45 Ok(_) => panic!("query with invalid parameters executed successfully"),
46 Err(err) => assert!(
47 err.to_string_with_causes()
48 .contains("operator does not exist"),
49 "unexpected error: {err}"
50 ),
51 }
52
53 assert!(
54 client
55 .query_one("SELECT ROW(1, 2) = ROW(1, $1)", &[&2_i32])
56 .unwrap()
57 .get::<_, bool>(0)
58 );
59
60 // Just ensure it does not panic (see database-issues#871).
61 client
62 .query(
63 "EXPLAIN OPTIMIZED PLAN AS VERBOSE TEXT FOR SELECT $1::int",
64 &[&42_i32],
65 )
66 .unwrap();
67
68 // Ensure that a type hint provided by the client is respected.
69 {
70 let stmt = client.prepare_typed("SELECT $1", &[Type::INT4]).unwrap();
71 let val: i32 = client.query_one(&stmt, &[&42_i32]).unwrap().get(0);
72 assert_eq!(val, 42);
73 }
74
75 // Ensure that unspecified type hints are inferred.
76 {
77 let stmt = client
78 .prepare_typed("SELECT $1 + $2", &[Type::INT4])
79 .unwrap();
80 let val: i32 = client.query_one(&stmt, &[&1, &2]).unwrap().get(0);
81 assert_eq!(val, 3);
82 }
83
84 // Ensure that the fractional component of a decimal is not lost.
85 {
86 let mut num = Numeric::from(mz_repr::adt::numeric::Numeric::from(123));
87 num.0.0.set_exponent(-2);
88 let stmt = client
89 .prepare_typed("SELECT $1 + 2.34", &[Type::NUMERIC])
90 .unwrap();
91 let val: Numeric = client.query_one(&stmt, &[&num]).unwrap().get(0);
92 assert_eq!(val.to_string(), "3.57");
93 }
94

Callers

nothing calls this directly

Calls 14

start_blockingMethod · 0.80
unsafe_modeMethod · 0.80
enable_feature_flagsMethod · 0.80
unwrapMethod · 0.80
unwrap_db_errorMethod · 0.80
expect_elementMethod · 0.80
batch_executeMethod · 0.80
connectMethod · 0.45
queryMethod · 0.45
getMethod · 0.45
query_oneMethod · 0.45
prepareMethod · 0.45

Tested by

no test coverage detected