resolved #176 & cache bug fixed

This commit is contained in:
Lunny Xiao 2015-04-01 16:32:17 +08:00
parent e06b88ec16
commit aa90a634d4
8 changed files with 51 additions and 42 deletions

View File

@ -41,26 +41,19 @@ Drivers for Go's sql package which currently support database/sql includes:
* MsSql: [github.com/lunny/godbc](https://github.com/lunny/godbc)
# Changelog
* **v0.4.1**
Features:
* Add deleted xorm tag for soft delete and add unscoped
* **v0.4.3**
* Json column type support
* oracle expirement support
* bug fixed
* **v0.4.0 RC1**
Changes:
* moved xorm cmd to [github.com/go-xorm/cmd](github.com/go-xorm/cmd)
* refactored general DB operation a core lib at [github.com/go-xorm/core](https://github.com/go-xorm/core)
* moved tests to github.com/go-xorm/tests [github.com/go-xorm/tests](github.com/go-xorm/tests)
* **v0.4.2**
* Transaction will auto rollback if not Rollback or Commit be called.
* Gonic Mapper support
* bug fixed
Improvements:
* Prepared statement cache
* Add Incr API
* Specify Timezone Location
[More changelogs ...](https://github.com/go-xorm/manual-en-US/tree/master/chapter-15)
[More changelogs ...](https://github.com/go-xorm/manual-en-US/tree/master/chapter-16)
# Installation

View File

@ -44,10 +44,15 @@ xorm是一个简单而强大的Go语言ORM库. 通过它可以使数据库操作
## 更新日志
* **v0.4.3**
* Json 字段类型支持
* oracle实验性支持
* bug修正
* **v0.4.2**
新特性:
* deleted标记
* bug fixed
* 事物如未Rollback或Commit在关闭时会自动Rollback
* Gonic 映射支持
* bug修正
[更多更新日志...](https://github.com/go-xorm/manual-zh-CN/tree/master/chapter-16)

View File

@ -238,7 +238,7 @@ func (db *mssql) SqlType(c *core.Column) string {
c.Length = 7
case core.MediumInt:
res = core.Int
case core.MediumText, core.TinyText, core.LongText:
case core.MediumText, core.TinyText, core.LongText, core.Json:
res = core.Text
case core.Double:
res = core.Real

View File

@ -221,6 +221,8 @@ func (db *mysql) SqlType(c *core.Column) string {
case core.Uuid:
res = core.Varchar
c.Length = 40
case core.Json:
res = core.Text
default:
res = t
}

View File

@ -518,7 +518,7 @@ func (db *oracle) SqlType(c *core.Column) string {
res = "TIMESTAMP WITH TIME ZONE"
case core.Float, core.Double, core.Numeric, core.Decimal:
res = "NUMBER"
case core.Text, core.MediumText, core.LongText:
case core.Text, core.MediumText, core.LongText, core.Json:
res = "CLOB"
case core.Char, core.Varchar, core.TinyText:
res = "VARCHAR2"

View File

@ -621,7 +621,8 @@ func (session *Session) cacheGet(bean interface{}, sqlStr string, args ...interf
// if has no reftable, then don't use cache currently
if session.Statement.RefTable == nil ||
session.Statement.JoinStr != "" ||
session.Statement.RawSQL != "" {
session.Statement.RawSQL != "" ||
session.Tx != nil {
return false, ErrCacheFailed
}
@ -721,7 +722,8 @@ func (session *Session) cacheGet(bean interface{}, sqlStr string, args ...interf
func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr interface{}, args ...interface{}) (err error) {
if session.Statement.RefTable == nil ||
indexNoCase(sqlStr, "having") != -1 ||
indexNoCase(sqlStr, "group by") != -1 {
indexNoCase(sqlStr, "group by") != -1 ||
session.Tx != nil {
return ErrCacheFailed
}
@ -863,7 +865,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
}
temps[ididxes[sid]] = bean
session.Engine.LogDebug("[cacheFind] cache bean:", tableName, id, bean)
session.Engine.LogDebug("[cacheFind] cache bean:", tableName, id, bean, temps)
cacher.PutBean(tableName, sid, bean)
}
}
@ -871,7 +873,7 @@ func (session *Session) cacheFind(t reflect.Type, sqlStr string, rowsSlicePtr in
for j := 0; j < len(temps); j++ {
bean := temps[j]
if bean == nil {
session.Engine.LogWarn("[cacheFind] cache no hit:", tableName, ides[j])
session.Engine.LogWarn("[cacheFind] cache no hit:", tableName, ides[j], temps)
// return errors.New("cache error") // !nashtsai! no need to return error, but continue instead
continue
}
@ -2356,7 +2358,6 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
} else {
x = 0
}
//fmt.Println("######", x, data)
} else if strings.HasPrefix(sdata, "0x") {
x, err = strconv.ParseInt(sdata, 16, 64)
} else if strings.HasPrefix(sdata, "0") {
@ -2605,7 +2606,6 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
} else {
x = 0
}
//fmt.Println("######", x, data)
} else if strings.HasPrefix(sdata, "0x") {
x, err = strconv.ParseInt(sdata, 16, 64)
} else if strings.HasPrefix(sdata, "0") {
@ -2631,7 +2631,6 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
} else {
x = 0
}
//fmt.Println("######", x, data)
} else if strings.HasPrefix(sdata, "0x") {
x1, err = strconv.ParseInt(sdata, 16, 64)
x = int(x1)
@ -2660,7 +2659,6 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
} else {
x = 0
}
//fmt.Println("######", x, data)
} else if strings.HasPrefix(sdata, "0x") {
x1, err = strconv.ParseInt(sdata, 16, 64)
x = int32(x1)
@ -2689,7 +2687,6 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
} else {
x = 0
}
//fmt.Println("######", x, data)
} else if strings.HasPrefix(sdata, "0x") {
x1, err = strconv.ParseInt(sdata, 16, 64)
x = int8(x1)
@ -2718,7 +2715,6 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
} else {
x = 0
}
//fmt.Println("######", x, data)
} else if strings.HasPrefix(sdata, "0x") {
x1, err = strconv.ParseInt(sdata, 16, 64)
x = int16(x1)
@ -3237,7 +3233,8 @@ func (session *Session) cacheInsert(tables ...string) error {
}
func (session *Session) cacheUpdate(sqlStr string, args ...interface{}) error {
if session.Statement.RefTable == nil || len(session.Statement.RefTable.PrimaryKeys) != 1 {
if session.Statement.RefTable == nil ||
session.Tx != nil {
return ErrCacheFailed
}
@ -3587,7 +3584,8 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
}
func (session *Session) cacheDelete(sqlStr string, args ...interface{}) error {
if session.Statement.RefTable == nil || len(session.Statement.RefTable.PrimaryKeys) != 1 {
if session.Statement.RefTable == nil ||
session.Tx != nil {
return ErrCacheFailed
}
@ -3612,15 +3610,25 @@ func (session *Session) cacheDelete(sqlStr string, args ...interface{}) error {
if len(resultsSlice) > 0 {
for _, data := range resultsSlice {
var id int64
if v, ok := data[session.Statement.RefTable.PrimaryKeys[0]]; !ok {
var pk core.PK = make([]interface{}, 0)
for _, col := range session.Statement.RefTable.PKColumns() {
if v, ok := data[col.Name]; !ok {
return errors.New("no id")
} else {
if col.SQLType.IsText() {
pk = append(pk, string(v))
} else if col.SQLType.IsNumeric() {
id, err = strconv.ParseInt(string(v), 10, 64)
if err != nil {
return err
}
pk = append(pk, id)
} else {
return errors.New("not supported primary key type")
}
ids = append(ids, core.PK{id})
}
}
ids = append(ids, pk)
}
}
} /*else {

View File

@ -156,7 +156,8 @@ func (db *sqlite3) SqlType(c *core.Column) string {
return core.DateTime
case core.TimeStampz:
return core.Text
case core.Char, core.Varchar, core.NVarchar, core.TinyText, core.Text, core.MediumText, core.LongText:
case core.Char, core.Varchar, core.NVarchar, core.TinyText,
core.Text, core.MediumText, core.LongText, core.Json:
return core.Text
case core.Bit, core.TinyInt, core.SmallInt, core.MediumInt, core.Int, core.Integer, core.BigInt, core.Bool:
return core.Integer

View File

@ -13,7 +13,7 @@ import (
)
const (
Version string = "0.4.2.0401"
Version string = "0.4.3.0401"
)
func regDrvsNDialects() bool {