コード例 #1
0
        private static void SetCheckConstraint(ExecuteNullStatement statement, Dictionary <string, Table> tables, List <Token> tokens)
        {
            string constraint = null;
            var    finder     = new TokenFinder(tokens);
            var    tableName  = finder.GetIdAfterToken("TOKEN_TABLE");
            var    isCheck    = finder.GetTokenAfterToken("TOKEN_CHECK", "TOKEN_ID");
            var    isAll      = finder.GetTokenAfterToken("TOKEN_ALL", "TOKEN_CONSTRAINT");

            if (isAll == null)
            {
                constraint = finder.GetTokenAfterToken("TOKEN_ID", "TOKEN_CONSTRAINT");
                constraint = Helper.CleanName(constraint);
            }
            var tc          = Helper.FindTable(tableName, tables);
            var constraints = tc.Table.ForeignKeyConstraints;

            if (isAll != null)
            {
                foreach (var keyConstraint in constraints)
                {
                    keyConstraint.CheckThrowsException = isCheck != null;
                }
            }
            else
            {
                var keyConstraint = constraints.SingleOrDefault(c => c.Name == constraint);
                if (keyConstraint == null)
                {
                    throw new SqlInvalidConstraintException(constraint);
                }

                keyConstraint.CheckThrowsException = isCheck != null;
            }
        }
コード例 #2
0
        private static void SetIdentityInsert(ExecuteNullStatement statement, Dictionary <string, Table> tables, List <Token> tokens)
        {
            var finder    = new TokenFinder(tokens);
            var tableName = finder.GetIdAfterToken("TOKEN_IDENTITY_INSERT");
            var isOn      = finder.GetTokenAfterToken("TOKEN_ON", "TOKEN_ID");
            var tc        = Helper.FindTable(tableName, tables);

            tc.Table.Options[Table.OptionEnum.IdentityInsert] = (isOn != null ? "on" : "off");
        }
コード例 #3
0
        private static void SetGlobalVariable(ExecuteNullStatement statement, Dictionary <string, Table> tables, List <Token> tokens)
        {
            var finder        = new TokenFinder(tokens);
            var variableName  = finder.GetIdAfterToken("TOKEN_SET", isSingleTokenId: true);
            var variableValue = finder.GetTokenAfterToken("TOKEN_ID", "TOKEN_ID");
            var options       = ((MemoryDbConnection )statement._Command.Connection).GetMemoryDatabase( ).Options;

            if (string.IsNullOrWhiteSpace(variableName) == false &&
                string.IsNullOrWhiteSpace(variableValue) == false &&
                options.ContainsKey(variableName))
            {
                if (variableValue == "NULL")
                {
                    variableValue = null;
                }

                options[variableName] = variableValue;
            }
        }