Skip to content

Commit 0288c64

Browse files
committed
Fix SQLite time zone reading
1 parent ee3748a commit 0288c64

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/executor/query.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -572,20 +572,15 @@ macro_rules! try_getable_date_time {
572572
.map_err(|e| sqlx_error_to_query_err(e).into())
573573
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx))),
574574
#[cfg(feature = "sqlx-sqlite")]
575-
QueryResultRow::SqlxSqlite(row) => {
576-
use chrono::{DateTime, Utc};
577-
row.try_get::<Option<DateTime<Utc>>, _>(idx.as_sqlx_sqlite_index())
578-
.map_err(|e| sqlx_error_to_query_err(e).into())
579-
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
580-
.map(|v| v.into())
581-
}
575+
QueryResultRow::SqlxSqlite(row) => row
576+
.try_get::<Option<$type>, _>(idx.as_sqlx_sqlite_index())
577+
.map_err(|e| sqlx_error_to_query_err(e).into())
578+
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx))),
582579
#[cfg(feature = "rusqlite")]
583-
QueryResultRow::Rusqlite(row) => {
584-
use chrono::{DateTime, Utc};
585-
row.try_get::<Option<DateTime<Utc>>, _>(idx)
586-
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
587-
.map(|v| v.into())
588-
}
580+
QueryResultRow::Rusqlite(row) => row
581+
.try_get::<Option<$type>, _>(idx)
582+
.and_then(|opt| opt.ok_or_else(|| err_null_idx_col(idx)))
583+
.map(|v| v.into()),
589584
#[cfg(feature = "mock")]
590585
QueryResultRow::Mock(row) => row.try_get(idx).map_err(|e| {
591586
debug_print!("{:#?}", e.to_string());

tests/timestamp_tests.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ pub async fn create_applog(db: &DatabaseConnection) -> Result<(), DbErr> {
106106
.await?;
107107

108108
assert_eq!(log.id, res.last_insert_id);
109-
assert_eq!(Applog::find().one(db).await?, Some(log.clone()));
109+
let read_back = Applog::find().one(db).await?;
110+
assert_eq!(read_back, Some(log.clone()));
111+
#[cfg(all(not(feature = "sync"), feature = "sqlx-sqlite"))]
112+
{
113+
let read_back = read_back.unwrap();
114+
assert_eq!(read_back.created_at.offset().local_minus_utc(), 8 * 60 * 60);
115+
}
110116

111117
#[cfg(all(not(feature = "sync"), feature = "sqlx-sqlite"))]
112118
assert_eq!(

0 commit comments

Comments
 (0)