This commit is contained in:
Andy Arthur
2020-05-13 16:40:03 -07:00
parent 2ec3b28258
commit 0ea313bc07
3 changed files with 15 additions and 19 deletions

View File

@@ -17,9 +17,9 @@ package sqlfmt
import (
"bytes"
"fmt"
"github.com/google/uuid"
"strings"
"github.com/google/uuid"
"vitess.io/vitess/go/sqltypes"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/row"
@@ -154,7 +154,7 @@ func RowAsUpdateStmt(r row.Row, tableName string, tableSch schema.Schema) (strin
b.WriteString(" WHERE (")
seenOne = false
_, err = r.IterSchema(tableSch, func(tag uint64, val types.Value) (stop bool, err error) {
col, _:= tableSch.GetAllCols().GetByTag(tag)
col, _ := tableSch.GetAllCols().GetByTag(tag)
if col.IsPartOfPK {
if seenOne {
b.WriteString(" AND ")
@@ -220,4 +220,3 @@ func quoteAndEscapeString(s string) string {
v.EncodeSQL(buf)
return buf.String()
}

View File

@@ -15,16 +15,16 @@
package sqlfmt
import (
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema/typeinfo"
"github.com/stretchr/testify/require"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/dtestutils"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/row"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema/typeinfo"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sql/sqltestutil"
"github.com/liquidata-inc/dolt/go/store/types"
)
@@ -104,21 +104,21 @@ func TestRowAsInsertStmt(t *testing.T) {
tests := []test{
{
name: "simple row",
row: dtestutils.NewTypedRow(id, "some guy", 100, false, strPointer("normie")),
sch: dtestutils.TypedSchema,
name: "simple row",
row: dtestutils.NewTypedRow(id, "some guy", 100, false, strPointer("normie")),
sch: dtestutils.TypedSchema,
expectedOutput: "INSERT INTO `people` (`id`,`name`,`age`,`is_married`,`title`) VALUES ('00000000-0000-0000-0000-000000000000','some guy',100,FALSE,'normie');",
},
{
name: "embedded quotes",
row: dtestutils.NewTypedRow(id, `It's "Mister Perfect" to you`, 100, false, strPointer("normie")),
sch: dtestutils.TypedSchema,
name: "embedded quotes",
row: dtestutils.NewTypedRow(id, `It's "Mister Perfect" to you`, 100, false, strPointer("normie")),
sch: dtestutils.TypedSchema,
expectedOutput: "INSERT INTO `people` (`id`,`name`,`age`,`is_married`,`title`) VALUES ('00000000-0000-0000-0000-000000000000','It\\'s \\\"Mister Perfect\\\" to you',100,FALSE,'normie');",
},
{
name: "null values",
row: dtestutils.NewTypedRow(id, "some guy", 100, false, nil),
sch: dtestutils.TypedSchema,
name: "null values",
row: dtestutils.NewTypedRow(id, "some guy", 100, false, nil),
sch: dtestutils.TypedSchema,
expectedOutput: "INSERT INTO `people` (`id`,`name`,`age`,`is_married`,`title`) VALUES ('00000000-0000-0000-0000-000000000000','some guy',100,FALSE,NULL);",
},
}
@@ -218,8 +218,7 @@ func TestRowAsUpdateStmt(t *testing.T) {
func TestValueAsSqlString(t *testing.T) {
tu, _ := uuid.Parse("00000000-0000-0000-0000-000000000000")
tests := []struct{
tests := []struct {
name string
val types.Value
ti typeinfo.TypeInfo
@@ -267,7 +266,6 @@ func TestValueAsSqlString(t *testing.T) {
}
}
func strPointer(s string) *string {
return &s
}

View File

@@ -61,7 +61,6 @@ func FmtColTagComment(tag uint64) string {
return fmt.Sprintf("%s%d", TagCommentPrefix, tag)
}
// SchemaAsCreateStmt takes a Schema and returns a string representing a SQL create table command that could be used to
// create this table
func SchemaAsCreateStmt(tableName string, sch schema.Schema) string {
@@ -184,4 +183,4 @@ func RenameTableStmt(fromName string, toName string) string {
b.WriteString(";")
return b.String()
}
}