MCPcopy Index your code
hub / github.com/LissaGreense/GO4SQL / ToString

Method ToString

engine/table.go:74–118  ·  view source on GitHub ↗

ToString - Return string contain all values and Column names in Table

()

Source from the content-addressed store, hash-verified

72
73// ToString - Return string contain all values and Column names in Table
74func (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
120func (table *Table) getTableCopyWithAddedPrefixToColumnNames(columnNamePrefix string) *Table {
121 newTable := &Table{Columns: []*Column{}}

Callers

nothing calls this directly

Calls 4

getColumWidthsFunction · 0.85
getBarFunction · 0.85
ToStringMethod · 0.65
GetTypeMethod · 0.65

Tested by

no test coverage detected