mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-08 17:54:22 +01:00
Merge 'Fix some Clippy warnings' from Lauri Virtanen
Reviewed-by: Pere Diaz Bou <limeng.1@bytedance.com> Closes #417
This commit is contained in:
@@ -57,10 +57,7 @@ impl Statement {
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn raw(mut self, toggle: Option<bool>) -> Self {
|
||||
self.raw = match toggle {
|
||||
Some(toggle) => toggle,
|
||||
None => true,
|
||||
};
|
||||
self.raw = toggle.unwrap_or(true);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ impl LinuxIO {
|
||||
}
|
||||
|
||||
impl InnerLinuxIO {
|
||||
pub fn get_iovec<'a>(&'a mut self, buf: *const u8, len: usize) -> &'a iovec {
|
||||
pub fn get_iovec(&mut self, buf: *const u8, len: usize) -> &iovec {
|
||||
let iovec = &mut self.iovecs[self.next_iovec];
|
||||
iovec.iov_base = buf as *mut std::ffi::c_void;
|
||||
iovec.iov_len = len;
|
||||
|
||||
14
core/lib.rs
14
core/lib.rs
@@ -187,7 +187,7 @@ impl Connection {
|
||||
match cmd {
|
||||
Cmd::Stmt(stmt) => {
|
||||
let program = Rc::new(translate::translate(
|
||||
&*self.schema.borrow(),
|
||||
&self.schema.borrow(),
|
||||
stmt,
|
||||
self.header.clone(),
|
||||
self.pager.clone(),
|
||||
@@ -212,18 +212,18 @@ impl Connection {
|
||||
match cmd {
|
||||
Cmd::Stmt(stmt) => {
|
||||
let program = Rc::new(translate::translate(
|
||||
&*self.schema.borrow(),
|
||||
&self.schema.borrow(),
|
||||
stmt,
|
||||
self.header.clone(),
|
||||
self.pager.clone(),
|
||||
Rc::downgrade(&self),
|
||||
Rc::downgrade(self),
|
||||
)?);
|
||||
let stmt = Statement::new(program, self.pager.clone());
|
||||
Ok(Some(Rows { stmt }))
|
||||
}
|
||||
Cmd::Explain(stmt) => {
|
||||
let program = translate::translate(
|
||||
&*self.schema.borrow(),
|
||||
&self.schema.borrow(),
|
||||
stmt,
|
||||
self.header.clone(),
|
||||
self.pager.clone(),
|
||||
@@ -235,7 +235,7 @@ impl Connection {
|
||||
Cmd::ExplainQueryPlan(stmt) => {
|
||||
match stmt {
|
||||
ast::Stmt::Select(select) => {
|
||||
let plan = prepare_select_plan(&*self.schema.borrow(), select)?;
|
||||
let plan = prepare_select_plan(&self.schema.borrow(), select)?;
|
||||
let (plan, _) = optimize_plan(plan)?;
|
||||
println!("{}", plan);
|
||||
}
|
||||
@@ -257,7 +257,7 @@ impl Connection {
|
||||
match cmd {
|
||||
Cmd::Explain(stmt) => {
|
||||
let program = translate::translate(
|
||||
&*self.schema.borrow(),
|
||||
&self.schema.borrow(),
|
||||
stmt,
|
||||
self.header.clone(),
|
||||
self.pager.clone(),
|
||||
@@ -268,7 +268,7 @@ impl Connection {
|
||||
Cmd::ExplainQueryPlan(_stmt) => todo!(),
|
||||
Cmd::Stmt(stmt) => {
|
||||
let program = translate::translate(
|
||||
&*self.schema.borrow(),
|
||||
&self.schema.borrow(),
|
||||
stmt,
|
||||
self.header.clone(),
|
||||
self.pager.clone(),
|
||||
|
||||
@@ -9,7 +9,6 @@ use crate::types::{Cursor, CursorResult, OwnedRecord, OwnedValue, SeekKey, SeekO
|
||||
use crate::Result;
|
||||
|
||||
use std::cell::{Ref, RefCell};
|
||||
use std::i32;
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -273,7 +272,7 @@ impl BTreeCursor {
|
||||
}
|
||||
}
|
||||
|
||||
if cell_idx >= contents.cell_count() + 1 {
|
||||
if cell_idx > contents.cell_count() {
|
||||
// end
|
||||
let has_parent = self.stack.current() > 0;
|
||||
if has_parent {
|
||||
@@ -875,8 +874,7 @@ impl BTreeCursor {
|
||||
scratch_cells
|
||||
.insert(overflow_cell.index, to_static_buf(&overflow_cell.payload));
|
||||
}
|
||||
*self.write_info.rightmost_pointer.borrow_mut() =
|
||||
page_copy.rightmost_pointer().clone();
|
||||
*self.write_info.rightmost_pointer.borrow_mut() = page_copy.rightmost_pointer();
|
||||
|
||||
self.write_info.page_copy.replace(Some(page_copy));
|
||||
|
||||
@@ -1222,7 +1220,7 @@ impl BTreeCursor {
|
||||
|
||||
fn allocate_page(&self, page_type: PageType, offset: usize) -> Rc<RefCell<Page>> {
|
||||
let page = self.pager.allocate_page().unwrap();
|
||||
btree_init_page(&page, page_type, &*self.database_header.borrow(), offset);
|
||||
btree_init_page(&page, page_type, &self.database_header.borrow(), offset);
|
||||
page
|
||||
}
|
||||
|
||||
@@ -1423,7 +1421,7 @@ impl BTreeCursor {
|
||||
// return SQLITE_CORRUPT_PAGE(pPage);
|
||||
// }
|
||||
// don't count header and cell pointers?
|
||||
nfree = nfree - first_cell as usize;
|
||||
nfree -= first_cell as usize;
|
||||
nfree as u16
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,6 @@ use crate::storage::database::DatabaseStorage;
|
||||
use crate::storage::pager::{Page, Pager};
|
||||
use crate::types::{OwnedRecord, OwnedValue};
|
||||
use crate::{File, Result};
|
||||
use cfg_block::cfg_block;
|
||||
use log::trace;
|
||||
use std::cell::RefCell;
|
||||
use std::pin::Pin;
|
||||
@@ -1191,7 +1190,7 @@ pub fn payload_overflows(
|
||||
|
||||
pub fn checksum_wal(
|
||||
buf: &[u8],
|
||||
wal_header: &WalHeader,
|
||||
_wal_header: &WalHeader,
|
||||
input: (u32, u32),
|
||||
native_endian: bool, // Sqlite interprets big endian as "native"
|
||||
) -> (u32, u32) {
|
||||
|
||||
@@ -159,7 +159,7 @@ impl Wal for WalFile {
|
||||
&page,
|
||||
db_size,
|
||||
write_counter,
|
||||
&*header,
|
||||
&header,
|
||||
checksums,
|
||||
)?;
|
||||
self.last_checksum.replace(checksums);
|
||||
@@ -235,9 +235,9 @@ impl Wal for WalFile {
|
||||
}
|
||||
|
||||
if *self.syncing.borrow() {
|
||||
return Ok(CheckpointStatus::IO);
|
||||
Ok(CheckpointStatus::IO)
|
||||
} else {
|
||||
return Ok(CheckpointStatus::Done);
|
||||
Ok(CheckpointStatus::Done)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::rc::{Rc, Weak};
|
||||
use std::usize;
|
||||
|
||||
use sqlite3_parser::ast;
|
||||
|
||||
|
||||
@@ -2420,7 +2420,7 @@ impl Program {
|
||||
let rows = Rows { stmt };
|
||||
let mut schema = RefCell::borrow_mut(&conn.schema);
|
||||
// TODO: This function below is synchronous, make it not async
|
||||
parse_schema_rows(Some(rows), &mut *schema, conn.pager.io.clone())?;
|
||||
parse_schema_rows(Some(rows), &mut schema, conn.pager.io.clone())?;
|
||||
state.pc += 1;
|
||||
}
|
||||
}
|
||||
@@ -3016,7 +3016,7 @@ fn exec_cast(value: &OwnedValue, datatype: &str) -> OwnedValue {
|
||||
match affinity(datatype) {
|
||||
// NONE Casting a value to a type-name with no affinity causes the value to be converted into a BLOB. Casting to a BLOB consists of first casting the value to TEXT in the encoding of the database connection, then interpreting the resulting byte sequence as a BLOB instead of as TEXT.
|
||||
// Historically called NONE, but it's the same as BLOB
|
||||
Affinity::BLOB => {
|
||||
Affinity::Blob => {
|
||||
// Convert to TEXT first, then interpret as BLOB
|
||||
// TODO: handle encoding
|
||||
let text = value.to_string();
|
||||
@@ -3024,12 +3024,12 @@ fn exec_cast(value: &OwnedValue, datatype: &str) -> OwnedValue {
|
||||
}
|
||||
// TEXT To cast a BLOB value to TEXT, the sequence of bytes that make up the BLOB is interpreted as text encoded using the database encoding.
|
||||
// Casting an INTEGER or REAL value into TEXT renders the value as if via sqlite3_snprintf() except that the resulting TEXT uses the encoding of the database connection.
|
||||
Affinity::TEXT => {
|
||||
Affinity::Text => {
|
||||
// Convert everything to text representation
|
||||
// TODO: handle encoding and whatever sqlite3_snprintf does
|
||||
OwnedValue::Text(Rc::new(value.to_string()))
|
||||
}
|
||||
Affinity::REAL => match value {
|
||||
Affinity::Real => match value {
|
||||
OwnedValue::Blob(b) => {
|
||||
// Convert BLOB to TEXT first
|
||||
let text = String::from_utf8_lossy(b);
|
||||
@@ -3040,7 +3040,7 @@ fn exec_cast(value: &OwnedValue, datatype: &str) -> OwnedValue {
|
||||
OwnedValue::Float(f) => OwnedValue::Float(*f),
|
||||
_ => OwnedValue::Float(0.0),
|
||||
},
|
||||
Affinity::INTEGER => match value {
|
||||
Affinity::Integer => match value {
|
||||
OwnedValue::Blob(b) => {
|
||||
// Convert BLOB to TEXT first
|
||||
let text = String::from_utf8_lossy(b);
|
||||
@@ -3064,7 +3064,7 @@ fn exec_cast(value: &OwnedValue, datatype: &str) -> OwnedValue {
|
||||
}
|
||||
_ => OwnedValue::Integer(0),
|
||||
},
|
||||
Affinity::NUMERIC => match value {
|
||||
Affinity::Numeric => match value {
|
||||
OwnedValue::Blob(b) => {
|
||||
let text = String::from_utf8_lossy(b);
|
||||
cast_text_to_numeric(&text)
|
||||
@@ -3078,11 +3078,11 @@ fn exec_cast(value: &OwnedValue, datatype: &str) -> OwnedValue {
|
||||
}
|
||||
|
||||
enum Affinity {
|
||||
INTEGER,
|
||||
TEXT,
|
||||
BLOB,
|
||||
REAL,
|
||||
NUMERIC,
|
||||
Integer,
|
||||
Text,
|
||||
Blob,
|
||||
Real,
|
||||
Numeric,
|
||||
}
|
||||
|
||||
/// For tables not declared as STRICT, the affinity of a column is determined by the declared type of the column, according to the following rules in the order shown:
|
||||
@@ -3096,26 +3096,26 @@ fn affinity(datatype: &str) -> Affinity {
|
||||
// Note: callers of this function must ensure that the datatype is uppercase.
|
||||
// Rule 1: INT -> INTEGER affinity
|
||||
if datatype.contains("INT") {
|
||||
return Affinity::INTEGER;
|
||||
return Affinity::Integer;
|
||||
}
|
||||
|
||||
// Rule 2: CHAR/CLOB/TEXT -> TEXT affinity
|
||||
if datatype.contains("CHAR") || datatype.contains("CLOB") || datatype.contains("TEXT") {
|
||||
return Affinity::TEXT;
|
||||
return Affinity::Text;
|
||||
}
|
||||
|
||||
// Rule 3: BLOB or empty -> BLOB affinity (historically called NONE)
|
||||
if datatype.contains("BLOB") || datatype.is_empty() {
|
||||
return Affinity::BLOB;
|
||||
return Affinity::Blob;
|
||||
}
|
||||
|
||||
// Rule 4: REAL/FLOA/DOUB -> REAL affinity
|
||||
if datatype.contains("REAL") || datatype.contains("FLOA") || datatype.contains("DOUB") {
|
||||
return Affinity::REAL;
|
||||
return Affinity::Real;
|
||||
}
|
||||
|
||||
// Rule 5: Otherwise -> NUMERIC affinity
|
||||
Affinity::NUMERIC
|
||||
Affinity::Numeric
|
||||
}
|
||||
|
||||
/// When casting a TEXT value to INTEGER, the longest possible prefix of the value that can be interpreted as an integer number
|
||||
@@ -3164,7 +3164,7 @@ fn cast_text_to_real(text: &str) -> OwnedValue {
|
||||
OwnedValue::Float(0.0)
|
||||
}
|
||||
|
||||
/// NUMERIC Casting a TEXT or BLOB value into NUMERIC yields either an INTEGER or a REAL result.
|
||||
/// NUMERIC Casting a TEXT or BLOB value into NUMERIC yields either an INTEGER or a REAL result.
|
||||
/// If the input text looks like an integer (there is no decimal point nor exponent) and the value
|
||||
/// is small enough to fit in a 64-bit signed integer, then the result will be INTEGER.
|
||||
/// Input text that looks like floating point (there is a decimal point and/or an exponent)
|
||||
@@ -3322,7 +3322,7 @@ mod tests {
|
||||
mock.expect_seek_to_last()
|
||||
.return_once(|| Ok(CursorResult::Ok(())));
|
||||
mock.expect_rowid()
|
||||
.return_once(|| Ok(Some(std::i64::MAX as u64)));
|
||||
.return_once(|| Ok(Some(i64::MAX as u64)));
|
||||
mock.expect_seek()
|
||||
.with(predicate::always(), predicate::always())
|
||||
.returning(|rowid, _| {
|
||||
@@ -3343,7 +3343,7 @@ mod tests {
|
||||
mock.expect_seek_to_last()
|
||||
.return_once(|| Ok(CursorResult::Ok(())));
|
||||
mock.expect_rowid()
|
||||
.return_once(|| Ok(Some(std::i64::MAX as u64)));
|
||||
.return_once(|| Ok(Some(i64::MAX as u64)));
|
||||
mock.expect_seek()
|
||||
.with(predicate::always(), predicate::always())
|
||||
.return_once(|_, _| Ok(CursorResult::IO));
|
||||
@@ -3356,7 +3356,7 @@ mod tests {
|
||||
mock.expect_seek_to_last()
|
||||
.return_once(|| Ok(CursorResult::Ok(())));
|
||||
mock.expect_rowid()
|
||||
.return_once(|| Ok(Some(std::i64::MAX as u64)));
|
||||
.return_once(|| Ok(Some(i64::MAX as u64)));
|
||||
mock.expect_seek()
|
||||
.with(predicate::always(), predicate::always())
|
||||
.returning(|_, _| Ok(CursorResult::Ok(true)));
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use limbo_core::{Connection, Database, File, OpenFlags, PlatformIO, Result, RowResult, IO};
|
||||
use log;
|
||||
use rand::prelude::*;
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
use std::cell::RefCell;
|
||||
@@ -203,7 +202,7 @@ fn do_write(env: &mut SimulatorEnv, conn: &mut Rc<Connection>) -> Result<()> {
|
||||
// gen insert query
|
||||
for column in &columns {
|
||||
let value = match column.column_type {
|
||||
ColumnType::Integer => Value::Integer(env.rng.gen_range(std::i64::MIN..std::i64::MAX)),
|
||||
ColumnType::Integer => Value::Integer(env.rng.gen_range(i64::MIN..i64::MAX)),
|
||||
ColumnType::Float => Value::Float(env.rng.gen_range(-1e10..1e10)),
|
||||
ColumnType::Text => Value::Text(gen_random_text(env)),
|
||||
ColumnType::Blob => Value::Blob(gen_random_text(env).as_bytes().to_vec()),
|
||||
@@ -225,7 +224,7 @@ fn do_write(env: &mut SimulatorEnv, conn: &mut Rc<Connection>) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compare_equal_rows(a: &Vec<Vec<Value>>, b: &Vec<Vec<Value>>) {
|
||||
fn compare_equal_rows(a: &[Vec<Value>], b: &[Vec<Value>]) {
|
||||
assert_eq!(a.len(), b.len(), "lengths are different");
|
||||
for (r1, r2) in a.iter().zip(b) {
|
||||
for (v1, v2) in r1.iter().zip(r2) {
|
||||
@@ -279,7 +278,7 @@ fn gen_random_text(env: &mut SimulatorEnv) -> String {
|
||||
let size = env.rng.gen_range(1024..max_size);
|
||||
let mut name = String::new();
|
||||
for i in 0..size {
|
||||
name.push(((i % 26) as u8 + 'A' as u8) as char);
|
||||
name.push(((i % 26) as u8 + b'A') as char);
|
||||
}
|
||||
name
|
||||
} else {
|
||||
@@ -527,7 +526,7 @@ impl limbo_core::File for SimulatorFile {
|
||||
}
|
||||
|
||||
fn size(&self) -> Result<u64> {
|
||||
Ok(self.inner.size()?)
|
||||
self.inner.size()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,12 +572,12 @@ impl Value {
|
||||
Value::Integer(i) => i.to_string(),
|
||||
Value::Float(f) => f.to_string(),
|
||||
Value::Text(t) => format!("'{}'", t.clone()),
|
||||
Value::Blob(vec) => to_sqlite_blob(&vec),
|
||||
Value::Blob(vec) => to_sqlite_blob(vec),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn to_sqlite_blob(bytes: &Vec<u8>) -> String {
|
||||
fn to_sqlite_blob(bytes: &[u8]) -> String {
|
||||
let hex: String = bytes.iter().map(|b| format!("{:02X}", b)).collect();
|
||||
format!("X'{}'", hex)
|
||||
}
|
||||
|
||||
@@ -340,8 +340,8 @@ mod tests {
|
||||
log::debug!("counting");
|
||||
let list_query = "SELECT count(x) FROM test";
|
||||
loop {
|
||||
match conn.query(list_query).unwrap() {
|
||||
Some(ref mut rows) => loop {
|
||||
if let Some(ref mut rows) = conn.query(list_query).unwrap() {
|
||||
loop {
|
||||
match rows.next_row()? {
|
||||
RowResult::Row(row) => {
|
||||
let first_value = &row.values[0];
|
||||
@@ -357,8 +357,7 @@ mod tests {
|
||||
}
|
||||
RowResult::Done => break,
|
||||
}
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user