#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("{message}")]
pub struct ParseError {
pub message: String,
pub position: usize,
sqlstate: &'static str,
}
impl ParseError {
pub fn new(message: impl Into<String>, position: usize) -> Self {
Self {
message: format!("syntax error at position {position}: {}", message.into()),
position,
sqlstate: "42601",
}
}
pub(crate) fn new_sqlstate(
sqlstate: &'static str,
message: impl Into<String>,
position: usize,
) -> Self {
Self {
message: message.into(),
position,
sqlstate,
}
}
#[must_use]
pub fn too_deep(position: usize) -> Self {
Self {
message: "stack depth limit exceeded".to_string(),
position,
sqlstate: "54001",
}
}
#[must_use]
pub fn sqlstate(&self) -> &'static str {
self.sqlstate
}
}