Skip to content

Commit 7284c37

Browse files
committed
need to do some interesting optimizations to this
1 parent 42dce6b commit 7284c37

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

dump.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io"
1010
"reflect"
11+
"strings"
1112
"text/template"
1213
"time"
1314
)
@@ -307,19 +308,34 @@ func (table *table) Init() (err error) {
307308

308309
var columns []string
309310

310-
colInfo, err := table.data.tx.Query("SHOW FIELDS FROM " + table.NameEsc())
311+
colInfo, err := table.data.tx.Query("SHOW COLUMNS FROM " + table.NameEsc())
311312
if err != nil {
312313
return err
313314
}
314315

315316
for colInfo.Next() {
316-
var field, t, null, key, def, extra string
317-
colInfo.Scan(&field, &t, &null, &key, &def, &extra)
318-
if field == "cert_blob_lookup_hash" {
317+
cols, err := colInfo.Columns()
318+
if err != nil {
319+
return err
320+
}
321+
322+
info := make([]sql.NullString, len(cols))
323+
scans := make([]interface{}, len(cols))
324+
for i := range info {
325+
scans[i] = &info[i]
326+
}
327+
328+
if err := colInfo.Scan(scans...); err != nil {
329+
return err
330+
}
331+
332+
// ignore all extras with VIRTUAL
333+
334+
if info[0].String == "cert_blob_lookup_hash" {
319335
fmt.Println("this is a thing")
320336
}
321337

322-
columns = append(columns, field)
338+
columns = append(columns, "`"+info[0].String+"`")
323339
}
324340

325341
if len(columns) == 0 {
@@ -328,7 +344,7 @@ func (table *table) Init() (err error) {
328344

329345
// Total query plus sanitization
330346

331-
table.rows, err = table.data.tx.Query("SELECT * FROM " + table.NameEsc())
347+
table.rows, err = table.data.tx.Query("SELECT " + strings.Join(columns, ",") + " FROM " + table.NameEsc())
332348
if err != nil {
333349
return err
334350
}
@@ -338,9 +354,9 @@ func (table *table) Init() (err error) {
338354
return err
339355
}
340356

341-
var t reflect.Type
342357
table.values = make([]interface{}, len(tt))
343358
for i, tp := range tt {
359+
var t reflect.Type
344360
st := tp.ScanType()
345361
dt := tp.DatabaseTypeName()
346362

0 commit comments

Comments
 (0)