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

Method parse

src/pgwire/src/protocol.rs:1232–1302  ·  view source on GitHub ↗
(
        &mut self,
        name: String,
        sql: String,
        param_oids: Vec<u32>,
    )

Source from the content-addressed store, hash-verified

1230
1231 #[instrument(level = "debug")]
1232 async fn parse(
1233 &mut self,
1234 name: String,
1235 sql: String,
1236 param_oids: Vec<u32>,
1237 ) -> Result<State, io::Error> {
1238 // Start a transaction if we aren't in one.
1239 self.ensure_transaction(1, "parse").await?;
1240
1241 let mut param_types = vec![];
1242 for oid in param_oids {
1243 match mz_pgrepr::Type::from_oid(oid) {
1244 Ok(ty) => match SqlScalarType::try_from(&ty) {
1245 Ok(ty) => param_types.push(Some(ty)),
1246 Err(err) => {
1247 return self
1248 .send_error_and_get_state(ErrorResponse::error(
1249 SqlState::INVALID_PARAMETER_VALUE,
1250 err.to_string(),
1251 ))
1252 .await;
1253 }
1254 },
1255 Err(_) if oid == 0 => param_types.push(None),
1256 Err(e) => {
1257 return self
1258 .send_error_and_get_state(ErrorResponse::error(
1259 SqlState::PROTOCOL_VIOLATION,
1260 e.to_string(),
1261 ))
1262 .await;
1263 }
1264 }
1265 }
1266
1267 let stmts = match self.parse_sql(&sql) {
1268 Ok(stmts) => stmts,
1269 Err(err) => {
1270 return self.send_error_and_get_state(err).await;
1271 }
1272 };
1273 if stmts.len() > 1 {
1274 return self
1275 .send_error_and_get_state(ErrorResponse::error(
1276 SqlState::INTERNAL_ERROR,
1277 "cannot insert multiple commands into a prepared statement",
1278 ))
1279 .await;
1280 }
1281 let (maybe_stmt, sql) = match stmts.into_iter().next() {
1282 None => (None, ""),
1283 Some(StatementParseResult { ast, sql }) => (Some(ast), sql),
1284 };
1285 if self.is_aborted_txn() && !is_txn_exit_stmt(maybe_stmt.as_ref()) {
1286 return self.aborted_txn_error().await;
1287 }
1288 match self
1289 .adapter_client

Callers 3

advance_readyMethod · 0.45
parse_sqlMethod · 0.45
handle_connectionMethod · 0.45

Calls 15

errorFunction · 0.85
ensure_transactionMethod · 0.80
parse_sqlMethod · 0.80
is_aborted_txnMethod · 0.80
aborted_txn_errorMethod · 0.80
is_txn_exit_stmtFunction · 0.70
pushMethod · 0.45
to_stringMethod · 0.45
lenMethod · 0.45
nextMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected