// must be run from the SQLite thread public static void Run(Notebook notebook, ScriptEnv env, ScriptRunner runner, Ast.ExportCsvStmt stmt, CancellationToken cancel ) { ExportCsvStmtRunner exporter = new(notebook, env, runner, stmt, cancel); exporter.Export(); }
private ExportCsvStmtRunner(Notebook notebook, ScriptEnv env, ScriptRunner runner, Ast.ExportCsvStmt stmt, CancellationToken cancel ) { _notebook = notebook; _env = env; _runner = runner; _stmt = stmt; _cancel = cancel; _filePath = GetFilePath(); foreach (var option in _stmt.OptionsList.GetOptionKeys()) { switch (option) { case "HEADER_ROW": _headerRow = _stmt.OptionsList.GetOptionBool(option, _runner, _env, true); break; case "SEPARATOR": { var separator = _stmt.OptionsList.GetOption(option, _runner, _env, ","); if (separator.Length != 1) { throw new Exception("EXPORT CSV: The separator must be a single character."); } _separator = separator[0]; break; } case "TRUNCATE_EXISTING_FILE": _truncateExistingFile = _stmt.OptionsList.GetOptionBool(option, _runner, _env, false); break; case "FILE_ENCODING": _fileEncoding = _stmt.OptionsList.GetOptionEncoding(option, _runner, _env); break; default: throw new Exception($"EXPORT CSV: \"{option}\" is not a recognized option name."); } } if (_fileEncoding == null) { _fileEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false); } }
private void ExecuteExportCsvStmt(Ast.ExportCsvStmt stmt, ScriptEnv env) { Notebook.WithCancellationToken(cancel => ExportCsvStmtRunner.Run(_notebook, env, this, stmt, cancel)); }