25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
use crate::SqlReadBytes;
use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
/// An error token returned from the server.
pub struct TokenError {
/// ErrorCode
pub(crate) code: u32,
/// ErrorState (describing code)
pub(crate) state: u8,
/// The class (severity) of the error
pub(crate) class: u8,
/// The error message
pub(crate) message: String,
pub(crate) server: String,
pub(crate) procedure: String,
pub(crate) line: u32,
}
impl TokenError {
pub(crate) async fn decode<R>(src: &mut R) -> crate::Result<Self>
where
R: SqlReadBytes + Unpin,
{
let length = src.read_u16_le().await? as usize;
let code = src.read_u32_le().await?;
let state = src.read_u8().await?;
let class = src.read_u8().await?;
let message = src.read_us_varchar().await?;
let server = src.read_b_varchar().await?;
let procedure = src.read_b_varchar().await?;
let width = super::message_line_number_bytes(length, &message, &server, &procedure)?;
let line = if width == 4 {
src.read_u32_le().await?
} else {
src.read_u16_le().await? as u32
};
let token = TokenError {
code,
state,
class,
message,
server,
procedure,
line,
};
Ok(token)
}
/// The error code, see descriptions from [the manual].
///
/// [the manual]: https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors?view=sql-server-ver15
pub fn code(&self) -> u32 {
self.code
}
/// The error state, used as a modifier to the error number.
pub fn state(&self) -> u8 {
self.state
}
/// The class (severity) of the error. A class of less than 10 indicates an
/// informational message.
pub fn class(&self) -> u8 {
self.class
}
/// The error message returned from the server.
pub fn message(&self) -> &str {
&self.message
}
/// The server name.
pub fn server(&self) -> &str {
&self.server
}
/// The name of the stored procedure causing the error.
pub fn procedure(&self) -> &str {
&self.procedure
}
/// The line number in the SQL batch or stored procedure that caused the
/// error. Line numbers begin at 1. If the line number is not applicable to
/// the message, the value is 0.
pub fn line(&self) -> u32 {
self.line
}
}
impl fmt::Display for TokenError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"'{}' on server {} executing {} on line {} (code: {}, state: {}, class: {})",
self.message, self.server, self.procedure, self.line, self.code, self.state, self.class
)
}
}