public override void Output(USQLINTERFACES.IRow row, USQLINTERFACES.IUnstructuredWriter output) { var streamWriter = new System.IO.StreamWriter(output.BaseStream); // Metadata schema initialization to enumerate column names var schema = row.Schema; if (this.row_count == 0) { if (this.OutputHeader) { streamWriter.Write("|"); for (int i = 0; i < schema.Count(); i++) { var col = schema[i]; streamWriter.Write(" "); streamWriter.Write(col.Name); streamWriter.Write(" "); if (this.OutputHeaderType) { streamWriter.Write(get_usql_type_name(col.Type)); streamWriter.Write(" "); } streamWriter.Write("|"); } streamWriter.Write("\r\n"); streamWriter.Flush(); streamWriter.Write("|"); for (int i = 0; i < schema.Count(); i++) { var col = schema[i]; streamWriter.Write(" "); streamWriter.Write("---"); streamWriter.Write(" "); streamWriter.Write("|"); } streamWriter.Write("\r\n"); streamWriter.Flush(); } } // Data row output streamWriter.Write("|"); for (int i = 0; i < schema.Count(); i++) { var col = schema[i]; string val = ""; try { var coltype = col.Type; if (coltype == typeof(string)) { val = row.Get <string>(col.Name); val = val ?? "NULL"; } else if (coltype == typeof(bool)) { val = row.Get <bool>(col.Name).ToString(); } else if (coltype == typeof(char)) { val = row.Get <char>(col.Name).ToString(); } else if (coltype == typeof(float)) { val = row.Get <float>(col.Name).ToString(); } else if (coltype == typeof(double)) { val = row.Get <double>(col.Name).ToString(); } else if (coltype == typeof(int)) { val = row.Get <int>(col.Name).ToString(); } else if (coltype == typeof(long)) { val = row.Get <long>(col.Name).ToString(); } else if (coltype == typeof(System.Guid)) { val = row.Get <System.Guid>(col.Name).ToString(); } else if (coltype == typeof(int?)) { val = row.Get <int?>(col.Name).ToString(); val = val ?? "NULL"; } else if (coltype == typeof(long?)) { val = row.Get <long?>(col.Name).ToString(); val = val ?? "NULL"; } else if (coltype == typeof(float?)) { val = row.Get <float?>(col.Name).ToString(); val = val ?? "NULL"; } else if (coltype == typeof(double?)) { val = row.Get <double?>(col.Name).ToString(); val = val ?? "NULL"; } else if (coltype == typeof(USQLTYPES.SqlArray <string>)) { val = _Get_val_from_usqlarray <string>(row, col, val); } else if (coltype == typeof(USQLTYPES.SqlArray <int>)) { val = _Get_val_from_usqlarray <int>(row, col, val); } else if (coltype == typeof(USQLTYPES.SqlArray <long>)) { val = _Get_val_from_usqlarray <long>(row, col, val); } else if (coltype == typeof(USQLTYPES.SqlMap <string, string>)) { val = _Get_val_from_usqlmap <string, string>(row, col, val); } else if (coltype == typeof(USQLTYPES.SqlMap <string, int?>)) { val = _Get_val_from_usqlmap <string, int?>(row, col, val); } else { val = "UNKNOWNTYPE:" + get_usql_type_name(coltype); } } catch (System.NullReferenceException exc) { // Handling NULL values--keeping them empty val = "NullReferenceException"; } streamWriter.Write(" "); streamWriter.Write(val); streamWriter.Write(" "); streamWriter.Write("|"); } streamWriter.Write("\n"); streamWriter.Flush(); this.row_count++; }
public override void Output(USQLINTERFACES.IRow row, USQLINTERFACES.IUnstructuredWriter output) { var streamWriter = new System.IO.StreamWriter(output.BaseStream); // Metadata schema initialization to enumerate column names var schema = row.Schema; var opts = new TypeDisplayNameOptions(); if (this.row_count == 0) { if (this.OutputHeader) { streamWriter.Write(this._FieldSeparator); for (int i = 0; i < schema.Count(); i++) { var col = schema[i]; streamWriter.Write(this._Space); streamWriter.Write(col.Name); streamWriter.Write(this._Space); if (this.OutputHeaderType) { streamWriter.Write(UdoUtils.GetUsqlTypeDisplayName(col.Type)); streamWriter.Write(this._Space); } streamWriter.Write(this._FieldSeparator); } streamWriter.Write(_LineSeparator); streamWriter.Flush(); streamWriter.Write(this._FieldSeparator); for (int i = 0; i < schema.Count(); i++) { var col = schema[i]; streamWriter.Write(this._Space); streamWriter.Write(this._Header); streamWriter.Write(this._Space); streamWriter.Write(this._FieldSeparator); } streamWriter.Write(_LineSeparator); streamWriter.Flush(); } } // Data row output streamWriter.Write(this._FieldSeparator); for (int i = 0; i < schema.Count(); i++) { var col = schema[i]; string val = string.Empty; try { var coltype = col.Type; val = UdoUtils.GetValueDisplayString(row, coltype, val, col, opts); } catch (System.NullReferenceException exc) { // Handling NULL values--keeping them empty val = "NullReferenceException"; } streamWriter.Write(this._Space); if (this.EncodeHtml) { var encoded_val = System.Web.HttpUtility.HtmlEncode(val); val = encoded_val; } streamWriter.Write(val); streamWriter.Write(this._Space); streamWriter.Write(this._FieldSeparator); } streamWriter.Write(this._LineSeparator); streamWriter.Flush(); this.row_count++; }