Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions sqlx-core/src/any/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ impl AnyArguments {
AnyValueKind::Null(AnyTypeInfoKind::SmallInt) => out.add(Option::<i16>::None),
AnyValueKind::Null(AnyTypeInfoKind::Integer) => out.add(Option::<i32>::None),
AnyValueKind::Null(AnyTypeInfoKind::BigInt) => out.add(Option::<i64>::None),
AnyValueKind::Null(AnyTypeInfoKind::Real) => out.add(Option::<f64>::None),
AnyValueKind::Null(AnyTypeInfoKind::Double) => out.add(Option::<f32>::None),
AnyValueKind::Null(AnyTypeInfoKind::Real) => out.add(Option::<f32>::None),
AnyValueKind::Null(AnyTypeInfoKind::Double) => out.add(Option::<f64>::None),
AnyValueKind::Null(AnyTypeInfoKind::Text) => out.add(Option::<String>::None),
AnyValueKind::Null(AnyTypeInfoKind::Blob) => out.add(Option::<Vec<u8>>::None),
AnyValueKind::Bool(b) => out.add(b),
Expand All @@ -85,3 +85,46 @@ impl AnyArguments {
Ok(out)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn convert_into_maps_null_real_to_f32_and_null_double_to_f64() {
let mut args = AnyArguments::default();
args.values.0.push(AnyValueKind::Null(AnyTypeInfoKind::Real));
args.values.0.push(AnyValueKind::Null(AnyTypeInfoKind::Double));

let out: AnyArguments = args.convert_into().unwrap();

assert_eq!(out.values.0.len(), 2);
assert!(matches!(
out.values.0[0],
AnyValueKind::Null(AnyTypeInfoKind::Real)
));
assert!(matches!(
out.values.0[1],
AnyValueKind::Null(AnyTypeInfoKind::Double)
));
}

#[test]
fn convert_into_preserves_non_float_null_types() {
let mut args = AnyArguments::default();
args.values.0.push(AnyValueKind::Null(AnyTypeInfoKind::Integer));
args.values.0.push(AnyValueKind::Null(AnyTypeInfoKind::BigInt));

let out: AnyArguments = args.convert_into().unwrap();

assert_eq!(out.values.0.len(), 2);
assert!(matches!(
out.values.0[0],
AnyValueKind::Null(AnyTypeInfoKind::Integer)
));
assert!(matches!(
out.values.0[1],
AnyValueKind::Null(AnyTypeInfoKind::BigInt)
));
}
}
2 changes: 1 addition & 1 deletion sqlx-core/src/any/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Connection for AnyConnection {
}

fn close_hard(self) -> impl Future<Output = Result<(), Error>> + Send + 'static {
self.backend.close()
self.backend.close_hard()
}

fn ping(&mut self) -> impl Future<Output = Result<(), Error>> + Send + '_ {
Expand Down
28 changes: 27 additions & 1 deletion sqlx-macros-core/src/query/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,33 @@ fn load_env(
}))
}

/// Returns `true` if `val` is `"true"`,
/// Returns `true` if `val` is `"true"` (case-insensitive) or `"1"`.
fn is_truthy_bool(val: &str) -> bool {
val.eq_ignore_ascii_case("true") || val == "1"
}

#[cfg(test)]
mod tests {
use super::is_truthy_bool;

#[test]
fn truthy_values_return_true() {
assert!(is_truthy_bool("true"));
assert!(is_truthy_bool("1"));
}

#[test]
fn truthy_is_case_insensitive() {
assert!(is_truthy_bool("TRUE"));
assert!(is_truthy_bool("True"));
assert!(is_truthy_bool("tRuE"));
}

#[test]
fn falsy_values_return_false() {
assert!(!is_truthy_bool("false"));
assert!(!is_truthy_bool("0"));
assert!(!is_truthy_bool(""));
assert!(!is_truthy_bool("yes"));
}
}
39 changes: 38 additions & 1 deletion sqlx-sqlite/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,43 @@ fn dot_escape_string(value: impl AsRef<str>) -> String {
.to_string()
}

#[cfg(test)]
mod tests {
use super::*;
use crate::connection::intmap::IntMap;
use std::collections::HashSet;

#[derive(Debug)]
struct TestState;

impl DebugDiff for TestState {
fn diff(&self, _prev: &Self) -> String {
String::new()
}
}

#[test]
fn max_branch_id_includes_branch_origins() {
let program: &[&str] = &["Init"];
let mut logger: QueryPlanLogger<'_, i64, TestState, &str> = QueryPlanLogger {
sql: "SELECT 1",
unknown_operations: HashSet::new(),
branch_origins: IntMap::new(),
branch_results: IntMap::new(),
branch_operations: IntMap::new(),
program,
};

logger
.branch_origins
.insert(7, BranchParent { id: 0, idx: 0 });

let rendered = logger.to_string();

assert!(rendered.contains('7'));
}
}

impl<R: Debug, S: Debug + DebugDiff, P: Debug> core::fmt::Display for QueryPlanLogger<'_, R, S, P> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
//writes query plan history in dot format
Expand Down Expand Up @@ -224,7 +261,7 @@ impl<R: Debug, S: Debug + DebugDiff, P: Debug> core::fmt::Display for QueryPlanL
let max_branch_id: i64 = [
self.branch_operations.last_index().unwrap_or(0),
self.branch_results.last_index().unwrap_or(0),
self.branch_results.last_index().unwrap_or(0),
self.branch_origins.last_index().unwrap_or(0),
]
.into_iter()
.max()
Expand Down
Loading