Example #1
0
        private static void CreateUserType(IQuery query)
        {
            var typeName = ObjectName.Parse("APP.test_type");
            var typeInfo = new UserTypeInfo(typeName);

            typeInfo.AddMember("a", PrimitiveTypes.String());
            typeInfo.AddMember("b", PrimitiveTypes.Integer());

            query.Access().CreateType(typeInfo);
        }
        protected override bool OnSetUp(string testName, IQuery query)
        {
            var typeName = ObjectName.Parse("APP.type1");
            var typeInfo = new UserTypeInfo(typeName);

            typeInfo.AddMember("a", PrimitiveTypes.Integer());
            typeInfo.AddMember("b", PrimitiveTypes.DateTime());
            query.Access().CreateObject(typeInfo);

            return(true);
        }
        protected override void OnAfterSetup(string testName)
        {
            if (testName == "UnderType")
            {
                var typeName = ObjectName.Parse("APP.parentType");
                var typeInfo = new UserTypeInfo(typeName);
                typeInfo.AddMember("id", PrimitiveTypes.Integer());
                typeInfo.AddMember("name", PrimitiveTypes.String());

                AdminQuery.Access().CreateObject(typeInfo);
            }

            base.OnAfterSetup(testName);
        }
        protected override bool OnSetUp(string testName, IQuery query)
        {
            if (testName.EndsWith("WithUserType"))
            {
                var typeName = ObjectName.Parse("APP.type1");
                var typeInfo = new UserTypeInfo(typeName);
                typeInfo.AddMember("a", PrimitiveTypes.String());
                typeInfo.AddMember("b", PrimitiveTypes.Integer());

                query.Access().CreateObject(typeInfo);
            }

            CreateTestTable(query, testName);
            return(true);
        }
        public static void TestSetUp()
        {
            var typeInfo = new UserTypeInfo(ObjectName.Parse("APP.test_type"));

            typeInfo.AddMember("a", PrimitiveTypes.Integer());
            Type = new UserType(typeInfo);
        }
        protected override void ExecuteStatement(ExecutionContext context)
        {
            //if (!context.User.CanCreateInSchema(TypeName.ParentName))
            //	throw new SecurityException(String.Format("The user '{0}' has no rights to create in schema '{1}'.",
            //		context.User.Name, TypeName.ParentName));

            if (ParentTypeName != null)
            {
                if (!context.DirectAccess.TypeExists(ParentTypeName))
                {
                    throw new StatementException(String.Format("The type '{0}' inherits from the type '{1}' that does not exist.",
                                                               TypeName, ParentTypeName));
                }

                if (context.DirectAccess.IsTypeSealed(ParentTypeName))
                {
                    throw new StatementException(String.Format("The type '{0}' is sealed and cannot be inherited by '{1}'.",
                                                               ParentTypeName, TypeName));
                }
            }

            if (context.DirectAccess.TypeExists(TypeName))
            {
                if (!ReplaceIfExists)
                {
                    throw new StatementException(String.Format("The type '{0}' already exists.", TypeName));
                }

                context.DirectAccess.DropType(TypeName);
            }

            var typeInfo = new UserTypeInfo(TypeName, ParentTypeName)
            {
                IsAbstract = IsAbstract,
                IsSealed   = IsSealed
            };

            foreach (var member in Members)
            {
                typeInfo.AddMember(member);
            }

            typeInfo.Owner = context.User.Name;

            context.DirectAccess.CreateType(typeInfo);
            context.DirectAccess.GrantOn(DbObjectType.Type, TypeName, context.User.Name, PrivilegeSets.TableAll, true);
        }