From 9ae245b54bed7552a2dc300ac7627ac9398998bb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 12 Mar 2015 17:46:24 +0800 Subject: [PATCH] bug fixed --- session.go | 8 ++++++++ statement.go | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/session.go b/session.go index 3f6e9853..55b91e4c 100644 --- a/session.go +++ b/session.go @@ -3477,6 +3477,10 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6 } } + if st.LimitN > 0 { + condition = condition + fmt.Sprintf(" LIMIT %d", st.LimitN) + } + sqlStr = fmt.Sprintf("UPDATE %v SET %v, %v %v", session.Engine.Quote(session.Statement.TableName()), strings.Join(colNames, ", "), @@ -3503,6 +3507,10 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6 } } + if st.LimitN > 0 { + condition = condition + fmt.Sprintf(" LIMIT %d", st.LimitN) + } + sqlStr = fmt.Sprintf("UPDATE %v SET %v %v", session.Engine.Quote(session.Statement.TableName()), strings.Join(colNames, ", "), diff --git a/statement.go b/statement.go index bdc1dc98..92ff991d 100644 --- a/statement.go +++ b/statement.go @@ -423,13 +423,14 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{}, pkField := reflect.Indirect(fieldValue).FieldByName(table.PKColumns()[0].FieldName) // fix non-int pk issues //if pkField.Int() != 0 { - if pkField.IsValid() { + if pkField.IsValid() && !isZero(pkField.Interface()) { val = pkField.Interface() } else { continue } } else { //TODO: how to handler? + panic("not supported") } } else { val = fieldValue.Interface() @@ -603,13 +604,14 @@ func buildConditions(engine *Engine, table *core.Table, bean interface{}, pkField := reflect.Indirect(fieldValue).FieldByName(table.PKColumns()[0].FieldName) // fix non-int pk issues //if pkField.Int() != 0 { - if pkField.IsValid() { + if pkField.IsValid() && !isZero(pkField.Interface()) { val = pkField.Interface() } else { continue } } else { //TODO: how to handler? + panic("not supported") } } else { val = fieldValue.Interface()