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
20 changes: 11 additions & 9 deletions src/xsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ impl<'vtab> VTab<'vtab> for XsvTable {
args.table_name.as_str(),
)?;
let vtab = XsvTable {
base: unsafe { mem::zeroed() },
base: unsafe{mem::zeroed()},
db,
input: arguments.filename.clone(),
input: arguments.filename,
header: arguments.header,
delimiter: arguments.delimiter,
quote: arguments.quote,
declared_columns: arguments.columns,
current_path: "".to_owned(),
current_path: String::new(),
current_line_number: 0,
};

Expand Down Expand Up @@ -238,15 +238,15 @@ impl XsvCursor {
))
})?;
let mut cursor = XsvCursor {
base: unsafe { mem::zeroed() },
base: unsafe{mem::zeroed()},
rowid: 0,
paths,
current_path: None,
current_reader: None,
current_line_number: 0,
record,
eof: false,
declared_columns: table.declared_columns.clone(),
declared_columns: table.declared_columns,
table: table as *mut XsvTable,
};
cursor.next().map(|_| cursor)
Expand Down Expand Up @@ -336,14 +336,16 @@ impl VTabCursor for XsvCursor {
}

fn column(&self, context: *mut sqlite3_context, i: c_int) -> Result<()> {
let i = usize::try_from(i)
.map_err(|_| Error::new_message(format!("what the fuck {}", i).as_str()))?;

// Change the content of ErrMsg + Handling Negative Index
if i<0{
return Err(Error::new_message(format!("negative index {}", i).as_str()))?
}
// This will typically only be None when a glob pattern is used, and the 1st sniffed CSV
// has more column than another CSV in the same glob pattern.
// For now we just return NULL for missing columns, not sure how flexible we should be
// across CSV files. If it's a single file, i'm pretty sure it's not flexible
let value = &self.record.get(i);
let i = usize::try_from(i).unwrap(); // Unwrap allow, try_from send Err only for out of range number.
let value = &self.record.get(i);

if let Some(value) = value {
match self.declared_columns.as_ref().and_then(|c| c.get(i)) {
Expand Down
4 changes: 2 additions & 2 deletions src/xsv_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'vtab> VTab<'vtab> for XsvFieldsTable {
_aux: Option<&Self::Aux>,
_args: VTabArguments,
) -> Result<(String, XsvFieldsTable)> {
let base: sqlite3_vtab = unsafe { mem::zeroed() };
let base: sqlite3_vtab = unsafe{mem::zeroed()};

let vtab = XsvFieldsTable { base };

Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct XsvFieldsCursor {
}
impl XsvFieldsCursor {
fn new() -> Result<XsvFieldsCursor> {
let base: sqlite3_vtab_cursor = unsafe { mem::zeroed() };
let base: sqlite3_vtab_cursor = unsafe{mem::zeroed()};
let record = csv::StringRecord::new();

let cursor = XsvFieldsCursor {
Expand Down
15 changes: 7 additions & 8 deletions src/xsv_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'vtab> VTab<'vtab> for XsvReaderTable {
args: VTabArguments,
) -> Result<(String, XsvReaderTable)> {
let arguments = parse_reader_arguments(args.arguments, aux.map(|a| a.to_owned()))?;
let base: sqlite3_vtab = unsafe { mem::zeroed() };
let base: sqlite3_vtab = unsafe{mem::zeroed()};

let vtab = XsvReaderTable {
base,
Expand Down Expand Up @@ -117,7 +117,7 @@ impl XsvReaderCursor<'_> {
columns: &Vec<ColumnDeclaration>,
header: bool,
) -> Result<XsvReaderCursor> {
let base: sqlite3_vtab_cursor = unsafe { mem::zeroed() };
let base: sqlite3_vtab_cursor = unsafe{mem::zeroed()};
let record = csv::StringRecord::new();

let cursor = XsvReaderCursor {
Expand Down Expand Up @@ -198,19 +198,18 @@ impl VTabCursor for XsvReaderCursor<'_> {
}

fn column(&self, context: *mut sqlite3_context, i: c_int) -> Result<()> {
if i < 1 {
if i < 0 {
return Ok(());
}
let i = usize::try_from(i - 1)
.map_err(|_| Error::new_message(format!("what the fuck {}", i).as_str()))?;
let i = usize::try_from(i).unwrap(); // i is positive
let column = self
.columns
.get(i)
.ok_or_else(|| Error::new_message("what the fuck"))?;
.ok_or_else(|| Error::new_message("OutOfRange Index ?"))?;
let s = &self
.record
.get(i)
.ok_or_else(|| Error::new_message(format!("wut {}", i).as_str()))?;
.ok_or_else(|| Error::new_message(format!("wut {}", i)))?;
column.affinity().result_text(context, s)?;
Ok(())
}
Expand Down Expand Up @@ -254,7 +253,7 @@ fn parse_reader_arguments(
_ => (),
},
},
Err(err) => return Err(Error::new_message(err.as_str())),
Err(err) => return Err(Error::new_message(err)),
};
}
let delimiter = delimiter.ok_or_else(|| {
Expand Down
4 changes: 2 additions & 2 deletions src/xsv_rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub struct XsvRowsCursor {
}
impl XsvRowsCursor {
fn new(delimiter: Option<u8>) -> Result<XsvRowsCursor> {
let base: sqlite3_vtab_cursor = unsafe { mem::zeroed() };
let base: sqlite3_vtab_cursor = unsafe{mem::zeroed()};
let record = csv::StringRecord::new();

let cursor = XsvRowsCursor {
Expand Down Expand Up @@ -221,7 +221,7 @@ impl VTabCursor for XsvRowsCursor {
"Error: UTF8 error while reading next row",
)),
_ => Err(Error::new_message(
format!("Error reading: {}", err).as_str(),
format!("Error reading: {}", err),
)),
},
}
Expand Down