ToString - Return string contain all values and Column names in Table
()
| 72 | |
| 73 | // ToString - Return string contain all values and Column names in Table |
| 74 | func (table *Table) ToString() string { |
| 75 | columWidths := getColumWidths(table.Columns) |
| 76 | bar := getBar(columWidths) |
| 77 | result := bar + "\n" |
| 78 | |
| 79 | result += "|" |
| 80 | for i := range table.Columns { |
| 81 | result += " " |
| 82 | for j := 0; j < columWidths[i]-len(table.Columns[i].Name); j++ { |
| 83 | result += " " |
| 84 | } |
| 85 | result += table.Columns[i].Name |
| 86 | result += " |" |
| 87 | } |
| 88 | result += "\n" + bar + "\n" |
| 89 | |
| 90 | if len(table.Columns) == 0 { |
| 91 | return result |
| 92 | } |
| 93 | |
| 94 | rowsCount := len(table.Columns[0].Values) |
| 95 | |
| 96 | for iRow := 0; iRow < rowsCount; iRow++ { |
| 97 | result += "|" |
| 98 | |
| 99 | for iColumn := range table.Columns { |
| 100 | result += " " |
| 101 | |
| 102 | printedValue := table.Columns[iColumn].Values[iRow].ToString() |
| 103 | if table.Columns[iColumn].Type.Literal == token.TEXT && |
| 104 | table.Columns[iColumn].Values[iRow].GetType() != NullType { |
| 105 | printedValue = "'" + printedValue + "'" |
| 106 | } |
| 107 | for i := 0; i < columWidths[iColumn]-len(printedValue); i++ { |
| 108 | result += " " |
| 109 | } |
| 110 | |
| 111 | result += printedValue + " |" |
| 112 | } |
| 113 | |
| 114 | result += "\n" |
| 115 | } |
| 116 | |
| 117 | return result + bar |
| 118 | } |
| 119 | |
| 120 | func (table *Table) getTableCopyWithAddedPrefixToColumnNames(columnNamePrefix string) *Table { |
| 121 | newTable := &Table{Columns: []*Column{}} |
nothing calls this directly
no test coverage detected