void ISqlElement.ToString(ISqlWriter writer) { writer.Write(Expression); writer.Write(" "); writer.Write(Ascending ? "ASC" : "DESC"); }
/// <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); }
void ISqlElement.ToString(ISqlWriter writer) { writer.Write(Expression); if (Alias != null) { writer.Write(" AS "); writer.Write(Alias); } }
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); } }
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"); }
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(", "); } } } }
void ISqlElement.ToString(ISqlWriter writer) { writer.Write(Expression); }
void ISqlElement.ToString(ISqlWriter writer) { writer.Write(":"); writer.Write(VariableName); }
protected override void WriteTo(ISqlWriter writer) { writer.Write(Value); }
public static void WriteLine(this ISqlWriter writer) { writer.Write(Environment.NewLine); }
protected override void WriteTo(ISqlWriter writer) { writer.Write(VariableName); }
protected virtual void WriteTo(ISqlWriter writer) { writer.Write(Name); }
protected override void WriteTo(ISqlWriter writer) { writer.Write(Left); writer.Write(" {0} ", Operator.AsString()); writer.Write(Right); }
public static void Write(this ISqlWriter writer, object obj) { var s = obj == null ? String.Empty : obj.ToString(); writer.Write(s); }
protected override void WriteTo(ISqlWriter writer) { writer.Write("("); writer.Write(Operand); writer.Write(")"); }
public static void Write(this ISqlWriter writer, string format, params object[] args) { writer.Write(String.Format(format, args)); }
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); }
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(", "); } } }
public static void WriteLine(this ISqlWriter writer, string s) { writer.Write(s); writer.Write(Environment.NewLine); }
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); } }