Пример #1
0
        void ISqlElement.ToString(ISqlWriter writer)
        {
            writer.Write(Expression);

            writer.Write(" ");
            writer.Write(Ascending ? "ASC" : "DESC");
        }
Пример #2
0
        void ISqlElement.ToString(ISqlWriter writer)
        {
            writer.Write(Expression);

            writer.Write(" ");
            writer.Write(Ascending ? "ASC" : "DESC");
        }
Пример #3
0
        /// <summary>
        /// Visits the children of the <see cref="T:System.Linq.Expressions.BinaryExpression"/>.
        /// </summary>
        /// <returns>
        /// The modified expression, if it or any subexpression was modified; otherwise, returns the original expression.
        /// </returns>
        /// <param name="node">The expression to visit.</param>
        protected override Expression VisitBinary(BinaryExpression node)
        {
            var        op    = node.GetOperator();
            Expression left  = node.Left;
            Expression right = node.Right;

            _serverWriter.OpenBrace();

            if (left.Type.IsBoolean())
            {
                Visit(left);
                _serverWriter.WhiteSpace();
                _serverWriter.Write(op);
                _serverWriter.WhiteSpace();
                Visit(right);
            }
            else
            {
                VisitValue(left);
                _serverWriter.WhiteSpace();
                _serverWriter.Write(op);
                _serverWriter.WhiteSpace();
                VisitValue(right);
            }

            _serverWriter.CloseBrace();

            return(node);
        }
Пример #4
0
        void ISqlElement.ToString(ISqlWriter writer)
        {
            writer.Write(Expression);

            if (Alias != null)
            {
                writer.Write(" AS ");
                writer.Write(Alias);
            }
        }
Пример #5
0
        void ISqlElement.ToString(ISqlWriter writer)
        {
            writer.Write("SELECT ");
            if (Into != null)
            {
                writer.Write("INTO ");
                // TODO:

                writer.WriteLine();
            }
            else
            {
                var colCount = Columns.Count;
                int i        = -1;
                foreach (var column in Columns)
                {
                    writer.Write(column);

                    if (++i < colCount - 1)
                    {
                        writer.Write(", ");
                    }
                }

                if (colCount > 0)
                {
                    writer.WriteLine();
                }
            }

            if (From != null)
            {
                writer.Indent(4);
                writer.Write(From);
                writer.WriteLine();
                writer.Deindent(4);
            }

            if (Where != null)
            {
                writer.Indent(4);
                writer.Write("WHERE ");
                writer.Write(Where);
                writer.WriteLine();
                writer.Deindent(4);
            }

            if (Having != null)
            {
                writer.Indent(4);
                writer.Write("HAVING ");
                writer.Write(Having);
                writer.WriteLine();
                writer.Deindent(4);
            }
        }
Пример #6
0
        protected override void WriteTo(ISqlWriter writer)
        {
            writer.Write("CASE ");
            writer.Write(IfTrue);
            writer.Write(" WHEN ");
            writer.Write(Test);

            if (IfFalse != null) {
                writer.Write(" THEN ");
                writer.Write(IfFalse);
            }

            writer.Write(" END");
        }
Пример #7
0
        protected override void WriteTo(ISqlWriter writer)
        {
            writer.Write(SelectExpression);

            if (OrderBy.Count > 0)
            {
                writer.Write("ORDER BY ");

                var orderByCount = OrderBy.Count;
                var i            = -1;
                foreach (var column in OrderBy)
                {
                    writer.Write(column);

                    if (++i < orderByCount - 1)
                    {
                        writer.Write(", ");
                    }
                }
            }
        }
Пример #8
0
        protected override void WriteTo(ISqlWriter writer)
        {
            writer.Write("CASE ");
            writer.Write(IfTrue);
            writer.Write(" WHEN ");
            writer.Write(Test);

            if (IfFalse != null)
            {
                writer.Write(" THEN ");
                writer.Write(IfFalse);
            }

            writer.Write(" END");
        }
Пример #9
0
 void ISqlElement.ToString(ISqlWriter writer)
 {
     writer.Write(Expression);
 }
Пример #10
0
 void ISqlElement.ToString(ISqlWriter writer)
 {
     writer.Write(":");
     writer.Write(VariableName);
 }
Пример #11
0
 void ISqlElement.ToString(ISqlWriter writer)
 {
     writer.Write(":");
     writer.Write(VariableName);
 }
Пример #12
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write(Value);
 }
Пример #13
0
 public static void WriteLine(this ISqlWriter writer)
 {
     writer.Write(Environment.NewLine);
 }
Пример #14
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write(VariableName);
 }
Пример #15
0
 protected virtual void WriteTo(ISqlWriter writer)
 {
     writer.Write(Name);
 }
Пример #16
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write(Left);
     writer.Write(" {0} ", Operator.AsString());
     writer.Write(Right);
 }
Пример #17
0
 void ISqlElement.ToString(ISqlWriter writer)
 {
     writer.Write(Expression);
 }
Пример #18
0
        void ISqlElement.ToString(ISqlWriter writer)
        {
            writer.Write(Expression);

            if (Alias != null) {
                writer.Write(" AS ");
                writer.Write(Alias);
            }
        }
Пример #19
0
        public static void Write(this ISqlWriter writer, object obj)
        {
            var s = obj == null ? String.Empty : obj.ToString();

            writer.Write(s);
        }
