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