Example #1
0
        public static IList <Field> GetFields(
            this InsertSource insertSource,
            ILogger logger,
            SchemaFile file
            )
        {
            switch (insertSource)
            {
            // TODO : when we have more than one VALUES() source they should all have same datatypes, is grabbing the first enough?
            case ValuesInsertSource valuesInsertSource:
                if (valuesInsertSource.IsDefaultValues)
                {
                    return(file
                           .FileContext
                           .StatementReferences
                           .Peek()
                           .First()
                           .Value
                           .Columns);
                }

                return(valuesInsertSource
                       .RowValues
                       .First()
                       .ColumnValues
                       .Select(f => f.GetField(null, logger, file))
                       .ToList());

            case SelectInsertSource selectInsertSource:
                return(selectInsertSource
                       .Select
                       .GetFields(logger, file)
                       .ToList());

            case ExecuteInsertSource executeInsertSource:
                return(executeInsertSource
                       .Execute
                       .ExecutableEntity
                       .GetFields(logger, file));

            default:
                logger.Log(LogLevel.Warning,
                           LogType.NotSupportedYet,
                           file.Path,
                           $"\"{insertSource.GetType()}\" insert source is not supported yet.");
                return(new List <Field>());
            }
        }
Example #2
0
        public static IEnumerable <SchemaObjectReference> GetSchemaObjectReferences(
            this InsertSource insertSource,
            ILogger logger,
            SchemaFile file
            )
        {
            switch (insertSource)
            {
            case SelectInsertSource selectInsertSource:
                return(selectInsertSource
                       .Select
                       .GetSchemaObjectReferences(logger, file)
                       .ToList());

            default:
                return(new List <SchemaObjectReference>());
            }
        }
        public override void AcceptChildren(WSqlFragmentVisitor visitor)
        {
            if (InsertSource != null)
            {
                InsertSource.Accept(visitor);
            }

            var index = 0;

            if (Columns != null)
            {
                for (var count = Columns.Count; index < count; ++index)
                {
                    Columns[index].Accept(visitor);
                }
            }

            base.AcceptChildren(visitor);
        }
        internal override string ToString(string indent)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("{0}INSERT INTO {1}", indent, Target.ToString());
            if (Columns != null && Columns.Count > 0)
            {
                sb.AppendFormat(" ({0}", Columns[0].ToString(indent));
                for (var i = 1; i < Columns.Count; ++i)
                {
                    sb.AppendFormat(", {0}", Columns[i].ToString(indent));
                }
                sb.Append(")");
            }
            sb.Append("\r\n");
            sb.Append(InsertSource.ToString(indent));

            return(sb.ToString());
        }
Example #5
0
        public static IList <FieldPairReference> GetFieldPairReferences(
            this InsertSource insertSource,
            ILogger logger,
            SchemaFile file
            )
        {
            switch (insertSource)
            {
            case SelectInsertSource selectInsertSource:
                return(selectInsertSource
                       .Select
                       .GetFieldPairReferences(logger, file)
                       .ToList());

            case ExecuteInsertSource executeInsertSource:
                return(executeInsertSource
                       .Execute
                       .GetFieldPairReferences(logger, file));

            case ValuesInsertSource valuesInsertSource:     // no extra pairs from pure values
            default:
                return(new List <FieldPairReference>());
            }
        }
Example #6
0
        private WInsertSource ParseInsertSource(InsertSource insSource)
        {
            if (insSource == null)
                return null;

            WInsertSource winsSouce = null;
            switch (insSource.GetType().Name)
            {
                case "SelectInsertSource":
                    {
                        var selInsSource = insSource as SelectInsertSource;
                        var wselInsSource = new WSelectInsertSource
                        {
                            Select = ParseSelectQueryStatement(selInsSource.Select),
                            FirstTokenIndex = selInsSource.FirstTokenIndex,
                            LastTokenIndex = selInsSource.LastTokenIndex

                        };
                        winsSouce = wselInsSource;
                        break;
                    }
                case "ValuesInsertSource":
                    {
                        var valInsSource = insSource as ValuesInsertSource;
                        var wvalInsSource = new WValuesInsertSource
                        {
                            IsDefaultValues = valInsSource.IsDefaultValues,
                            RowValues = new List<WRowValue>(valInsSource.RowValues.Count),
                            FirstTokenIndex = valInsSource.FirstTokenIndex,
                            LastTokenIndex = valInsSource.LastTokenIndex
                        };

                        foreach (var rowValue in valInsSource.RowValues)
                        {
                            wvalInsSource.RowValues.Add(ParseRowValue(rowValue));
                        }

                        winsSouce = wvalInsSource;
                        break;
                    }
            }

            return winsSouce;
        }
 public override void ExplicitVisit(InsertSource fragment)
 {
     _fragments.Add(fragment);
 }
 public sealed override void ExplicitVisit(InsertSource node)
 {
     base.ExplicitVisit(node);
 }
 public sealed override void Visit(InsertSource node)
 {
     base.Visit(node);
 }
Example #10
0
 public override void ExplicitVisit(InsertSource node) { this.action(node); }