mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-03 15:55:45 +00:00
fix(sqlite): support column types changing per row
This commit is contained in:
parent
dc5fc1b6c1
commit
25b8fc7c04
@ -89,6 +89,12 @@ fn emplace_row_metadata(
|
|||||||
Ok(())
|
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 {
|
impl<'c> Executor<'c> for &'c mut SqliteConnection {
|
||||||
type Database = Sqlite;
|
type Database = Sqlite;
|
||||||
|
|
||||||
@ -144,6 +150,8 @@ impl<'c> Executor<'c> for &'c mut SqliteConnection {
|
|||||||
Arc::make_mut(columns),
|
Arc::make_mut(columns),
|
||||||
Arc::make_mut(scratch_row_column_names),
|
Arc::make_mut(scratch_row_column_names),
|
||||||
)?;
|
)?;
|
||||||
|
} else {
|
||||||
|
update_column_type_metadata(handle, Arc::make_mut(columns));
|
||||||
}
|
}
|
||||||
|
|
||||||
match s {
|
match s {
|
||||||
|
@ -92,6 +92,34 @@ async fn it_maths() -> anyhow::Result<()> {
|
|||||||
Ok(())
|
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]
|
#[sqlx_macros::test]
|
||||||
async fn it_binds_positional_parameters_issue_467() -> anyhow::Result<()> {
|
async fn it_binds_positional_parameters_issue_467() -> anyhow::Result<()> {
|
||||||
let mut conn = new::<Sqlite>().await?;
|
let mut conn = new::<Sqlite>().await?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user