2022-04-20 04:58:21 +00:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
2022-11-23 00:58:11 +00:00
|
|
|
#[cfg(feature = "sqlite")]
|
2022-04-20 04:58:21 +00:00
|
|
|
#[test]
|
|
|
|
fn can_query_single_table() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.db
|
2022-07-31 19:36:14 +00:00
|
|
|
| query db "select * from strings"
|
2022-04-20 04:58:21 +00:00
|
|
|
| where x =~ ell
|
|
|
|
| length
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "4");
|
|
|
|
}
|
|
|
|
|
2022-11-23 00:58:11 +00:00
|
|
|
#[cfg(feature = "sqlite")]
|
2022-04-20 04:58:21 +00:00
|
|
|
#[test]
|
|
|
|
fn invalid_sql_fails() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
open sample.db
|
2022-07-31 19:36:14 +00:00
|
|
|
| query db "select *asdfasdf"
|
2022-04-20 04:58:21 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("syntax error"));
|
|
|
|
}
|
|
|
|
|
2022-11-23 00:58:11 +00:00
|
|
|
#[cfg(feature = "sqlite")]
|
2022-04-20 04:58:21 +00:00
|
|
|
#[test]
|
|
|
|
fn invalid_input_fails() {
|
|
|
|
let actual = nu!(
|
2022-04-24 09:29:21 +00:00
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
2022-04-20 04:58:21 +00:00
|
|
|
r#"
|
2022-07-31 19:36:14 +00:00
|
|
|
"foo" | query db "select * from asdf"
|
2022-04-20 04:58:21 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-04-24 09:29:21 +00:00
|
|
|
assert!(actual.err.contains("can't convert string"));
|
2022-04-20 04:58:21 +00:00
|
|
|
}
|