Skip to content

Commit d2d66ba

Browse files
committed
need to start trying the restore with virtual columns
1 parent 7284c37 commit d2d66ba

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed

dump.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -301,49 +301,68 @@ func (table *table) CreateSQL() (string, error) {
301301
return tableSQL.String, nil
302302
}
303303

304-
func (table *table) Init() (err error) {
305-
if len(table.values) != 0 {
306-
return errors.New("can't init twice")
307-
}
308-
309-
var columns []string
310-
304+
func (table *table) getColumnsToDump() ([]string, error) {
311305
colInfo, err := table.data.tx.Query("SHOW COLUMNS FROM " + table.NameEsc())
312306
if err != nil {
313-
return err
307+
return nil, err
314308
}
315309

310+
var result []string
311+
316312
for colInfo.Next() {
317313
cols, err := colInfo.Columns()
318314
if err != nil {
319-
return err
315+
return nil, err
320316
}
321317

318+
// Allocate and link space to scan to this must be done every iteration
322319
info := make([]sql.NullString, len(cols))
323320
scans := make([]interface{}, len(cols))
324321
for i := range info {
325322
scans[i] = &info[i]
326323
}
327324

325+
// Read into the pointers to the info marker
328326
if err := colInfo.Scan(scans...); err != nil {
329-
return err
327+
return nil, err
330328
}
331329

332-
// ignore all extras with VIRTUAL
330+
// Find the the fields we care about
331+
var field, extra *sql.NullString
332+
for i, col := range cols {
333+
switch col {
334+
case "Field", "field":
335+
field = &info[i]
336+
case "Extra", "extra":
337+
extra = &info[i]
338+
}
339+
if field != nil && extra != nil {
340+
break
341+
}
342+
}
333343

334-
if info[0].String == "cert_blob_lookup_hash" {
335-
fmt.Println("this is a thing")
344+
if !extra.Valid || !strings.Contains(extra.String, "VIRTUAL") {
345+
result = append(result, "`"+field.String+"`")
336346
}
347+
}
348+
return result, nil
349+
}
350+
351+
func (table *table) Init() error {
352+
if len(table.values) != 0 {
353+
return errors.New("can't init twice")
354+
}
337355

338-
columns = append(columns, "`"+info[0].String+"`")
356+
columns, err := table.getColumnsToDump()
357+
if err != nil {
358+
return err
339359
}
340360

341361
if len(columns) == 0 {
342-
return errors.New("No columns in table " + table.Name + ".")
362+
// No data to dump since this is a virtual table
363+
return nil
343364
}
344365

345-
// Total query plus sanitization
346-
347366
table.rows, err = table.data.tx.Query("SELECT " + strings.Join(columns, ",") + " FROM " + table.NameEsc())
348367
if err != nil {
349368
return err

0 commit comments

Comments
 (0)