Example #1
0
        public void RefFreeViewTest()
        {
            var model  = PersistentModel.Compile(@"
class a prototype=dbtable
	string Code
	string Name
class b prototype=dbtable
	string Code
	ref a
	view Full
		selffields
		reffields free
			by a, nosuch
			use Code Name NoSuch
");
            var view   = model["b"].SqlObjects.OfType <SqlView>().First();
            var writer = new SqlViewWriter(view)
            {
                NoComment = true
            };
            var res = writer.ToString();

            Console.WriteLine(res.Replace("\"", "\"\""));
            Assert.AreEqual(@"IF OBJECT_ID('""dbo"".""bFull""') IS NOT NULL DROP VIEW ""dbo"".""bFull"";
GO
CREATE VIEW ""dbo"".""bFull"" AS SELECT
""id"", --
""code"", --
""a"", --
(select x.""code"" from ""dbo"".""a"" x where x.""id"" = ""dbo"".""b"".""a"") as aCode,
(select x.""name"" from ""dbo"".""a"" x where x.""id"" = ""dbo"".""b"".""a"") as aName,

1 as __TERMINAL FROM ""dbo"".""b""
".Trim(), res.Trim());
        }
Example #2
0
        public void ViewWithFromTest(string from, string result)
        {
            var model = PersistentModel.Compile(@"
class a prototype=dbtable schema=test
    view y
    view x from='" + from + @"'	
");
            var cls   = model["a"];

            Assert.AreEqual("test", cls.Schema);
            var f      = cls.SqlObjects.OfType <SqlView>().Last();
            var writer = new SqlViewWriter(f)
            {
                Dialect = DbDialect.SqlServer, NoComment = true
            };
            var res = writer.ToString();

            Console.WriteLine(res.Replace("\"", "\"\""));
            Assert.AreEqual(@"IF OBJECT_ID('""test"".""ax""') IS NOT NULL DROP VIEW ""test"".""ax"";
GO
CREATE VIEW ""test"".""ax"" AS SELECT

1 as __TERMINAL FROM ZZZZZZZ


GO".Replace("ZZZZZZZ", result).Trim().Replace("\r", ""), res.Trim().Replace("\r", ""));
        }
Example #3
0
        public void BaseViewTest()
        {
            var model  = PersistentModel.Compile(@"
class a prototype=dbtable
	string Code
	view Full 
		selffields
");
            var view   = model["a"].SqlObjects.OfType <SqlView>().First();
            var writer = new SqlViewWriter(view)
            {
                NoComment = true
            };
            var res = writer.ToString();

            Console.WriteLine(res.Replace("\"", "\"\""));
            Assert.AreEqual(@"IF OBJECT_ID('""dbo"".""aFull""') IS NOT NULL DROP VIEW ""dbo"".""aFull"";
GO
CREATE VIEW ""dbo"".""aFull"" AS SELECT
""id"", --
""code"", --

1 as __TERMINAL FROM ""dbo"".""a""".Trim(), res.Trim());
        }