diff --git a/sqlx-sqlite/src/connection/explain.rs b/sqlx-sqlite/src/connection/explain.rs index 550f21557e..3a3807545f 100644 --- a/sqlx-sqlite/src/connection/explain.rs +++ b/sqlx-sqlite/src/connection/explain.rs @@ -373,9 +373,9 @@ fn opcode_to_type(op: &str) -> DataType { fn root_block_columns( conn: &mut ConnectionState, ) -> Result>, Error> { - let table_block_columns: Vec<(i64, i64, i64, String, bool)> = execute::iter( + let table_block_columns: Vec<(i64, i64, i64, String, bool, i64)> = execute::iter( conn, - "SELECT s.dbnum, s.rootpage, col.cid as colnum, col.type, col.\"notnull\" + "SELECT s.dbnum, s.rootpage, col.cid as colnum, col.type, col.\"notnull\", col.pk FROM ( select 1 dbnum, tss.* from temp.sqlite_schema tss UNION ALL select 0 dbnum, mss.* from main.sqlite_schema mss @@ -383,7 +383,7 @@ fn root_block_columns( JOIN pragma_table_info(s.name) AS col WHERE s.type = 'table' UNION ALL - SELECT s.dbnum, s.rootpage, idx.seqno as colnum, col.type, col.\"notnull\" + SELECT s.dbnum, s.rootpage, idx.seqno as colnum, col.type, col.\"notnull\", col.pk FROM ( select 1 dbnum, tss.* from temp.sqlite_schema tss UNION ALL select 0 dbnum, mss.* from main.sqlite_schema mss @@ -400,13 +400,13 @@ fn root_block_columns( .collect::, Error>>()?; let mut row_info: HashMap<(i64, i64), IntMap> = HashMap::new(); - for (dbnum, block, colnum, datatype, notnull) in table_block_columns { + for (dbnum, block, colnum, datatype, notnull, pk) in table_block_columns { let row_info = row_info.entry((dbnum, block)).or_default(); row_info.insert( colnum, ColumnType::Single { datatype: datatype.parse().unwrap_or(DataType::Null), - nullable: Some(!notnull), + nullable: Some(!(notnull || (pk > 0 && datatype.to_lowercase() == "integer"))), }, ); } @@ -1640,7 +1640,7 @@ fn test_root_block_columns_has_types() { assert_eq!( Some(&ColumnType::Single { datatype: DataType::Integer, - nullable: Some(true) //sqlite primary key columns are nullable unless declared not null + nullable: Some(false) }), root_block_cols[&table_db_block].get(&0) ); @@ -1665,7 +1665,7 @@ fn test_root_block_columns_has_types() { assert_eq!( Some(&ColumnType::Single { datatype: DataType::Integer, - nullable: Some(true) //sqlite primary key columns are nullable unless declared not null + nullable: Some(false) }), root_block_cols[&table_db_block].get(&0) ); @@ -1683,7 +1683,7 @@ fn test_root_block_columns_has_types() { assert_eq!( Some(&ColumnType::Single { datatype: DataType::Integer, - nullable: Some(true) //sqlite primary key columns are nullable unless declared not null + nullable: Some(false) }), root_block_cols[&table_db_block].get(&0) ); diff --git a/sqlx-sqlite/src/statement/handle.rs b/sqlx-sqlite/src/statement/handle.rs index c78ce98414..c450c7f934 100644 --- a/sqlx-sqlite/src/statement/handle.rs +++ b/sqlx-sqlite/src/statement/handle.rs @@ -271,7 +271,7 @@ impl StatementHandle { .to_bytes() .eq_ignore_ascii_case("integer".as_bytes()) { - None + Some(false) } else { Some(not_null == 0) }, diff --git a/sqlx-sqlite/src/types/time.rs b/sqlx-sqlite/src/types/time.rs index 0e0027882d..950f51544a 100644 --- a/sqlx-sqlite/src/types/time.rs +++ b/sqlx-sqlite/src/types/time.rs @@ -192,6 +192,7 @@ fn decode_datetime_from_text(value: &str) -> Option { None } +#[allow(deprecated)] mod formats { use time::format_description::BorrowedFormatItem::{Component, Literal, Optional}; use time::format_description::{modifier, BorrowedFormatItem, Component::*};