mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-30 06:01:36 +08:00
Fix escape_double_quote
This commit is contained in:
parent
38209ffef3
commit
1dd5c49937
@ -47,7 +47,7 @@ impl VTab<CSVTabCursor> for CSVTab {
|
||||
}
|
||||
let filename = try!(str::from_utf8(c_filename));
|
||||
let mut reader = try!(csv::Reader::from_file(filename)).has_headers(false); // TODO flexible ?
|
||||
let mut cols = Vec::new();
|
||||
let mut cols: Vec<String> = Vec::new();
|
||||
|
||||
let args = &args[4..];
|
||||
for c_arg in args {
|
||||
@ -64,7 +64,7 @@ impl VTab<CSVTabCursor> for CSVTab {
|
||||
} else if uc.contains("NO_QUOTE") {
|
||||
reader = reader.quote(0);
|
||||
} else {
|
||||
cols.push(escape_double_quote(String::from(arg)));
|
||||
cols.push(escape_double_quote(arg).into_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,13 +13,13 @@ pub fn create_int_array(conn: &Connection, name: &str) -> Result<Rc<RefCell<Vec<
|
||||
let array = Rc::new(RefCell::new(Vec::new()));
|
||||
try!(conn.create_module(name, &INT_ARRAY_MODULE, Some(array.clone())));
|
||||
try!(conn.execute_batch(&format!("CREATE VIRTUAL TABLE temp.\"{0}\" USING \"{0}\"",
|
||||
escape_double_quote(name.to_string()))));
|
||||
escape_double_quote(name))));
|
||||
Ok(array)
|
||||
}
|
||||
|
||||
pub fn drop_int_array(conn: &Connection, name: &str) -> Result<()> {
|
||||
conn.execute_batch(&format!("DROP TABLE temp.\"{0}\"",
|
||||
escape_double_quote(name.to_string())))
|
||||
escape_double_quote(name)))
|
||||
}
|
||||
|
||||
init_module!(INT_ARRAY_MODULE, IntArrayVTab, IntArrayVTabCursor,
|
||||
|
@ -1,5 +1,7 @@
|
||||
//! Create virtual tables.
|
||||
//! (See http://sqlite.org/vtab.html)
|
||||
use std::borrow::Cow;
|
||||
use std::borrow::Cow::{Borrowed, Owned};
|
||||
use std::ffi::CString;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
@ -128,12 +130,12 @@ pub fn declare_vtab(db: *mut ffi::sqlite3, sql: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
/// Escape double-quote (`"`) character occurences by doubling them (`""`).
|
||||
pub fn escape_double_quote(identifier: String) -> String {
|
||||
pub fn escape_double_quote<'a>(identifier: &'a str) -> Cow<'a, str> {
|
||||
if identifier.contains('"') {
|
||||
// escape quote by doubling them
|
||||
identifier.replace("\"", "\"\"")
|
||||
Owned(identifier.replace("\"", "\"\""))
|
||||
} else {
|
||||
identifier
|
||||
Borrowed(identifier)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user