Fix issue with unregistered types
Previously if you tried to dump or select from a
database that held types not compiled into your
program and registered via vdl.Register, the
writers would fail with a message demanding that
you vdl.Register the types. This update alows
dump/selecting arbitrary types.
Change-Id: Ic13ae4da498ffb28792a59c74b87ef65e72070cd
diff --git a/cmd/sb/commands/dump.go b/cmd/sb/commands/dump.go
index 324dc3b..a2b0cfd 100644
--- a/cmd/sb/commands/dump.go
+++ b/cmd/sb/commands/dump.go
@@ -11,10 +11,6 @@
"v.io/v23/context"
"v.io/v23/syncbase"
"v.io/x/lib/cmdline"
-
- // TODO(zsterling): This is a temporary hack-around to avoid a permissions issue.
- // Investigate why this is needed and how to get rid of it.
- _ "v.io/x/ref/cmd/sb/internal/demodb"
)
var cmdDump = &cmdline.Command{
diff --git a/cmd/sb/internal/writer/writer.go b/cmd/sb/internal/writer/writer.go
index 71c66b6..88a15c0 100644
--- a/cmd/sb/internal/writer/writer.go
+++ b/cmd/sb/internal/writer/writer.go
@@ -51,7 +51,7 @@
row := make([]string, len(columnNames))
columnCount := rs.ResultCount()
for i := 0; i != columnCount; i++ {
- var column interface{}
+ var column *vdl.Value
if err := rs.Result(i, &column); err != nil {
return err
}
@@ -61,7 +61,7 @@
if justification[i] == Unknown {
justification[i] = getJustification(column)
}
- columnStr := toStringRaw(column, false)
+ columnStr := toString(column, false)
row[i] = columnStr
columnLen := utf8.RuneCountInString(columnStr)
if columnLen > columnWidths[i] {
@@ -107,11 +107,11 @@
io.WriteString(out, "-+\n")
}
-func getJustification(val interface{}) Justification {
- switch val.(type) {
+func getJustification(val *vdl.Value) Justification {
+ switch val.Kind() {
// TODO(kash): Floating point numbers should have the decimal point line up.
- case bool, uint8, uint16, uint32, uint64, int8, int16, int32, int64,
- float32, float64, complex64, complex128, int, uint, uintptr:
+ case vdl.Bool, vdl.Byte, vdl.Uint16, vdl.Uint32, vdl.Uint64, vdl.Int8,
+ vdl.Int16, vdl.Int32, vdl.Int64, vdl.Float32, vdl.Float64:
return Right
// TODO(kash): Leave nil values as unknown.
default:
@@ -140,11 +140,11 @@
for rs.Advance() {
delim := ""
for i, n := 0, rs.ResultCount(); i != n; i++ {
- var column interface{}
+ var column *vdl.Value
if err := rs.Result(i, &column); err != nil {
return err
}
- str := doubleQuoteForCSV(toStringRaw(column, false), c.delimiter)
+ str := doubleQuoteForCSV(toString(column, false), c.delimiter)
io.WriteString(c.w, fmt.Sprintf("%s%s", delim, str))
delim = c.delimiter
}
@@ -193,7 +193,7 @@
io.WriteString(j.w, bOpen)
linestart := "\n "
for i, n := 0, rs.ResultCount(); i != n; i++ {
- var column interface{}
+ var column *vdl.Value
if err := rs.Result(i, &column); err != nil {
return err
}
@@ -208,10 +208,6 @@
return rs.Err()
}
-func toStringRaw(rb interface{}, nested bool) string {
- return toString(vdl.ValueOf(rb), nested)
-}
-
// Converts VDL value to readable yet parseable string representation.
// If nested is not set, strings outside composites are left unquoted.
// TODO(ivanpi): Handle cycles and improve non-tree DAG handling.
@@ -319,8 +315,8 @@
}
// Converts VDL value to JSON representation.
-func toJson(val interface{}) string {
- jf := toJsonFriendly(vdl.ValueOf(val))
+func toJson(val *vdl.Value) string {
+ jf := toJsonFriendly(val)
jOut, err := json.Marshal(jf)
if err != nil {
panic(fmt.Sprintf("JSON marshalling failed: %v", err))
diff --git a/cmd/sb/internal/writer/writer_test.go b/cmd/sb/internal/writer/writer_test.go
index 982e6ce..e4b8c2f 100644
--- a/cmd/sb/internal/writer/writer_test.go
+++ b/cmd/sb/internal/writer/writer_test.go
@@ -19,7 +19,7 @@
)
type fakeResultStream struct {
- rows [][]interface{}
+ rows [][]vdl.Value
curr int
}
@@ -58,11 +58,11 @@
}
func newResultStream(iRows [][]interface{}) syncbase.ResultStream {
- vRows := make([][]interface{}, len(iRows))
+ vRows := make([][]vdl.Value, len(iRows))
for i, iRow := range iRows {
- vRow := make([]interface{}, len(iRow))
+ vRow := make([]vdl.Value, len(iRow))
for j, iCol := range iRow {
- vRow[j] = iCol
+ vRow[j] = *vdl.ValueOf(iCol)
}
vRows[i] = vRow
}
@@ -89,8 +89,8 @@
panic("call advance first")
}
switch intf := value.(type) {
- case *interface{}:
- *intf = f.rows[f.curr][i]
+ case **vdl.Value:
+ *intf = &f.rows[f.curr][i]
default:
err = fmt.Errorf("unsupported value type: %t", value)
}