diff --git a/.gitmodules b/.gitmodules index 5bef02654..54ad5d33f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "crates/pgls_query/vendor/libpg_query"] path = crates/pgls_query/vendor/libpg_query - url = https://github.com/pganalyze/libpg_query.git - branch = 17-latest + url = https://github.com/psteinroe/libpg_query.git + branch = feat/plpgsql-protobuf diff --git a/crates/pgls_query/build.rs b/crates/pgls_query/build.rs index 92d437e10..0fb82fd37 100644 --- a/crates/pgls_query/build.rs +++ b/crates/pgls_query/build.rs @@ -100,7 +100,9 @@ fn run_bindgen( .allowlist_function("pg_query_split_with_parser") .allowlist_function("pg_query_split_with_scanner") .allowlist_function("pg_query_parse_plpgsql") + .allowlist_function("pg_query_parse_plpgsql_protobuf") .allowlist_function("pg_query_free_protobuf_parse_result") + .allowlist_function("pg_query_free_plpgsql_protobuf_parse_result") .allowlist_function("pg_query_free_scan_result") .allowlist_function("pg_query_free_deparse_result") .allowlist_function("pg_query_free_normalize_result") @@ -117,6 +119,7 @@ fn run_bindgen( .allowlist_type("PgQueryFingerprintResult") .allowlist_type("PgQuerySplitResult") .allowlist_type("PgQuerySplitStmt") + .allowlist_type("PgQueryPlpgsqlProtobufParseResult") // Also generate bindings for size_t since it's used in PgQueryProtobuf .allowlist_type("size_t") .allowlist_var("PG_VERSION_NUM"); @@ -269,6 +272,7 @@ fn main() -> Result<(), Box> { bindings_content.push_str(" pub fn pg_query_scan(input: *const ::std::os::raw::c_char) -> PgQueryScanResult;\n"); bindings_content.push_str(" pub fn pg_query_parse_protobuf(input: *const ::std::os::raw::c_char) -> PgQueryProtobufParseResult;\n"); bindings_content.push_str(" pub fn pg_query_parse_plpgsql(input: *const ::std::os::raw::c_char) -> PgQueryPlpgsqlParseResult;\n"); + bindings_content.push_str(" pub fn pg_query_parse_plpgsql_protobuf(input: *const ::std::os::raw::c_char) -> PgQueryPlpgsqlProtobufParseResult;\n"); bindings_content.push_str(" pub fn pg_query_deparse_protobuf(protobuf: PgQueryProtobuf) -> PgQueryDeparseResult;\n"); bindings_content.push_str(" pub fn pg_query_normalize(input: *const ::std::os::raw::c_char) -> PgQueryNormalizeResult;\n"); bindings_content.push_str(" pub fn pg_query_fingerprint(input: *const ::std::os::raw::c_char) -> PgQueryFingerprintResult;\n"); @@ -278,6 +282,7 @@ fn main() -> Result<(), Box> { .push_str(" pub fn pg_query_free_scan_result(result: PgQueryScanResult);\n"); bindings_content.push_str(" pub fn pg_query_free_protobuf_parse_result(result: PgQueryProtobufParseResult);\n"); bindings_content.push_str(" pub fn pg_query_free_plpgsql_parse_result(result: PgQueryPlpgsqlParseResult);\n"); + bindings_content.push_str(" pub fn pg_query_free_plpgsql_protobuf_parse_result(result: PgQueryPlpgsqlProtobufParseResult);\n"); bindings_content.push_str( " pub fn pg_query_free_deparse_result(result: PgQueryDeparseResult);\n", ); diff --git a/crates/pgls_query/src/lib.rs b/crates/pgls_query/src/lib.rs index e89817196..ad9a63e1e 100644 --- a/crates/pgls_query/src/lib.rs +++ b/crates/pgls_query/src/lib.rs @@ -28,6 +28,9 @@ pub use scan::*; pub use split::*; pub use protobuf::Node; +pub use protobuf::PLpgSqlFunction; +pub use protobuf::PLpgSqlParseResult; +pub use protobuf::PLpgSqlStmt; // Include the generated bindings with 2024 edition compatibility #[allow(non_upper_case_globals)] diff --git a/crates/pgls_query/src/plpgsql.rs b/crates/pgls_query/src/plpgsql.rs index 9aa66e903..1c9c03b0c 100644 --- a/crates/pgls_query/src/plpgsql.rs +++ b/crates/pgls_query/src/plpgsql.rs @@ -1,15 +1,19 @@ use std::ffi::{CStr, CString}; +use prost::Message; + use crate::bindings::*; use crate::error::*; +use crate::protobuf; -/// An experimental API which parses a PLPGSQL function. This currently drops the returned -/// structure and returns only a Result<()>. +/// Parses the given PL/pgSQL function into an abstract syntax tree. /// /// # Example /// /// ```rust -/// let result = pgls_query::parse_plpgsql(" +/// use pgls_query::parse_plpgsql; +/// +/// let result = parse_plpgsql(" /// CREATE OR REPLACE FUNCTION cs_fmt_browser_version(v_name varchar, v_version varchar) /// RETURNS varchar AS $$ /// BEGIN @@ -21,18 +25,255 @@ use crate::error::*; /// $$ LANGUAGE plpgsql; /// "); /// assert!(result.is_ok()); +/// let result = result.unwrap(); +/// assert_eq!(result.functions().len(), 1); /// ``` -pub fn parse_plpgsql(stmt: &str) -> Result<()> { +pub fn parse_plpgsql(stmt: &str) -> Result { let input = CString::new(stmt)?; - let result = unsafe { pg_query_parse_plpgsql(input.as_ptr()) }; - let structure = if !result.error.is_null() { + let result = unsafe { pg_query_parse_plpgsql_protobuf(input.as_ptr()) }; + let parse_result = if !result.error.is_null() { let message = unsafe { CStr::from_ptr((*result.error).message) } .to_string_lossy() .to_string(); Err(Error::Parse(message)) } else { - Ok(()) + let data = unsafe { + std::slice::from_raw_parts( + result.parse_tree.data as *const u8, + result.parse_tree.len as usize, + ) + }; + protobuf::PLpgSqlParseResult::decode(data) + .map_err(Error::Decode) + .map(PlpgsqlParseResult::new) }; - unsafe { pg_query_free_plpgsql_parse_result(result) }; - structure + unsafe { pg_query_free_plpgsql_protobuf_parse_result(result) }; + parse_result +} + +/// The result of parsing a PL/pgSQL function +#[derive(Debug)] +pub struct PlpgsqlParseResult { + /// The parsed protobuf result + pub protobuf: protobuf::PLpgSqlParseResult, +} + +impl PlpgsqlParseResult { + /// Create a new PlpgsqlParseResult + pub fn new(protobuf: protobuf::PLpgSqlParseResult) -> Self { + Self { protobuf } + } + + /// Returns a reference to the single parsed PL/pgSQL function. + /// + /// Returns `None` if there is not exactly one function in the parse result. + /// Use `functions()` if you need to handle multiple functions. + pub fn function(&self) -> Option<&protobuf::PLpgSqlFunction> { + if self.protobuf.plpgsql_funcs.len() != 1 { + return None; + } + self.protobuf.plpgsql_funcs.first() + } + + /// Consumes the result and returns the single parsed function. + /// + /// Returns `None` if there is not exactly one function in the parse result. + /// Use `into_functions()` if you need to handle multiple functions. + pub fn into_function(self) -> Option { + if self.protobuf.plpgsql_funcs.len() != 1 { + return None; + } + self.protobuf.plpgsql_funcs.into_iter().next() + } + + /// Returns a reference to the list of parsed PL/pgSQL functions + pub fn functions(&self) -> &[protobuf::PLpgSqlFunction] { + &self.protobuf.plpgsql_funcs + } + + /// Consumes the result and returns the list of parsed functions + pub fn into_functions(self) -> Vec { + self.protobuf.plpgsql_funcs + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::protobuf::p_lpg_sql_stmt::Stmt; + + #[test] + fn test_parse_plpgsql_simple() { + let result = parse_plpgsql( + " + CREATE OR REPLACE FUNCTION test_func() + RETURNS void AS $$ + BEGIN + NULL; + END; + $$ LANGUAGE plpgsql; + ", + ); + assert!(result.is_ok()); + let result = result.unwrap(); + + // Use function() for single function access + let func = result.function().expect("should have exactly one function"); + assert!(func.action.is_some()); + + // The body should contain statements + let action = func.action.as_ref().unwrap(); + assert!(!action.body.is_empty()); + } + + #[test] + fn test_parse_plpgsql_with_assignment() { + let result = parse_plpgsql( + " + CREATE OR REPLACE FUNCTION add_numbers(a int, b int) + RETURNS int AS $$ + DECLARE + result int; + BEGIN + result := a + b; + RETURN result; + END; + $$ LANGUAGE plpgsql; + ", + ); + assert!(result.is_ok()); + let result = result.unwrap(); + assert_eq!(result.functions().len(), 1); + + let func = &result.functions()[0]; + let action = func.action.as_ref().unwrap(); + + // Should have assignment and return statements + assert!(action.body.len() >= 2); + + // First statement should be an assignment + let first_stmt = &action.body[0]; + assert!(matches!(first_stmt.stmt, Some(Stmt::StmtAssign(_)))); + + // Second statement should be a return + let second_stmt = &action.body[1]; + assert!(matches!(second_stmt.stmt, Some(Stmt::StmtReturn(_)))); + + // Verify the assignment expression contains the query + if let Some(Stmt::StmtAssign(assign)) = &first_stmt.stmt { + assert!(assign.expr.is_some()); + let expr = assign.expr.as_ref().unwrap(); + assert!(expr.query.contains("a + b")); + } + } + + #[test] + fn test_parse_plpgsql_with_if() { + let result = parse_plpgsql( + " + CREATE OR REPLACE FUNCTION cs_fmt_browser_version(v_name varchar, v_version varchar) + RETURNS varchar AS $$ + BEGIN + IF v_version IS NULL THEN + RETURN v_name; + END IF; + RETURN v_name || '/' || v_version; + END; + $$ LANGUAGE plpgsql; + ", + ); + assert!(result.is_ok()); + let result = result.unwrap(); + assert_eq!(result.functions().len(), 1); + + let func = &result.functions()[0]; + let action = func.action.as_ref().unwrap(); + + // Should have IF and RETURN statements + assert!(action.body.len() >= 2); + + // First statement should be IF + let if_stmt = &action.body[0]; + assert!(matches!(if_stmt.stmt, Some(Stmt::StmtIf(_)))); + + // Verify the IF statement structure + if let Some(Stmt::StmtIf(if_node)) = &if_stmt.stmt { + // Should have a condition + assert!(if_node.cond.is_some()); + let cond = if_node.cond.as_ref().unwrap(); + assert!(cond.query.contains("v_version IS NULL")); + + // Should have a then_body with RETURN statement + assert!(!if_node.then_body.is_empty()); + assert!(matches!( + if_node.then_body[0].stmt, + Some(Stmt::StmtReturn(_)) + )); + } + + // Second statement should be RETURN + let return_stmt = &action.body[1]; + assert!(matches!(return_stmt.stmt, Some(Stmt::StmtReturn(_)))); + } + + #[test] + fn test_parse_plpgsql_with_loop() { + let result = parse_plpgsql( + " + CREATE OR REPLACE FUNCTION count_down(n int) + RETURNS void AS $$ + BEGIN + WHILE n > 0 LOOP + n := n - 1; + END LOOP; + END; + $$ LANGUAGE plpgsql; + ", + ); + assert!(result.is_ok()); + let result = result.unwrap(); + + let func = &result.functions()[0]; + let action = func.action.as_ref().unwrap(); + + // First statement should be WHILE loop + let while_stmt = &action.body[0]; + assert!(matches!(while_stmt.stmt, Some(Stmt::StmtWhile(_)))); + + if let Some(Stmt::StmtWhile(while_node)) = &while_stmt.stmt { + // Should have a condition + assert!(while_node.cond.is_some()); + let cond = while_node.cond.as_ref().unwrap(); + assert!(cond.query.contains("n > 0")); + + // Should have a body with assignment + assert!(!while_node.body.is_empty()); + } + } + + #[test] + fn test_parse_plpgsql_error() { + let result = parse_plpgsql("not valid plpgsql"); + assert!(result.is_err()); + } + + #[test] + fn test_parse_plpgsql_multiple_functions() { + let result = parse_plpgsql( + " + CREATE FUNCTION foo() RETURNS void AS $$ BEGIN NULL; END; $$ LANGUAGE plpgsql; + CREATE FUNCTION bar() RETURNS int AS $$ BEGIN RETURN 1; END; $$ LANGUAGE plpgsql; + ", + ); + assert!(result.is_ok()); + let result = result.unwrap(); + + // function() returns None when multiple functions present + assert!(result.function().is_none()); + + // Use functions() for multiple + assert_eq!(result.functions().len(), 2); + assert_eq!(result.functions()[0].fn_signature, "foo"); + assert_eq!(result.functions()[1].fn_signature, "bar"); + } } diff --git a/crates/pgls_query/src/protobuf.rs b/crates/pgls_query/src/protobuf.rs index c47bfe52b..f2477fc43 100644 --- a/crates/pgls_query/src/protobuf.rs +++ b/crates/pgls_query/src/protobuf.rs @@ -4181,6 +4181,771 @@ pub struct ScanToken { #[prost(enumeration = "KeywordKind", tag = "5")] pub keyword_kind: i32, } +/// protobuf-c doesn't support optional fields, so any optional strings +/// are just an empty string if it should be the equivalent of None/nil. +/// +/// These fields have `// optional` at the end of the line. +/// +/// Upstream issue: +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct SummaryResult { + #[prost(message, repeated, tag = "1")] + pub tables: ::prost::alloc::vec::Vec, + /// The value here is the table name (i.e. schema.table or just table). + #[prost(map = "string, string", tag = "2")] + pub aliases: ::std::collections::HashMap< + ::prost::alloc::string::String, + ::prost::alloc::string::String, + >, + #[prost(string, repeated, tag = "3")] + pub cte_names: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + #[prost(message, repeated, tag = "4")] + pub functions: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "5")] + pub filter_columns: ::prost::alloc::vec::Vec, + #[prost(string, repeated, tag = "6")] + pub statement_types: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// optional, empty if truncation limit is -1 + #[prost(string, tag = "7")] + pub truncated_query: ::prost::alloc::string::String, +} +/// Nested message and enum types in `SummaryResult`. +pub mod summary_result { + #[derive(Clone, PartialEq, ::prost::Message)] + pub struct Table { + #[prost(string, tag = "1")] + pub name: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub schema_name: ::prost::alloc::string::String, + #[prost(string, tag = "3")] + pub table_name: ::prost::alloc::string::String, + #[prost(enumeration = "Context", tag = "4")] + pub context: i32, + } + #[derive(Clone, PartialEq, ::prost::Message)] + pub struct Function { + #[prost(string, tag = "1")] + pub name: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub function_name: ::prost::alloc::string::String, + /// optional + #[prost(string, tag = "3")] + pub schema_name: ::prost::alloc::string::String, + #[prost(enumeration = "Context", tag = "4")] + pub context: i32, + } + #[derive(Clone, PartialEq, ::prost::Message)] + pub struct FilterColumn { + /// optional + #[prost(string, tag = "1")] + pub schema_name: ::prost::alloc::string::String, + /// optional + #[prost(string, tag = "2")] + pub table_name: ::prost::alloc::string::String, + #[prost(string, tag = "3")] + pub column: ::prost::alloc::string::String, + } + #[derive( + Clone, + Copy, + Debug, + PartialEq, + Eq, + Hash, + PartialOrd, + Ord, + ::prost::Enumeration + )] + #[repr(i32)] + pub enum Context { + None = 0, + Select = 1, + Dml = 2, + Ddl = 3, + Call = 4, + } + impl Context { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::None => "None", + Self::Select => "Select", + Self::Dml => "DML", + Self::Ddl => "DDL", + Self::Call => "Call", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "None" => Some(Self::None), + "Select" => Some(Self::Select), + "DML" => Some(Self::Dml), + "DDL" => Some(Self::Ddl), + "Call" => Some(Self::Call), + _ => None, + } + } + } +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlParseResult { + #[prost(int32, tag = "1")] + pub version: i32, + #[prost(message, repeated, tag = "2")] + pub plpgsql_funcs: ::prost::alloc::vec::Vec, +} +/// PLpgSQL statement wrapper with oneof for polymorphism +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmt { + #[prost( + oneof = "p_lpg_sql_stmt::Stmt", + tags = "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27" + )] + pub stmt: ::core::option::Option, +} +/// Nested message and enum types in `PLpgSQL_stmt`. +pub mod p_lpg_sql_stmt { + #[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Stmt { + #[prost(message, tag = "1")] + StmtBlock(super::PLpgSqlStmtBlock), + #[prost(message, tag = "2")] + StmtAssign(super::PLpgSqlStmtAssign), + #[prost(message, tag = "3")] + StmtIf(super::PLpgSqlStmtIf), + #[prost(message, tag = "4")] + StmtCase(super::PLpgSqlStmtCase), + #[prost(message, tag = "5")] + StmtLoop(super::PLpgSqlStmtLoop), + #[prost(message, tag = "6")] + StmtWhile(super::PLpgSqlStmtWhile), + #[prost(message, tag = "7")] + StmtFori(super::PLpgSqlStmtFori), + #[prost(message, tag = "8")] + StmtFors(super::PLpgSqlStmtFors), + #[prost(message, tag = "9")] + StmtForc(super::PLpgSqlStmtForc), + #[prost(message, tag = "10")] + StmtForeachA(super::PLpgSqlStmtForeachA), + #[prost(message, tag = "11")] + StmtExit(super::PLpgSqlStmtExit), + #[prost(message, tag = "12")] + StmtReturn(super::PLpgSqlStmtReturn), + #[prost(message, tag = "13")] + StmtReturnNext(super::PLpgSqlStmtReturnNext), + #[prost(message, tag = "14")] + StmtReturnQuery(super::PLpgSqlStmtReturnQuery), + #[prost(message, tag = "15")] + StmtRaise(super::PLpgSqlStmtRaise), + #[prost(message, tag = "16")] + StmtAssert(super::PLpgSqlStmtAssert), + #[prost(message, tag = "17")] + StmtExecsql(super::PLpgSqlStmtExecsql), + #[prost(message, tag = "18")] + StmtDynexecute(super::PLpgSqlStmtDynexecute), + #[prost(message, tag = "19")] + StmtDynfors(super::PLpgSqlStmtDynfors), + #[prost(message, tag = "20")] + StmtGetdiag(super::PLpgSqlStmtGetdiag), + #[prost(message, tag = "21")] + StmtOpen(super::PLpgSqlStmtOpen), + #[prost(message, tag = "22")] + StmtFetch(super::PLpgSqlStmtFetch), + #[prost(message, tag = "23")] + StmtClose(super::PLpgSqlStmtClose), + #[prost(message, tag = "24")] + StmtPerform(super::PLpgSqlStmtPerform), + #[prost(message, tag = "25")] + StmtCall(super::PLpgSqlStmtCall), + #[prost(message, tag = "26")] + StmtCommit(super::PLpgSqlStmtCommit), + #[prost(message, tag = "27")] + StmtRollback(super::PLpgSqlStmtRollback), + } +} +/// PLpgSQL datum wrapper with oneof for polymorphism +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlDatum { + #[prost(oneof = "p_lpg_sql_datum::Datum", tags = "1, 3, 4, 5")] + pub datum: ::core::option::Option, +} +/// Nested message and enum types in `PLpgSQL_datum`. +pub mod p_lpg_sql_datum { + #[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Datum { + #[prost(message, tag = "1")] + Var(super::PLpgSqlVar), + #[prost(message, tag = "3")] + Row(super::PLpgSqlRow), + #[prost(message, tag = "4")] + Rec(super::PLpgSqlRec), + #[prost(message, tag = "5")] + Recfield(super::PLpgSqlRecfield), + } +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlType { + #[prost(string, tag = "1")] + pub typname: ::prost::alloc::string::String, + #[prost(enumeration = "PLpgSqlTypeType", tag = "2")] + pub ttype: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlExpr { + #[prost(string, tag = "1")] + pub query: ::prost::alloc::string::String, + #[prost(int32, tag = "2")] + pub parse_mode: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlVar { + #[prost(enumeration = "PLpgSqlDatumType", tag = "1")] + pub dtype: i32, + #[prost(int32, tag = "2")] + pub dno: i32, + #[prost(string, tag = "3")] + pub refname: ::prost::alloc::string::String, + #[prost(int32, tag = "4")] + pub lineno: i32, + #[prost(bool, tag = "5")] + pub isconst: bool, + #[prost(bool, tag = "6")] + pub notnull: bool, + #[prost(message, optional, tag = "7")] + pub default_val: ::core::option::Option, + #[prost(message, optional, tag = "8")] + pub datatype: ::core::option::Option, + #[prost(message, optional, tag = "9")] + pub cursor_explicit_expr: ::core::option::Option, + #[prost(int32, tag = "10")] + pub cursor_explicit_argrow: i32, + #[prost(int32, tag = "11")] + pub cursor_options: i32, + #[prost(enumeration = "PLpgSqlPromiseType", tag = "12")] + pub promise: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlRow { + #[prost(enumeration = "PLpgSqlDatumType", tag = "1")] + pub dtype: i32, + #[prost(int32, tag = "2")] + pub dno: i32, + #[prost(string, tag = "3")] + pub refname: ::prost::alloc::string::String, + #[prost(int32, tag = "4")] + pub lineno: i32, + #[prost(bool, tag = "5")] + pub isconst: bool, + #[prost(bool, tag = "6")] + pub notnull: bool, + #[prost(message, optional, tag = "7")] + pub default_val: ::core::option::Option, + #[prost(int32, tag = "8")] + pub nfields: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlRec { + #[prost(enumeration = "PLpgSqlDatumType", tag = "1")] + pub dtype: i32, + #[prost(int32, tag = "2")] + pub dno: i32, + #[prost(string, tag = "3")] + pub refname: ::prost::alloc::string::String, + #[prost(int32, tag = "4")] + pub lineno: i32, + #[prost(bool, tag = "5")] + pub isconst: bool, + #[prost(bool, tag = "6")] + pub notnull: bool, + #[prost(message, optional, tag = "7")] + pub default_val: ::core::option::Option, + #[prost(message, optional, tag = "8")] + pub datatype: ::core::option::Option, + #[prost(int32, tag = "9")] + pub firstfield: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlRecfield { + #[prost(enumeration = "PLpgSqlDatumType", tag = "1")] + pub dtype: i32, + #[prost(int32, tag = "2")] + pub dno: i32, + #[prost(string, tag = "3")] + pub fieldname: ::prost::alloc::string::String, + #[prost(int32, tag = "4")] + pub recparentno: i32, + #[prost(int32, tag = "5")] + pub nextfield: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlCondition { + #[prost(int32, tag = "1")] + pub sqlerrstate: i32, + #[prost(string, tag = "2")] + pub condname: ::prost::alloc::string::String, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlExceptionBlock { + #[prost(int32, tag = "1")] + pub sqlstate_varno: i32, + #[prost(int32, tag = "2")] + pub sqlerrm_varno: i32, + #[prost(message, repeated, tag = "3")] + pub exc_list: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlException { + #[prost(int32, tag = "1")] + pub lineno: i32, + #[prost(message, optional, tag = "2")] + pub conditions: ::core::option::Option, + #[prost(message, repeated, tag = "3")] + pub action: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtBlock { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(message, repeated, tag = "4")] + pub body: ::prost::alloc::vec::Vec, + #[prost(int32, tag = "5")] + pub n_initvars: i32, + #[prost(message, optional, tag = "6")] + pub exceptions: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtAssign { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(int32, tag = "3")] + pub varno: i32, + #[prost(message, optional, tag = "4")] + pub expr: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtPerform { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub expr: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtCall { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub expr: ::core::option::Option, + #[prost(bool, tag = "4")] + pub is_call: bool, + #[prost(message, optional, tag = "5")] + pub target: ::core::option::Option, +} +#[derive(Clone, Copy, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtCommit { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(bool, tag = "3")] + pub chain: bool, +} +#[derive(Clone, Copy, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtRollback { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(bool, tag = "3")] + pub chain: bool, +} +#[derive(Clone, Copy, PartialEq, ::prost::Message)] +pub struct PLpgSqlDiagItem { + #[prost(enumeration = "PLpgSqlGetdiagKind", tag = "1")] + pub kind: i32, + #[prost(int32, tag = "2")] + pub target: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtGetdiag { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(bool, tag = "3")] + pub is_stacked: bool, + #[prost(message, repeated, tag = "4")] + pub diag_items: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtIf { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub cond: ::core::option::Option, + #[prost(message, repeated, tag = "4")] + pub then_body: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "5")] + pub elsif_list: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "6")] + pub else_body: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlIfElsif { + #[prost(int32, tag = "1")] + pub lineno: i32, + #[prost(message, optional, tag = "2")] + pub cond: ::core::option::Option, + #[prost(message, repeated, tag = "3")] + pub stmts: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtCase { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub t_expr: ::core::option::Option, + #[prost(int32, tag = "4")] + pub t_varno: i32, + #[prost(message, repeated, tag = "5")] + pub case_when_list: ::prost::alloc::vec::Vec, + #[prost(bool, tag = "6")] + pub have_else: bool, + #[prost(message, repeated, tag = "7")] + pub else_stmts: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlCaseWhen { + #[prost(int32, tag = "1")] + pub lineno: i32, + #[prost(message, optional, tag = "2")] + pub expr: ::core::option::Option, + #[prost(message, repeated, tag = "3")] + pub stmts: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtLoop { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(message, repeated, tag = "4")] + pub body: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtWhile { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(message, optional, tag = "4")] + pub cond: ::core::option::Option, + #[prost(message, repeated, tag = "5")] + pub body: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtFori { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(message, optional, tag = "4")] + pub var: ::core::option::Option, + #[prost(message, optional, tag = "5")] + pub lower: ::core::option::Option, + #[prost(message, optional, tag = "6")] + pub upper: ::core::option::Option, + #[prost(message, optional, tag = "7")] + pub step: ::core::option::Option, + #[prost(int32, tag = "8")] + pub reverse: i32, + #[prost(message, repeated, tag = "9")] + pub body: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtFors { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(message, optional, tag = "4")] + pub var: ::core::option::Option, + #[prost(message, repeated, tag = "5")] + pub body: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag = "6")] + pub query: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtForc { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(message, optional, tag = "4")] + pub var: ::core::option::Option, + #[prost(message, repeated, tag = "5")] + pub body: ::prost::alloc::vec::Vec, + #[prost(int32, tag = "6")] + pub curvar: i32, + #[prost(message, optional, tag = "7")] + pub argquery: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtDynfors { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(message, optional, tag = "4")] + pub var: ::core::option::Option, + #[prost(message, repeated, tag = "5")] + pub body: ::prost::alloc::vec::Vec, + #[prost(message, optional, tag = "6")] + pub query: ::core::option::Option, + #[prost(message, repeated, tag = "7")] + pub params: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtForeachA { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(string, tag = "3")] + pub label: ::prost::alloc::string::String, + #[prost(int32, tag = "4")] + pub varno: i32, + #[prost(int32, tag = "5")] + pub slice: i32, + #[prost(message, optional, tag = "6")] + pub expr: ::core::option::Option, + #[prost(message, repeated, tag = "7")] + pub body: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtOpen { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(int32, tag = "3")] + pub curvar: i32, + #[prost(int32, tag = "4")] + pub cursor_options: i32, + #[prost(message, optional, tag = "5")] + pub argquery: ::core::option::Option, + #[prost(message, optional, tag = "6")] + pub query: ::core::option::Option, + #[prost(message, optional, tag = "7")] + pub dynquery: ::core::option::Option, + #[prost(message, repeated, tag = "8")] + pub params: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtFetch { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub target: ::core::option::Option, + #[prost(int32, tag = "4")] + pub curvar: i32, + #[prost(int32, tag = "5")] + pub direction: i32, + #[prost(int64, tag = "6")] + pub how_many: i64, + #[prost(message, optional, tag = "7")] + pub expr: ::core::option::Option, + #[prost(bool, tag = "8")] + pub is_move: bool, + #[prost(bool, tag = "9")] + pub returns_multiple_rows: bool, +} +#[derive(Clone, Copy, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtClose { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(int32, tag = "3")] + pub curvar: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtExit { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(bool, tag = "3")] + pub is_exit: bool, + #[prost(string, tag = "4")] + pub label: ::prost::alloc::string::String, + #[prost(message, optional, tag = "5")] + pub cond: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtReturn { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub expr: ::core::option::Option, + #[prost(int32, tag = "4")] + pub retvarno: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtReturnNext { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub expr: ::core::option::Option, + #[prost(int32, tag = "4")] + pub retvarno: i32, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtReturnQuery { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub query: ::core::option::Option, + #[prost(message, optional, tag = "4")] + pub dynquery: ::core::option::Option, + #[prost(message, repeated, tag = "5")] + pub params: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtRaise { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(int32, tag = "3")] + pub elog_level: i32, + #[prost(string, tag = "4")] + pub condname: ::prost::alloc::string::String, + #[prost(string, tag = "5")] + pub message: ::prost::alloc::string::String, + #[prost(message, repeated, tag = "6")] + pub params: ::prost::alloc::vec::Vec, + #[prost(message, repeated, tag = "7")] + pub options: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlRaiseOption { + #[prost(enumeration = "PLpgSqlRaiseOptionType", tag = "1")] + pub opt_type: i32, + #[prost(message, optional, tag = "2")] + pub expr: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtAssert { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub cond: ::core::option::Option, + #[prost(message, optional, tag = "4")] + pub message: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtExecsql { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub sqlstmt: ::core::option::Option, + #[prost(bool, tag = "4")] + pub mod_stmt: bool, + #[prost(bool, tag = "5")] + pub mod_stmt_set: bool, + #[prost(bool, tag = "6")] + pub into: bool, + #[prost(bool, tag = "7")] + pub strict: bool, + #[prost(message, optional, tag = "8")] + pub target: ::core::option::Option, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlStmtDynexecute { + #[prost(enumeration = "PLpgSqlStmtType", tag = "1")] + pub cmd_type: i32, + #[prost(int32, tag = "2")] + pub lineno: i32, + #[prost(message, optional, tag = "3")] + pub query: ::core::option::Option, + #[prost(bool, tag = "4")] + pub into: bool, + #[prost(bool, tag = "5")] + pub strict: bool, + #[prost(message, optional, tag = "6")] + pub target: ::core::option::Option, + #[prost(message, repeated, tag = "7")] + pub params: ::prost::alloc::vec::Vec, +} +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PLpgSqlFunction { + #[prost(string, tag = "1")] + pub fn_signature: ::prost::alloc::string::String, + #[prost(enumeration = "PLpgSqlTrigtype", tag = "2")] + pub fn_is_trigger: i32, + #[prost(int32, tag = "3")] + pub out_param_varno: i32, + #[prost(int32, tag = "4")] + pub found_varno: i32, + #[prost(int32, tag = "5")] + pub new_varno: i32, + #[prost(int32, tag = "6")] + pub old_varno: i32, + #[prost(enumeration = "PLpgSqlResolveOption", tag = "7")] + pub resolve_option: i32, + #[prost(bool, tag = "8")] + pub print_strict_params: bool, + #[prost(int32, tag = "9")] + pub extra_warnings: i32, + #[prost(int32, tag = "10")] + pub extra_errors: i32, + #[prost(int32, tag = "11")] + pub ndatums: i32, + #[prost(message, optional, tag = "12")] + pub action: ::core::option::Option, +} #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] #[repr(i32)] pub enum QuerySource { @@ -8844,3 +9609,478 @@ impl Token { } } } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlNsitemType { + Undefined = 0, + PlpgsqlNstypeLabel = 1, + PlpgsqlNstypeVar = 2, + PlpgsqlNstypeRec = 3, +} +impl PLpgSqlNsitemType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_NSITEM_TYPE_UNDEFINED", + Self::PlpgsqlNstypeLabel => "PLPGSQL_NSTYPE_LABEL", + Self::PlpgsqlNstypeVar => "PLPGSQL_NSTYPE_VAR", + Self::PlpgsqlNstypeRec => "PLPGSQL_NSTYPE_REC", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_NSITEM_TYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_NSTYPE_LABEL" => Some(Self::PlpgsqlNstypeLabel), + "PLPGSQL_NSTYPE_VAR" => Some(Self::PlpgsqlNstypeVar), + "PLPGSQL_NSTYPE_REC" => Some(Self::PlpgsqlNstypeRec), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlLabelType { + Undefined = 0, + PlpgsqlLabelBlock = 1, + PlpgsqlLabelLoop = 2, + PlpgsqlLabelOther = 3, +} +impl PLpgSqlLabelType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_LABEL_TYPE_UNDEFINED", + Self::PlpgsqlLabelBlock => "PLPGSQL_LABEL_BLOCK", + Self::PlpgsqlLabelLoop => "PLPGSQL_LABEL_LOOP", + Self::PlpgsqlLabelOther => "PLPGSQL_LABEL_OTHER", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_LABEL_TYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_LABEL_BLOCK" => Some(Self::PlpgsqlLabelBlock), + "PLPGSQL_LABEL_LOOP" => Some(Self::PlpgsqlLabelLoop), + "PLPGSQL_LABEL_OTHER" => Some(Self::PlpgsqlLabelOther), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlDatumType { + Undefined = 0, + PlpgsqlDtypeVar = 1, + PlpgsqlDtypeRow = 2, + PlpgsqlDtypeRec = 3, + PlpgsqlDtypeRecfield = 4, + PlpgsqlDtypePromise = 5, +} +impl PLpgSqlDatumType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_DATUM_TYPE_UNDEFINED", + Self::PlpgsqlDtypeVar => "PLPGSQL_DTYPE_VAR", + Self::PlpgsqlDtypeRow => "PLPGSQL_DTYPE_ROW", + Self::PlpgsqlDtypeRec => "PLPGSQL_DTYPE_REC", + Self::PlpgsqlDtypeRecfield => "PLPGSQL_DTYPE_RECFIELD", + Self::PlpgsqlDtypePromise => "PLPGSQL_DTYPE_PROMISE", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_DATUM_TYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_DTYPE_VAR" => Some(Self::PlpgsqlDtypeVar), + "PLPGSQL_DTYPE_ROW" => Some(Self::PlpgsqlDtypeRow), + "PLPGSQL_DTYPE_REC" => Some(Self::PlpgsqlDtypeRec), + "PLPGSQL_DTYPE_RECFIELD" => Some(Self::PlpgsqlDtypeRecfield), + "PLPGSQL_DTYPE_PROMISE" => Some(Self::PlpgsqlDtypePromise), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlPromiseType { + Undefined = 0, + PlpgsqlPromiseNone = 1, + PlpgsqlPromiseTgName = 2, + PlpgsqlPromiseTgWhen = 3, + PlpgsqlPromiseTgLevel = 4, + PlpgsqlPromiseTgOp = 5, + PlpgsqlPromiseTgRelid = 6, + PlpgsqlPromiseTgTableName = 7, + PlpgsqlPromiseTgTableSchema = 8, + PlpgsqlPromiseTgNargs = 9, + PlpgsqlPromiseTgArgv = 10, + PlpgsqlPromiseTgEvent = 11, + PlpgsqlPromiseTgTag = 12, +} +impl PLpgSqlPromiseType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_PROMISE_TYPE_UNDEFINED", + Self::PlpgsqlPromiseNone => "PLPGSQL_PROMISE_NONE", + Self::PlpgsqlPromiseTgName => "PLPGSQL_PROMISE_TG_NAME", + Self::PlpgsqlPromiseTgWhen => "PLPGSQL_PROMISE_TG_WHEN", + Self::PlpgsqlPromiseTgLevel => "PLPGSQL_PROMISE_TG_LEVEL", + Self::PlpgsqlPromiseTgOp => "PLPGSQL_PROMISE_TG_OP", + Self::PlpgsqlPromiseTgRelid => "PLPGSQL_PROMISE_TG_RELID", + Self::PlpgsqlPromiseTgTableName => "PLPGSQL_PROMISE_TG_TABLE_NAME", + Self::PlpgsqlPromiseTgTableSchema => "PLPGSQL_PROMISE_TG_TABLE_SCHEMA", + Self::PlpgsqlPromiseTgNargs => "PLPGSQL_PROMISE_TG_NARGS", + Self::PlpgsqlPromiseTgArgv => "PLPGSQL_PROMISE_TG_ARGV", + Self::PlpgsqlPromiseTgEvent => "PLPGSQL_PROMISE_TG_EVENT", + Self::PlpgsqlPromiseTgTag => "PLPGSQL_PROMISE_TG_TAG", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_PROMISE_TYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_PROMISE_NONE" => Some(Self::PlpgsqlPromiseNone), + "PLPGSQL_PROMISE_TG_NAME" => Some(Self::PlpgsqlPromiseTgName), + "PLPGSQL_PROMISE_TG_WHEN" => Some(Self::PlpgsqlPromiseTgWhen), + "PLPGSQL_PROMISE_TG_LEVEL" => Some(Self::PlpgsqlPromiseTgLevel), + "PLPGSQL_PROMISE_TG_OP" => Some(Self::PlpgsqlPromiseTgOp), + "PLPGSQL_PROMISE_TG_RELID" => Some(Self::PlpgsqlPromiseTgRelid), + "PLPGSQL_PROMISE_TG_TABLE_NAME" => Some(Self::PlpgsqlPromiseTgTableName), + "PLPGSQL_PROMISE_TG_TABLE_SCHEMA" => Some(Self::PlpgsqlPromiseTgTableSchema), + "PLPGSQL_PROMISE_TG_NARGS" => Some(Self::PlpgsqlPromiseTgNargs), + "PLPGSQL_PROMISE_TG_ARGV" => Some(Self::PlpgsqlPromiseTgArgv), + "PLPGSQL_PROMISE_TG_EVENT" => Some(Self::PlpgsqlPromiseTgEvent), + "PLPGSQL_PROMISE_TG_TAG" => Some(Self::PlpgsqlPromiseTgTag), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlTypeType { + Undefined = 0, + PlpgsqlTtypeScalar = 1, + PlpgsqlTtypeRec = 2, + PlpgsqlTtypePseudo = 3, +} +impl PLpgSqlTypeType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_TYPE_TYPE_UNDEFINED", + Self::PlpgsqlTtypeScalar => "PLPGSQL_TTYPE_SCALAR", + Self::PlpgsqlTtypeRec => "PLPGSQL_TTYPE_REC", + Self::PlpgsqlTtypePseudo => "PLPGSQL_TTYPE_PSEUDO", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_TYPE_TYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_TTYPE_SCALAR" => Some(Self::PlpgsqlTtypeScalar), + "PLPGSQL_TTYPE_REC" => Some(Self::PlpgsqlTtypeRec), + "PLPGSQL_TTYPE_PSEUDO" => Some(Self::PlpgsqlTtypePseudo), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlStmtType { + Undefined = 0, + PlpgsqlStmtBlock = 1, + PlpgsqlStmtAssign = 2, + PlpgsqlStmtIf = 3, + PlpgsqlStmtCase = 4, + PlpgsqlStmtLoop = 5, + PlpgsqlStmtWhile = 6, + PlpgsqlStmtFori = 7, + PlpgsqlStmtFors = 8, + PlpgsqlStmtForc = 9, + PlpgsqlStmtForeachA = 10, + PlpgsqlStmtExit = 11, + PlpgsqlStmtReturn = 12, + PlpgsqlStmtReturnNext = 13, + PlpgsqlStmtReturnQuery = 14, + PlpgsqlStmtRaise = 15, + PlpgsqlStmtAssert = 16, + PlpgsqlStmtExecsql = 17, + PlpgsqlStmtDynexecute = 18, + PlpgsqlStmtDynfors = 19, + PlpgsqlStmtGetdiag = 20, + PlpgsqlStmtOpen = 21, + PlpgsqlStmtFetch = 22, + PlpgsqlStmtClose = 23, + PlpgsqlStmtPerform = 24, + PlpgsqlStmtCall = 25, + PlpgsqlStmtCommit = 26, + PlpgsqlStmtRollback = 27, +} +impl PLpgSqlStmtType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_STMT_TYPE_UNDEFINED", + Self::PlpgsqlStmtBlock => "PLPGSQL_STMT_BLOCK", + Self::PlpgsqlStmtAssign => "PLPGSQL_STMT_ASSIGN", + Self::PlpgsqlStmtIf => "PLPGSQL_STMT_IF", + Self::PlpgsqlStmtCase => "PLPGSQL_STMT_CASE", + Self::PlpgsqlStmtLoop => "PLPGSQL_STMT_LOOP", + Self::PlpgsqlStmtWhile => "PLPGSQL_STMT_WHILE", + Self::PlpgsqlStmtFori => "PLPGSQL_STMT_FORI", + Self::PlpgsqlStmtFors => "PLPGSQL_STMT_FORS", + Self::PlpgsqlStmtForc => "PLPGSQL_STMT_FORC", + Self::PlpgsqlStmtForeachA => "PLPGSQL_STMT_FOREACH_A", + Self::PlpgsqlStmtExit => "PLPGSQL_STMT_EXIT", + Self::PlpgsqlStmtReturn => "PLPGSQL_STMT_RETURN", + Self::PlpgsqlStmtReturnNext => "PLPGSQL_STMT_RETURN_NEXT", + Self::PlpgsqlStmtReturnQuery => "PLPGSQL_STMT_RETURN_QUERY", + Self::PlpgsqlStmtRaise => "PLPGSQL_STMT_RAISE", + Self::PlpgsqlStmtAssert => "PLPGSQL_STMT_ASSERT", + Self::PlpgsqlStmtExecsql => "PLPGSQL_STMT_EXECSQL", + Self::PlpgsqlStmtDynexecute => "PLPGSQL_STMT_DYNEXECUTE", + Self::PlpgsqlStmtDynfors => "PLPGSQL_STMT_DYNFORS", + Self::PlpgsqlStmtGetdiag => "PLPGSQL_STMT_GETDIAG", + Self::PlpgsqlStmtOpen => "PLPGSQL_STMT_OPEN", + Self::PlpgsqlStmtFetch => "PLPGSQL_STMT_FETCH", + Self::PlpgsqlStmtClose => "PLPGSQL_STMT_CLOSE", + Self::PlpgsqlStmtPerform => "PLPGSQL_STMT_PERFORM", + Self::PlpgsqlStmtCall => "PLPGSQL_STMT_CALL", + Self::PlpgsqlStmtCommit => "PLPGSQL_STMT_COMMIT", + Self::PlpgsqlStmtRollback => "PLPGSQL_STMT_ROLLBACK", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_STMT_TYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_STMT_BLOCK" => Some(Self::PlpgsqlStmtBlock), + "PLPGSQL_STMT_ASSIGN" => Some(Self::PlpgsqlStmtAssign), + "PLPGSQL_STMT_IF" => Some(Self::PlpgsqlStmtIf), + "PLPGSQL_STMT_CASE" => Some(Self::PlpgsqlStmtCase), + "PLPGSQL_STMT_LOOP" => Some(Self::PlpgsqlStmtLoop), + "PLPGSQL_STMT_WHILE" => Some(Self::PlpgsqlStmtWhile), + "PLPGSQL_STMT_FORI" => Some(Self::PlpgsqlStmtFori), + "PLPGSQL_STMT_FORS" => Some(Self::PlpgsqlStmtFors), + "PLPGSQL_STMT_FORC" => Some(Self::PlpgsqlStmtForc), + "PLPGSQL_STMT_FOREACH_A" => Some(Self::PlpgsqlStmtForeachA), + "PLPGSQL_STMT_EXIT" => Some(Self::PlpgsqlStmtExit), + "PLPGSQL_STMT_RETURN" => Some(Self::PlpgsqlStmtReturn), + "PLPGSQL_STMT_RETURN_NEXT" => Some(Self::PlpgsqlStmtReturnNext), + "PLPGSQL_STMT_RETURN_QUERY" => Some(Self::PlpgsqlStmtReturnQuery), + "PLPGSQL_STMT_RAISE" => Some(Self::PlpgsqlStmtRaise), + "PLPGSQL_STMT_ASSERT" => Some(Self::PlpgsqlStmtAssert), + "PLPGSQL_STMT_EXECSQL" => Some(Self::PlpgsqlStmtExecsql), + "PLPGSQL_STMT_DYNEXECUTE" => Some(Self::PlpgsqlStmtDynexecute), + "PLPGSQL_STMT_DYNFORS" => Some(Self::PlpgsqlStmtDynfors), + "PLPGSQL_STMT_GETDIAG" => Some(Self::PlpgsqlStmtGetdiag), + "PLPGSQL_STMT_OPEN" => Some(Self::PlpgsqlStmtOpen), + "PLPGSQL_STMT_FETCH" => Some(Self::PlpgsqlStmtFetch), + "PLPGSQL_STMT_CLOSE" => Some(Self::PlpgsqlStmtClose), + "PLPGSQL_STMT_PERFORM" => Some(Self::PlpgsqlStmtPerform), + "PLPGSQL_STMT_CALL" => Some(Self::PlpgsqlStmtCall), + "PLPGSQL_STMT_COMMIT" => Some(Self::PlpgsqlStmtCommit), + "PLPGSQL_STMT_ROLLBACK" => Some(Self::PlpgsqlStmtRollback), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlGetdiagKind { + Undefined = 0, + PlpgsqlGetdiagRowCount = 1, + PlpgsqlGetdiagRoutineOid = 2, + PlpgsqlGetdiagContext = 3, + PlpgsqlGetdiagErrorContext = 4, + PlpgsqlGetdiagErrorDetail = 5, + PlpgsqlGetdiagErrorHint = 6, + PlpgsqlGetdiagReturnedSqlstate = 7, + PlpgsqlGetdiagColumnName = 8, + PlpgsqlGetdiagConstraintName = 9, + PlpgsqlGetdiagDatatypeName = 10, + PlpgsqlGetdiagMessageText = 11, + PlpgsqlGetdiagTableName = 12, + PlpgsqlGetdiagSchemaName = 13, +} +impl PLpgSqlGetdiagKind { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_GETDIAG_KIND_UNDEFINED", + Self::PlpgsqlGetdiagRowCount => "PLPGSQL_GETDIAG_ROW_COUNT", + Self::PlpgsqlGetdiagRoutineOid => "PLPGSQL_GETDIAG_ROUTINE_OID", + Self::PlpgsqlGetdiagContext => "PLPGSQL_GETDIAG_CONTEXT", + Self::PlpgsqlGetdiagErrorContext => "PLPGSQL_GETDIAG_ERROR_CONTEXT", + Self::PlpgsqlGetdiagErrorDetail => "PLPGSQL_GETDIAG_ERROR_DETAIL", + Self::PlpgsqlGetdiagErrorHint => "PLPGSQL_GETDIAG_ERROR_HINT", + Self::PlpgsqlGetdiagReturnedSqlstate => "PLPGSQL_GETDIAG_RETURNED_SQLSTATE", + Self::PlpgsqlGetdiagColumnName => "PLPGSQL_GETDIAG_COLUMN_NAME", + Self::PlpgsqlGetdiagConstraintName => "PLPGSQL_GETDIAG_CONSTRAINT_NAME", + Self::PlpgsqlGetdiagDatatypeName => "PLPGSQL_GETDIAG_DATATYPE_NAME", + Self::PlpgsqlGetdiagMessageText => "PLPGSQL_GETDIAG_MESSAGE_TEXT", + Self::PlpgsqlGetdiagTableName => "PLPGSQL_GETDIAG_TABLE_NAME", + Self::PlpgsqlGetdiagSchemaName => "PLPGSQL_GETDIAG_SCHEMA_NAME", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_GETDIAG_KIND_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_GETDIAG_ROW_COUNT" => Some(Self::PlpgsqlGetdiagRowCount), + "PLPGSQL_GETDIAG_ROUTINE_OID" => Some(Self::PlpgsqlGetdiagRoutineOid), + "PLPGSQL_GETDIAG_CONTEXT" => Some(Self::PlpgsqlGetdiagContext), + "PLPGSQL_GETDIAG_ERROR_CONTEXT" => Some(Self::PlpgsqlGetdiagErrorContext), + "PLPGSQL_GETDIAG_ERROR_DETAIL" => Some(Self::PlpgsqlGetdiagErrorDetail), + "PLPGSQL_GETDIAG_ERROR_HINT" => Some(Self::PlpgsqlGetdiagErrorHint), + "PLPGSQL_GETDIAG_RETURNED_SQLSTATE" => { + Some(Self::PlpgsqlGetdiagReturnedSqlstate) + } + "PLPGSQL_GETDIAG_COLUMN_NAME" => Some(Self::PlpgsqlGetdiagColumnName), + "PLPGSQL_GETDIAG_CONSTRAINT_NAME" => Some(Self::PlpgsqlGetdiagConstraintName), + "PLPGSQL_GETDIAG_DATATYPE_NAME" => Some(Self::PlpgsqlGetdiagDatatypeName), + "PLPGSQL_GETDIAG_MESSAGE_TEXT" => Some(Self::PlpgsqlGetdiagMessageText), + "PLPGSQL_GETDIAG_TABLE_NAME" => Some(Self::PlpgsqlGetdiagTableName), + "PLPGSQL_GETDIAG_SCHEMA_NAME" => Some(Self::PlpgsqlGetdiagSchemaName), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlRaiseOptionType { + Undefined = 0, + PlpgsqlRaiseoptionErrcode = 1, + PlpgsqlRaiseoptionMessage = 2, + PlpgsqlRaiseoptionDetail = 3, + PlpgsqlRaiseoptionHint = 4, + PlpgsqlRaiseoptionColumn = 5, + PlpgsqlRaiseoptionConstraint = 6, + PlpgsqlRaiseoptionDatatype = 7, + PlpgsqlRaiseoptionTable = 8, + PlpgsqlRaiseoptionSchema = 9, +} +impl PLpgSqlRaiseOptionType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_RAISE_OPTION_TYPE_UNDEFINED", + Self::PlpgsqlRaiseoptionErrcode => "PLPGSQL_RAISEOPTION_ERRCODE", + Self::PlpgsqlRaiseoptionMessage => "PLPGSQL_RAISEOPTION_MESSAGE", + Self::PlpgsqlRaiseoptionDetail => "PLPGSQL_RAISEOPTION_DETAIL", + Self::PlpgsqlRaiseoptionHint => "PLPGSQL_RAISEOPTION_HINT", + Self::PlpgsqlRaiseoptionColumn => "PLPGSQL_RAISEOPTION_COLUMN", + Self::PlpgsqlRaiseoptionConstraint => "PLPGSQL_RAISEOPTION_CONSTRAINT", + Self::PlpgsqlRaiseoptionDatatype => "PLPGSQL_RAISEOPTION_DATATYPE", + Self::PlpgsqlRaiseoptionTable => "PLPGSQL_RAISEOPTION_TABLE", + Self::PlpgsqlRaiseoptionSchema => "PLPGSQL_RAISEOPTION_SCHEMA", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_RAISE_OPTION_TYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_RAISEOPTION_ERRCODE" => Some(Self::PlpgsqlRaiseoptionErrcode), + "PLPGSQL_RAISEOPTION_MESSAGE" => Some(Self::PlpgsqlRaiseoptionMessage), + "PLPGSQL_RAISEOPTION_DETAIL" => Some(Self::PlpgsqlRaiseoptionDetail), + "PLPGSQL_RAISEOPTION_HINT" => Some(Self::PlpgsqlRaiseoptionHint), + "PLPGSQL_RAISEOPTION_COLUMN" => Some(Self::PlpgsqlRaiseoptionColumn), + "PLPGSQL_RAISEOPTION_CONSTRAINT" => Some(Self::PlpgsqlRaiseoptionConstraint), + "PLPGSQL_RAISEOPTION_DATATYPE" => Some(Self::PlpgsqlRaiseoptionDatatype), + "PLPGSQL_RAISEOPTION_TABLE" => Some(Self::PlpgsqlRaiseoptionTable), + "PLPGSQL_RAISEOPTION_SCHEMA" => Some(Self::PlpgsqlRaiseoptionSchema), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlResolveOption { + Undefined = 0, + PlpgsqlResolveError = 1, + PlpgsqlResolveVariable = 2, + PlpgsqlResolveColumn = 3, +} +impl PLpgSqlResolveOption { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_RESOLVE_OPTION_UNDEFINED", + Self::PlpgsqlResolveError => "PLPGSQL_RESOLVE_ERROR", + Self::PlpgsqlResolveVariable => "PLPGSQL_RESOLVE_VARIABLE", + Self::PlpgsqlResolveColumn => "PLPGSQL_RESOLVE_COLUMN", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_RESOLVE_OPTION_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_RESOLVE_ERROR" => Some(Self::PlpgsqlResolveError), + "PLPGSQL_RESOLVE_VARIABLE" => Some(Self::PlpgsqlResolveVariable), + "PLPGSQL_RESOLVE_COLUMN" => Some(Self::PlpgsqlResolveColumn), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum PLpgSqlTrigtype { + Undefined = 0, + PlpgsqlDmlTrigger = 1, + PlpgsqlEventTrigger = 2, + PlpgsqlNotTrigger = 3, +} +impl PLpgSqlTrigtype { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Self::Undefined => "P__LPG_SQL_TRIGTYPE_UNDEFINED", + Self::PlpgsqlDmlTrigger => "PLPGSQL_DML_TRIGGER", + Self::PlpgsqlEventTrigger => "PLPGSQL_EVENT_TRIGGER", + Self::PlpgsqlNotTrigger => "PLPGSQL_NOT_TRIGGER", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "P__LPG_SQL_TRIGTYPE_UNDEFINED" => Some(Self::Undefined), + "PLPGSQL_DML_TRIGGER" => Some(Self::PlpgsqlDmlTrigger), + "PLPGSQL_EVENT_TRIGGER" => Some(Self::PlpgsqlEventTrigger), + "PLPGSQL_NOT_TRIGGER" => Some(Self::PlpgsqlNotTrigger), + _ => None, + } + } +} diff --git a/crates/pgls_query/vendor/libpg_query b/crates/pgls_query/vendor/libpg_query index 9ac12d29f..80a3249ae 160000 --- a/crates/pgls_query/vendor/libpg_query +++ b/crates/pgls_query/vendor/libpg_query @@ -1 +1 @@ -Subproject commit 9ac12d29f2ffc0e49de8f4239223d50aaccd1549 +Subproject commit 80a3249ae54304fc791ffde2e65664fde4dd9251 diff --git a/crates/pgls_query_macros/build.rs b/crates/pgls_query_macros/build.rs index c33a1b9c1..e0d762c81 100644 --- a/crates/pgls_query_macros/build.rs +++ b/crates/pgls_query_macros/build.rs @@ -3,7 +3,7 @@ use std::fs; use std::io::Write; use std::path::PathBuf; -static LIBPG_QUERY_TAG: &str = "17-latest"; +static LIBPG_QUERY_TAG: &str = "feat/plpgsql-protobuf"; fn main() -> Result<(), Box> { let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); @@ -19,7 +19,7 @@ fn main() -> Result<(), Box> { fs::create_dir_all(&vendor_dir)?; let proto_url = format!( - "https://raw.githubusercontent.com/pganalyze/libpg_query/{LIBPG_QUERY_TAG}/protobuf/pg_query.proto" + "https://raw.githubusercontent.com/psteinroe/libpg_query/{LIBPG_QUERY_TAG}/protobuf/pg_query.proto" ); let response = ureq::get(&proto_url).call()?; diff --git a/crates/pgls_query_macros/src/proto_analyser.rs b/crates/pgls_query_macros/src/proto_analyser.rs index 7e16d606b..410c1db0e 100644 --- a/crates/pgls_query_macros/src/proto_analyser.rs +++ b/crates/pgls_query_macros/src/proto_analyser.rs @@ -74,7 +74,25 @@ impl ProtoAnalyzer { let mut nodes = Vec::new(); for msg in self.pool.all_messages() { - if ["ParseResult", "ScanResult", "Node", "ScanToken"].contains(&msg.name()) { + // Skip non-Node types (top-level results, helper messages) + if [ + "ParseResult", + "ScanResult", + "Node", + "ScanToken", + "SummaryResult", + "PLpgSQLParseResult", + ] + .contains(&msg.name()) + { + continue; + } + // Skip PLpgSQL types (they have their own separate AST) + if msg.name().starts_with("PLpgSQL") || msg.name().starts_with("PLpgSql") { + continue; + } + // Skip nested messages in SummaryResult (Table, Function, FilterColumn, Context) + if msg.full_name().starts_with("pg_query.SummaryResult.") { continue; } let fields = msg diff --git a/crates/pgls_query_macros/vendor/17-latest/pg_query.proto b/crates/pgls_query_macros/vendor/feat/plpgsql-protobuf/pg_query.proto similarity index 90% rename from crates/pgls_query_macros/vendor/17-latest/pg_query.proto rename to crates/pgls_query_macros/vendor/feat/plpgsql-protobuf/pg_query.proto index 24a8f14cd..41f453ac5 100644 --- a/crates/pgls_query_macros/vendor/17-latest/pg_query.proto +++ b/crates/pgls_query_macros/vendor/feat/plpgsql-protobuf/pg_query.proto @@ -4108,3 +4108,568 @@ enum Token { MODE_PLPGSQL_ASSIGN3 = 777; UMINUS = 778; } + + +// protobuf-c doesn't support optional fields, so any optional strings +// are just an empty string if it should be the equivalent of None/nil. +// +// These fields have `// optional` at the end of the line. +// +// Upstream issue: https://github.com/protobuf-c/protobuf-c/issues/476 +message SummaryResult { + enum Context { + None = 0; + Select = 1; + DML = 2; + DDL = 3; + Call = 4; + } + + message Table { + string name = 1; + string schema_name = 2; + string table_name = 3; + Context context = 4; + } + repeated Table tables = 1; + + // The value here is the table name (i.e. schema.table or just table). + map aliases = 2; + + repeated string cte_names = 3; + + message Function { + string name = 1; + string function_name = 2; + string schema_name = 3; // optional + Context context = 4; + } + repeated Function functions = 4; + + message FilterColumn { + string schema_name = 1; // optional + string table_name = 2; // optional + string column = 3; + } + repeated FilterColumn filter_columns = 5; + repeated string statement_types = 6; + string truncated_query = 7; /* optional, empty if truncation limit is -1 */ +} +// PLpgSQL Protobuf Definitions +// This file is autogenerated by ./scripts/generate_plpgsql_protobuf.rb + +message PLpgSQLParseResult { + int32 version = 1; + repeated PLpgSQL_function plpgsql_funcs = 2; +} + +// PLpgSQL statement wrapper with oneof for polymorphism +message PLpgSQL_stmt { + oneof stmt { + PLpgSQL_stmt_block stmt_block = 1; + PLpgSQL_stmt_assign stmt_assign = 2; + PLpgSQL_stmt_if stmt_if = 3; + PLpgSQL_stmt_case stmt_case_ = 4; + PLpgSQL_stmt_loop stmt_loop = 5; + PLpgSQL_stmt_while stmt_while = 6; + PLpgSQL_stmt_fori stmt_fori = 7; + PLpgSQL_stmt_fors stmt_fors = 8; + PLpgSQL_stmt_forc stmt_forc = 9; + PLpgSQL_stmt_foreach_a stmt_foreach_a = 10; + PLpgSQL_stmt_exit stmt_exit = 11; + PLpgSQL_stmt_return stmt_return = 12; + PLpgSQL_stmt_return_next stmt_return_next = 13; + PLpgSQL_stmt_return_query stmt_return_query = 14; + PLpgSQL_stmt_raise stmt_raise = 15; + PLpgSQL_stmt_assert stmt_assert = 16; + PLpgSQL_stmt_execsql stmt_execsql = 17; + PLpgSQL_stmt_dynexecute stmt_dynexecute = 18; + PLpgSQL_stmt_dynfors stmt_dynfors = 19; + PLpgSQL_stmt_getdiag stmt_getdiag = 20; + PLpgSQL_stmt_open stmt_open = 21; + PLpgSQL_stmt_fetch stmt_fetch = 22; + PLpgSQL_stmt_close stmt_close = 23; + PLpgSQL_stmt_perform stmt_perform = 24; + PLpgSQL_stmt_call stmt_call = 25; + PLpgSQL_stmt_commit stmt_commit = 26; + PLpgSQL_stmt_rollback stmt_rollback = 27; + } +} + +// PLpgSQL datum wrapper with oneof for polymorphism +message PLpgSQL_datum { + oneof datum { + PLpgSQL_var var = 1; + PLpgSQL_row row = 3; + PLpgSQL_rec rec = 4; + PLpgSQL_recfield recfield = 5; + } +} + +// PLpgSQL Messages + +message PLpgSQL_type { + string typname = 1; + PLpgSQL_type_type ttype = 2; +} + +message PLpgSQL_expr { + string query = 1; + int32 parse_mode = 2; +} + +message PLpgSQL_var { + PLpgSQL_datum_type dtype = 1; + int32 dno = 2; + string refname = 3; + int32 lineno = 4; + bool isconst = 5; + bool notnull = 6; + PLpgSQL_expr default_val = 7; + PLpgSQL_type datatype = 8; + PLpgSQL_expr cursor_explicit_expr = 9; + int32 cursor_explicit_argrow = 10; + int32 cursor_options = 11; + PLpgSQL_promise_type promise = 12; +} + +message PLpgSQL_row { + PLpgSQL_datum_type dtype = 1; + int32 dno = 2; + string refname = 3; + int32 lineno = 4; + bool isconst = 5; + bool notnull = 6; + PLpgSQL_expr default_val = 7; + int32 nfields = 8; +} + +message PLpgSQL_rec { + PLpgSQL_datum_type dtype = 1; + int32 dno = 2; + string refname = 3; + int32 lineno = 4; + bool isconst = 5; + bool notnull = 6; + PLpgSQL_expr default_val = 7; + PLpgSQL_type datatype = 8; + int32 firstfield = 9; +} + +message PLpgSQL_recfield { + PLpgSQL_datum_type dtype = 1; + int32 dno = 2; + string fieldname = 3; + int32 recparentno = 4; + int32 nextfield = 5; +} + +message PLpgSQL_condition { + int32 sqlerrstate = 1; + string condname = 2; +} + +message PLpgSQL_exception_block { + int32 sqlstate_varno = 1; + int32 sqlerrm_varno = 2; + repeated PLpgSQL_exception exc_list = 3; +} + +message PLpgSQL_exception { + int32 lineno = 1; + PLpgSQL_condition conditions = 2; + repeated PLpgSQL_stmt action = 3; +} + +message PLpgSQL_stmt_block { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + repeated PLpgSQL_stmt body = 4; + int32 n_initvars = 5; + PLpgSQL_exception_block exceptions = 6; +} + +message PLpgSQL_stmt_assign { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + int32 varno = 3; + PLpgSQL_expr expr = 4; +} + +message PLpgSQL_stmt_perform { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr expr = 3; +} + +message PLpgSQL_stmt_call { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr expr = 3; + bool is_call = 4; + PLpgSQL_datum target = 5; +} + +message PLpgSQL_stmt_commit { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + bool chain = 3; +} + +message PLpgSQL_stmt_rollback { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + bool chain = 3; +} + +message PLpgSQL_diag_item { + PLpgSQL_getdiag_kind kind = 1; + int32 target = 2; +} + +message PLpgSQL_stmt_getdiag { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + bool is_stacked = 3; + repeated PLpgSQL_diag_item diag_items = 4; +} + +message PLpgSQL_stmt_if { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr cond = 3; + repeated PLpgSQL_stmt then_body = 4; + repeated PLpgSQL_if_elsif elsif_list = 5; + repeated PLpgSQL_stmt else_body = 6; +} + +message PLpgSQL_if_elsif { + int32 lineno = 1; + PLpgSQL_expr cond = 2; + repeated PLpgSQL_stmt stmts = 3; +} + +message PLpgSQL_stmt_case { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr t_expr = 3; + int32 t_varno = 4; + repeated PLpgSQL_case_when case_when_list = 5; + bool have_else = 6; + repeated PLpgSQL_stmt else_stmts = 7; +} + +message PLpgSQL_case_when { + int32 lineno = 1; + PLpgSQL_expr expr = 2; + repeated PLpgSQL_stmt stmts = 3; +} + +message PLpgSQL_stmt_loop { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + repeated PLpgSQL_stmt body = 4; +} + +message PLpgSQL_stmt_while { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + PLpgSQL_expr cond = 4; + repeated PLpgSQL_stmt body = 5; +} + +message PLpgSQL_stmt_fori { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + PLpgSQL_var var = 4; + PLpgSQL_expr lower = 5; + PLpgSQL_expr upper = 6; + PLpgSQL_expr step = 7; + int32 reverse = 8; + repeated PLpgSQL_stmt body = 9; +} + +message PLpgSQL_stmt_fors { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + PLpgSQL_datum var = 4; + repeated PLpgSQL_stmt body = 5; + PLpgSQL_expr query = 6; +} + +message PLpgSQL_stmt_forc { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + PLpgSQL_datum var = 4; + repeated PLpgSQL_stmt body = 5; + int32 curvar = 6; + PLpgSQL_expr argquery = 7; +} + +message PLpgSQL_stmt_dynfors { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + PLpgSQL_datum var = 4; + repeated PLpgSQL_stmt body = 5; + PLpgSQL_expr query = 6; + repeated PLpgSQL_expr params = 7; +} + +message PLpgSQL_stmt_foreach_a { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + string label = 3; + int32 varno = 4; + int32 slice = 5; + PLpgSQL_expr expr = 6; + repeated PLpgSQL_stmt body = 7; +} + +message PLpgSQL_stmt_open { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + int32 curvar = 3; + int32 cursor_options = 4; + PLpgSQL_expr argquery = 5; + PLpgSQL_expr query = 6; + PLpgSQL_expr dynquery = 7; + repeated PLpgSQL_expr params = 8; +} + +message PLpgSQL_stmt_fetch { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_datum target = 3; + int32 curvar = 4; + int32 direction = 5; + int64 how_many = 6; + PLpgSQL_expr expr = 7; + bool is_move = 8; + bool returns_multiple_rows = 9; +} + +message PLpgSQL_stmt_close { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + int32 curvar = 3; +} + +message PLpgSQL_stmt_exit { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + bool is_exit = 3; + string label = 4; + PLpgSQL_expr cond = 5; +} + +message PLpgSQL_stmt_return { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr expr = 3; + int32 retvarno = 4; +} + +message PLpgSQL_stmt_return_next { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr expr = 3; + int32 retvarno = 4; +} + +message PLpgSQL_stmt_return_query { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr query = 3; + PLpgSQL_expr dynquery = 4; + repeated PLpgSQL_expr params = 5; +} + +message PLpgSQL_stmt_raise { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + int32 elog_level = 3; + string condname = 4; + string message = 5; + repeated PLpgSQL_expr params = 6; + repeated PLpgSQL_raise_option options = 7; +} + +message PLpgSQL_raise_option { + PLpgSQL_raise_option_type opt_type = 1; + PLpgSQL_expr expr = 2; +} + +message PLpgSQL_stmt_assert { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr cond = 3; + PLpgSQL_expr message = 4; +} + +message PLpgSQL_stmt_execsql { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr sqlstmt = 3; + bool mod_stmt = 4; + bool mod_stmt_set = 5; + bool into = 6; + bool strict = 7; + PLpgSQL_datum target = 8; +} + +message PLpgSQL_stmt_dynexecute { + PLpgSQL_stmt_type cmd_type = 1; + int32 lineno = 2; + PLpgSQL_expr query = 3; + bool into = 4; + bool strict = 5; + PLpgSQL_datum target = 6; + repeated PLpgSQL_expr params = 7; +} + +message PLpgSQL_function { + string fn_signature = 1; + PLpgSQL_trigtype fn_is_trigger = 2; + int32 out_param_varno = 3; + int32 found_varno = 4; + int32 new_varno = 5; + int32 old_varno = 6; + PLpgSQL_resolve_option resolve_option = 7; + bool print_strict_params = 8; + int32 extra_warnings = 9; + int32 extra_errors = 10; + int32 ndatums = 11; + PLpgSQL_stmt_block action = 12; +} + + +// PLpgSQL Enums + +enum PLpgSQL_nsitem_type { + P__LPG_SQL_NSITEM_TYPE_UNDEFINED = 0; + PLPGSQL_NSTYPE_LABEL = 1; + PLPGSQL_NSTYPE_VAR = 2; + PLPGSQL_NSTYPE_REC = 3; +} + +enum PLpgSQL_label_type { + P__LPG_SQL_LABEL_TYPE_UNDEFINED = 0; + PLPGSQL_LABEL_BLOCK = 1; + PLPGSQL_LABEL_LOOP = 2; + PLPGSQL_LABEL_OTHER = 3; +} + +enum PLpgSQL_datum_type { + P__LPG_SQL_DATUM_TYPE_UNDEFINED = 0; + PLPGSQL_DTYPE_VAR = 1; + PLPGSQL_DTYPE_ROW = 2; + PLPGSQL_DTYPE_REC = 3; + PLPGSQL_DTYPE_RECFIELD = 4; + PLPGSQL_DTYPE_PROMISE = 5; +} + +enum PLpgSQL_promise_type { + P__LPG_SQL_PROMISE_TYPE_UNDEFINED = 0; + PLPGSQL_PROMISE_NONE = 1; + PLPGSQL_PROMISE_TG_NAME = 2; + PLPGSQL_PROMISE_TG_WHEN = 3; + PLPGSQL_PROMISE_TG_LEVEL = 4; + PLPGSQL_PROMISE_TG_OP = 5; + PLPGSQL_PROMISE_TG_RELID = 6; + PLPGSQL_PROMISE_TG_TABLE_NAME = 7; + PLPGSQL_PROMISE_TG_TABLE_SCHEMA = 8; + PLPGSQL_PROMISE_TG_NARGS = 9; + PLPGSQL_PROMISE_TG_ARGV = 10; + PLPGSQL_PROMISE_TG_EVENT = 11; + PLPGSQL_PROMISE_TG_TAG = 12; +} + +enum PLpgSQL_type_type { + P__LPG_SQL_TYPE_TYPE_UNDEFINED = 0; + PLPGSQL_TTYPE_SCALAR = 1; + PLPGSQL_TTYPE_REC = 2; + PLPGSQL_TTYPE_PSEUDO = 3; +} + +enum PLpgSQL_stmt_type { + P__LPG_SQL_STMT_TYPE_UNDEFINED = 0; + PLPGSQL_STMT_BLOCK = 1; + PLPGSQL_STMT_ASSIGN = 2; + PLPGSQL_STMT_IF = 3; + PLPGSQL_STMT_CASE = 4; + PLPGSQL_STMT_LOOP = 5; + PLPGSQL_STMT_WHILE = 6; + PLPGSQL_STMT_FORI = 7; + PLPGSQL_STMT_FORS = 8; + PLPGSQL_STMT_FORC = 9; + PLPGSQL_STMT_FOREACH_A = 10; + PLPGSQL_STMT_EXIT = 11; + PLPGSQL_STMT_RETURN = 12; + PLPGSQL_STMT_RETURN_NEXT = 13; + PLPGSQL_STMT_RETURN_QUERY = 14; + PLPGSQL_STMT_RAISE = 15; + PLPGSQL_STMT_ASSERT = 16; + PLPGSQL_STMT_EXECSQL = 17; + PLPGSQL_STMT_DYNEXECUTE = 18; + PLPGSQL_STMT_DYNFORS = 19; + PLPGSQL_STMT_GETDIAG = 20; + PLPGSQL_STMT_OPEN = 21; + PLPGSQL_STMT_FETCH = 22; + PLPGSQL_STMT_CLOSE = 23; + PLPGSQL_STMT_PERFORM = 24; + PLPGSQL_STMT_CALL = 25; + PLPGSQL_STMT_COMMIT = 26; + PLPGSQL_STMT_ROLLBACK = 27; +} + +enum PLpgSQL_getdiag_kind { + P__LPG_SQL_GETDIAG_KIND_UNDEFINED = 0; + PLPGSQL_GETDIAG_ROW_COUNT = 1; + PLPGSQL_GETDIAG_ROUTINE_OID = 2; + PLPGSQL_GETDIAG_CONTEXT = 3; + PLPGSQL_GETDIAG_ERROR_CONTEXT = 4; + PLPGSQL_GETDIAG_ERROR_DETAIL = 5; + PLPGSQL_GETDIAG_ERROR_HINT = 6; + PLPGSQL_GETDIAG_RETURNED_SQLSTATE = 7; + PLPGSQL_GETDIAG_COLUMN_NAME = 8; + PLPGSQL_GETDIAG_CONSTRAINT_NAME = 9; + PLPGSQL_GETDIAG_DATATYPE_NAME = 10; + PLPGSQL_GETDIAG_MESSAGE_TEXT = 11; + PLPGSQL_GETDIAG_TABLE_NAME = 12; + PLPGSQL_GETDIAG_SCHEMA_NAME = 13; +} + +enum PLpgSQL_raise_option_type { + P__LPG_SQL_RAISE_OPTION_TYPE_UNDEFINED = 0; + PLPGSQL_RAISEOPTION_ERRCODE = 1; + PLPGSQL_RAISEOPTION_MESSAGE = 2; + PLPGSQL_RAISEOPTION_DETAIL = 3; + PLPGSQL_RAISEOPTION_HINT = 4; + PLPGSQL_RAISEOPTION_COLUMN = 5; + PLPGSQL_RAISEOPTION_CONSTRAINT = 6; + PLPGSQL_RAISEOPTION_DATATYPE = 7; + PLPGSQL_RAISEOPTION_TABLE = 8; + PLPGSQL_RAISEOPTION_SCHEMA = 9; +} + +enum PLpgSQL_resolve_option { + P__LPG_SQL_RESOLVE_OPTION_UNDEFINED = 0; + PLPGSQL_RESOLVE_ERROR = 1; + PLPGSQL_RESOLVE_VARIABLE = 2; + PLPGSQL_RESOLVE_COLUMN = 3; +} + +enum PLpgSQL_trigtype { + P__LPG_SQL_TRIGTYPE_UNDEFINED = 0; + PLPGSQL_DML_TRIGGER = 1; + PLPGSQL_EVENT_TRIGGER = 2; + PLPGSQL_NOT_TRIGGER = 3; +} + diff --git a/crates/pgls_workspace/src/workspace/server/pg_query.rs b/crates/pgls_workspace/src/workspace/server/pg_query.rs index cce1744cc..59bf51641 100644 --- a/crates/pgls_workspace/src/workspace/server/pg_query.rs +++ b/crates/pgls_workspace/src/workspace/server/pg_query.rs @@ -83,6 +83,7 @@ impl PgQueryStore { let range = TextRange::new(start.try_into().unwrap(), end.try_into().unwrap()); let r = pgls_query::parse_plpgsql(statement.content()) + .map(|_| ()) // discard result, we only care about syntax errors .or_else(|e| match &e { // ignore `is not a known variable` for composite types because libpg_query reports a false positive. // https://github.com/pganalyze/libpg_query/issues/159