Ejemplo n.º 1
0
        protected virtual void LoadProcedureTableSchema(
            DataConnection dataConnection, ProcedureSchema procedure, string commandText, List <TableSchema> tables)
        {
            CommandType commandType;

            DataParameter[] parameters;

            if (procedure.IsTableFunction)
            {
                commandText = "SELECT * FROM " + commandText + "(";

                for (var i = 0; i < procedure.Parameters.Count; i++)
                {
                    if (i != 0)
                    {
                        commandText += ",";
                    }
                    commandText += "NULL";
                }

                commandText += ")";
                commandType  = CommandType.Text;
                parameters   = new DataParameter[0];
            }
            else
            {
                commandType = CommandType.StoredProcedure;
                parameters  = procedure.Parameters.Select(p =>
                                                          new DataParameter
                {
                    Name  = p.ParameterName,
                    Value =
                        p.SystemType == typeof(string)   ? "" :
                        p.SystemType == typeof(DateTime) ? DateTime.Now :
                        DefaultValue.GetValue(p.SystemType),
                    DataType  = p.DataType,
                    Size      = (int?)p.Size,
                    Direction =
                        p.IsIn ?
                        p.IsOut ?
                        ParameterDirection.InputOutput :
                        ParameterDirection.Input :
                        ParameterDirection.Output
                }).ToArray();
            }

            try
            {
                var st = GetProcedureSchema(dataConnection, commandText, commandType, parameters);

                procedure.IsLoaded = true;

                if (st != null)
                {
                    procedure.ResultTable = new TableSchema
                    {
                        IsProcedureResult = true,
                        TypeName          = ToValidName(procedure.ProcedureName + "Result"),
                        ForeignKeys       = new List <ForeignKeySchema>(),
                        Columns           = GetProcedureResultColumns(st)
                    };

                    foreach (var column in procedure.ResultTable.Columns)
                    {
                        column.Table = procedure.ResultTable;
                    }

                    procedure.SimilarTables =
                        (
                            from t in tables
                            where t.Columns.Count == procedure.ResultTable.Columns.Count
                            let zip = t.Columns.Zip(procedure.ResultTable.Columns, (c1, c2) => new { c1, c2 })
                                      where zip.All(z => z.c1.ColumnName == z.c2.ColumnName && z.c1.SystemType == z.c2.SystemType)
                                      select t
                        ).ToList();
                }
            }
            catch (Exception ex)
            {
                procedure.ResultException = ex;
            }
        }
Ejemplo n.º 2
0
        protected virtual void LoadProcedureTableSchema(
            DataConnection dataConnection,
            GetSchemaOptions options,
            ProcedureSchema procedure,
            string commandText,
            List <TableSchema> tables)
        {
            CommandType commandType;

            DataParameter[] parameters;

            if (procedure.IsTableFunction)
            {
                commandText = BuildTableFunctionLoadTableSchemaCommand(procedure, commandText);
                commandType = CommandType.Text;
                parameters  = Array <DataParameter> .Empty;
            }
            else
            {
                commandType = CommandType.StoredProcedure;
                parameters  = procedure.Parameters.Select(BuildProcedureParameter).ToArray();
            }

            try
            {
                var st = GetProcedureSchema(dataConnection, commandText, commandType, parameters, options);

                procedure.IsLoaded = true;

                if (st != null && st.Columns.Count > 0)
                {
                    var columns = GetProcedureResultColumns(st, options);

                    if (columns.Count > 0)
                    {
                        procedure.ResultTable = new TableSchema
                        {
                            IsProcedureResult = true,
                            TypeName          = ToValidName(procedure.ProcedureName + "Result"),
                            ForeignKeys       = new List <ForeignKeySchema>(),
                            Columns           = columns
                        };

                        foreach (var column in procedure.ResultTable.Columns)
                        {
                            column.Table = procedure.ResultTable;
                        }

                        procedure.SimilarTables =
                            (
                                from t in tables
                                where t.Columns.Count == procedure.ResultTable.Columns.Count
                                let zip = t.Columns.Zip(procedure.ResultTable.Columns, (c1, c2) => new { c1, c2 })
                                          where zip.All(z => z.c1.ColumnName == z.c2.ColumnName && z.c1.SystemType == z.c2.SystemType)
                                          select t
                            ).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                procedure.ResultException = ex;
            }
        }
Ejemplo n.º 3
0
		protected virtual void LoadProcedureTableSchema(
			DataConnection dataConnection, ProcedureSchema procedure, string commandText, List<TableSchema> tables)
		{
			CommandType     commandType;
			DataParameter[] parameters;

			if (procedure.IsTableFunction)
			{
				commandText = "SELECT * FROM " + commandText + "(";

				for (var i = 0; i < procedure.Parameters.Count; i++)
				{
					if (i != 0)
						commandText += ",";
					commandText += "NULL";
				}

				commandText += ")";
				commandType = CommandType.Text;
				parameters  = new DataParameter[0];
			}
			else
			{
				commandType = CommandType.StoredProcedure;
				parameters  = procedure.Parameters.Select(p =>
					new DataParameter
					{
						Name      = p.ParameterName,
						Value     =
							p.SystemType == typeof(string)   ? "" :
							p.SystemType == typeof(DateTime) ? DateTime.Now :
								DefaultValue.GetValue(p.SystemType),
						DataType  = p.DataType,
						Size      = (int?)p.Size,
						Direction =
							p.IsIn ?
								p.IsOut ?
									ParameterDirection.InputOutput :
									ParameterDirection.Input :
								ParameterDirection.Output
					}).ToArray();
			}

			try
			{
				var st = GetProcedureSchema(dataConnection, commandText, commandType, parameters);

				procedure.IsLoaded = true;

				if (st != null)
				{
					procedure.ResultTable = new TableSchema
					{
						IsProcedureResult = true,
						TypeName          = ToValidName(procedure.ProcedureName + "Result"),
						ForeignKeys       = new List<ForeignKeySchema>(),
						Columns           = GetProcedureResultColumns(st)
					};

					foreach (var column in procedure.ResultTable.Columns)
						column.Table = procedure.ResultTable;

					procedure.SimilarTables =
					(
						from  t in tables
						where t.Columns.Count == procedure.ResultTable.Columns.Count
						let zip = t.Columns.Zip(procedure.ResultTable.Columns, (c1, c2) => new { c1, c2 })
						where zip.All(z => z.c1.ColumnName == z.c2.ColumnName && z.c1.SystemType == z.c2.SystemType)
						select t
					).ToList();
				}
			}
			catch (Exception ex)
			{
				procedure.ResultException = ex;
			}
		}