public static CodeExpression BuildFromCheckConstraintDefinition(string schemaName, DataTable table, string check_name, string check_definition, out bool hasError, out string errorText)
        {
            string       select_statement = "SELECT colx = IIF((" + check_definition + "), 1, 0) FROM " + schemaName + ".[" + table.TableName + "] WHERE " + check_definition;
            TSqlFragment sqlF             = ScriptDomFacade.Parse(select_statement);
            IIFVisitor   iif_visitor      = new IIFVisitor();

            sqlF.Accept(iif_visitor);
            if (iif_visitor.result == null)
            {
                throw new NotSupportedException("Expression 'IIF' could not be found:" + sqlF.AsText());
            }

            BooleanExpression iif_predicate = iif_visitor.result.Predicate;

            //if (iif_visitor != null)
            //{
            //    //return null; // comment out if it needed
            //}

            //Console.WriteLine("");
            //Console.WriteLine("==== " + check_name + " ============");
            //Console.WriteLine(ScriptDomFacade.GenerateScript(iif_predicate));
            //Console.WriteLine("-------------------------------------------");
            //Console.WriteLine("");

            var databaseMetadata = new DatabaseMetadataOnTable(table);

            hasError  = false;
            errorText = null;
            return(BooleanExpressionGeneratorVisitor.TryBuildFromFragment(databaseMetadata, iif_predicate, ref hasError, ref errorText));
        }
        internal static cs.CodeExpression TryBuildFromFragment(IDatabaseMetadataProvider databaseMetadata, TSqlFragment node, ref bool hasError, ref string error)
        {
            var vstor = new BooleanExpressionGeneratorVisitor(databaseMetadata, node);

            node.Accept(vstor);
            if (vstor.HasError())
            {
                //Console.WriteLine(vstor.lastError);
                hasError = true;
                error    = vstor.lastError;
                return(null);
            }
            //hasError = false;
            //error = null;
            return(vstor.BuildResult());
        }