private ImportTxtStmtRunner(Notebook notebook, ScriptEnv env, ScriptRunner runner, Ast.ImportTxtStmt stmt) { _notebook = notebook; _env = env; _runner = runner; _stmt = stmt; _tableName = _runner.EvaluateIdentifierOrExpr(_stmt.TableName, _env); _lineNumberColumnName = _stmt.LineNumberColumnName == null ? null : _runner.EvaluateIdentifierOrExpr(_stmt.LineNumberColumnName, _env); _textColumnName = _stmt.TextColumnName == null ? null : _runner.EvaluateIdentifierOrExpr(_stmt.TextColumnName, _env); foreach (var option in _stmt.OptionsList.GetOptionKeys()) { switch (option) { case "SKIP_LINES": _skipLines = _stmt.OptionsList.GetOptionLong(option, _runner, _env, 0, minValue: 0); break; case "TAKE_LINES": _takeLines = _stmt.OptionsList.GetOptionLong(option, _runner, _env, -1, minValue: -1); if (_takeLines == -1) { _takeLines = null; } break; case "TRUNCATE_EXISTING_TABLE": _truncateExistingTable = _stmt.OptionsList.GetOptionBool(option, _runner, _env, false); break; case "TEMPORARY_TABLE": _temporaryTable = _stmt.OptionsList.GetOptionBool(option, _runner, _env, false); break; case "FILE_ENCODING": _fileEncoding = _stmt.OptionsList.GetOptionEncoding(option, _runner, _env); break; default: throw new Exception($"\"{option}\" is not a recognized option name."); } } }
private readonly Encoding _fileEncoding; // or null for automatic // must be run from the SQLite thread public static void Run(Notebook notebook, ScriptEnv env, ScriptRunner runner, Ast.ImportTxtStmt stmt) { var importer = new ImportTxtStmtRunner(notebook, env, runner, stmt); SqlUtil.WithTransaction(notebook, importer.Import); }
private void ExecuteImportTxtStmt(Ast.ImportTxtStmt stmt, ScriptEnv env) { ImportTxtStmtRunner.Run(_notebook, env, this, stmt); }