Merge 6b5b20a545
into 069f551119
This commit is contained in:
commit
1572e53881
|
@ -478,6 +478,13 @@ func (engine *Engine) Where(querystring string, args ...interface{}) *Session {
|
||||||
return session.Where(querystring, args...)
|
return session.Where(querystring, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Where method provide a condition query without bean's non-empty fields.
|
||||||
|
func (engine *Engine) NoAutoCondition(querystring string, args ...interface{}) *Session {
|
||||||
|
session := engine.NewSession()
|
||||||
|
session.IsAutoClose = true
|
||||||
|
return session.NoAutoCondition(querystring, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// Id mehtod provoide a condition as (id) = ?
|
// Id mehtod provoide a condition as (id) = ?
|
||||||
func (engine *Engine) Id(id interface{}) *Session {
|
func (engine *Engine) Id(id interface{}) *Session {
|
||||||
session := engine.NewSession()
|
session := engine.NewSession()
|
||||||
|
|
12
session.go
12
session.go
|
@ -118,6 +118,12 @@ func (session *Session) Where(querystring string, args ...interface{}) *Session
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Method Where provides custom query condition without bean's non-empty fields.
|
||||||
|
func (session *Session) NoAutoCondition(querystring string, args ...interface{}) *Session {
|
||||||
|
session.Statement.NoAutoCondition(querystring, args...)
|
||||||
|
return session
|
||||||
|
}
|
||||||
|
|
||||||
// Method Where provides custom query condition.
|
// Method Where provides custom query condition.
|
||||||
func (session *Session) And(querystring string, args ...interface{}) *Session {
|
func (session *Session) And(querystring string, args ...interface{}) *Session {
|
||||||
session.Statement.And(querystring, args...)
|
session.Statement.And(querystring, args...)
|
||||||
|
@ -1884,7 +1890,7 @@ func (session *Session) _row2Bean(rows *core.Rows, fields []string, fieldsCount
|
||||||
structInter := reflect.New(fieldValue.Type())
|
structInter := reflect.New(fieldValue.Type())
|
||||||
newsession := session.Engine.NewSession()
|
newsession := session.Engine.NewSession()
|
||||||
defer newsession.Close()
|
defer newsession.Close()
|
||||||
has, err := newsession.Id(pk).NoCascade().Get(structInter.Interface())
|
has, err := newsession.Id(pk).Cascade().Get(structInter.Interface()) // FIXME NoCascade
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2623,7 +2629,7 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
|
||||||
structInter := reflect.New(fieldValue.Type())
|
structInter := reflect.New(fieldValue.Type())
|
||||||
newsession := session.Engine.NewSession()
|
newsession := session.Engine.NewSession()
|
||||||
defer newsession.Close()
|
defer newsession.Close()
|
||||||
has, err := newsession.Id(pk).NoCascade().Get(structInter.Interface())
|
has, err := newsession.Id(pk).Cascade().Get(structInter.Interface()) // FIXME NoCascade
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2971,7 +2977,7 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value,
|
||||||
// property to be fetched lazily
|
// property to be fetched lazily
|
||||||
newsession := session.Engine.NewSession()
|
newsession := session.Engine.NewSession()
|
||||||
defer newsession.Close()
|
defer newsession.Close()
|
||||||
has, err := newsession.Id(pk).NoCascade().Get(structInter.Interface())
|
has, err := newsession.Id(pk).Cascade().Get(structInter.Interface()) // FIXME NoCascade
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
27
statement.go
27
statement.go
|
@ -78,6 +78,8 @@ type Statement struct {
|
||||||
incrColumns map[string]incrParam
|
incrColumns map[string]incrParam
|
||||||
decrColumns map[string]decrParam
|
decrColumns map[string]decrParam
|
||||||
exprColumns map[string]exprParam
|
exprColumns map[string]exprParam
|
||||||
|
|
||||||
|
IsNoAutoCondition bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// init
|
// init
|
||||||
|
@ -117,6 +119,8 @@ func (statement *Statement) Init() {
|
||||||
statement.incrColumns = make(map[string]incrParam)
|
statement.incrColumns = make(map[string]incrParam)
|
||||||
statement.decrColumns = make(map[string]decrParam)
|
statement.decrColumns = make(map[string]decrParam)
|
||||||
statement.exprColumns = make(map[string]exprParam)
|
statement.exprColumns = make(map[string]exprParam)
|
||||||
|
|
||||||
|
statement.IsNoAutoCondition = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the raw sql statement
|
// add the raw sql statement
|
||||||
|
@ -142,6 +146,17 @@ func (statement *Statement) Where(querystring string, args ...interface{}) *Stat
|
||||||
return statement
|
return statement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add where statment without bean's non-empty fields for Get Count
|
||||||
|
func (statement *Statement) NoAutoCondition(querystring string, args ...interface{}) *Statement {
|
||||||
|
if !strings.Contains(querystring, statement.Engine.dialect.EqStr()) {
|
||||||
|
querystring = strings.Replace(querystring, "=", statement.Engine.dialect.EqStr(), -1)
|
||||||
|
}
|
||||||
|
statement.WhereStr = querystring
|
||||||
|
statement.Params = args
|
||||||
|
statement.IsNoAutoCondition = true
|
||||||
|
return statement
|
||||||
|
}
|
||||||
|
|
||||||
// add Where & and statment
|
// add Where & and statment
|
||||||
func (statement *Statement) And(querystring string, args ...interface{}) *Statement {
|
func (statement *Statement) And(querystring string, args ...interface{}) *Statement {
|
||||||
if len(statement.WhereStr) > 0 {
|
if len(statement.WhereStr) > 0 {
|
||||||
|
@ -1115,8 +1130,10 @@ func (statement *Statement) genGetSql(bean interface{}) (string, []interface{})
|
||||||
false, true, statement.allUseBool, statement.useAllCols,
|
false, true, statement.allUseBool, statement.useAllCols,
|
||||||
statement.unscoped, statement.mustColumnMap, statement.TableName(), addedTableName)
|
statement.unscoped, statement.mustColumnMap, statement.TableName(), addedTableName)
|
||||||
|
|
||||||
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.dialect.AndStr()+" ")
|
if !statement.IsNoAutoCondition {
|
||||||
statement.BeanArgs = args
|
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.dialect.AndStr()+" ")
|
||||||
|
statement.BeanArgs = args
|
||||||
|
}
|
||||||
|
|
||||||
var columnStr string = statement.ColumnStr
|
var columnStr string = statement.ColumnStr
|
||||||
if len(statement.selectStr) > 0 {
|
if len(statement.selectStr) > 0 {
|
||||||
|
@ -1176,8 +1193,10 @@ func (statement *Statement) genCountSql(bean interface{}) (string, []interface{}
|
||||||
true, statement.allUseBool, statement.useAllCols,
|
true, statement.allUseBool, statement.useAllCols,
|
||||||
statement.unscoped, statement.mustColumnMap, statement.TableName(), addedTableName)
|
statement.unscoped, statement.mustColumnMap, statement.TableName(), addedTableName)
|
||||||
|
|
||||||
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.Dialect().AndStr()+" ")
|
if !statement.IsNoAutoCondition {
|
||||||
statement.BeanArgs = args
|
statement.ConditionStr = strings.Join(colNames, " "+statement.Engine.Dialect().AndStr()+" ")
|
||||||
|
statement.BeanArgs = args
|
||||||
|
}
|
||||||
|
|
||||||
// count(index fieldname) > count(0) > count(*)
|
// count(index fieldname) > count(0) > count(*)
|
||||||
var id string = "*"
|
var id string = "*"
|
||||||
|
|
Loading…
Reference in New Issue