Ejemplo n.º 1
0
        /// <summary><see cref="Edrych.DataAccess.DataAccessBase.GetColumns"/></summary>
        public override List<Column> GetColumns(string TableName)
        {
            string sql = DataAccessResources.SQLite_FindColumns.Replace("@TableName", TableName);
            List<Column> cols = GetDbItems<Column>(sql,
                (reader) =>
                {
                    Column col = new Column();
                    col.Name = reader["name"].ToString();
                    col.DataType = reader["type"].ToString();
                    col.IsNullable = reader["notnull"].ToString() == "0";
                    col.Key = int.Parse(reader["pk"].ToString()) > 0 ? KeyType.Primary : KeyType.None;
                    return col;
                });
            List<string> fks = GetDbItems<string>(DataAccessResources.SQLite_FindForeignKeys.Replace("@TableName", TableName),
                (reader) =>
                {
                    return reader["from"].ToString();
                });

            foreach(Column col in cols.Where(c => c.Key != KeyType.Primary && fks.Contains(c.Name)))
            {
                col.Key = KeyType.Foreign;
            }

            return cols;
        }
Ejemplo n.º 2
0
 /// <summary><see cref="Edrych.DataAccess.DataAccessBase.GetColumns"/></summary>
 public override List<Column> GetColumns(string TableName)
 {
     this.ClearParameters();
     this.AddTableParams(TableName);
     List<Column> cols = GetDbItems<Column>(DataAccessResources.ANSI_FindColumns,
         (reader) =>
         {
             Column col = new Column();
             col.Name = reader["name"].ToString();
             col.DataType = reader["type"].ToString();
             col.IsNullable = reader["IS_NULLABLE"].ToString() == "YES";
             col.Key = (int)reader["PKCount"] > 0 ? KeyType.Primary : (int)reader["FKCount"] > 0 ? KeyType.Foreign : KeyType.None;
             return col;
         });
     this.ClearParameters();
     return cols;
 }
Ejemplo n.º 3
0
        /// <summary><see cref="Edrych.DataAccess.DataAccessBase.GetColumns"/></summary>
        public override List<Column> GetColumns(string TableName)
        {
            string sql = DataAccessResources.Teradata_FindColumns.Replace("@DatabaseName", this.SelectedDatabase).Replace("@TableName", TableName);
            List<Column> columns = GetDbItems<Column>(sql,
                (reader) =>
                {
                    Column col = new Column();
                    col.Name = reader["Column Name"].ToString().Trim();
                    string dataType = COLUMN_TYPE_LOOKUP[reader["Type"].ToString().Trim()];
                    string maxLength = reader["Max Length"].ToString().Trim();
                    string scale = reader["Decimal Total Digits"].ToString().Trim();
                    string precision = reader["Decimal Fractional Digits"].ToString().Trim();
                    if (dataType.Contains("CHAR") && !string.IsNullOrEmpty(maxLength))
                    {
                        col.DataType = dataType + " (" + maxLength + ")";
                    }
                    else if (dataType == "DECIMAL" && !string.IsNullOrEmpty(scale) && !string.IsNullOrEmpty(precision))
                    {
                        col.DataType = dataType + " (" + scale + ", " + precision + ")";
                    }
                    else
                    {
                        col.DataType = dataType;
                    }
                    col.IsNullable = reader["Nullable"].ToString() == "Y";
                    col.Key = reader["Primary?"].ToString().Trim() == "P" ? KeyType.Primary : KeyType.None;

                    return col;
                });
            sql = DataAccessResources.Teradata_FindForeignKeys.Replace("@DatabaseName", "'" + this.SelectedDatabase + "'").Replace("@TableName", "'" + TableName + "'");
            List<string> fks = GetDbItems<string>(sql,
                (reader) =>
                {
                    return reader["ChildKeyColumn"].ToString().Trim();
                });

            foreach (Column col in columns.Where(c => c.Key != KeyType.Primary && fks.Contains(c.Name)))
            {
                col.Key = KeyType.Foreign;
            }

            return columns;
        }
Ejemplo n.º 4
0
        /// <summary><see cref="Edrych.DataAccess.DataAccessBase.GetColumns"/></summary>
        public override List<Column> GetColumns(string TableName)
        {
            List<Column> cols = new List<Column>();
            if (AddTableParameters(TableName))
            {
                cols = GetDbItems<Column>(DataAccessResources.DB2_FindColumns,
                    (reader) =>
                    {
                        Column col = new Column();
                        col.Name = reader["COLNAME"].ToString();
                        col.DataType = reader["COLTYPE"].ToString();
                        col.IsNullable = reader["NULLS"].ToString() == "Y";
                        col.Key = (int)reader["IsPrimaryKey"] > 0 ? KeyType.Primary : (int)reader["FKCount"] > 0 ? KeyType.Foreign : KeyType.None;
                        return col;
                    });
                this.ClearParameters();
            }

            return cols;
        }