Browse Source

bug fixed

xormplus 10 years ago
parent
commit
8173ee561a
4 changed files with 16 additions and 12 deletions
  1. 13 9
      session.go
  2. 0 1
      sessionplus.go
  3. 2 1
      statement.go
  4. 1 1
      xorm.go

+ 13 - 9
session.go

@@ -3005,16 +3005,20 @@ func (session *Session) value2Interface(col *core.Column, fieldValue reflect.Val
 			return tf, nil
 		}
 
-		if fieldTable, ok := session.Engine.Tables[fieldValue.Type()]; ok {
-			if len(fieldTable.PrimaryKeys) == 1 {
-				pkField := reflect.Indirect(fieldValue).FieldByName(fieldTable.PKColumns()[0].FieldName)
-				return pkField.Interface(), nil
+		if !col.SQLType.IsJson() {
+			// !<winxxp>! 增加支持driver.Valuer接口的结构,如sql.NullString
+			if v, ok := fieldValue.Interface().(driver.Valuer); ok {
+				return v.Value()
 			}
-			return 0, fmt.Errorf("no primary key for col %v", col.Name)
-		}
-		// !<winxxp>! 增加支持driver.Valuer接口的结构,如sql.NullString
-		if v, ok := fieldValue.Interface().(driver.Valuer); ok {
-			return v.Value()
+
+			fieldTable := session.Engine.autoMapType(fieldValue)
+			//if fieldTable, ok := session.Engine.Tables[fieldValue.Type()]; ok {
+				if len(fieldTable.PrimaryKeys) == 1 {
+					pkField := reflect.Indirect(fieldValue).FieldByName(fieldTable.PKColumns()[0].FieldName)
+					return pkField.Interface(), nil
+				}
+				return 0, fmt.Errorf("no primary key for col %v", col.Name)
+			//}
 		}
 
 		if col.SQLType.IsText() {

+ 0 - 1
sessionplus.go

@@ -8,7 +8,6 @@ import (
 	"database/sql"
 	"encoding/json"
 	"errors"
-	"fmt"
 	//	"fmt"
 	"reflect"
 	"regexp"

+ 2 - 1
statement.go

@@ -5,6 +5,7 @@
 package xorm
 
 import (
+	"database/sql/driver"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -49,7 +50,7 @@ type Statement struct {
 	GroupByStr    string
 	HavingStr     string
 	ColumnStr     string
-	selectStr string
+	selectStr     string
 	columnMap     map[string]bool
 	useAllCols    bool
 	OmitStr       string

+ 1 - 1
xorm.go

@@ -17,7 +17,7 @@ import (
 )
 
 const (
-	Version string = "0.4.3.0627"
+	Version string = "0.4.3.0824"
 )
 
 func regDrvsNDialects() bool {