Exemple #1
0
        public void CheckTable(MetaColumn column)
        {
            if (_source == null)
            {
                return;
            }

            _information = "";
            _error       = "";

            if (IsMasterTable && IsSQL && string.IsNullOrEmpty(Sql))
            {
                _information = Helper.FormatMessage("No Select SQL Statement defined for the Master table...");
                return;
            }
            if (IsMasterTable && !IsSQL && string.IsNullOrEmpty(DefinitionScript))
            {
                _information = Helper.FormatMessage("No Script defined for the Master table...");
                return;
            }

            try
            {
                if (IsSQL)
                {
                    string colNames = "", groupByNames = "";
                    foreach (var col in Columns)
                    {
                        if (column != null && col != column)
                        {
                            continue;
                        }
                        Helper.AddValue(ref colNames, ",", col.Name);
                        if (!col.IsAggregate)
                        {
                            Helper.AddValue(ref groupByNames, ",", col.Name);
                        }
                    }
                    if (string.IsNullOrEmpty(colNames))
                    {
                        colNames = "1";
                    }

                    string sql = string.Format("SELECT {0} FROM {1} WHERE 1=0", colNames, FullSQLName);

                    if (!string.IsNullOrEmpty(WhereSQL))
                    {
                        sql += string.Format("\r\nAND ({0})", Helper.ParseRazor(WhereSQL, this));
                    }
                    if (Columns.Exists(i => i.IsAggregate) && !string.IsNullOrEmpty(groupByNames))
                    {
                        sql += string.Format("\r\nGROUP BY {0}", groupByNames);
                    }
                    _error = _source.CheckSQL(sql, new List <MetaTable>()
                    {
                        this
                    }, null, false);
                }
                else
                {
                    BuildNoSQLTable(true);
                }

                if (string.IsNullOrEmpty(_error))
                {
                    _information = "Table checked successfully";
                }
                else
                {
                    _information = "Error got when checking table.";
                }
                if (column != null)
                {
                    column.Error = _error;
                    if (string.IsNullOrEmpty(column.Error))
                    {
                        column.Information = "Column checked successfully";
                    }
                    else
                    {
                        column.Information = "Error got when checking column.";
                    }
                    column.Information = Helper.FormatMessage(column.Information);
                }
            }
            catch (TemplateCompilationException ex)
            {
                _error = Helper.GetExceptionMessage(ex);
            }
            catch (Exception ex)
            {
                _error       = ex.Message;
                _information = "Error got when checking the table.";
            }
            _information = Helper.FormatMessage(_information);
            UpdateEditorAttributes();
        }
Exemple #2
0
        /// <summary>
        /// Check the table. If a MetaColumn is specified, only the column is checked.
        /// </summary>
        public void CheckTable(MetaColumn column)
        {
            if (_source == null)
            {
                return;
            }

            Information = "";
            Error       = "";

            if (IsMasterTable && IsSQL && string.IsNullOrEmpty(Sql))
            {
                Information = Helper.FormatMessage("No SQL Select Statement defined for the Master table...");
                return;
            }
            if (IsMasterTable && !IsSQL && string.IsNullOrEmpty(DefinitionScript))
            {
                Information = Helper.FormatMessage("No Script defined for the Master table...");
                return;
            }

            try
            {
                if (IsSQL)
                {
                    string colNames = "", groupByNames = "";
                    foreach (var col in Columns)
                    {
                        if (column != null && col != column)
                        {
                            continue;
                        }
                        Helper.AddValue(ref colNames, ",", col.Name);
                        if (!col.IsAggregate)
                        {
                            Helper.AddValue(ref groupByNames, ",", col.Name);
                        }
                    }
                    if (string.IsNullOrEmpty(colNames))
                    {
                        colNames = "1";
                    }

                    string CTE = "", name = "";
                    GetExecSQLName(ref CTE, ref name);
                    string sql = string.Format("{0}SELECT {1} FROM {2} WHERE 1=0", CTE, colNames, name);

                    if (!string.IsNullOrWhiteSpace(WhereSQL))
                    {
                        var where = RazorHelper.CompileExecute(WhereSQL, this);
                        if (!string.IsNullOrWhiteSpace(where))
                        {
                            sql += string.Format("\r\nAND ({0})", RazorHelper.CompileExecute(where, this));
                        }
                    }
                    if (Columns.Exists(i => i.IsAggregate) && !string.IsNullOrEmpty(groupByNames))
                    {
                        sql += string.Format("\r\nGROUP BY {0}", groupByNames);
                    }
                    Error = _source.CheckSQL(sql, new List <MetaTable>()
                    {
                        this
                    }, null, false);
                }
                else
                {
                    BuildNoSQLTable(true);
                }

                if (string.IsNullOrEmpty(Error))
                {
                    Information = "Table checked successfully";
                }
                else
                {
                    Information = "Error got when checking table.";
                }
                if (column != null)
                {
                    column.Error = Error;
                    if (string.IsNullOrEmpty(column.Error))
                    {
                        column.Information = "Column checked successfully";
                    }
                    else
                    {
                        column.Information = "Error got when checking column.";
                    }
                    column.Information = Helper.FormatMessage(column.Information);
                }
            }
            catch (TemplateCompilationException ex)
            {
                Error = Helper.GetExceptionMessage(ex);
            }
            catch (Exception ex)
            {
                Error       = ex.Message;
                Information = "Error got when checking the table.";
            }
            Information = Helper.FormatMessage(Information);
        }