private static int WriteColumnHeader(NpSqlDataReader reader) { var rowLength = 2; if (reader.GetColumnSchema().Count() == 0) { return(0); } rowLength = WriteVerticalSeperator(reader, rowLength); Console.Write(" |"); foreach (NpSqlColumnDefinition column in reader.GetColumnSchema()) { var minLength = column.Name.Length + 8; // 4 whitespace before and aftername //Write beginning whitespace Console.Write(new string(' ', 4)); //Write column Name Console.Write(column.Name); //write trailing whitespace Console.Write(new string(' ', 4)); Console.Write("|"); rowLength += minLength + 1; } Console.WriteLine(); return(rowLength); }
private static void WriteRow(NpSqlDataReader reader) { Console.Write(" |"); var i = 0; var leadingSpace = 0; var s = string.Empty; foreach (NpSqlColumnDefinition column in reader.GetColumnSchema()) { var columnLength = column.Name.Length + 8; switch (column.Type) { case NpSql.Nqp.NqpTypes.Char: s = reader.GetString(i).Trim(); break; case NpSql.Nqp.NqpTypes.Int: s = reader.GetInt32(i).ToString(); break; } if (s.Length > columnLength) { s = s.Substring(0, columnLength - 5); s += "..."; } leadingSpace = columnLength - (s.Length + 1); if (leadingSpace < 0) { leadingSpace = 0; } Console.Write(new string(' ', leadingSpace)); Console.Write(s); Console.Write(' '); Console.Write("|"); i++; } Console.WriteLine(); }
private static int WriteVerticalSeperator(NpSqlDataReader reader, int rowLength) { if (rowLength == 0) { return(rowLength); } Console.Write(" +"); foreach (NpSqlColumnDefinition column in reader.GetColumnSchema()) { var minLength = column.Name.Length + 8; // 4 whitespace before and aftername Console.Write(new string('-', minLength)); Console.Write("+"); rowLength += minLength + 1; } Console.WriteLine(); return(rowLength); }