Exemplo n.º 1
0
        private static void PopulateProcedureInfo(IWriteEnumerable <ProcedureDefinition> procedureList, IDataReader reader, ActiveMapCodeGenConfigurationSection configuration)
        {
            ProcedureDefinition procedureDefinition = null;
            string lastOwner = null;
            string lastTable = null;

            while (reader.Read())
            {
                string newOwner     = reader.GetString(0);
                string newProcedure = reader.GetString(1);
                if (procedureDefinition == null || (newOwner != lastOwner || newProcedure != lastTable))
                {
                    procedureDefinition = new ProcedureDefinition(newProcedure, newOwner);
                    procedureList.Add(procedureDefinition);
                }

                ProcedureParameterDefinition parameterDefinition = new ProcedureParameterDefinition(configuration)
                {
                    Name          = reader.GetString(2),
                    Position      = Convert.ToInt32(reader[3]),
                    ParameterType = GetParameterType(reader.GetString(4)),
                    IsResult      = reader.GetString(5) == SchemaValue.Yes,
                    MaxLength     = reader.IsDBNull(7) ? 0 : reader.GetInt32(7)
                };

                parameterDefinition.DbType = GetDbType(reader.GetString(6), parameterDefinition.MaxLength);
                procedureDefinition.Parameters.Add(parameterDefinition);

                lastOwner = procedureDefinition.Owner;
                lastTable = procedureDefinition.Name;
            }
        }
Exemplo n.º 2
0
        private static void PopulateTableInfo(IWriteEnumerable <TableDefinition> tableList, IDataReader reader, ActiveMapCodeGenConfigurationSection configuration)
        {
            TableDefinition tableInfo = null;
            string          lastOwner = null;
            string          lastTable = null;

            while (reader.Read())
            {
                string newOwner = reader.GetString(0);
                string newTable = reader.GetString(1);

                if (newTable.StartsWith("sys", StringComparison.OrdinalIgnoreCase) ||
                    newTable.StartsWith("dt", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                if (tableInfo == null || (newOwner != lastOwner || newTable != lastTable))
                {
                    // TODO: Implement data source name usage
                    // TODO: Separate Views from Tables
                    tableInfo = new TableDefinition(null, newTable, newOwner, configuration)
                    {
                        IsReadOnly = reader.GetString(2) != SchemaValue.BaseTable
                    };

                    tableList.Add(tableInfo);
                }

                TableColumnDefinition columnInfo = new TableColumnDefinition(configuration)
                {
                    Name         = reader.GetString(3),
                    IsNullable   = reader.GetString(4) == SchemaValue.Yes,
                    MaxLength    = reader.IsDBNull(6) ? 0 : reader.GetInt32(6),
                    IsComputed   = reader.GetInt32(7) == 1,
                    IsIdentity   = reader.GetInt32(8) == 1,
                    Ordinal      = Convert.ToInt32(reader[9]),
                    Description  = Convert.ToString(reader[10]),
                    DefaultValue = Convert.ToString(reader[11])
                };

                columnInfo.DbType = GetDbType(reader.GetString(5), columnInfo.MaxLength);
                tableInfo.Columns.Add(columnInfo);

                lastOwner = tableInfo.Owner;
                lastTable = tableInfo.Name;
            }
        }