8
8
"fmt"
9
9
"io"
10
10
"reflect"
11
+ "strings"
11
12
"text/template"
12
13
"time"
13
14
)
@@ -307,19 +308,34 @@ func (table *table) Init() (err error) {
307
308
308
309
var columns []string
309
310
310
- colInfo , err := table .data .tx .Query ("SHOW FIELDS FROM " + table .NameEsc ())
311
+ colInfo , err := table .data .tx .Query ("SHOW COLUMNS FROM " + table .NameEsc ())
311
312
if err != nil {
312
313
return err
313
314
}
314
315
315
316
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" {
319
335
fmt .Println ("this is a thing" )
320
336
}
321
337
322
- columns = append (columns , field )
338
+ columns = append (columns , "`" + info [ 0 ]. String + "`" )
323
339
}
324
340
325
341
if len (columns ) == 0 {
@@ -328,7 +344,7 @@ func (table *table) Init() (err error) {
328
344
329
345
// Total query plus sanitization
330
346
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 ())
332
348
if err != nil {
333
349
return err
334
350
}
@@ -338,9 +354,9 @@ func (table *table) Init() (err error) {
338
354
return err
339
355
}
340
356
341
- var t reflect.Type
342
357
table .values = make ([]interface {}, len (tt ))
343
358
for i , tp := range tt {
359
+ var t reflect.Type
344
360
st := tp .ScanType ()
345
361
dt := tp .DatabaseTypeName ()
346
362
0 commit comments