private ExportTxtStmtRunner(INotebook notebook, ScriptEnv env, ScriptRunner runner, Ast.ExportTxtStmt stmt)
        {
            _notebook = notebook;
            _env      = env;
            _runner   = runner;
            _stmt     = stmt;

            _filePath = GetFilePath();

            foreach (var option in _stmt.OptionsList.GetOptionKeys())
            {
                switch (option)
                {
                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($"\"{option}\" is not a recognized option name.");
                }
            }

            if (_fileEncoding == null)
            {
                _fileEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
            }
        }
Esempio n. 2
0
        private Ast.ExportTxtStmt ParseExportTxtStmt(TokenQueue q)   // or null
        {
            var stmt = new Ast.ExportTxtStmt {
                SourceToken = q.SourceToken
            };
            var start = q.GetLocation();

            if (!q.TakeMaybe("export"))
            {
                q.Jump(start); return(null);
            }
            if (!q.TakeMaybe("txt", "text"))
            {
                q.Jump(start); return(null);
            }
            stmt.FilenameExpr = ParseExpr(q);
            q.Take("from");
            q.Take("(");
            stmt.SelectStmt = ParseSqlStmt(q, "select-stmt");
            q.Take(")");
            if (q.TakeMaybe("options"))
            {
                stmt.OptionsList = Check(q, ParseOptionsList(q));
            }
            ConsumeSemicolon(q);
            return(stmt);
        }
 private void ExecuteExportTxtStmt(Ast.ExportTxtStmt stmt, ScriptEnv env)
 {
     try {
         ExportTxtStmtRunner.Run(_notebook, env, this, stmt);
     } catch (Exception ex) {
         Throw(env, -1, ex.Message, -1);
     }
 }
        // must be run from the SQLite thread
        public static void Run(INotebook notebook, ScriptEnv env, ScriptRunner runner, Ast.ExportTxtStmt stmt)
        {
            var exporter = new ExportTxtStmtRunner(notebook, env, runner, stmt);

            exporter.Export();
        }