Beispiel #1
0
        public override string GetFomattedString(TableData tableData, IValueProvider valueProvider)
        {
            var builder = new StringBuilder();
            var first   = true;

            builder.Append("[");
            while (valueProvider.MoveNext())
            {
                if (!first)
                {
                    builder.AppendLine(",");
                }

                var firstColumn = true;
                builder.AppendLine("{");

                foreach (var column in tableData.TableDescriptor.AllColumns)
                {
                    if (!firstColumn)
                    {
                        builder.AppendLine(",");
                    }

                    builder.AppendFormat("\t\"{0}\": {1}", column.ColumnName, this.FormatValue(valueProvider.GetValue(column)));

                    firstColumn = false;
                }

                builder.Append("\n}");
                first = false;
            }

            builder.Append("]");
            return(builder.ToString());
        }
Beispiel #2
0
        public override string GetFomattedString(TableData tableData, IValueProvider valueProvider)
        {
            var builder = new StringBuilder();

            builder.AppendLine(string.Join(",", tableData.TableDescriptor.AllColumns.Select(x => x.ColumnName)));

            while (valueProvider.MoveNext())
            {
                builder.AppendLine(string.Join(",", tableData.TableDescriptor.AllColumns.Select(x => this.FormatValue(valueProvider.GetValue(x)))));
            }

            return(builder.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// Gets a delete command query ready to delete one or more entities.
        /// </summary>
        /// <param name="valueProvider"></param>
        /// <returns>
        /// A delete command already parametrized to delete the entities.
        /// </returns>
        public IDatabaseCommand GetCommand(IValueProvider valueProvider)
        {
            var builder = new StringBuilder();

            builder.Append(this.CommandText);
            builder.Append(" WHERE ");

            if (this.Descriptor.PrimaryKeyColumns.Count == 1)
            {
                var primaryKey = this.Descriptor.PrimaryKeyColumns[0];

                builder.Append(this.FormatProvider.GetEscapedName(primaryKey.ColumnName));
                builder.Append(" IN (");

                while (valueProvider.MoveNext())
                {
                    builder.Append(this.FormatProvider.GetColumnValue(valueProvider.GetValue(primaryKey), primaryKey.DataType));
                    builder.Append(",");
                }

                builder.Remove(builder.Length - 1, 1);
                builder.Append(")");
            }
            else
            {
                while (valueProvider.MoveNext())
                {
                    builder.Append("(");
                    builder.AppendFormat(this.WhereClause, this.Descriptor.PrimaryKeyColumns.Select(x => this.FormatProvider.GetColumnValue(valueProvider.GetValue(x), x.DataType)).Cast <object>().ToArray());
                    builder.Append(") OR");
                }

                builder.Remove(builder.Length - 3, 3);
            }

            this.Command.CommandText = builder.ToString();
            return(this.Command);
        }
Beispiel #4
0
        protected override void ProcessData(TableData tableData, IValueProvider valueProvider)
        {
            using (var commandBuilder = new InsertCommandBuilder(this.DestinationDatabase, tableData.TableDescriptor))
            {
                if (this.Verbose)
                {
                    this.LoggingService.WriteLine("Command Created...");
                }

                while (valueProvider.MoveNext())
                {
                    var command = commandBuilder.GetCommand(valueProvider);
                    command.ExecuteNonQuery();
                }

                if (this.Verbose)
                {
                    this.LoggingService.WriteLine("Inserts Finished.");
                }
            }
        }
        public override string GetFomattedString(TableData tableData, IValueProvider valueProvider)
        {
            var builder = new StringBuilder();

            var insertCommandBuilder = new InsertCommandBuilder(this.Connector, tableData.TableDescriptor);

            while (valueProvider.MoveNext())
            {
                var command     = insertCommandBuilder.GetCommand(valueProvider);
                var commandText = command.CommandText;

                foreach (var parameter in command.Parameters)
                {
                    commandText = commandText.Replace(parameter.ParameterName, this.FormatProvider.GetColumnValue(parameter.Value, parameter.Value.GetType()));
                }

                builder.Append(commandText);
                builder.AppendLine(this.FormatProvider.GetQuerySeparator());
            }

            return(builder.ToString());
        }