fix(sqlite): support column types changing per row

This commit is contained in:
Ryan Leckey 2020-07-15 02:05:00 -07:00
parent dc5fc1b6c1
commit 25b8fc7c04
2 changed files with 36 additions and 0 deletions

View file

@ -89,6 +89,12 @@ fn emplace_row_metadata(
Ok(())
}
fn update_column_type_metadata(statement: &StatementHandle, columns: &mut Vec<SqliteColumn>) {
for col in columns.iter_mut() {
col.type_info = statement.column_type_info(col.ordinal);
}
}
impl<'c> Executor<'c> for &'c mut SqliteConnection {
type Database = Sqlite;
@ -144,6 +150,8 @@ impl<'c> Executor<'c> for &'c mut SqliteConnection {
Arc::make_mut(columns),
Arc::make_mut(scratch_row_column_names),
)?;
} else {
update_column_type_metadata(handle, Arc::make_mut(columns));
}
match s {

View file

@ -92,6 +92,34 @@ async fn it_maths() -> anyhow::Result<()> {
Ok(())
}
#[sqlx_macros::test]
async fn it_can_describe_with_pragma() -> anyhow::Result<()> {
use sqlx::{ValueRef, TypeInfo, Decode};
let mut conn = new::<Sqlite>().await?;
let defaults = sqlx::query("pragma table_info (tweet)")
.try_map(|row: SqliteRow| {
let val = row.try_get_raw("dflt_value")?;
let ty = val.type_info().clone();
let val: Option<i32> = Decode::decode(val).map_err(sqlx::Error::Decode)?;
if val.is_some() {
assert_eq!(ty.name(), "TEXT");
}
Ok(val)
})
.fetch_all(&mut conn)
.await?;
assert_eq!(defaults[0], None);
assert_eq!(defaults[2], Some(0));
Ok(())
}
#[sqlx_macros::test]
async fn it_binds_positional_parameters_issue_467() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;