From dbe0a64d50603696f86b407205cde5a8db148c92 Mon Sep 17 00:00:00 2001 From: m0hossam Date: Mon, 3 Mar 2025 16:43:21 +0200 Subject: [PATCH 1/2] Display blob literals in .dump --- cli/app.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cli/app.rs b/cli/app.rs index 3082701d6..92ac970fc 100644 --- a/cli/app.rs +++ b/cli/app.rs @@ -307,6 +307,11 @@ impl<'a> Limbo<'a> { || value_type.contains("TEXT") { format!("'{}'", value.to_string().replace("'", "''")) + } else if value_type.contains("BLOB") { + let blob = value.to_blob().unwrap_or(&[]); + let hex_string: String = + blob.iter().map(|b| format!("{:02x}", b)).collect(); + format!("X'{}'", hex_string) } else { value.to_string() } From 37df657b872fc7979d19b1c3801f546e0c67b3f4 Mon Sep 17 00:00:00 2001 From: m0hossam Date: Mon, 3 Mar 2025 17:31:49 +0200 Subject: [PATCH 2/2] Use fold() and write! macro instead of format! --- cli/app.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/app.rs b/cli/app.rs index 92ac970fc..9925585c0 100644 --- a/cli/app.rs +++ b/cli/app.rs @@ -9,6 +9,7 @@ use limbo_core::{Database, LimboError, OwnedValue, Statement, StepResult}; use clap::{Parser, ValueEnum}; use rustyline::DefaultEditor; use std::{ + fmt, io::{self, Write}, path::PathBuf, rc::Rc, @@ -310,7 +311,11 @@ impl<'a> Limbo<'a> { } else if value_type.contains("BLOB") { let blob = value.to_blob().unwrap_or(&[]); let hex_string: String = - blob.iter().map(|b| format!("{:02x}", b)).collect(); + blob.iter().fold(String::new(), |mut output, b| { + let _ = + fmt::Write::write_fmt(&mut output, format_args!("{b:02x}")); + output + }); format!("X'{}'", hex_string) } else { value.to_string()