diff --git a/Cargo.toml b/Cargo.toml index 2424197c..86e7becf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ members = [ "codegen", "postgres-protocol", - "postgres-shared", "tokio-postgres", "tokio-postgres-native-tls", "tokio-postgres-openssl", diff --git a/codegen/src/main.rs b/codegen/src/main.rs index 9aa9a974..70e734c7 100644 --- a/codegen/src/main.rs +++ b/codegen/src/main.rs @@ -9,7 +9,7 @@ mod sqlstate; mod type_gen; fn main() { - let path = Path::new("../postgres-shared/src"); + let path = Path::new("../tokio-postgres/src"); sqlstate::build(path); type_gen::build(path); } diff --git a/postgres-shared/Cargo.toml b/postgres-shared/Cargo.toml deleted file mode 100644 index 2bdeb171..00000000 --- a/postgres-shared/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "postgres-shared" -version = "0.4.1" -authors = ["Steven Fackler "] -license = "MIT" -description = "Internal crate used by postgres and postgres-tokio" -repository = "https://github.com/sfackler/rust-postgres" - -[features] -"with-bit-vec-0.5" = ["bit-vec"] -"with-chrono-0.4" = ["chrono"] -"with-eui48-0.3" = ["eui48"] -"with-geo-0.10" = ["geo"] -with-serde_json-1 = ["serde", "serde_json"] -"with-uuid-0.6" = ["uuid"] - -[dependencies] -hex = "0.3" -fallible-iterator = "0.1.3" -phf = "0.7.22" -postgres-protocol = { version = "0.3", path = "../postgres-protocol" } - -bit-vec = { version = "0.5", optional = true } -chrono = { version = "0.4", optional = true } -eui48 = { version = "0.3", optional = true } -geo = { version = "0.10", optional = true } -serde = { version = "1.0", optional = true } -serde_json = { version = "1.0", optional = true } -uuid = { version = "0.6", optional = true } diff --git a/postgres-shared/src/error/mod.rs b/postgres-shared/src/error/mod.rs deleted file mode 100644 index c437219c..00000000 --- a/postgres-shared/src/error/mod.rs +++ /dev/null @@ -1,448 +0,0 @@ -//! Errors. - -use fallible_iterator::FallibleIterator; -use postgres_protocol::message::backend::{ErrorFields, ErrorResponseBody}; -use std::convert::From; -use std::error; -use std::fmt; -use std::io; - -pub use self::sqlstate::*; - -mod sqlstate; - -/// The severity of a Postgres error or notice. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum Severity { - /// PANIC - Panic, - /// FATAL - Fatal, - /// ERROR - Error, - /// WARNING - Warning, - /// NOTICE - Notice, - /// DEBUG - Debug, - /// INFO - Info, - /// LOG - Log, -} - -impl fmt::Display for Severity { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let s = match *self { - Severity::Panic => "PANIC", - Severity::Fatal => "FATAL", - Severity::Error => "ERROR", - Severity::Warning => "WARNING", - Severity::Notice => "NOTICE", - Severity::Debug => "DEBUG", - Severity::Info => "INFO", - Severity::Log => "LOG", - }; - fmt.write_str(s) - } -} - -impl Severity { - fn from_str(s: &str) -> Option { - match s { - "PANIC" => Some(Severity::Panic), - "FATAL" => Some(Severity::Fatal), - "ERROR" => Some(Severity::Error), - "WARNING" => Some(Severity::Warning), - "NOTICE" => Some(Severity::Notice), - "DEBUG" => Some(Severity::Debug), - "INFO" => Some(Severity::Info), - "LOG" => Some(Severity::Log), - _ => None, - } - } -} - -/// A Postgres error or notice. -#[derive(Clone, PartialEq, Eq)] -pub struct DbError { - /// The field contents are ERROR, FATAL, or PANIC (in an error message), - /// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a - /// localized translation of one of these. - pub severity: String, - - /// A parsed, nonlocalized version of `severity`. (PostgreSQL 9.6+) - pub parsed_severity: Option, - - /// The SQLSTATE code for the error. - pub code: SqlState, - - /// The primary human-readable error message. This should be accurate but - /// terse (typically one line). - pub message: String, - - /// An optional secondary error message carrying more detail about the - /// problem. Might run to multiple lines. - pub detail: Option, - - /// An optional suggestion what to do about the problem. This is intended - /// to differ from Detail in that it offers advice (potentially - /// inappropriate) rather than hard facts. Might run to multiple lines. - pub hint: Option, - - /// An optional error cursor position into either the original query string - /// or an internally generated query. - pub position: Option, - - /// An indication of the context in which the error occurred. Presently - /// this includes a call stack traceback of active procedural language - /// functions and internally-generated queries. The trace is one entry per - /// line, most recent first. - pub where_: Option, - - /// If the error was associated with a specific database object, the name - /// of the schema containing that object, if any. (PostgreSQL 9.3+) - pub schema: Option, - - /// If the error was associated with a specific table, the name of the - /// table. (Refer to the schema name field for the name of the table's - /// schema.) (PostgreSQL 9.3+) - pub table: Option, - - /// If the error was associated with a specific table column, the name of - /// the column. (Refer to the schema and table name fields to identify the - /// table.) (PostgreSQL 9.3+) - pub column: Option, - - /// If the error was associated with a specific data type, the name of the - /// data type. (Refer to the schema name field for the name of the data - /// type's schema.) (PostgreSQL 9.3+) - pub datatype: Option, - - /// If the error was associated with a specific constraint, the name of the - /// constraint. Refer to fields listed above for the associated table or - /// domain. (For this purpose, indexes are treated as constraints, even if - /// they weren't created with constraint syntax.) (PostgreSQL 9.3+) - pub constraint: Option, - - /// The file name of the source-code location where the error was reported. - pub file: Option, - - /// The line number of the source-code location where the error was - /// reported. - pub line: Option, - - /// The name of the source-code routine reporting the error. - pub routine: Option, - - _p: (), -} - -impl DbError { - #[doc(hidden)] - pub fn new(fields: &mut ErrorFields) -> io::Result { - let mut severity = None; - let mut parsed_severity = None; - let mut code = None; - let mut message = None; - let mut detail = None; - let mut hint = None; - let mut normal_position = None; - let mut internal_position = None; - let mut internal_query = None; - let mut where_ = None; - let mut schema = None; - let mut table = None; - let mut column = None; - let mut datatype = None; - let mut constraint = None; - let mut file = None; - let mut line = None; - let mut routine = None; - - while let Some(field) = fields.next()? { - match field.type_() { - b'S' => severity = Some(field.value().to_owned()), - b'C' => code = Some(SqlState::from_code(field.value())), - b'M' => message = Some(field.value().to_owned()), - b'D' => detail = Some(field.value().to_owned()), - b'H' => hint = Some(field.value().to_owned()), - b'P' => { - normal_position = Some(field.value().parse::().map_err(|_| { - io::Error::new( - io::ErrorKind::InvalidInput, - "`P` field did not contain an integer", - ) - })?); - } - b'p' => { - internal_position = Some(field.value().parse::().map_err(|_| { - io::Error::new( - io::ErrorKind::InvalidInput, - "`p` field did not contain an integer", - ) - })?); - } - b'q' => internal_query = Some(field.value().to_owned()), - b'W' => where_ = Some(field.value().to_owned()), - b's' => schema = Some(field.value().to_owned()), - b't' => table = Some(field.value().to_owned()), - b'c' => column = Some(field.value().to_owned()), - b'd' => datatype = Some(field.value().to_owned()), - b'n' => constraint = Some(field.value().to_owned()), - b'F' => file = Some(field.value().to_owned()), - b'L' => { - line = Some(field.value().parse::().map_err(|_| { - io::Error::new( - io::ErrorKind::InvalidInput, - "`L` field did not contain an integer", - ) - })?); - } - b'R' => routine = Some(field.value().to_owned()), - b'V' => { - parsed_severity = Some(Severity::from_str(field.value()).ok_or_else(|| { - io::Error::new( - io::ErrorKind::InvalidInput, - "`V` field contained an invalid value", - ) - })?); - } - _ => {} - } - } - - Ok(DbError { - severity: severity - .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "`S` field missing"))?, - parsed_severity: parsed_severity, - code: code - .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "`C` field missing"))?, - message: message - .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "`M` field missing"))?, - detail: detail, - hint: hint, - position: match normal_position { - Some(position) => Some(ErrorPosition::Normal(position)), - None => match internal_position { - Some(position) => Some(ErrorPosition::Internal { - position: position, - query: internal_query.ok_or_else(|| { - io::Error::new( - io::ErrorKind::InvalidInput, - "`q` field missing but `p` field present", - ) - })?, - }), - None => None, - }, - }, - where_: where_, - schema: schema, - table: table, - column: column, - datatype: datatype, - constraint: constraint, - file: file, - line: line, - routine: routine, - _p: (), - }) - } -} - -// manual impl to leave out _p -impl fmt::Debug for DbError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.debug_struct("DbError") - .field("severity", &self.severity) - .field("parsed_severity", &self.parsed_severity) - .field("code", &self.code) - .field("message", &self.message) - .field("detail", &self.detail) - .field("hint", &self.hint) - .field("position", &self.position) - .field("where_", &self.where_) - .field("schema", &self.schema) - .field("table", &self.table) - .field("column", &self.column) - .field("datatype", &self.datatype) - .field("constraint", &self.constraint) - .field("file", &self.file) - .field("line", &self.line) - .field("routine", &self.routine) - .finish() - } -} - -impl fmt::Display for DbError { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "{}: {}", self.severity, self.message) - } -} - -impl error::Error for DbError { - fn description(&self) -> &str { - &self.message - } -} - -/// Represents the position of an error in a query. -#[derive(Clone, PartialEq, Eq, Debug)] -pub enum ErrorPosition { - /// A position in the original query. - Normal(u32), - /// A position in an internally generated query. - Internal { - /// The byte position. - position: u32, - /// A query generated by the Postgres server. - query: String, - }, -} - -#[doc(hidden)] -pub fn connect(e: Box) -> Error { - Error(Box::new(ErrorKind::ConnectParams(e))) -} - -#[doc(hidden)] -pub fn tls(e: Box) -> Error { - Error(Box::new(ErrorKind::Tls(e))) -} - -#[doc(hidden)] -pub fn db(e: DbError) -> Error { - Error(Box::new(ErrorKind::Db(e))) -} - -#[doc(hidden)] -pub fn __db(e: ErrorResponseBody) -> Error { - match DbError::new(&mut e.fields()) { - Ok(e) => Error(Box::new(ErrorKind::Db(e))), - Err(e) => Error(Box::new(ErrorKind::Io(e))), - } -} - -#[doc(hidden)] -pub fn __user(e: T) -> Error -where - T: Into>, -{ - Error(Box::new(ErrorKind::Conversion(e.into()))) -} - -#[doc(hidden)] -pub fn io(e: io::Error) -> Error { - Error(Box::new(ErrorKind::Io(e))) -} - -#[doc(hidden)] -pub fn conversion(e: Box) -> Error { - Error(Box::new(ErrorKind::Conversion(e))) -} - -#[derive(Debug)] -enum ErrorKind { - ConnectParams(Box), - Tls(Box), - Db(DbError), - Io(io::Error), - Conversion(Box), -} - -/// An error communicating with the Postgres server. -#[derive(Debug)] -pub struct Error(Box); - -impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.write_str(error::Error::description(self))?; - match *self.0 { - ErrorKind::ConnectParams(ref err) => write!(fmt, ": {}", err), - ErrorKind::Tls(ref err) => write!(fmt, ": {}", err), - ErrorKind::Db(ref err) => write!(fmt, ": {}", err), - ErrorKind::Io(ref err) => write!(fmt, ": {}", err), - ErrorKind::Conversion(ref err) => write!(fmt, ": {}", err), - } - } -} - -impl error::Error for Error { - fn description(&self) -> &str { - match *self.0 { - ErrorKind::ConnectParams(_) => "invalid connection parameters", - ErrorKind::Tls(_) => "TLS handshake error", - ErrorKind::Db(_) => "database error", - ErrorKind::Io(_) => "IO error", - ErrorKind::Conversion(_) => "type conversion error", - } - } - - fn cause(&self) -> Option<&error::Error> { - match *self.0 { - ErrorKind::ConnectParams(ref err) => Some(&**err), - ErrorKind::Tls(ref err) => Some(&**err), - ErrorKind::Db(ref err) => Some(err), - ErrorKind::Io(ref err) => Some(err), - ErrorKind::Conversion(ref err) => Some(&**err), - } - } -} - -impl Error { - /// Returns the SQLSTATE error code associated with this error if it is a DB - /// error. - pub fn code(&self) -> Option<&SqlState> { - self.as_db().map(|e| &e.code) - } - - /// Returns the inner error if this is a connection parameter error. - pub fn as_connection(&self) -> Option<&(error::Error + 'static + Sync + Send)> { - match *self.0 { - ErrorKind::ConnectParams(ref err) => Some(&**err), - _ => None, - } - } - - /// Returns the `DbError` associated with this error if it is a DB error. - pub fn as_db(&self) -> Option<&DbError> { - match *self.0 { - ErrorKind::Db(ref err) => Some(err), - _ => None, - } - } - - /// Returns the inner error if this is a conversion error. - pub fn as_conversion(&self) -> Option<&(error::Error + 'static + Sync + Send)> { - match *self.0 { - ErrorKind::Conversion(ref err) => Some(&**err), - _ => None, - } - } - - /// Returns the inner `io::Error` associated with this error if it is an IO - /// error. - pub fn as_io(&self) -> Option<&io::Error> { - match *self.0 { - ErrorKind::Io(ref err) => Some(err), - _ => None, - } - } -} - -impl From for Error { - fn from(err: io::Error) -> Error { - Error(Box::new(ErrorKind::Io(err))) - } -} - -impl From for io::Error { - fn from(err: Error) -> io::Error { - match *err.0 { - ErrorKind::Io(e) => e, - _ => io::Error::new(io::ErrorKind::Other, err), - } - } -} diff --git a/postgres-shared/src/error/sqlstate.rs b/postgres-shared/src/error/sqlstate.rs deleted file mode 100644 index 7dddfc7e..00000000 --- a/postgres-shared/src/error/sqlstate.rs +++ /dev/null @@ -1,1076 +0,0 @@ -// Autogenerated file - DO NOT EDIT -use phf; -use std::borrow::Cow; - -/// A SQLSTATE error code -#[derive(PartialEq, Eq, Clone, Debug)] -pub struct SqlState(Cow<'static, str>); - -impl SqlState { - /// Creates a `SqlState` from its error code. - pub fn from_code(s: &str) -> SqlState { - match SQLSTATE_MAP.get(s) { - Some(state) => state.clone(), - None => SqlState(Cow::Owned(s.to_string())), - } - } - - /// Returns the error code corresponding to the `SqlState`. - pub fn code(&self) -> &str { - &self.0 - } - - /// 00000 - pub const SUCCESSFUL_COMPLETION: SqlState = SqlState(Cow::Borrowed("00000")); - - /// 01000 - pub const WARNING: SqlState = SqlState(Cow::Borrowed("01000")); - - /// 0100C - pub const WARNING_DYNAMIC_RESULT_SETS_RETURNED: SqlState = SqlState(Cow::Borrowed("0100C")); - - /// 01008 - pub const WARNING_IMPLICIT_ZERO_BIT_PADDING: SqlState = SqlState(Cow::Borrowed("01008")); - - /// 01003 - pub const WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION: SqlState = - SqlState(Cow::Borrowed("01003")); - - /// 01007 - pub const WARNING_PRIVILEGE_NOT_GRANTED: SqlState = SqlState(Cow::Borrowed("01007")); - - /// 01006 - pub const WARNING_PRIVILEGE_NOT_REVOKED: SqlState = SqlState(Cow::Borrowed("01006")); - - /// 01004 - pub const WARNING_STRING_DATA_RIGHT_TRUNCATION: SqlState = SqlState(Cow::Borrowed("01004")); - - /// 01P01 - pub const WARNING_DEPRECATED_FEATURE: SqlState = SqlState(Cow::Borrowed("01P01")); - - /// 02000 - pub const NO_DATA: SqlState = SqlState(Cow::Borrowed("02000")); - - /// 02001 - pub const NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED: SqlState = - SqlState(Cow::Borrowed("02001")); - - /// 03000 - pub const SQL_STATEMENT_NOT_YET_COMPLETE: SqlState = SqlState(Cow::Borrowed("03000")); - - /// 08000 - pub const CONNECTION_EXCEPTION: SqlState = SqlState(Cow::Borrowed("08000")); - - /// 08003 - pub const CONNECTION_DOES_NOT_EXIST: SqlState = SqlState(Cow::Borrowed("08003")); - - /// 08006 - pub const CONNECTION_FAILURE: SqlState = SqlState(Cow::Borrowed("08006")); - - /// 08001 - pub const SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION: SqlState = - SqlState(Cow::Borrowed("08001")); - - /// 08004 - pub const SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION: SqlState = - SqlState(Cow::Borrowed("08004")); - - /// 08007 - pub const TRANSACTION_RESOLUTION_UNKNOWN: SqlState = SqlState(Cow::Borrowed("08007")); - - /// 08P01 - pub const PROTOCOL_VIOLATION: SqlState = SqlState(Cow::Borrowed("08P01")); - - /// 09000 - pub const TRIGGERED_ACTION_EXCEPTION: SqlState = SqlState(Cow::Borrowed("09000")); - - /// 0A000 - pub const FEATURE_NOT_SUPPORTED: SqlState = SqlState(Cow::Borrowed("0A000")); - - /// 0B000 - pub const INVALID_TRANSACTION_INITIATION: SqlState = SqlState(Cow::Borrowed("0B000")); - - /// 0F000 - pub const LOCATOR_EXCEPTION: SqlState = SqlState(Cow::Borrowed("0F000")); - - /// 0F001 - pub const L_E_INVALID_SPECIFICATION: SqlState = SqlState(Cow::Borrowed("0F001")); - - /// 0L000 - pub const INVALID_GRANTOR: SqlState = SqlState(Cow::Borrowed("0L000")); - - /// 0LP01 - pub const INVALID_GRANT_OPERATION: SqlState = SqlState(Cow::Borrowed("0LP01")); - - /// 0P000 - pub const INVALID_ROLE_SPECIFICATION: SqlState = SqlState(Cow::Borrowed("0P000")); - - /// 0Z000 - pub const DIAGNOSTICS_EXCEPTION: SqlState = SqlState(Cow::Borrowed("0Z000")); - - /// 0Z002 - pub const STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER: SqlState = - SqlState(Cow::Borrowed("0Z002")); - - /// 20000 - pub const CASE_NOT_FOUND: SqlState = SqlState(Cow::Borrowed("20000")); - - /// 21000 - pub const CARDINALITY_VIOLATION: SqlState = SqlState(Cow::Borrowed("21000")); - - /// 22000 - pub const DATA_EXCEPTION: SqlState = SqlState(Cow::Borrowed("22000")); - - /// 2202E - pub const ARRAY_ELEMENT_ERROR: SqlState = SqlState(Cow::Borrowed("2202E")); - - /// 2202E - pub const ARRAY_SUBSCRIPT_ERROR: SqlState = SqlState(Cow::Borrowed("2202E")); - - /// 22021 - pub const CHARACTER_NOT_IN_REPERTOIRE: SqlState = SqlState(Cow::Borrowed("22021")); - - /// 22008 - pub const DATETIME_FIELD_OVERFLOW: SqlState = SqlState(Cow::Borrowed("22008")); - - /// 22008 - pub const DATETIME_VALUE_OUT_OF_RANGE: SqlState = SqlState(Cow::Borrowed("22008")); - - /// 22012 - pub const DIVISION_BY_ZERO: SqlState = SqlState(Cow::Borrowed("22012")); - - /// 22005 - pub const ERROR_IN_ASSIGNMENT: SqlState = SqlState(Cow::Borrowed("22005")); - - /// 2200B - pub const ESCAPE_CHARACTER_CONFLICT: SqlState = SqlState(Cow::Borrowed("2200B")); - - /// 22022 - pub const INDICATOR_OVERFLOW: SqlState = SqlState(Cow::Borrowed("22022")); - - /// 22015 - pub const INTERVAL_FIELD_OVERFLOW: SqlState = SqlState(Cow::Borrowed("22015")); - - /// 2201E - pub const INVALID_ARGUMENT_FOR_LOG: SqlState = SqlState(Cow::Borrowed("2201E")); - - /// 22014 - pub const INVALID_ARGUMENT_FOR_NTILE: SqlState = SqlState(Cow::Borrowed("22014")); - - /// 22016 - pub const INVALID_ARGUMENT_FOR_NTH_VALUE: SqlState = SqlState(Cow::Borrowed("22016")); - - /// 2201F - pub const INVALID_ARGUMENT_FOR_POWER_FUNCTION: SqlState = SqlState(Cow::Borrowed("2201F")); - - /// 2201G - pub const INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION: SqlState = - SqlState(Cow::Borrowed("2201G")); - - /// 22018 - pub const INVALID_CHARACTER_VALUE_FOR_CAST: SqlState = SqlState(Cow::Borrowed("22018")); - - /// 22007 - pub const INVALID_DATETIME_FORMAT: SqlState = SqlState(Cow::Borrowed("22007")); - - /// 22019 - pub const INVALID_ESCAPE_CHARACTER: SqlState = SqlState(Cow::Borrowed("22019")); - - /// 2200D - pub const INVALID_ESCAPE_OCTET: SqlState = SqlState(Cow::Borrowed("2200D")); - - /// 22025 - pub const INVALID_ESCAPE_SEQUENCE: SqlState = SqlState(Cow::Borrowed("22025")); - - /// 22P06 - pub const NONSTANDARD_USE_OF_ESCAPE_CHARACTER: SqlState = SqlState(Cow::Borrowed("22P06")); - - /// 22010 - pub const INVALID_INDICATOR_PARAMETER_VALUE: SqlState = SqlState(Cow::Borrowed("22010")); - - /// 22023 - pub const INVALID_PARAMETER_VALUE: SqlState = SqlState(Cow::Borrowed("22023")); - - /// 2201B - pub const INVALID_REGULAR_EXPRESSION: SqlState = SqlState(Cow::Borrowed("2201B")); - - /// 2201W - pub const INVALID_ROW_COUNT_IN_LIMIT_CLAUSE: SqlState = SqlState(Cow::Borrowed("2201W")); - - /// 2201X - pub const INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE: SqlState = - SqlState(Cow::Borrowed("2201X")); - - /// 2202H - pub const INVALID_TABLESAMPLE_ARGUMENT: SqlState = SqlState(Cow::Borrowed("2202H")); - - /// 2202G - pub const INVALID_TABLESAMPLE_REPEAT: SqlState = SqlState(Cow::Borrowed("2202G")); - - /// 22009 - pub const INVALID_TIME_ZONE_DISPLACEMENT_VALUE: SqlState = SqlState(Cow::Borrowed("22009")); - - /// 2200C - pub const INVALID_USE_OF_ESCAPE_CHARACTER: SqlState = SqlState(Cow::Borrowed("2200C")); - - /// 2200G - pub const MOST_SPECIFIC_TYPE_MISMATCH: SqlState = SqlState(Cow::Borrowed("2200G")); - - /// 22004 - pub const NULL_VALUE_NOT_ALLOWED: SqlState = SqlState(Cow::Borrowed("22004")); - - /// 22002 - pub const NULL_VALUE_NO_INDICATOR_PARAMETER: SqlState = SqlState(Cow::Borrowed("22002")); - - /// 22003 - pub const NUMERIC_VALUE_OUT_OF_RANGE: SqlState = SqlState(Cow::Borrowed("22003")); - - /// 2200H - pub const SEQUENCE_GENERATOR_LIMIT_EXCEEDED: SqlState = SqlState(Cow::Borrowed("2200H")); - - /// 22026 - pub const STRING_DATA_LENGTH_MISMATCH: SqlState = SqlState(Cow::Borrowed("22026")); - - /// 22001 - pub const STRING_DATA_RIGHT_TRUNCATION: SqlState = SqlState(Cow::Borrowed("22001")); - - /// 22011 - pub const SUBSTRING_ERROR: SqlState = SqlState(Cow::Borrowed("22011")); - - /// 22027 - pub const TRIM_ERROR: SqlState = SqlState(Cow::Borrowed("22027")); - - /// 22024 - pub const UNTERMINATED_C_STRING: SqlState = SqlState(Cow::Borrowed("22024")); - - /// 2200F - pub const ZERO_LENGTH_CHARACTER_STRING: SqlState = SqlState(Cow::Borrowed("2200F")); - - /// 22P01 - pub const FLOATING_POINT_EXCEPTION: SqlState = SqlState(Cow::Borrowed("22P01")); - - /// 22P02 - pub const INVALID_TEXT_REPRESENTATION: SqlState = SqlState(Cow::Borrowed("22P02")); - - /// 22P03 - pub const INVALID_BINARY_REPRESENTATION: SqlState = SqlState(Cow::Borrowed("22P03")); - - /// 22P04 - pub const BAD_COPY_FILE_FORMAT: SqlState = SqlState(Cow::Borrowed("22P04")); - - /// 22P05 - pub const UNTRANSLATABLE_CHARACTER: SqlState = SqlState(Cow::Borrowed("22P05")); - - /// 2200L - pub const NOT_AN_XML_DOCUMENT: SqlState = SqlState(Cow::Borrowed("2200L")); - - /// 2200M - pub const INVALID_XML_DOCUMENT: SqlState = SqlState(Cow::Borrowed("2200M")); - - /// 2200N - pub const INVALID_XML_CONTENT: SqlState = SqlState(Cow::Borrowed("2200N")); - - /// 2200S - pub const INVALID_XML_COMMENT: SqlState = SqlState(Cow::Borrowed("2200S")); - - /// 2200T - pub const INVALID_XML_PROCESSING_INSTRUCTION: SqlState = SqlState(Cow::Borrowed("2200T")); - - /// 23000 - pub const INTEGRITY_CONSTRAINT_VIOLATION: SqlState = SqlState(Cow::Borrowed("23000")); - - /// 23001 - pub const RESTRICT_VIOLATION: SqlState = SqlState(Cow::Borrowed("23001")); - - /// 23502 - pub const NOT_NULL_VIOLATION: SqlState = SqlState(Cow::Borrowed("23502")); - - /// 23503 - pub const FOREIGN_KEY_VIOLATION: SqlState = SqlState(Cow::Borrowed("23503")); - - /// 23505 - pub const UNIQUE_VIOLATION: SqlState = SqlState(Cow::Borrowed("23505")); - - /// 23514 - pub const CHECK_VIOLATION: SqlState = SqlState(Cow::Borrowed("23514")); - - /// 23P01 - pub const EXCLUSION_VIOLATION: SqlState = SqlState(Cow::Borrowed("23P01")); - - /// 24000 - pub const INVALID_CURSOR_STATE: SqlState = SqlState(Cow::Borrowed("24000")); - - /// 25000 - pub const INVALID_TRANSACTION_STATE: SqlState = SqlState(Cow::Borrowed("25000")); - - /// 25001 - pub const ACTIVE_SQL_TRANSACTION: SqlState = SqlState(Cow::Borrowed("25001")); - - /// 25002 - pub const BRANCH_TRANSACTION_ALREADY_ACTIVE: SqlState = SqlState(Cow::Borrowed("25002")); - - /// 25008 - pub const HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL: SqlState = - SqlState(Cow::Borrowed("25008")); - - /// 25003 - pub const INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION: SqlState = - SqlState(Cow::Borrowed("25003")); - - /// 25004 - pub const INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION: SqlState = - SqlState(Cow::Borrowed("25004")); - - /// 25005 - pub const NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION: SqlState = - SqlState(Cow::Borrowed("25005")); - - /// 25006 - pub const READ_ONLY_SQL_TRANSACTION: SqlState = SqlState(Cow::Borrowed("25006")); - - /// 25007 - pub const SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED: SqlState = - SqlState(Cow::Borrowed("25007")); - - /// 25P01 - pub const NO_ACTIVE_SQL_TRANSACTION: SqlState = SqlState(Cow::Borrowed("25P01")); - - /// 25P02 - pub const IN_FAILED_SQL_TRANSACTION: SqlState = SqlState(Cow::Borrowed("25P02")); - - /// 25P03 - pub const IDLE_IN_TRANSACTION_SESSION_TIMEOUT: SqlState = SqlState(Cow::Borrowed("25P03")); - - /// 26000 - pub const INVALID_SQL_STATEMENT_NAME: SqlState = SqlState(Cow::Borrowed("26000")); - - /// 26000 - pub const UNDEFINED_PSTATEMENT: SqlState = SqlState(Cow::Borrowed("26000")); - - /// 27000 - pub const TRIGGERED_DATA_CHANGE_VIOLATION: SqlState = SqlState(Cow::Borrowed("27000")); - - /// 28000 - pub const INVALID_AUTHORIZATION_SPECIFICATION: SqlState = SqlState(Cow::Borrowed("28000")); - - /// 28P01 - pub const INVALID_PASSWORD: SqlState = SqlState(Cow::Borrowed("28P01")); - - /// 2B000 - pub const DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST: SqlState = - SqlState(Cow::Borrowed("2B000")); - - /// 2BP01 - pub const DEPENDENT_OBJECTS_STILL_EXIST: SqlState = SqlState(Cow::Borrowed("2BP01")); - - /// 2D000 - pub const INVALID_TRANSACTION_TERMINATION: SqlState = SqlState(Cow::Borrowed("2D000")); - - /// 2F000 - pub const SQL_ROUTINE_EXCEPTION: SqlState = SqlState(Cow::Borrowed("2F000")); - - /// 2F005 - pub const S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT: SqlState = - SqlState(Cow::Borrowed("2F005")); - - /// 2F002 - pub const S_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED: SqlState = SqlState(Cow::Borrowed("2F002")); - - /// 2F003 - pub const S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED: SqlState = SqlState(Cow::Borrowed("2F003")); - - /// 2F004 - pub const S_R_E_READING_SQL_DATA_NOT_PERMITTED: SqlState = SqlState(Cow::Borrowed("2F004")); - - /// 34000 - pub const INVALID_CURSOR_NAME: SqlState = SqlState(Cow::Borrowed("34000")); - - /// 34000 - pub const UNDEFINED_CURSOR: SqlState = SqlState(Cow::Borrowed("34000")); - - /// 38000 - pub const EXTERNAL_ROUTINE_EXCEPTION: SqlState = SqlState(Cow::Borrowed("38000")); - - /// 38001 - pub const E_R_E_CONTAINING_SQL_NOT_PERMITTED: SqlState = SqlState(Cow::Borrowed("38001")); - - /// 38002 - pub const E_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED: SqlState = SqlState(Cow::Borrowed("38002")); - - /// 38003 - pub const E_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED: SqlState = SqlState(Cow::Borrowed("38003")); - - /// 38004 - pub const E_R_E_READING_SQL_DATA_NOT_PERMITTED: SqlState = SqlState(Cow::Borrowed("38004")); - - /// 39000 - pub const EXTERNAL_ROUTINE_INVOCATION_EXCEPTION: SqlState = SqlState(Cow::Borrowed("39000")); - - /// 39001 - pub const E_R_I_E_INVALID_SQLSTATE_RETURNED: SqlState = SqlState(Cow::Borrowed("39001")); - - /// 39004 - pub const E_R_I_E_NULL_VALUE_NOT_ALLOWED: SqlState = SqlState(Cow::Borrowed("39004")); - - /// 39P01 - pub const E_R_I_E_TRIGGER_PROTOCOL_VIOLATED: SqlState = SqlState(Cow::Borrowed("39P01")); - - /// 39P02 - pub const E_R_I_E_SRF_PROTOCOL_VIOLATED: SqlState = SqlState(Cow::Borrowed("39P02")); - - /// 39P03 - pub const E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED: SqlState = SqlState(Cow::Borrowed("39P03")); - - /// 3B000 - pub const SAVEPOINT_EXCEPTION: SqlState = SqlState(Cow::Borrowed("3B000")); - - /// 3B001 - pub const S_E_INVALID_SPECIFICATION: SqlState = SqlState(Cow::Borrowed("3B001")); - - /// 3D000 - pub const INVALID_CATALOG_NAME: SqlState = SqlState(Cow::Borrowed("3D000")); - - /// 3D000 - pub const UNDEFINED_DATABASE: SqlState = SqlState(Cow::Borrowed("3D000")); - - /// 3F000 - pub const INVALID_SCHEMA_NAME: SqlState = SqlState(Cow::Borrowed("3F000")); - - /// 3F000 - pub const UNDEFINED_SCHEMA: SqlState = SqlState(Cow::Borrowed("3F000")); - - /// 40000 - pub const TRANSACTION_ROLLBACK: SqlState = SqlState(Cow::Borrowed("40000")); - - /// 40002 - pub const T_R_INTEGRITY_CONSTRAINT_VIOLATION: SqlState = SqlState(Cow::Borrowed("40002")); - - /// 40001 - pub const T_R_SERIALIZATION_FAILURE: SqlState = SqlState(Cow::Borrowed("40001")); - - /// 40003 - pub const T_R_STATEMENT_COMPLETION_UNKNOWN: SqlState = SqlState(Cow::Borrowed("40003")); - - /// 40P01 - pub const T_R_DEADLOCK_DETECTED: SqlState = SqlState(Cow::Borrowed("40P01")); - - /// 42000 - pub const SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION: SqlState = SqlState(Cow::Borrowed("42000")); - - /// 42601 - pub const SYNTAX_ERROR: SqlState = SqlState(Cow::Borrowed("42601")); - - /// 42501 - pub const INSUFFICIENT_PRIVILEGE: SqlState = SqlState(Cow::Borrowed("42501")); - - /// 42846 - pub const CANNOT_COERCE: SqlState = SqlState(Cow::Borrowed("42846")); - - /// 42803 - pub const GROUPING_ERROR: SqlState = SqlState(Cow::Borrowed("42803")); - - /// 42P20 - pub const WINDOWING_ERROR: SqlState = SqlState(Cow::Borrowed("42P20")); - - /// 42P19 - pub const INVALID_RECURSION: SqlState = SqlState(Cow::Borrowed("42P19")); - - /// 42830 - pub const INVALID_FOREIGN_KEY: SqlState = SqlState(Cow::Borrowed("42830")); - - /// 42602 - pub const INVALID_NAME: SqlState = SqlState(Cow::Borrowed("42602")); - - /// 42622 - pub const NAME_TOO_LONG: SqlState = SqlState(Cow::Borrowed("42622")); - - /// 42939 - pub const RESERVED_NAME: SqlState = SqlState(Cow::Borrowed("42939")); - - /// 42804 - pub const DATATYPE_MISMATCH: SqlState = SqlState(Cow::Borrowed("42804")); - - /// 42P18 - pub const INDETERMINATE_DATATYPE: SqlState = SqlState(Cow::Borrowed("42P18")); - - /// 42P21 - pub const COLLATION_MISMATCH: SqlState = SqlState(Cow::Borrowed("42P21")); - - /// 42P22 - pub const INDETERMINATE_COLLATION: SqlState = SqlState(Cow::Borrowed("42P22")); - - /// 42809 - pub const WRONG_OBJECT_TYPE: SqlState = SqlState(Cow::Borrowed("42809")); - - /// 428C9 - pub const GENERATED_ALWAYS: SqlState = SqlState(Cow::Borrowed("428C9")); - - /// 42703 - pub const UNDEFINED_COLUMN: SqlState = SqlState(Cow::Borrowed("42703")); - - /// 42883 - pub const UNDEFINED_FUNCTION: SqlState = SqlState(Cow::Borrowed("42883")); - - /// 42P01 - pub const UNDEFINED_TABLE: SqlState = SqlState(Cow::Borrowed("42P01")); - - /// 42P02 - pub const UNDEFINED_PARAMETER: SqlState = SqlState(Cow::Borrowed("42P02")); - - /// 42704 - pub const UNDEFINED_OBJECT: SqlState = SqlState(Cow::Borrowed("42704")); - - /// 42701 - pub const DUPLICATE_COLUMN: SqlState = SqlState(Cow::Borrowed("42701")); - - /// 42P03 - pub const DUPLICATE_CURSOR: SqlState = SqlState(Cow::Borrowed("42P03")); - - /// 42P04 - pub const DUPLICATE_DATABASE: SqlState = SqlState(Cow::Borrowed("42P04")); - - /// 42723 - pub const DUPLICATE_FUNCTION: SqlState = SqlState(Cow::Borrowed("42723")); - - /// 42P05 - pub const DUPLICATE_PSTATEMENT: SqlState = SqlState(Cow::Borrowed("42P05")); - - /// 42P06 - pub const DUPLICATE_SCHEMA: SqlState = SqlState(Cow::Borrowed("42P06")); - - /// 42P07 - pub const DUPLICATE_TABLE: SqlState = SqlState(Cow::Borrowed("42P07")); - - /// 42712 - pub const DUPLICATE_ALIAS: SqlState = SqlState(Cow::Borrowed("42712")); - - /// 42710 - pub const DUPLICATE_OBJECT: SqlState = SqlState(Cow::Borrowed("42710")); - - /// 42702 - pub const AMBIGUOUS_COLUMN: SqlState = SqlState(Cow::Borrowed("42702")); - - /// 42725 - pub const AMBIGUOUS_FUNCTION: SqlState = SqlState(Cow::Borrowed("42725")); - - /// 42P08 - pub const AMBIGUOUS_PARAMETER: SqlState = SqlState(Cow::Borrowed("42P08")); - - /// 42P09 - pub const AMBIGUOUS_ALIAS: SqlState = SqlState(Cow::Borrowed("42P09")); - - /// 42P10 - pub const INVALID_COLUMN_REFERENCE: SqlState = SqlState(Cow::Borrowed("42P10")); - - /// 42611 - pub const INVALID_COLUMN_DEFINITION: SqlState = SqlState(Cow::Borrowed("42611")); - - /// 42P11 - pub const INVALID_CURSOR_DEFINITION: SqlState = SqlState(Cow::Borrowed("42P11")); - - /// 42P12 - pub const INVALID_DATABASE_DEFINITION: SqlState = SqlState(Cow::Borrowed("42P12")); - - /// 42P13 - pub const INVALID_FUNCTION_DEFINITION: SqlState = SqlState(Cow::Borrowed("42P13")); - - /// 42P14 - pub const INVALID_PSTATEMENT_DEFINITION: SqlState = SqlState(Cow::Borrowed("42P14")); - - /// 42P15 - pub const INVALID_SCHEMA_DEFINITION: SqlState = SqlState(Cow::Borrowed("42P15")); - - /// 42P16 - pub const INVALID_TABLE_DEFINITION: SqlState = SqlState(Cow::Borrowed("42P16")); - - /// 42P17 - pub const INVALID_OBJECT_DEFINITION: SqlState = SqlState(Cow::Borrowed("42P17")); - - /// 44000 - pub const WITH_CHECK_OPTION_VIOLATION: SqlState = SqlState(Cow::Borrowed("44000")); - - /// 53000 - pub const INSUFFICIENT_RESOURCES: SqlState = SqlState(Cow::Borrowed("53000")); - - /// 53100 - pub const DISK_FULL: SqlState = SqlState(Cow::Borrowed("53100")); - - /// 53200 - pub const OUT_OF_MEMORY: SqlState = SqlState(Cow::Borrowed("53200")); - - /// 53300 - pub const TOO_MANY_CONNECTIONS: SqlState = SqlState(Cow::Borrowed("53300")); - - /// 53400 - pub const CONFIGURATION_LIMIT_EXCEEDED: SqlState = SqlState(Cow::Borrowed("53400")); - - /// 54000 - pub const PROGRAM_LIMIT_EXCEEDED: SqlState = SqlState(Cow::Borrowed("54000")); - - /// 54001 - pub const STATEMENT_TOO_COMPLEX: SqlState = SqlState(Cow::Borrowed("54001")); - - /// 54011 - pub const TOO_MANY_COLUMNS: SqlState = SqlState(Cow::Borrowed("54011")); - - /// 54023 - pub const TOO_MANY_ARGUMENTS: SqlState = SqlState(Cow::Borrowed("54023")); - - /// 55000 - pub const OBJECT_NOT_IN_PREREQUISITE_STATE: SqlState = SqlState(Cow::Borrowed("55000")); - - /// 55006 - pub const OBJECT_IN_USE: SqlState = SqlState(Cow::Borrowed("55006")); - - /// 55P02 - pub const CANT_CHANGE_RUNTIME_PARAM: SqlState = SqlState(Cow::Borrowed("55P02")); - - /// 55P03 - pub const LOCK_NOT_AVAILABLE: SqlState = SqlState(Cow::Borrowed("55P03")); - - /// 55P04 - pub const UNSAFE_NEW_ENUM_VALUE_USAGE: SqlState = SqlState(Cow::Borrowed("55P04")); - - /// 57000 - pub const OPERATOR_INTERVENTION: SqlState = SqlState(Cow::Borrowed("57000")); - - /// 57014 - pub const QUERY_CANCELED: SqlState = SqlState(Cow::Borrowed("57014")); - - /// 57P01 - pub const ADMIN_SHUTDOWN: SqlState = SqlState(Cow::Borrowed("57P01")); - - /// 57P02 - pub const CRASH_SHUTDOWN: SqlState = SqlState(Cow::Borrowed("57P02")); - - /// 57P03 - pub const CANNOT_CONNECT_NOW: SqlState = SqlState(Cow::Borrowed("57P03")); - - /// 57P04 - pub const DATABASE_DROPPED: SqlState = SqlState(Cow::Borrowed("57P04")); - - /// 58000 - pub const SYSTEM_ERROR: SqlState = SqlState(Cow::Borrowed("58000")); - - /// 58030 - pub const IO_ERROR: SqlState = SqlState(Cow::Borrowed("58030")); - - /// 58P01 - pub const UNDEFINED_FILE: SqlState = SqlState(Cow::Borrowed("58P01")); - - /// 58P02 - pub const DUPLICATE_FILE: SqlState = SqlState(Cow::Borrowed("58P02")); - - /// 72000 - pub const SNAPSHOT_TOO_OLD: SqlState = SqlState(Cow::Borrowed("72000")); - - /// F0000 - pub const CONFIG_FILE_ERROR: SqlState = SqlState(Cow::Borrowed("F0000")); - - /// F0001 - pub const LOCK_FILE_EXISTS: SqlState = SqlState(Cow::Borrowed("F0001")); - - /// HV000 - pub const FDW_ERROR: SqlState = SqlState(Cow::Borrowed("HV000")); - - /// HV005 - pub const FDW_COLUMN_NAME_NOT_FOUND: SqlState = SqlState(Cow::Borrowed("HV005")); - - /// HV002 - pub const FDW_DYNAMIC_PARAMETER_VALUE_NEEDED: SqlState = SqlState(Cow::Borrowed("HV002")); - - /// HV010 - pub const FDW_FUNCTION_SEQUENCE_ERROR: SqlState = SqlState(Cow::Borrowed("HV010")); - - /// HV021 - pub const FDW_INCONSISTENT_DESCRIPTOR_INFORMATION: SqlState = SqlState(Cow::Borrowed("HV021")); - - /// HV024 - pub const FDW_INVALID_ATTRIBUTE_VALUE: SqlState = SqlState(Cow::Borrowed("HV024")); - - /// HV007 - pub const FDW_INVALID_COLUMN_NAME: SqlState = SqlState(Cow::Borrowed("HV007")); - - /// HV008 - pub const FDW_INVALID_COLUMN_NUMBER: SqlState = SqlState(Cow::Borrowed("HV008")); - - /// HV004 - pub const FDW_INVALID_DATA_TYPE: SqlState = SqlState(Cow::Borrowed("HV004")); - - /// HV006 - pub const FDW_INVALID_DATA_TYPE_DESCRIPTORS: SqlState = SqlState(Cow::Borrowed("HV006")); - - /// HV091 - pub const FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER: SqlState = SqlState(Cow::Borrowed("HV091")); - - /// HV00B - pub const FDW_INVALID_HANDLE: SqlState = SqlState(Cow::Borrowed("HV00B")); - - /// HV00C - pub const FDW_INVALID_OPTION_INDEX: SqlState = SqlState(Cow::Borrowed("HV00C")); - - /// HV00D - pub const FDW_INVALID_OPTION_NAME: SqlState = SqlState(Cow::Borrowed("HV00D")); - - /// HV090 - pub const FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH: SqlState = - SqlState(Cow::Borrowed("HV090")); - - /// HV00A - pub const FDW_INVALID_STRING_FORMAT: SqlState = SqlState(Cow::Borrowed("HV00A")); - - /// HV009 - pub const FDW_INVALID_USE_OF_NULL_POINTER: SqlState = SqlState(Cow::Borrowed("HV009")); - - /// HV014 - pub const FDW_TOO_MANY_HANDLES: SqlState = SqlState(Cow::Borrowed("HV014")); - - /// HV001 - pub const FDW_OUT_OF_MEMORY: SqlState = SqlState(Cow::Borrowed("HV001")); - - /// HV00P - pub const FDW_NO_SCHEMAS: SqlState = SqlState(Cow::Borrowed("HV00P")); - - /// HV00J - pub const FDW_OPTION_NAME_NOT_FOUND: SqlState = SqlState(Cow::Borrowed("HV00J")); - - /// HV00K - pub const FDW_REPLY_HANDLE: SqlState = SqlState(Cow::Borrowed("HV00K")); - - /// HV00Q - pub const FDW_SCHEMA_NOT_FOUND: SqlState = SqlState(Cow::Borrowed("HV00Q")); - - /// HV00R - pub const FDW_TABLE_NOT_FOUND: SqlState = SqlState(Cow::Borrowed("HV00R")); - - /// HV00L - pub const FDW_UNABLE_TO_CREATE_EXECUTION: SqlState = SqlState(Cow::Borrowed("HV00L")); - - /// HV00M - pub const FDW_UNABLE_TO_CREATE_REPLY: SqlState = SqlState(Cow::Borrowed("HV00M")); - - /// HV00N - pub const FDW_UNABLE_TO_ESTABLISH_CONNECTION: SqlState = SqlState(Cow::Borrowed("HV00N")); - - /// P0000 - pub const PLPGSQL_ERROR: SqlState = SqlState(Cow::Borrowed("P0000")); - - /// P0001 - pub const RAISE_EXCEPTION: SqlState = SqlState(Cow::Borrowed("P0001")); - - /// P0002 - pub const NO_DATA_FOUND: SqlState = SqlState(Cow::Borrowed("P0002")); - - /// P0003 - pub const TOO_MANY_ROWS: SqlState = SqlState(Cow::Borrowed("P0003")); - - /// P0004 - pub const ASSERT_FAILURE: SqlState = SqlState(Cow::Borrowed("P0004")); - - /// XX000 - pub const INTERNAL_ERROR: SqlState = SqlState(Cow::Borrowed("XX000")); - - /// XX001 - pub const DATA_CORRUPTED: SqlState = SqlState(Cow::Borrowed("XX001")); - - /// XX002 - pub const INDEX_CORRUPTED: SqlState = SqlState(Cow::Borrowed("XX002")); -} -#[cfg_attr(rustfmt, rustfmt_skip)] -static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = ::phf::Map { - key: 1897749892740154578, - disps: ::phf::Slice::Static(&[ - (1, 99), - (0, 0), - (1, 5), - (0, 3), - (0, 110), - (0, 54), - (0, 3), - (0, 13), - (0, 0), - (0, 24), - (0, 214), - (0, 52), - (1, 34), - (0, 33), - (0, 44), - (0, 130), - (0, 16), - (0, 187), - (0, 3), - (13, 168), - (0, 4), - (0, 19), - (0, 13), - (0, 87), - (0, 0), - (0, 108), - (0, 123), - (7, 181), - (0, 109), - (0, 32), - (0, 0), - (1, 69), - (1, 81), - (1, 219), - (0, 157), - (2, 41), - (8, 141), - (0, 5), - (0, 0), - (1, 6), - (0, 3), - (1, 146), - (1, 227), - (9, 94), - (10, 158), - (29, 65), - (3, 2), - (0, 33), - (1, 94), - ]), - entries: ::phf::Slice::Static(&[ - ("23001", SqlState::RESTRICT_VIOLATION), - ("42830", SqlState::INVALID_FOREIGN_KEY), - ("P0000", SqlState::PLPGSQL_ERROR), - ("58000", SqlState::SYSTEM_ERROR), - ("57P01", SqlState::ADMIN_SHUTDOWN), - ("22P04", SqlState::BAD_COPY_FILE_FORMAT), - ("42P05", SqlState::DUPLICATE_PSTATEMENT), - ("28000", SqlState::INVALID_AUTHORIZATION_SPECIFICATION), - ("2202E", SqlState::ARRAY_ELEMENT_ERROR), - ("2F005", SqlState::S_R_E_FUNCTION_EXECUTED_NO_RETURN_STATEMENT), - ("53400", SqlState::CONFIGURATION_LIMIT_EXCEEDED), - ("20000", SqlState::CASE_NOT_FOUND), - ("25004", SqlState::INAPPROPRIATE_ISOLATION_LEVEL_FOR_BRANCH_TRANSACTION), - ("09000", SqlState::TRIGGERED_ACTION_EXCEPTION), - ("42P10", SqlState::INVALID_COLUMN_REFERENCE), - ("39P03", SqlState::E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED), - ("08000", SqlState::CONNECTION_EXCEPTION), - ("08006", SqlState::CONNECTION_FAILURE), - ("2201W", SqlState::INVALID_ROW_COUNT_IN_LIMIT_CLAUSE), - ("03000", SqlState::SQL_STATEMENT_NOT_YET_COMPLETE), - ("22014", SqlState::INVALID_ARGUMENT_FOR_NTILE), - ("42611", SqlState::INVALID_COLUMN_DEFINITION), - ("42P11", SqlState::INVALID_CURSOR_DEFINITION), - ("2200N", SqlState::INVALID_XML_CONTENT), - ("57014", SqlState::QUERY_CANCELED), - ("01003", SqlState::WARNING_NULL_VALUE_ELIMINATED_IN_SET_FUNCTION), - ("01000", SqlState::WARNING), - ("55P04", SqlState::UNSAFE_NEW_ENUM_VALUE_USAGE), - ("25003", SqlState::INAPPROPRIATE_ACCESS_MODE_FOR_BRANCH_TRANSACTION), - ("2200L", SqlState::NOT_AN_XML_DOCUMENT), - ("42846", SqlState::CANNOT_COERCE), - ("55P03", SqlState::LOCK_NOT_AVAILABLE), - ("08007", SqlState::TRANSACTION_RESOLUTION_UNKNOWN), - ("XX000", SqlState::INTERNAL_ERROR), - ("22005", SqlState::ERROR_IN_ASSIGNMENT), - ("22P03", SqlState::INVALID_BINARY_REPRESENTATION), - ("2201X", SqlState::INVALID_ROW_COUNT_IN_RESULT_OFFSET_CLAUSE), - ("54011", SqlState::TOO_MANY_COLUMNS), - ("HV008", SqlState::FDW_INVALID_COLUMN_NUMBER), - ("HV009", SqlState::FDW_INVALID_USE_OF_NULL_POINTER), - ("0LP01", SqlState::INVALID_GRANT_OPERATION), - ("42704", SqlState::UNDEFINED_OBJECT), - ("25005", SqlState::NO_ACTIVE_SQL_TRANSACTION_FOR_BRANCH_TRANSACTION), - ("25P03", SqlState::IDLE_IN_TRANSACTION_SESSION_TIMEOUT), - ("44000", SqlState::WITH_CHECK_OPTION_VIOLATION), - ("22024", SqlState::UNTERMINATED_C_STRING), - ("0L000", SqlState::INVALID_GRANTOR), - ("40000", SqlState::TRANSACTION_ROLLBACK), - ("42P08", SqlState::AMBIGUOUS_PARAMETER), - ("38000", SqlState::EXTERNAL_ROUTINE_EXCEPTION), - ("42939", SqlState::RESERVED_NAME), - ("40001", SqlState::T_R_SERIALIZATION_FAILURE), - ("HV00K", SqlState::FDW_REPLY_HANDLE), - ("2F002", SqlState::S_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED), - ("HV001", SqlState::FDW_OUT_OF_MEMORY), - ("42P19", SqlState::INVALID_RECURSION), - ("HV002", SqlState::FDW_DYNAMIC_PARAMETER_VALUE_NEEDED), - ("0A000", SqlState::FEATURE_NOT_SUPPORTED), - ("58P02", SqlState::DUPLICATE_FILE), - ("25006", SqlState::READ_ONLY_SQL_TRANSACTION), - ("22009", SqlState::INVALID_TIME_ZONE_DISPLACEMENT_VALUE), - ("0F001", SqlState::L_E_INVALID_SPECIFICATION), - ("P0002", SqlState::NO_DATA_FOUND), - ("2F000", SqlState::SQL_ROUTINE_EXCEPTION), - ("01006", SqlState::WARNING_PRIVILEGE_NOT_REVOKED), - ("22025", SqlState::INVALID_ESCAPE_SEQUENCE), - ("22027", SqlState::TRIM_ERROR), - ("54001", SqlState::STATEMENT_TOO_COMPLEX), - ("42602", SqlState::INVALID_NAME), - ("54023", SqlState::TOO_MANY_ARGUMENTS), - ("2200T", SqlState::INVALID_XML_PROCESSING_INSTRUCTION), - ("01007", SqlState::WARNING_PRIVILEGE_NOT_GRANTED), - ("22000", SqlState::DATA_EXCEPTION), - ("28P01", SqlState::INVALID_PASSWORD), - ("23514", SqlState::CHECK_VIOLATION), - ("39P02", SqlState::E_R_I_E_SRF_PROTOCOL_VIOLATED), - ("57P02", SqlState::CRASH_SHUTDOWN), - ("42P03", SqlState::DUPLICATE_CURSOR), - ("22021", SqlState::CHARACTER_NOT_IN_REPERTOIRE), - ("HV00P", SqlState::FDW_NO_SCHEMAS), - ("42701", SqlState::DUPLICATE_COLUMN), - ("42P15", SqlState::INVALID_SCHEMA_DEFINITION), - ("HV00B", SqlState::FDW_INVALID_HANDLE), - ("34000", SqlState::INVALID_CURSOR_NAME), - ("22P06", SqlState::NONSTANDARD_USE_OF_ESCAPE_CHARACTER), - ("P0001", SqlState::RAISE_EXCEPTION), - ("08P01", SqlState::PROTOCOL_VIOLATION), - ("42723", SqlState::DUPLICATE_FUNCTION), - ("08001", SqlState::SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), - ("HV006", SqlState::FDW_INVALID_DATA_TYPE_DESCRIPTORS), - ("23000", SqlState::INTEGRITY_CONSTRAINT_VIOLATION), - ("42712", SqlState::DUPLICATE_ALIAS), - ("2201G", SqlState::INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION), - ("2200F", SqlState::ZERO_LENGTH_CHARACTER_STRING), - ("XX002", SqlState::INDEX_CORRUPTED), - ("53300", SqlState::TOO_MANY_CONNECTIONS), - ("38002", SqlState::E_R_E_MODIFYING_SQL_DATA_NOT_PERMITTED), - ("22015", SqlState::INTERVAL_FIELD_OVERFLOW), - ("22P01", SqlState::FLOATING_POINT_EXCEPTION), - ("22012", SqlState::DIVISION_BY_ZERO), - ("XX001", SqlState::DATA_CORRUPTED), - ("0100C", SqlState::WARNING_DYNAMIC_RESULT_SETS_RETURNED), - ("42P01", SqlState::UNDEFINED_TABLE), - ("25002", SqlState::BRANCH_TRANSACTION_ALREADY_ACTIVE), - ("2D000", SqlState::INVALID_TRANSACTION_TERMINATION), - ("P0004", SqlState::ASSERT_FAILURE), - ("2200C", SqlState::INVALID_USE_OF_ESCAPE_CHARACTER), - ("HV00R", SqlState::FDW_TABLE_NOT_FOUND), - ("22016", SqlState::INVALID_ARGUMENT_FOR_NTH_VALUE), - ("01P01", SqlState::WARNING_DEPRECATED_FEATURE), - ("F0000", SqlState::CONFIG_FILE_ERROR), - ("0Z000", SqlState::DIAGNOSTICS_EXCEPTION), - ("42P02", SqlState::UNDEFINED_PARAMETER), - ("2200S", SqlState::INVALID_XML_COMMENT), - ("2200H", SqlState::SEQUENCE_GENERATOR_LIMIT_EXCEEDED), - ("HV00C", SqlState::FDW_INVALID_OPTION_INDEX), - ("38004", SqlState::E_R_E_READING_SQL_DATA_NOT_PERMITTED), - ("42703", SqlState::UNDEFINED_COLUMN), - ("23503", SqlState::FOREIGN_KEY_VIOLATION), - ("42000", SqlState::SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION), - ("22004", SqlState::NULL_VALUE_NOT_ALLOWED), - ("25008", SqlState::HELD_CURSOR_REQUIRES_SAME_ISOLATION_LEVEL), - ("22018", SqlState::INVALID_CHARACTER_VALUE_FOR_CAST), - ("22023", SqlState::INVALID_PARAMETER_VALUE), - ("22011", SqlState::SUBSTRING_ERROR), - ("40002", SqlState::T_R_INTEGRITY_CONSTRAINT_VIOLATION), - ("42803", SqlState::GROUPING_ERROR), - ("72000", SqlState::SNAPSHOT_TOO_OLD), - ("HV010", SqlState::FDW_FUNCTION_SEQUENCE_ERROR), - ("42809", SqlState::WRONG_OBJECT_TYPE), - ("42P16", SqlState::INVALID_TABLE_DEFINITION), - ("HV00D", SqlState::FDW_INVALID_OPTION_NAME), - ("39000", SqlState::EXTERNAL_ROUTINE_INVOCATION_EXCEPTION), - ("2202G", SqlState::INVALID_TABLESAMPLE_REPEAT), - ("42601", SqlState::SYNTAX_ERROR), - ("42622", SqlState::NAME_TOO_LONG), - ("HV00L", SqlState::FDW_UNABLE_TO_CREATE_EXECUTION), - ("25000", SqlState::INVALID_TRANSACTION_STATE), - ("3B000", SqlState::SAVEPOINT_EXCEPTION), - ("42P21", SqlState::COLLATION_MISMATCH), - ("23505", SqlState::UNIQUE_VIOLATION), - ("22001", SqlState::STRING_DATA_RIGHT_TRUNCATION), - ("02001", SqlState::NO_ADDITIONAL_DYNAMIC_RESULT_SETS_RETURNED), - ("21000", SqlState::CARDINALITY_VIOLATION), - ("58P01", SqlState::UNDEFINED_FILE), - ("HV091", SqlState::FDW_INVALID_DESCRIPTOR_FIELD_IDENTIFIER), - ("25P01", SqlState::NO_ACTIVE_SQL_TRANSACTION), - ("40P01", SqlState::T_R_DEADLOCK_DETECTED), - ("HV021", SqlState::FDW_INCONSISTENT_DESCRIPTOR_INFORMATION), - ("42P09", SqlState::AMBIGUOUS_ALIAS), - ("25007", SqlState::SCHEMA_AND_DATA_STATEMENT_MIXING_NOT_SUPPORTED), - ("23P01", SqlState::EXCLUSION_VIOLATION), - ("HV00J", SqlState::FDW_OPTION_NAME_NOT_FOUND), - ("58030", SqlState::IO_ERROR), - ("HV004", SqlState::FDW_INVALID_DATA_TYPE), - ("42710", SqlState::DUPLICATE_OBJECT), - ("HV090", SqlState::FDW_INVALID_STRING_LENGTH_OR_BUFFER_LENGTH), - ("42P18", SqlState::INDETERMINATE_DATATYPE), - ("HV00M", SqlState::FDW_UNABLE_TO_CREATE_REPLY), - ("42804", SqlState::DATATYPE_MISMATCH), - ("24000", SqlState::INVALID_CURSOR_STATE), - ("HV007", SqlState::FDW_INVALID_COLUMN_NAME), - ("2201E", SqlState::INVALID_ARGUMENT_FOR_LOG), - ("42P22", SqlState::INDETERMINATE_COLLATION), - ("22P05", SqlState::UNTRANSLATABLE_CHARACTER), - ("42P07", SqlState::DUPLICATE_TABLE), - ("2F004", SqlState::S_R_E_READING_SQL_DATA_NOT_PERMITTED), - ("23502", SqlState::NOT_NULL_VIOLATION), - ("57000", SqlState::OPERATOR_INTERVENTION), - ("HV000", SqlState::FDW_ERROR), - ("42883", SqlState::UNDEFINED_FUNCTION), - ("2201B", SqlState::INVALID_REGULAR_EXPRESSION), - ("2200D", SqlState::INVALID_ESCAPE_OCTET), - ("42P06", SqlState::DUPLICATE_SCHEMA), - ("38003", SqlState::E_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED), - ("22026", SqlState::STRING_DATA_LENGTH_MISMATCH), - ("P0003", SqlState::TOO_MANY_ROWS), - ("3D000", SqlState::INVALID_CATALOG_NAME), - ("0B000", SqlState::INVALID_TRANSACTION_INITIATION), - ("55006", SqlState::OBJECT_IN_USE), - ("53200", SqlState::OUT_OF_MEMORY), - ("3F000", SqlState::INVALID_SCHEMA_NAME), - ("53100", SqlState::DISK_FULL), - ("2F003", SqlState::S_R_E_PROHIBITED_SQL_STATEMENT_ATTEMPTED), - ("55P02", SqlState::CANT_CHANGE_RUNTIME_PARAM), - ("01004", SqlState::WARNING_STRING_DATA_RIGHT_TRUNCATION), - ("3B001", SqlState::S_E_INVALID_SPECIFICATION), - ("2200G", SqlState::MOST_SPECIFIC_TYPE_MISMATCH), - ("428C9", SqlState::GENERATED_ALWAYS), - ("HV005", SqlState::FDW_COLUMN_NAME_NOT_FOUND), - ("2201F", SqlState::INVALID_ARGUMENT_FOR_POWER_FUNCTION), - ("22022", SqlState::INDICATOR_OVERFLOW), - ("HV00Q", SqlState::FDW_SCHEMA_NOT_FOUND), - ("0F000", SqlState::LOCATOR_EXCEPTION), - ("22002", SqlState::NULL_VALUE_NO_INDICATOR_PARAMETER), - ("02000", SqlState::NO_DATA), - ("2202H", SqlState::INVALID_TABLESAMPLE_ARGUMENT), - ("27000", SqlState::TRIGGERED_DATA_CHANGE_VIOLATION), - ("2BP01", SqlState::DEPENDENT_OBJECTS_STILL_EXIST), - ("55000", SqlState::OBJECT_NOT_IN_PREREQUISITE_STATE), - ("39001", SqlState::E_R_I_E_INVALID_SQLSTATE_RETURNED), - ("08004", SqlState::SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION), - ("42P13", SqlState::INVALID_FUNCTION_DEFINITION), - ("HV024", SqlState::FDW_INVALID_ATTRIBUTE_VALUE), - ("22019", SqlState::INVALID_ESCAPE_CHARACTER), - ("54000", SqlState::PROGRAM_LIMIT_EXCEEDED), - ("42501", SqlState::INSUFFICIENT_PRIVILEGE), - ("HV00A", SqlState::FDW_INVALID_STRING_FORMAT), - ("42702", SqlState::AMBIGUOUS_COLUMN), - ("53000", SqlState::INSUFFICIENT_RESOURCES), - ("25P02", SqlState::IN_FAILED_SQL_TRANSACTION), - ("22010", SqlState::INVALID_INDICATOR_PARAMETER_VALUE), - ("01008", SqlState::WARNING_IMPLICIT_ZERO_BIT_PADDING), - ("HV014", SqlState::FDW_TOO_MANY_HANDLES), - ("42P20", SqlState::WINDOWING_ERROR), - ("42725", SqlState::AMBIGUOUS_FUNCTION), - ("F0001", SqlState::LOCK_FILE_EXISTS), - ("08003", SqlState::CONNECTION_DOES_NOT_EXIST), - ("2200M", SqlState::INVALID_XML_DOCUMENT), - ("22003", SqlState::NUMERIC_VALUE_OUT_OF_RANGE), - ("39004", SqlState::E_R_I_E_NULL_VALUE_NOT_ALLOWED), - ("2200B", SqlState::ESCAPE_CHARACTER_CONFLICT), - ("0P000", SqlState::INVALID_ROLE_SPECIFICATION), - ("00000", SqlState::SUCCESSFUL_COMPLETION), - ("22P02", SqlState::INVALID_TEXT_REPRESENTATION), - ("25001", SqlState::ACTIVE_SQL_TRANSACTION), - ("HV00N", SqlState::FDW_UNABLE_TO_ESTABLISH_CONNECTION), - ("39P01", SqlState::E_R_I_E_TRIGGER_PROTOCOL_VIOLATED), - ("2B000", SqlState::DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST), - ("22008", SqlState::DATETIME_FIELD_OVERFLOW), - ("42P14", SqlState::INVALID_PSTATEMENT_DEFINITION), - ("57P04", SqlState::DATABASE_DROPPED), - ("26000", SqlState::INVALID_SQL_STATEMENT_NAME), - ("42P17", SqlState::INVALID_OBJECT_DEFINITION), - ("42P04", SqlState::DUPLICATE_DATABASE), - ("38001", SqlState::E_R_E_CONTAINING_SQL_NOT_PERMITTED), - ("0Z002", SqlState::STACKED_DIAGNOSTICS_ACCESSED_WITHOUT_ACTIVE_HANDLER), - ("22007", SqlState::INVALID_DATETIME_FORMAT), - ("40003", SqlState::T_R_STATEMENT_COMPLETION_UNKNOWN), - ("42P12", SqlState::INVALID_DATABASE_DEFINITION), - ("57P03", SqlState::CANNOT_CONNECT_NOW), - ]), -}; diff --git a/postgres-shared/src/lib.rs b/postgres-shared/src/lib.rs deleted file mode 100644 index 84506f7d..00000000 --- a/postgres-shared/src/lib.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![allow(unknown_lints)] // for clippy - -extern crate fallible_iterator; -extern crate hex; -extern crate phf; -extern crate postgres_protocol; - -pub mod error; -pub mod params; -pub mod rows; -pub mod stmt; -pub mod types; - -/// Contains information necessary to cancel queries for a session. -#[derive(Copy, Clone, Debug)] -pub struct CancelData { - /// The process ID of the session. - pub process_id: i32, - /// The secret key for the session. - pub secret_key: i32, -} - -/// An asynchronous notification. -#[derive(Clone, Debug)] -pub struct Notification { - /// The process ID of the notifying backend process. - pub process_id: i32, - /// The name of the channel that the notify has been raised on. - pub channel: String, - /// The "payload" string passed from the notifying process. - pub payload: String, -} diff --git a/postgres-shared/src/params/mod.rs b/postgres-shared/src/params/mod.rs deleted file mode 100644 index 296483f9..00000000 --- a/postgres-shared/src/params/mod.rs +++ /dev/null @@ -1,295 +0,0 @@ -//! Connection parameters -use std::error::Error; -use std::mem; -use std::path::PathBuf; -use std::str::FromStr; -use std::time::Duration; - -use error; -use params::url::Url; - -mod url; - -/// The host. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub enum Host { - /// A TCP hostname. - Tcp(String), - /// The path to a directory containing the server's Unix socket. - Unix(PathBuf), -} - -/// Authentication information. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct User { - name: String, - password: Option, -} - -impl User { - /// The username. - pub fn name(&self) -> &str { - &self.name - } - - /// An optional password. - pub fn password(&self) -> Option<&str> { - self.password.as_ref().map(|p| &**p) - } -} - -/// Information necessary to open a new connection to a Postgres server. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -pub struct ConnectParams { - host: Host, - port: u16, - user: Option, - database: Option, - options: Vec<(String, String)>, - connect_timeout: Option, - keepalive: Option, -} - -impl ConnectParams { - /// Returns a new builder. - pub fn builder() -> Builder { - Builder::new() - } - - /// The target host. - pub fn host(&self) -> &Host { - &self.host - } - - /// The target port. - /// - /// Defaults to 5432. - pub fn port(&self) -> u16 { - self.port - } - - /// The user to log in as. - /// - /// A user is required to open a new connection but not to cancel a query. - pub fn user(&self) -> Option<&User> { - self.user.as_ref() - } - - /// The database to connect to. - pub fn database(&self) -> Option<&str> { - self.database.as_ref().map(|d| &**d) - } - - /// Runtime parameters to be passed to the Postgres backend. - pub fn options(&self) -> &[(String, String)] { - &self.options - } - - /// A timeout to apply to each socket-level connection attempt. - pub fn connect_timeout(&self) -> Option { - self.connect_timeout - } - - /// The interval at which TCP keepalive messages are sent on the socket. - /// - /// This is ignored for Unix sockets. - pub fn keepalive(&self) -> Option { - self.keepalive - } -} - -impl FromStr for ConnectParams { - type Err = error::Error; - - fn from_str(s: &str) -> Result { - s.into_connect_params().map_err(error::connect) - } -} - -/// A builder for `ConnectParams`. -pub struct Builder { - port: u16, - user: Option, - database: Option, - options: Vec<(String, String)>, - connect_timeout: Option, - keepalive: Option, -} - -impl Builder { - /// Creates a new builder. - pub fn new() -> Builder { - Builder { - port: 5432, - user: None, - database: None, - options: vec![], - connect_timeout: None, - keepalive: None, - } - } - - /// Sets the port. - pub fn port(&mut self, port: u16) -> &mut Builder { - self.port = port; - self - } - - /// Sets the user. - pub fn user(&mut self, name: &str, password: Option<&str>) -> &mut Builder { - self.user = Some(User { - name: name.to_string(), - password: password.map(ToString::to_string), - }); - self - } - - /// Sets the database. - pub fn database(&mut self, database: &str) -> &mut Builder { - self.database = Some(database.to_string()); - self - } - - /// Adds a runtime parameter. - pub fn option(&mut self, name: &str, value: &str) -> &mut Builder { - self.options.push((name.to_string(), value.to_string())); - self - } - - /// Sets the connection timeout. - pub fn connect_timeout(&mut self, connect_timeout: Option) -> &mut Builder { - self.connect_timeout = connect_timeout; - self - } - - /// Sets the keepalive interval. - pub fn keepalive(&mut self, keepalive: Option) -> &mut Builder { - self.keepalive = keepalive; - self - } - - /// Constructs a `ConnectParams` from the builder. - pub fn build(&mut self, host: Host) -> ConnectParams { - ConnectParams { - host: host, - port: self.port, - user: self.user.take(), - database: self.database.take(), - options: mem::replace(&mut self.options, vec![]), - connect_timeout: self.connect_timeout, - keepalive: self.keepalive, - } - } -} - -/// A trait implemented by types that can be converted into a `ConnectParams`. -pub trait IntoConnectParams { - /// Converts the value of `self` into a `ConnectParams`. - fn into_connect_params(self) -> Result>; -} - -impl IntoConnectParams for ConnectParams { - fn into_connect_params(self) -> Result> { - Ok(self) - } -} - -impl<'a> IntoConnectParams for &'a str { - fn into_connect_params(self) -> Result> { - match Url::parse(self) { - Ok(url) => url.into_connect_params(), - Err(err) => Err(err.into()), - } - } -} - -impl IntoConnectParams for String { - fn into_connect_params(self) -> Result> { - self.as_str().into_connect_params() - } -} - -impl IntoConnectParams for Url { - fn into_connect_params(self) -> Result> { - let Url { - host, - port, - user, - path: - url::Path { - path, - query: options, - .. - }, - .. - } = self; - - let mut builder = ConnectParams::builder(); - - if let Some(port) = port { - builder.port(port); - } - - if let Some(info) = user { - builder.user(&info.user, info.pass.as_ref().map(|p| &**p)); - } - - if !path.is_empty() { - // path contains the leading / - builder.database(&path[1..]); - } - - for (name, value) in options { - match &*name { - "connect_timeout" => { - let timeout = value.parse().map_err(|_| "invalid connect_timeout")?; - let timeout = Duration::from_secs(timeout); - builder.connect_timeout(Some(timeout)); - } - "keepalive" => { - let keepalive = value.parse().map_err(|_| "invalid keepalive")?; - let keepalive = Duration::from_secs(keepalive); - builder.keepalive(Some(keepalive)); - } - _ => { - builder.option(&name, &value); - } - } - } - - let maybe_path = url::decode_component(&host)?; - let host = if maybe_path.starts_with('/') { - Host::Unix(maybe_path.into()) - } else { - Host::Tcp(maybe_path) - }; - - Ok(builder.build(host)) - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn parse_url() { - let params = "postgres://user@host:44/dbname?connect_timeout=10&application_name=foo"; - let params = params.into_connect_params().unwrap(); - assert_eq!( - params.user(), - Some(&User { - name: "user".to_string(), - password: None, - }) - ); - assert_eq!(params.host(), &Host::Tcp("host".to_string())); - assert_eq!(params.port(), 44); - assert_eq!(params.database(), Some("dbname")); - assert_eq!( - params.options(), - &[("application_name".to_string(), "foo".to_string())][..] - ); - assert_eq!(params.connect_timeout(), Some(Duration::from_secs(10))); - } -} diff --git a/postgres-shared/src/params/url.rs b/postgres-shared/src/params/url.rs deleted file mode 100644 index e965f215..00000000 --- a/postgres-shared/src/params/url.rs +++ /dev/null @@ -1,465 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -use hex::FromHex; -use std::str::FromStr; - -pub struct Url { - pub scheme: String, - pub user: Option, - pub host: String, - pub port: Option, - pub path: Path, -} - -pub struct Path { - pub path: String, - pub query: Query, - pub fragment: Option, -} - -pub struct UserInfo { - pub user: String, - pub pass: Option, -} - -pub type Query = Vec<(String, String)>; - -impl Url { - pub fn new( - scheme: String, - user: Option, - host: String, - port: Option, - path: String, - query: Query, - fragment: Option, - ) -> Url { - Url { - scheme: scheme, - user: user, - host: host, - port: port, - path: Path::new(path, query, fragment), - } - } - - pub fn parse(rawurl: &str) -> DecodeResult { - // scheme - let (scheme, rest) = get_scheme(rawurl)?; - - // authority - let (userinfo, host, port, rest) = get_authority(rest)?; - - // path - let has_authority = !host.is_empty(); - let (path, rest) = get_path(rest, has_authority)?; - - // query and fragment - let (query, fragment) = get_query_fragment(rest)?; - - let url = Url::new( - scheme.to_owned(), - userinfo, - host.to_owned(), - port, - path, - query, - fragment, - ); - Ok(url) - } -} - -impl Path { - pub fn new(path: String, query: Query, fragment: Option) -> Path { - Path { - path: path, - query: query, - fragment: fragment, - } - } - - pub fn parse(rawpath: &str) -> DecodeResult { - let (path, rest) = get_path(rawpath, false)?; - - // query and fragment - let (query, fragment) = get_query_fragment(&rest)?; - - Ok(Path { - path: path, - query: query, - fragment: fragment, - }) - } -} - -impl UserInfo { - #[inline] - pub fn new(user: String, pass: Option) -> UserInfo { - UserInfo { - user: user, - pass: pass, - } - } -} - -pub type DecodeResult = Result; - -pub fn decode_component(container: &str) -> DecodeResult { - decode_inner(container, false) -} - -fn decode_inner(c: &str, full_url: bool) -> DecodeResult { - let mut out = String::new(); - let mut iter = c.as_bytes().iter().cloned(); - - loop { - match iter.next() { - Some(b) => { - match b as char { - '%' => { - let bytes = match (iter.next(), iter.next()) { - (Some(one), Some(two)) => [one, two], - _ => { - return Err("Malformed input: found '%' without two \ - trailing bytes" - .to_owned()) - } - }; - - let bytes_from_hex = match Vec::::from_hex(&bytes) { - Ok(b) => b, - _ => { - return Err("Malformed input: found '%' followed by \ - invalid hex values. Character '%' must \ - escaped." - .to_owned()) - } - }; - - // Only decode some characters if full_url: - match bytes_from_hex[0] as char { - // gen-delims: - ':' | '/' | '?' | '#' | '[' | ']' | '@' | '!' | '$' | '&' | '"' - | '(' | ')' | '*' | '+' | ',' | ';' | '=' - if full_url => - { - out.push('%'); - out.push(bytes[0] as char); - out.push(bytes[1] as char); - } - - ch => out.push(ch), - } - } - ch => out.push(ch), - } - } - None => return Ok(out), - } - } -} - -fn split_char_first(s: &str, c: char) -> (&str, &str) { - let mut iter = s.splitn(2, c); - - match (iter.next(), iter.next()) { - (Some(a), Some(b)) => (a, b), - (Some(a), None) => (a, ""), - (None, _) => unreachable!(), - } -} - -fn query_from_str(rawquery: &str) -> DecodeResult { - let mut query: Query = vec![]; - if !rawquery.is_empty() { - for p in rawquery.split('&') { - let (k, v) = split_char_first(p, '='); - query.push((decode_component(k)?, decode_component(v)?)); - } - } - - Ok(query) -} - -pub fn get_scheme(rawurl: &str) -> DecodeResult<(&str, &str)> { - for (i, c) in rawurl.chars().enumerate() { - let result = match c { - 'A'...'Z' | 'a'...'z' => continue, - '0'...'9' | '+' | '-' | '.' => { - if i != 0 { - continue; - } - - Err("url: Scheme must begin with a letter.".to_owned()) - } - ':' => { - if i == 0 { - Err("url: Scheme cannot be empty.".to_owned()) - } else { - Ok((&rawurl[0..i], &rawurl[i + 1..rawurl.len()])) - } - } - _ => Err("url: Invalid character in scheme.".to_owned()), - }; - - return result; - } - - Err("url: Scheme must be terminated with a colon.".to_owned()) -} - -// returns userinfo, host, port, and unparsed part, or an error -fn get_authority(rawurl: &str) -> DecodeResult<(Option, &str, Option, &str)> { - enum State { - Start, // starting state - PassHostPort, // could be in user or port - Ip6Port, // either in ipv6 host or port - Ip6Host, // are in an ipv6 host - InHost, // are in a host - may be ipv6, but don't know yet - InPort, // are in port - } - - #[derive(Clone, PartialEq)] - enum Input { - Digit, // all digits - Hex, // digits and letters a-f - Unreserved, // all other legal characters - } - - if !rawurl.starts_with("//") { - // there is no authority. - return Ok((None, "", None, rawurl)); - } - - let len = rawurl.len(); - let mut st = State::Start; - let mut input = Input::Digit; // most restricted, start here. - - let mut userinfo = None; - let mut host = ""; - let mut port = None; - - let mut colon_count = 0usize; - let mut pos = 0; - let mut begin = 2; - let mut end = len; - - for (i, c) in rawurl.chars().enumerate().skip(2) { - // deal with input class first - match c { - '0'...'9' => (), - 'A'...'F' | 'a'...'f' => { - if input == Input::Digit { - input = Input::Hex; - } - } - 'G'...'Z' - | 'g'...'z' - | '-' - | '.' - | '_' - | '~' - | '%' - | '&' - | '\'' - | '(' - | ')' - | '+' - | '!' - | '*' - | ',' - | ';' - | '=' => input = Input::Unreserved, - ':' | '@' | '?' | '#' | '/' => { - // separators, don't change anything - } - _ => return Err("Illegal character in authority".to_owned()), - } - - // now process states - match c { - ':' => { - colon_count += 1; - match st { - State::Start => { - pos = i; - st = State::PassHostPort; - } - State::PassHostPort => { - // multiple colons means ipv6 address. - if input == Input::Unreserved { - return Err("Illegal characters in IPv6 address.".to_owned()); - } - st = State::Ip6Host; - } - State::InHost => { - pos = i; - if input == Input::Unreserved { - // must be port - host = &rawurl[begin..i]; - st = State::InPort; - } else { - // can't be sure whether this is an ipv6 address or a port - st = State::Ip6Port; - } - } - State::Ip6Port => { - if input == Input::Unreserved { - return Err("Illegal characters in authority.".to_owned()); - } - st = State::Ip6Host; - } - State::Ip6Host => { - if colon_count > 7 { - host = &rawurl[begin..i]; - pos = i; - st = State::InPort; - } - } - _ => return Err("Invalid ':' in authority.".to_owned()), - } - input = Input::Digit; // reset input class - } - - '@' => { - input = Input::Digit; // reset input class - colon_count = 0; // reset count - match st { - State::Start => { - let user = decode_component(&rawurl[begin..i])?; - userinfo = Some(UserInfo::new(user, None)); - st = State::InHost; - } - State::PassHostPort => { - let user = decode_component(&rawurl[begin..pos])?; - let pass = decode_component(&rawurl[pos + 1..i])?; - userinfo = Some(UserInfo::new(user, Some(pass))); - st = State::InHost; - } - _ => return Err("Invalid '@' in authority.".to_owned()), - } - begin = i + 1; - } - - '?' | '#' | '/' => { - end = i; - break; - } - _ => (), - } - } - - // finish up - match st { - State::PassHostPort | State::Ip6Port => { - if input != Input::Digit { - return Err("Non-digit characters in port.".to_owned()); - } - host = &rawurl[begin..pos]; - port = Some(&rawurl[pos + 1..end]); - } - State::Ip6Host | State::InHost | State::Start => host = &rawurl[begin..end], - State::InPort => { - if input != Input::Digit { - return Err("Non-digit characters in port.".to_owned()); - } - port = Some(&rawurl[pos + 1..end]); - } - } - - let rest = &rawurl[end..len]; - // If we have a port string, ensure it parses to u16. - let port = match port { - None => None, - opt => match opt.and_then(|p| FromStr::from_str(p).ok()) { - None => return Err(format!("Failed to parse port: {:?}", port)), - opt => opt, - }, - }; - - Ok((userinfo, host, port, rest)) -} - -// returns the path and unparsed part of url, or an error -fn get_path(rawurl: &str, is_authority: bool) -> DecodeResult<(String, &str)> { - let len = rawurl.len(); - let mut end = len; - for (i, c) in rawurl.chars().enumerate() { - match c { - 'A'...'Z' - | 'a'...'z' - | '0'...'9' - | '&' - | '\'' - | '(' - | ')' - | '.' - | '@' - | ':' - | '%' - | '/' - | '+' - | '!' - | '*' - | ',' - | ';' - | '=' - | '_' - | '-' - | '~' => continue, - '?' | '#' => { - end = i; - break; - } - _ => return Err("Invalid character in path.".to_owned()), - } - } - - if is_authority && end != 0 && !rawurl.starts_with('/') { - Err("Non-empty path must begin with '/' in presence of authority.".to_owned()) - } else { - Ok((decode_component(&rawurl[0..end])?, &rawurl[end..len])) - } -} - -// returns the parsed query and the fragment, if present -fn get_query_fragment(rawurl: &str) -> DecodeResult<(Query, Option)> { - let (before_fragment, raw_fragment) = split_char_first(rawurl, '#'); - - // Parse the fragment if available - let fragment = match raw_fragment { - "" => None, - raw => Some(decode_component(raw)?), - }; - - match before_fragment.chars().next() { - Some('?') => Ok((query_from_str(&before_fragment[1..])?, fragment)), - None => Ok((vec![], fragment)), - _ => Err(format!( - "Query didn't start with '?': '{}..'", - before_fragment - )), - } -} - -impl FromStr for Url { - type Err = String; - fn from_str(s: &str) -> Result { - Url::parse(s) - } -} - -impl FromStr for Path { - type Err = String; - fn from_str(s: &str) -> Result { - Path::parse(s) - } -} diff --git a/tokio-postgres/Cargo.toml b/tokio-postgres/Cargo.toml index ae1e43ea..538929c7 100644 --- a/tokio-postgres/Cargo.toml +++ b/tokio-postgres/Cargo.toml @@ -23,12 +23,12 @@ features = [ circle-ci = { repository = "sfackler/rust-postgres" } [features] -"with-bit-vec-0.5" = ["postgres-shared/with-bit-vec-0.5"] -"with-chrono-0.4" = ["postgres-shared/with-chrono-0.4"] -"with-eui48-0.3" = ["postgres-shared/with-eui48-0.3"] -"with-geo-0.10" = ["postgres-shared/with-geo-0.10"] -"with-serde_json-1" = ["postgres-shared/with-serde_json-1"] -"with-uuid-0.6" = ["postgres-shared/with-uuid-0.6"] +"with-bit-vec-0.5" = ["bit-vec"] +"with-chrono-0.4" = ["chrono"] +"with-eui48-0.3" = ["eui48"] +"with-geo-0.10" = ["geo"] +with-serde_json-1 = ["serde", "serde_json"] +"with-uuid-0.6" = ["uuid"] [dependencies] antidote = "1.0" @@ -37,14 +37,21 @@ fallible-iterator = "0.1.3" futures = "0.1.7" futures-cpupool = "0.1" log = "0.4" -phf = "=0.7.22" +phf = "0.7.23" postgres-protocol = { version = "0.3.0", path = "../postgres-protocol" } -postgres-shared = { version = "0.4.0", path = "../postgres-shared" } state_machine_future = "0.1.7" tokio-codec = "0.1" tokio-io = "0.1" void = "1.0" +bit-vec = { version = "0.5", optional = true } +chrono = { version = "0.4", optional = true } +eui48 = { version = "0.3", optional = true } +geo = { version = "0.10", optional = true } +serde = { version = "1.0", optional = true } +serde_json = { version = "1.0", optional = true } +uuid = { version = "0.6", optional = true } + [dev-dependencies] tokio = "0.1.7" env_logger = "0.5" diff --git a/tokio-postgres/src/lib.rs b/tokio-postgres/src/lib.rs index 022a79b2..b13a47c2 100644 --- a/tokio-postgres/src/lib.rs +++ b/tokio-postgres/src/lib.rs @@ -4,7 +4,6 @@ extern crate fallible_iterator; extern crate futures_cpupool; extern crate phf; extern crate postgres_protocol; -extern crate postgres_shared; extern crate tokio_codec; extern crate tokio_io; extern crate void; @@ -18,29 +17,26 @@ extern crate state_machine_future; use bytes::{Bytes, IntoBuf}; use futures::{Async, Future, Poll, Stream}; -use postgres_shared::rows::RowIndex; use std::error::Error as StdError; use std::fmt; use std::sync::atomic::{AtomicUsize, Ordering}; use tokio_io::{AsyncRead, AsyncWrite}; -#[doc(inline)] -pub use postgres_shared::stmt::Column; -#[doc(inline)] -pub use postgres_shared::{params, types}; -#[doc(inline)] -pub use postgres_shared::{CancelData, Notification}; - pub use builder::*; pub use error::*; use proto::CancelFuture; +use rows::RowIndex; +pub use stmt::Column; pub use tls::*; use types::{FromSql, ToSql, Type}; mod builder; pub mod error; mod proto; +pub mod rows; +mod stmt; mod tls; +pub mod types; fn next_statement() -> String { static ID: AtomicUsize = AtomicUsize::new(0); @@ -386,3 +382,23 @@ impl Future for BatchExecute { self.0.poll() } } + +/// Contains information necessary to cancel queries for a session. +#[derive(Copy, Clone, Debug)] +pub struct CancelData { + /// The process ID of the session. + pub process_id: i32, + /// The secret key for the session. + pub secret_key: i32, +} + +/// An asynchronous notification. +#[derive(Clone, Debug)] +pub struct Notification { + /// The process ID of the notifying backend process. + pub process_id: i32, + /// The name of the channel that the notify has been raised on. + pub channel: String, + /// The "payload" string passed from the notifying process. + pub payload: String, +} diff --git a/tokio-postgres/src/proto/row.rs b/tokio-postgres/src/proto/row.rs index 38c270d4..86348f46 100644 --- a/tokio-postgres/src/proto/row.rs +++ b/tokio-postgres/src/proto/row.rs @@ -1,8 +1,8 @@ use postgres_protocol::message::backend::DataRowBody; -use postgres_shared::rows::{RowData, RowIndex}; use std::fmt; use proto::statement::Statement; +use rows::{RowData, RowIndex}; use types::{FromSql, WrongType}; use {Column, Error}; diff --git a/tokio-postgres/src/proto/statement.rs b/tokio-postgres/src/proto/statement.rs index 3460a76c..12bee1a2 100644 --- a/tokio-postgres/src/proto/statement.rs +++ b/tokio-postgres/src/proto/statement.rs @@ -1,8 +1,8 @@ -use postgres_shared::stmt::Column; use std::sync::Arc; use proto::client::WeakClient; use types::Type; +use Column; pub struct StatementInner { client: WeakClient, diff --git a/postgres-shared/src/rows.rs b/tokio-postgres/src/rows.rs similarity index 100% rename from postgres-shared/src/rows.rs rename to tokio-postgres/src/rows.rs diff --git a/postgres-shared/src/stmt.rs b/tokio-postgres/src/stmt.rs similarity index 100% rename from postgres-shared/src/stmt.rs rename to tokio-postgres/src/stmt.rs diff --git a/postgres-shared/src/types/bit_vec.rs b/tokio-postgres/src/types/bit_vec.rs similarity index 100% rename from postgres-shared/src/types/bit_vec.rs rename to tokio-postgres/src/types/bit_vec.rs diff --git a/postgres-shared/src/types/chrono.rs b/tokio-postgres/src/types/chrono.rs similarity index 100% rename from postgres-shared/src/types/chrono.rs rename to tokio-postgres/src/types/chrono.rs diff --git a/postgres-shared/src/types/eui48.rs b/tokio-postgres/src/types/eui48.rs similarity index 100% rename from postgres-shared/src/types/eui48.rs rename to tokio-postgres/src/types/eui48.rs diff --git a/postgres-shared/src/types/geo.rs b/tokio-postgres/src/types/geo.rs similarity index 100% rename from postgres-shared/src/types/geo.rs rename to tokio-postgres/src/types/geo.rs diff --git a/postgres-shared/src/types/mod.rs b/tokio-postgres/src/types/mod.rs similarity index 100% rename from postgres-shared/src/types/mod.rs rename to tokio-postgres/src/types/mod.rs diff --git a/postgres-shared/src/types/serde_json.rs b/tokio-postgres/src/types/serde_json.rs similarity index 100% rename from postgres-shared/src/types/serde_json.rs rename to tokio-postgres/src/types/serde_json.rs diff --git a/postgres-shared/src/types/special.rs b/tokio-postgres/src/types/special.rs similarity index 100% rename from postgres-shared/src/types/special.rs rename to tokio-postgres/src/types/special.rs diff --git a/postgres-shared/src/types/type_gen.rs b/tokio-postgres/src/types/type_gen.rs similarity index 100% rename from postgres-shared/src/types/type_gen.rs rename to tokio-postgres/src/types/type_gen.rs diff --git a/postgres-shared/src/types/uuid.rs b/tokio-postgres/src/types/uuid.rs similarity index 100% rename from postgres-shared/src/types/uuid.rs rename to tokio-postgres/src/types/uuid.rs