Example #1
0
        public IEnumerable <string> GenerateDataDefintionLanguage(Dialect dialect)
        {
            var formatter = new DdlFormatter();

            foreach (var s in _versioningStrategy.EnsureDbObjectsStatements)
            {
                if (!String.IsNullOrWhiteSpace(s))
                {
                    yield return(formatter.Format(s).TrimEnd());
                }
            }
            foreach (var m in _migrations)
            {
                foreach (var o in m.Operations)
                {
                    foreach (var s in o.GetStatements(dialect))
                    {
                        if (!String.IsNullOrWhiteSpace(s))
                        {
                            yield return(formatter.Format(s).TrimEnd());
                        }
                    }
                }
                var updateVersionStatements = _versioningStrategy.GetUpdateVersionStatements(m.Version, m.Context);
                foreach (var s in updateVersionStatements)
                {
                    if (!String.IsNullOrWhiteSpace(s))
                    {
                        yield return(formatter.Format(s).TrimEnd());
                    }
                }
            }
        }
Example #2
0
        public static string ApplyFormat(string sql)
        {
            if (string.IsNullOrWhiteSpace(sql))
            {
                return string.Empty;
            }

            sql = sql.Trim();

            if (sql.ToLowerInvariant().StartsWith("create table"))
            {
                return sql;
            }

            if (sql.ToLowerInvariant().StartsWith("alter table") || sql.ToLowerInvariant().StartsWith("comment on"))
            {
                sql = new DdlFormatter().Format(sql);
            }
            else
            {
                sql = new BasicFormatter().Format(sql).Trim();
            }

            return FormatParams(sql);
        }