示例#1
0
        public virtual bool AnalyzeDatabaseData(out string msg)
        {
            msg = null;
            if (tablesToBeAnalyzed.Count > 0)
            {
                DbTable t = tablesToBeAnalyzed.First();
                tablesToBeAnalyzed.RemoveAt(0);
                msg = t.AnalyzeData();
                return(true);
            }
            else if (columnsToBeAnalyzed.Count > 0)
            {
                DbColumn c = columnsToBeAnalyzed.First();
                columnsToBeAnalyzed.RemoveAt(0);
                msg = c.AnalyzeData();
                return(true);
            }
            else
            {
                foreach (DbColumn c in DbColumn.allColumns)
                {
                    if (c.lastAnalyzed == 0)
                    {
                        columnsToBeAnalyzed.Insert(0, c);
                    }
                }

                if (columnsToBeAnalyzed.Count > 0)
                {
                    return(true);
                }

                foreach (DbTable t in tables.Values)
                {
                    if (t.lastAnalyzed == 0)
                    {
                        tablesToBeAnalyzed.Insert(0, t);
                    }
                    else if (!t.recentlyAnalyzed)
                    {
                        tablesToBeAnalyzed.Add(t);
                    }
                }
                if (tablesToBeAnalyzed.Count > 0)
                {
                    return(true);
                }

                foreach (DbColumn c in DbColumn.allColumns)
                {
                    if (!c.recentlyAnalyzed)
                    {
                        columnsToBeAnalyzed.Add(c);
                    }
                }

                if (columnsToBeAnalyzed.Count > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
示例#2
0
        public string GetAliasForTable(string table, bool makeUsed = true)
        {
            string result = null;

            if (result == null)
            {
                DbTable dbTable = tables[table];
                if (dbTable.lastAlias != null && !AliasUsedByAnotherActiveTable(dbTable.lastAlias, table))
                {
                    result = dbTable.lastAlias;
                }
                else
                {
                    foreach (string a in dbTable.aliases.Keys)
                    {
                        if (!AliasUsedByAnotherActiveTable(a, table))
                        {
                            result = a;
                            break;
                        }
                    }
                }
            }

            if (result == null)
            {
                if (proposedAliases.ContainsKey(table))
                {
                    if (AliasUsedByAnotherActiveTable(proposedAliases[table], table))
                    {
                        proposedAliases.Remove(table);
                    }
                    else
                    {
                        result = proposedAliases[table];
                    }
                }
            }
            if (result == null)
            {
                string txt = T.CamelCaseToDbCase(table);
                txt = txt.Replace("__", "_");
                string[] tokens = txt.Split('_');
                for (int i = 1; i < 5; i++)
                {
                    string alias = "";
                    foreach (string word in tokens)
                    {
                        alias += word.Left(i);
                    }
                    alias = alias.ToLower();
                    if (!AliasUsedByAnotherActiveTable(alias, table))
                    {
                        proposedAliases.Add(table, alias);
                        result = alias;
                        break;
                    }
                }
            }

            T.Assert(result != "");
            T.Assert(result != null);
            if (makeUsed)
            {
                AliasUsed(result, table);
            }
            return(result);
        }