aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/schema
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/sqlvm/schema')
-rw-r--r--core/vm/sqlvm/schema/schema.go30
-rw-r--r--core/vm/sqlvm/schema/schema_test.go37
2 files changed, 51 insertions, 16 deletions
diff --git a/core/vm/sqlvm/schema/schema.go b/core/vm/sqlvm/schema/schema.go
index 0d40a9612..d50a3ff46 100644
--- a/core/vm/sqlvm/schema/schema.go
+++ b/core/vm/sqlvm/schema/schema.go
@@ -158,14 +158,13 @@ type Index struct {
}
type column struct {
- Name []byte
- Type ast.DataType
- Attr ColumnAttr
- ForeignTable TableRef
- ForeignColumn ColumnRef
- Sequence SequenceRef
- SlotOffset uint8
- ByteOffset uint8
+ Name []byte
+ Type ast.DataType
+ Attr ColumnAttr
+ ForeignKeys []ColumnDescriptor
+ Sequence SequenceRef
+ SlotOffset uint8
+ ByteOffset uint8
// Rest is a special field reserved for use in EncodeRLP. The value stored
// in it will be overwritten every time EncodeRLP is called.
Rest interface{}
@@ -178,15 +177,14 @@ type Column struct {
}
// NewColumn return a Column instance.
-func NewColumn(Name []byte, Type ast.DataType, Attr ColumnAttr, Sequence SequenceRef,
- FT TableRef, FC ColumnRef) Column {
+func NewColumn(Name []byte, Type ast.DataType, Attr ColumnAttr,
+ ForeignKeys []ColumnDescriptor, Sequence SequenceRef) Column {
c := column{
- Name: Name,
- Type: Type,
- Attr: Attr,
- Sequence: Sequence,
- ForeignTable: FT,
- ForeignColumn: FC,
+ Name: Name,
+ Type: Type,
+ Attr: Attr,
+ ForeignKeys: ForeignKeys,
+ Sequence: Sequence,
}
return Column{
diff --git a/core/vm/sqlvm/schema/schema_test.go b/core/vm/sqlvm/schema/schema_test.go
index 0c75b0cb6..71f0ee6d3 100644
--- a/core/vm/sqlvm/schema/schema_test.go
+++ b/core/vm/sqlvm/schema/schema_test.go
@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"io/ioutil"
+ "reflect"
"testing"
"github.com/shopspring/decimal"
@@ -16,6 +17,39 @@ import (
type SchemaTestSuite struct{ suite.Suite }
+func (s *SchemaTestSuite) normalizeEmptySlice(i interface{}) {
+ var process func(reflect.Type, reflect.Value)
+ process = func(t reflect.Type, v reflect.Value) {
+ switch t.Kind() {
+ case reflect.Ptr:
+ process(t.Elem(), v.Elem())
+ case reflect.Array:
+ l := v.Len()
+ for i := 0; i < l; i++ {
+ process(t.Elem(), v.Index(i))
+ }
+ case reflect.Slice:
+ if v.IsNil() {
+ s := reflect.MakeSlice(t, 0, 0)
+ v.Set(s)
+ } else {
+ l := v.Len()
+ for i := 0; i < l; i++ {
+ process(t.Elem(), v.Index(i))
+ }
+ }
+ case reflect.Struct:
+ l := t.NumField()
+ for i := 0; i < l; i++ {
+ ft := t.Field(i).Type
+ fv := v.Field(i)
+ process(ft, fv)
+ }
+ }
+ }
+ process(reflect.TypeOf(i), reflect.ValueOf(i))
+}
+
func (s *SchemaTestSuite) requireEncodeAndDecodeColumnNoError(c Column) {
buffer := bytes.Buffer{}
w := bufio.NewWriter(&buffer)
@@ -25,6 +59,9 @@ func (s *SchemaTestSuite) requireEncodeAndDecodeColumnNoError(c Column) {
c2 := Column{}
r := ioutil.NopCloser(bufio.NewReader(&buffer))
s.Require().NoError(rlp.Decode(r, &c2))
+
+ s.normalizeEmptySlice(&c.column)
+ s.normalizeEmptySlice(&c2.column)
s.Require().Equal(c, c2)
}