示例#1
0
        public HashSet <DBColumn> Load(Tabloid Tabloid)
        {
            // in cache
            string tabloidRealName = _db.CommandSet.ToRealTableName(_db.Application, Tabloid.Name);

            if (Cache.ContainsKey(tabloidRealName))
            {
                return(Cache[tabloidRealName]);
            }

            HashSet <DBColumn> result = new HashSet <DBColumn>();

            using (DBReader reader = _db.ExecuteCommand(_db.CommandSet.LIST_column(_db, Tabloid.Name)))
            {
                while (reader.Read())
                {
                    string defaultValue = null;
                    if (reader["default"] != DBNull.Value)
                    {
                        defaultValue = Convert.ToString(reader["default"]).Trim(new char[] { '(', ')' }); // removes ('value')
                        if ((!defaultValue.StartsWith("'") || !defaultValue.EndsWith("'")) && defaultValue.ToUpper() != "NULL")
                        {
                            defaultValue = $"'{defaultValue}'";
                        }
                    }

                    result.Add(new DBColumn(_db)
                    {
                        Tabloid      = Tabloid,
                        Name         = (string)reader["name"],
                        Type         = DataType.FromDBName((string)reader["typeName"], _db.Type),
                        MaxLength    = reader["max_length"] != DBNull.Value ? Convert.ToInt32(reader["max_length"]) : -1,
                        IsNullable   = Convert.ToBoolean(reader["is_nullable"]),
                        IsUnique     = Convert.ToBoolean(reader["is_unique"] != DBNull.Value ? reader["is_unique"] : false) || (string)reader["name"] == DBCommandSet.PrimaryKey,
                        DefaultValue = defaultValue
                                       //,Scale = Convert.ToInt32(reader["scale"])
                    });
                }
            }

            Cache.Add(tabloidRealName, result);

            return(result);
        }
示例#2
0
        public HashSet <DBForeignKey> Load(Tabloid tabloid)
        {
            HashSet <DBForeignKey> result = new HashSet <DBForeignKey>();

            using (DBReader reader = _db.ExecuteCommand(_db.CommandSet.LIST_foreignKey(_db, tabloid.Name, true, false)))
            {
                while (reader.Read())
                {
                    result.Add(new DBForeignKey(_db)
                    {
                        SourceTable  = (tabloid as DBTable),
                        SourceColumn = (string)reader["sourceColumn"],
                        TargetTable  = _db.Table(_db.CommandSet.FromRealTableName(_db.Application, (string)reader["targetTable"])),
                        TargetColumn = (string)reader["targetColumn"],
                        OnDelete     = (string)reader["onDelete"],
                        OnUpdate     = (string)reader["onUpdate"]
                    });
                }
            }

            return(result);
        }