run and execute SQL statements and commands from a file, against a context with the given print options
(
ctx: &dyn CliSessionContext,
reader: &mut BufReader<File>,
print_options: &PrintOptions,
)
| 65 | |
| 66 | /// run and execute SQL statements and commands from a file, against a context with the given print options |
| 67 | pub async fn exec_from_lines( |
| 68 | ctx: &dyn CliSessionContext, |
| 69 | reader: &mut BufReader<File>, |
| 70 | print_options: &PrintOptions, |
| 71 | ) -> Result<()> { |
| 72 | let mut query = "".to_owned(); |
| 73 | |
| 74 | for line in reader.lines() { |
| 75 | match line { |
| 76 | Ok(line) if line.starts_with("#!") => { |
| 77 | continue; |
| 78 | } |
| 79 | Ok(line) if line.starts_with("--") => { |
| 80 | continue; |
| 81 | } |
| 82 | Ok(line) => { |
| 83 | let line = line.trim_end(); |
| 84 | query.push_str(line); |
| 85 | if line.ends_with(';') { |
| 86 | match exec_and_print(ctx, print_options, query).await { |
| 87 | Ok(_) => {} |
| 88 | Err(err) => eprintln!("{err}"), |
| 89 | } |
| 90 | query = "".to_string(); |
| 91 | } else { |
| 92 | query.push('\n'); |
| 93 | } |
| 94 | } |
| 95 | _ => { |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // run the left over query if the last statement doesn't contain ‘;’ |
| 102 | // ignore if it only consists of '\n' |
| 103 | if query.contains(|c| c != '\n') { |
| 104 | exec_and_print(ctx, print_options, query).await?; |
| 105 | } |
| 106 | |
| 107 | Ok(()) |
| 108 | } |
| 109 | |
| 110 | pub async fn exec_from_files( |
| 111 | ctx: &dyn CliSessionContext, |
no test coverage detected
searching dependent graphs…