private void ExecuteSqlStmt(Ast.SqlStmt stmt, ScriptEnv env)
        {
            foreach (var beforeStmt in stmt.RunBefore)
            {
                ExecuteStmt(beforeStmt, env);
                if (env.DidThrow)
                {
                    return;
                }
            }

            try {
                var dt = _notebook.Query(stmt.Sql, env.Vars);
                if (dt.Columns.Any())
                {
                    env.Output.DataTables.Add(dt);
                }
            } finally {
                foreach (var afterStmt in stmt.RunAfter)
                {
                    ExecuteStmt(afterStmt, env);
                    if (env.DidThrow)
                    {
                        break;
                    }
                }
            }
        }
        private void Export()
        {
            var fileMode = _truncateExistingFile ? FileMode.Create : FileMode.Append;

            using (var stream = File.Open(_filePath, fileMode, FileAccess.Write, FileShare.None))
                using (var writer = new StreamWriter(stream, _fileEncoding)) {
                    var sdt = _notebook.Query(_stmt.SelectStmt.Sql, _env.Vars);
                    foreach (var row in sdt.Rows)
                    {
                        writer.WriteLine(string.Join("", row));
                    }
                }
        }
Esempio n. 3
0
        public static void VerifyColumnsExist(string[] colNames, string tableName, INotebook notebook)
        {
            var tableInfo      = notebook.Query($"PRAGMA TABLE_INFO ({tableName.DoubleQuote()})");
            var nameColIndex   = tableInfo.GetIndex("name");
            var actualColNames = tableInfo.Rows.Select(x => x[nameColIndex].ToString().ToLower()).ToList();

            foreach (var name in colNames.Where(x => x != null))
            {
                if (!actualColNames.Contains(name.ToLower()))
                {
                    throw new Exception($"The table \"{tableName}\" does not contain the column \"{name}\".");
                }
            }
        }