quaint/connector/sqlite/
error.rs1use crate::error::Error;
2use libsqlite3_sys as ffi;
3use rusqlite::types::FromSqlError;
4
5impl From<rusqlite::Error> for Error {
6 fn from(e: rusqlite::Error) -> Error {
7 match e {
8 rusqlite::Error::QueryReturnedNoRows => Error::NotFound,
9
10 rusqlite::Error::SqliteFailure(
11 ffi::Error {
12 code: ffi::ErrorCode::ConstraintViolation,
13 extended_code: 2067,
14 },
15 Some(description),
16 ) => {
17 let splitted: Vec<&str> = description.split(": ").collect();
18 let splitted: Vec<&str> = splitted[1].split('.').collect();
19
20 Error::UniqueConstraintViolation {
21 field_name: splitted[1].into(),
22 }
23 }
24
25 rusqlite::Error::SqliteFailure(
26 ffi::Error {
27 code: ffi::ErrorCode::ConstraintViolation,
28 extended_code: 1555,
29 },
30 Some(description),
31 ) => {
32 let splitted: Vec<&str> = description.split(": ").collect();
33 let splitted: Vec<&str> = splitted[1].split('.').collect();
34
35 Error::UniqueConstraintViolation {
36 field_name: splitted[1].into(),
37 }
38 }
39
40 rusqlite::Error::SqliteFailure(
41 ffi::Error {
42 code: ffi::ErrorCode::ConstraintViolation,
43 extended_code: 1299,
44 },
45 Some(description),
46 ) => {
47 let splitted: Vec<&str> = description.split(": ").collect();
48 let splitted: Vec<&str> = splitted[1].split('.').collect();
49
50 Error::NullConstraintViolation {
51 field_name: splitted[1].into(),
52 }
53 }
54
55 rusqlite::Error::SqliteFailure(
56 ffi::Error {
57 code: ffi::ErrorCode::DatabaseBusy,
58 ..
59 },
60 _
61 ) => {
62 Error::Timeout
63 }
64
65 e => Error::QueryError(e.into()),
66 }
67 }
68}
69
70impl From<FromSqlError> for Error {
71 fn from(e: FromSqlError) -> Error {
72 Error::ColumnReadFailure(e.into())
73 }
74}