Пример #20
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write("(");
     writer.Write(Operand);
     writer.Write(")");
 }
Пример #21
0
 public static void Write(this ISqlWriter writer, string format, params object[] args)
 {
     writer.Write(String.Format(format, args));
 }
Пример #22
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write("(");
     writer.Write(Operand);
     writer.Write(")");
 }
Пример #23
0
        public int Read(ImportFileOptions importTask, ISqlWriter sqlWriter)
        {
            Log.Debug($"ReadCsv for '{importTask.file}'");

            Stopwatch _timer = new Stopwatch();

            _timer.Start();

            List <List <string> > batchLineFields = new List <List <string> >();
            var fileInfo = new System.IO.FileInfo(importTask.file);

            if (!System.IO.File.Exists(importTask.file))
            {
                Log.Error($"ReadCSV : '{importTask.file}' not exists!");
                return(-1);
            }

            var firstLine = ReadFirstLine(fileInfo);

            Char delimiter = string.IsNullOrWhiteSpace(importTask.delimiter) ? GuessDelimeter(firstLine) : importTask.delimiter.First <char>();
            //Char quotingCharacter = '\0'; // no quoting-character;
            Char quotingCharacter = string.IsNullOrWhiteSpace(importTask.quoting) ? GuessquotingCharacter(firstLine) : importTask.quoting.First <char>();
            var  rowCounter       = 0;

            try
            {
                using (var reader = new System.IO.StreamReader(fileInfo.FullName, Encoding.Default))
                {
                    Char escapeCharacter = quotingCharacter;
                    using (var csv = new CsvReader(reader, false, delimiter, quotingCharacter, escapeCharacter, '\0', ValueTrimmingOptions.All))
                    {
                        csv.DefaultParseErrorAction = ParseErrorAction.ThrowException;
                        csv.SkipEmptyLines          = true;

                        var headers = ReadHeaders(csv);
                        Log.Debug("Read:Headers : " + string.Join(",", headers));
                        sqlWriter.Init(importTask, headers);

                        if (!sqlWriter.EnsureFileIsUnique(fileInfo.Length))
                        {
                            Log.Debug($"Read: Import failed. The File '{importTask.file}' with size:'{fileInfo.Length}' has been allready imported.");
                            sqlWriter.UpdateStatusTable(-1, new TimeSpan(), fileInfo.Length);
                            return(-2);
                        }

                        do
                        {
                            // Read a pies of CSV
                            batchLineFields = ReadNextBatch(csv, importTask.batchSize);
                            if (batchLineFields.Count == 0)
                            {
                                break;
                            }
                            Log.Debug($"Read next batch : {batchLineFields.Count} entries start at {rowCounter} to {batchLineFields.Count + rowCounter}");

                            //Create & Write SQL
                            sqlWriter.Write(batchLineFields);

                            rowCounter += batchLineFields.Count;
                        } while (batchLineFields.Count > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error($"ReadCsv catch exception : {ex.Message}");
                return(-1);
            }

            _timer.Stop();

            var timeSpan = TimeSpan.FromMilliseconds(_timer.ElapsedMilliseconds);

            Log.Debug($"Import from '{importTask.file}' lenght:'{fileInfo.Length}' takes {_timer.ElapsedMilliseconds / 1000.0} seconds or {timeSpan.ToString("c")} of time. {rowCounter} rows inserted.");
            sqlWriter.UpdateStatusTable(rowCounter, timeSpan, fileInfo.Length);

            sqlWriter.ExecuteAdditionalSql();

            return(rowCounter);
        }
Пример #24
0
        protected override void WriteTo(ISqlWriter writer)
        {
            writer.Write(SelectExpression);

            if (OrderBy.Count > 0) {
                writer.Write("ORDER BY ");

                var orderByCount = OrderBy.Count;
                var i = -1;
                foreach (var column in OrderBy) {
                    writer.Write(column);

                    if (++i < orderByCount - 1)
                        writer.Write(", ");
                }
            }
        }
Пример #25
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write(VariableName);
 }
Пример #26
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write(Left);
     writer.Write(" {0} ", Operator.AsString());
     writer.Write(Right);
 }
Пример #27
0
 public static void WriteLine(this ISqlWriter writer, string s)
 {
     writer.Write(s);
     writer.Write(Environment.NewLine);
 }
Пример #28
0
        void ISqlElement.ToString(ISqlWriter writer)
        {
            writer.Write("SELECT ");
            if (Into != null) {
                writer.Write("INTO ");
                // TODO:

                writer.WriteLine();
            } else {
                var colCount = Columns.Count;
                int i = -1;
                foreach (var column in Columns) {
                    writer.Write(column);

                    if (++i < colCount - 1)
                        writer.Write(", ");
                }

                if (colCount > 0)
                    writer.WriteLine();
            }

            if (From != null) {
                writer.Indent(4);
                writer.Write(From);
                writer.WriteLine();
                writer.Deindent(4);
            }

            if (Where != null) {
                writer.Indent(4);
                writer.Write("WHERE ");
                writer.Write(Where);
                writer.WriteLine();
                writer.Deindent(4);
            }

            if (Having != null) {
                writer.Indent(4);
                writer.Write("HAVING ");
                writer.Write(Having);
                writer.WriteLine();
                writer.Deindent(4);
            }
        }
Пример #29
0
 protected override void WriteTo(ISqlWriter writer)
 {
     writer.Write(Value);
 }