Remove regex dependency from query_sql. Fixes #771.
This commit is contained in:
parent
f65512158b
commit
ad2b646700
2 changed files with 20 additions and 9 deletions
|
@ -4,7 +4,6 @@ version = "0.0.1"
|
||||||
workspace = ".."
|
workspace = ".."
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "0.2"
|
|
||||||
|
|
||||||
[dependencies.mentat_core]
|
[dependencies.mentat_core]
|
||||||
path = "../core"
|
path = "../core"
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
// specific language governing permissions and limitations under the License.
|
// specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
extern crate regex;
|
|
||||||
#[macro_use] extern crate mentat_core;
|
#[macro_use] extern crate mentat_core;
|
||||||
extern crate mentat_query;
|
extern crate mentat_query;
|
||||||
extern crate mentat_query_algebrizer;
|
extern crate mentat_query_algebrizer;
|
||||||
|
@ -559,15 +558,21 @@ impl QueryFragment for FromClause {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `var` is something like `?foo99-people`.
|
||||||
|
/// Trim the `?` and escape the rest. Prepend `i` to distinguish from
|
||||||
|
/// the inline value space `v`.
|
||||||
|
fn format_select_var(var: &str) -> String {
|
||||||
|
use std::iter::once;
|
||||||
|
let without_question = var.split_at(1).1;
|
||||||
|
let replaced_iter = without_question.chars().map(|c|
|
||||||
|
if c.is_ascii_alphanumeric() { c } else { '_' });
|
||||||
|
// Prefix with `i` (Avoiding this copy is probably not worth the trouble but whatever).
|
||||||
|
once('i').chain(replaced_iter).collect()
|
||||||
|
}
|
||||||
|
|
||||||
impl SelectQuery {
|
impl SelectQuery {
|
||||||
fn push_variable_param(&self, var: &Variable, out: &mut QueryBuilder) -> BuildQueryResult {
|
fn push_variable_param(&self, var: &Variable, out: &mut QueryBuilder) -> BuildQueryResult {
|
||||||
// `var` is something like `?foo99-people`.
|
let bind_param = format_select_var(var.as_str());
|
||||||
// Trim the `?` and escape the rest. Prepend `i` to distinguish from
|
|
||||||
// the inline value space `v`.
|
|
||||||
let re = regex::Regex::new("[^a-zA-Z_0-9]").unwrap();
|
|
||||||
let without_question = var.as_str().split_at(1).1;
|
|
||||||
let replaced = re.replace_all(without_question, "_");
|
|
||||||
let bind_param = format!("i{}", replaced); // We _could_ avoid this copying.
|
|
||||||
out.push_bind_param(bind_param.as_str())
|
out.push_bind_param(bind_param.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -817,4 +822,11 @@ mod tests {
|
||||||
assert!(args.is_empty());
|
assert!(args.is_empty());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_format_select_var() {
|
||||||
|
assert_eq!(format_select_var("?foo99-people"), "ifoo99_people");
|
||||||
|
assert_eq!(format_select_var("?FOO99-pëople.123"), "iFOO99_p_ople_123");
|
||||||
|
assert_eq!(format_select_var("?foo①bar越"), "ifoo_bar_");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue