From 21666494098acc8b575412678ad0704810d68092 Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Tue, 13 Jan 2015 15:27:35 -0800 Subject: [PATCH 1/3] Ensure identifiers are quoted for `RETURNING` and `DROP INDEX` statements. --- postgres.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres.go b/postgres.go index b2624448..218d594d 100644 --- a/postgres.go +++ b/postgres.go @@ -66,7 +66,7 @@ func (s *postgres) PrimaryKeyTag(value reflect.Value, size int) string { } func (s *postgres) ReturningStr(tableName, key string) string { - return fmt.Sprintf("RETURNING \"%v\".%v", tableName, key) + return fmt.Sprintf("RETURNING %v.%v", s.Quote(tableName), s.Quote(key)) } func (s *postgres) SelectFromDummyTable() string { @@ -97,7 +97,7 @@ func (s *postgres) HasColumn(scope *Scope, tableName string, columnName string) } func (s *postgres) RemoveIndex(scope *Scope, indexName string) { - scope.Raw(fmt.Sprintf("DROP INDEX %v", indexName)).Exec() + scope.Raw(fmt.Sprintf("DROP INDEX %v", s.Quote(indexName))).Exec() } var hstoreType = reflect.TypeOf(Hstore{}) From 73c47b90feef8dbd61f292a12ae94decdd96ac5f Mon Sep 17 00:00:00 2001 From: Travis Donia Date: Tue, 13 Jan 2015 17:57:47 -0500 Subject: [PATCH 2/3] check isIgnored when compiling attrs to update --- utils_private.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils_private.go b/utils_private.go index cf941f61..0b46cfdb 100644 --- a/utils_private.go +++ b/utils_private.go @@ -65,7 +65,7 @@ func convertInterfaceToMap(values interface{}) map[string]interface{} { default: scope := Scope{Value: values} for _, field := range scope.Fields() { - if !field.IsBlank { + if !field.IsBlank && !field.IsIgnored { attrs[field.DBName] = field.Field.Interface() } } From aa8bc02c115c07dc967cd38f23d67c5ae0d84460 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 14 Jan 2015 07:59:21 +0800 Subject: [PATCH 3/3] Fix broken test for postgres --- callback_create.go | 2 +- postgres.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/callback_create.go b/callback_create.go index 4734d65e..52e9369c 100644 --- a/callback_create.go +++ b/callback_create.go @@ -36,7 +36,7 @@ func Create(scope *Scope) { returningKey := "*" if scope.PrimaryKey() != "" { - returningKey = scope.PrimaryKey() + returningKey = scope.Quote(scope.PrimaryKey()) } if len(columns) == 0 { diff --git a/postgres.go b/postgres.go index 218d594d..2229e7b1 100644 --- a/postgres.go +++ b/postgres.go @@ -4,8 +4,9 @@ import ( "database/sql" "database/sql/driver" "fmt" - "github.com/lib/pq/hstore" "reflect" + + "github.com/lib/pq/hstore" ) type postgres struct { @@ -66,7 +67,7 @@ func (s *postgres) PrimaryKeyTag(value reflect.Value, size int) string { } func (s *postgres) ReturningStr(tableName, key string) string { - return fmt.Sprintf("RETURNING %v.%v", s.Quote(tableName), s.Quote(key)) + return fmt.Sprintf("RETURNING %v.%v", s.Quote(tableName), key) } func (s *postgres) SelectFromDummyTable() string {