Show blob as hex

This commit is contained in:
Spxg
2025-05-18 00:08:05 +08:00
parent 52f7a53e41
commit 06110db136
6 changed files with 20 additions and 12 deletions

7
Cargo.lock generated
View File

@@ -641,6 +641,12 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "html-escape"
version = "0.2.13"
@@ -1705,6 +1711,7 @@ dependencies = [
"console_log",
"floating-ui",
"fragile",
"hex",
"istyles",
"js-sys",
"leptos",

View File

@@ -36,3 +36,4 @@ wasm-bindgen-futures = "0.4.50"
console_log = "1.0.0"
log = "0.4.27"
fragile = "2.0.1"
hex = "0.4.3"

View File

@@ -19,7 +19,10 @@ fn get_output(table: &SQLiteStatementTable) -> Option<AnyView> {
};
Some(
view! {
<table class=styles::table>
<table
class=styles::table
style="table-layout: fixed; width: 100%; word-wrap: break-word;"
>
<tr>
{values
.columns

View File

@@ -13,9 +13,7 @@ pub fn Section(label: String, children: Children) -> impl IntoView {
view! {
<div>
<Header label=label />
<pre>
<code class=styles::code>{children()}</code>
</pre>
{children()}
</div>
}
}

View File

@@ -6,7 +6,6 @@ use app::{GlobalState, GlobalStateStoreFields};
use fragile::Fragile;
use leptos::prelude::*;
use reactive_stores::Store;
use serde_json::Value as JsonValue;
use std::{
ops::{Deref, DerefMut},
sync::Arc,
@@ -152,7 +151,7 @@ pub struct SQLiteStatementTable {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SQLiteStatementValues {
pub columns: Vec<String>,
pub rows: Vec<Vec<JsonValue>>,
pub rows: Vec<Vec<String>>,
}
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]

View File

@@ -1,4 +1,3 @@
use serde_json::Value as JsonValue;
use sqlite_wasm_rs::*;
use std::ffi::{CStr, CString};
use std::sync::Arc;
@@ -215,12 +214,12 @@ impl SQLitePreparedStatement {
// https://www.sqlite.org/c3ref/column_blob.html
let value = unsafe {
match column_type {
SQLITE_NULL => JsonValue::Null,
SQLITE_NULL => "Null".to_string(),
SQLITE_INTEGER => {
let number = sqlite3_column_int64(self.stmt, col_ndx);
JsonValue::from(number)
number.to_string()
}
SQLITE_FLOAT => JsonValue::from(sqlite3_column_double(self.stmt, col_ndx)),
SQLITE_FLOAT => sqlite3_column_double(self.stmt, col_ndx).to_string(),
SQLITE_TEXT => {
let slice = {
let text = sqlite3_column_text(self.stmt, col_ndx);
@@ -232,7 +231,7 @@ impl SQLitePreparedStatement {
let Ok(text) = std::str::from_utf8(slice) else {
return Err(SQLitendError::Utf8Text);
};
JsonValue::from(text)
format!("{text:?}")
}
SQLITE_BLOB => {
let slice = {
@@ -240,7 +239,8 @@ impl SQLitePreparedStatement {
let len = sqlite3_column_bytes(self.stmt, col_ndx);
std::slice::from_raw_parts(blob.cast::<u8>(), len as usize)
};
JsonValue::from(slice)
let hex = hex::encode(slice);
format!("x'{hex}'")
}
_ => return Err(SQLitendError::UnsupportColumnType(column_type)),
}