resolved #431
This commit is contained in:
parent
dddc985b86
commit
01a03a3092
|
@ -1291,9 +1291,9 @@ func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session.Statement.Params = append(session.Statement.joinArgs, append(session.Statement.Params, session.Statement.BeanArgs...)...)
|
|
||||||
|
|
||||||
session.Statement.attachInSql()
|
session.Statement.attachInSql()
|
||||||
|
session.Statement.Params = append(append(append(session.Statement.joinArgs, session.Statement.Params...),
|
||||||
|
session.Statement.BeanArgs...), session.Statement.inParams...)
|
||||||
|
|
||||||
sqlStr = session.Statement.genSelectSQL(columnStr)
|
sqlStr = session.Statement.genSelectSQL(columnStr)
|
||||||
args = session.Statement.Params
|
args = session.Statement.Params
|
||||||
|
@ -1874,7 +1874,6 @@ func (session *Session) _row2Bean(rows *core.Rows, fields []string, fieldsCount
|
||||||
// !<winxxp>! 增加支持sql.Scanner接口的结构,如sql.NullString
|
// !<winxxp>! 增加支持sql.Scanner接口的结构,如sql.NullString
|
||||||
hasAssigned = true
|
hasAssigned = true
|
||||||
if err := nulVal.Scan(vv.Interface()); err != nil {
|
if err := nulVal.Scan(vv.Interface()); err != nil {
|
||||||
//fmt.Println("sql.Sanner error:", err.Error())
|
|
||||||
session.Engine.logger.Error("sql.Sanner error:", err.Error())
|
session.Engine.logger.Error("sql.Sanner error:", err.Error())
|
||||||
hasAssigned = false
|
hasAssigned = false
|
||||||
}
|
}
|
||||||
|
@ -2469,13 +2468,11 @@ func (session *Session) str2Time(col *core.Column, data string) (outTime time.Ti
|
||||||
if err == nil {
|
if err == nil {
|
||||||
x = time.Unix(sd, 0)
|
x = time.Unix(sd, 0)
|
||||||
// !nashtsai! HACK mymysql driver is casuing Local location being change to CHAT and cause wrong time conversion
|
// !nashtsai! HACK mymysql driver is casuing Local location being change to CHAT and cause wrong time conversion
|
||||||
//fmt.Println(x.In(session.Engine.TZLocation), "===")
|
|
||||||
if col.TimeZone == nil {
|
if col.TimeZone == nil {
|
||||||
x = x.In(session.Engine.TZLocation)
|
x = x.In(session.Engine.TZLocation)
|
||||||
} else {
|
} else {
|
||||||
x = x.In(col.TimeZone)
|
x = x.In(col.TimeZone)
|
||||||
}
|
}
|
||||||
//fmt.Println(x, "=====")
|
|
||||||
session.Engine.logger.Debugf("time(0) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
|
session.Engine.logger.Debugf("time(0) key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
|
||||||
} else {
|
} else {
|
||||||
session.Engine.logger.Debugf("time(0) err key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
|
session.Engine.logger.Debugf("time(0) err key[%v]: %+v | sdata: [%v]\n", col.FieldName, x, sdata)
|
||||||
|
|
29
statement.go
29
statement.go
|
@ -46,6 +46,7 @@ type Statement struct {
|
||||||
WhereStr string
|
WhereStr string
|
||||||
IdParam *core.PK
|
IdParam *core.PK
|
||||||
Params []interface{}
|
Params []interface{}
|
||||||
|
inParams []interface{}
|
||||||
OrderStr string
|
OrderStr string
|
||||||
JoinStr string
|
JoinStr string
|
||||||
joinArgs []interface{}
|
joinArgs []interface{}
|
||||||
|
@ -90,6 +91,7 @@ func (statement *Statement) Init() {
|
||||||
statement.LimitN = 0
|
statement.LimitN = 0
|
||||||
statement.WhereStr = ""
|
statement.WhereStr = ""
|
||||||
statement.Params = make([]interface{}, 0)
|
statement.Params = make([]interface{}, 0)
|
||||||
|
statement.inParams = make([]interface{}, 0)
|
||||||
statement.OrderStr = ""
|
statement.OrderStr = ""
|
||||||
statement.UseCascade = true
|
statement.UseCascade = true
|
||||||
statement.JoinStr = ""
|
statement.JoinStr = ""
|
||||||
|
@ -432,7 +434,6 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
|
||||||
}
|
}
|
||||||
|
|
||||||
APPEND:
|
APPEND:
|
||||||
//fmt.Println("==", col.Name, "==", fmt.Sprintf("%v", val))
|
|
||||||
args = append(args, val)
|
args = append(args, val)
|
||||||
if col.IsPrimaryKey && engine.dialect.DBType() == "ql" {
|
if col.IsPrimaryKey && engine.dialect.DBType() == "ql" {
|
||||||
continue
|
continue
|
||||||
|
@ -821,7 +822,7 @@ func (statement *Statement) attachInSql() {
|
||||||
statement.ConditionStr += " " + statement.Engine.dialect.AndStr() + " "
|
statement.ConditionStr += " " + statement.Engine.dialect.AndStr() + " "
|
||||||
}
|
}
|
||||||
statement.ConditionStr += inSql
|
statement.ConditionStr += inSql
|
||||||
statement.Params = append(statement.Params, inArgs...)
|
statement.inParams = inArgs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,7 +874,6 @@ func (statement *Statement) Cols(columns ...string) *Statement {
|
||||||
}
|
}
|
||||||
|
|
||||||
newColumns := statement.col2NewColsWithQuote(columns...)
|
newColumns := statement.col2NewColsWithQuote(columns...)
|
||||||
//fmt.Println("=====", columns, newColumns, cols)
|
|
||||||
statement.ColumnStr = strings.Join(newColumns, ", ")
|
statement.ColumnStr = strings.Join(newColumns, ", ")
|
||||||
statement.ColumnStr = strings.Replace(statement.ColumnStr, statement.Engine.quote("*"), "*", -1)
|
statement.ColumnStr = strings.Replace(statement.ColumnStr, statement.Engine.quote("*"), "*", -1)
|
||||||
return statement
|
return statement
|
||||||
|
@ -1166,7 +1166,8 @@ func (statement *Statement) genGetSql(bean interface{}) (string, []interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
statement.attachInSql() // !admpub! fix bug:Iterate func missing "... IN (...)"
|
statement.attachInSql() // !admpub! fix bug:Iterate func missing "... IN (...)"
|
||||||
return statement.genSelectSQL(columnStr), append(append(statement.joinArgs, statement.Params...), statement.BeanArgs...)
|
return statement.genSelectSQL(columnStr), append(append(append(statement.joinArgs, statement.Params...),
|
||||||
|
statement.BeanArgs...), statement.inParams...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Statement) genAddColumnStr(col *core.Column) (string, []interface{}) {
|
func (s *Statement) genAddColumnStr(col *core.Column) (string, []interface{}) {
|
||||||
|
@ -1176,20 +1177,6 @@ func (s *Statement) genAddColumnStr(col *core.Column) (string, []interface{}) {
|
||||||
return sql, []interface{}{}
|
return sql, []interface{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func (s *Statement) genAddIndexStr(idxName string, cols []string) (string, []interface{}) {
|
|
||||||
quote := s.Engine.Quote
|
|
||||||
colstr := quote(strings.Join(cols, quote(", ")))
|
|
||||||
sql := fmt.Sprintf("CREATE INDEX %v ON %v (%v);", quote(idxName), quote(s.TableName()), colstr)
|
|
||||||
return sql, []interface{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Statement) genAddUniqueStr(uqeName string, cols []string) (string, []interface{}) {
|
|
||||||
quote := s.Engine.Quote
|
|
||||||
colstr := quote(strings.Join(cols, quote(", ")))
|
|
||||||
sql := fmt.Sprintf("CREATE UNIQUE INDEX %v ON %v (%v);", quote(uqeName), quote(s.TableName()), colstr)
|
|
||||||
return sql, []interface{}{}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
func (statement *Statement) buildConditions(table *core.Table, bean interface{}, includeVersion bool, includeUpdated bool, includeNil bool, includeAutoIncr bool, addedTableName bool) ([]string, []interface{}) {
|
func (statement *Statement) buildConditions(table *core.Table, bean interface{}, includeVersion bool, includeUpdated bool, includeNil bool, includeAutoIncr bool, addedTableName bool) ([]string, []interface{}) {
|
||||||
return buildConditions(statement.Engine, table, bean, includeVersion, includeUpdated, includeNil, includeAutoIncr, statement.allUseBool, statement.useAllCols,
|
return buildConditions(statement.Engine, table, bean, includeVersion, includeUpdated, includeNil, includeAutoIncr, statement.allUseBool, statement.useAllCols,
|
||||||
statement.unscoped, statement.mustColumnMap, statement.TableName(), statement.TableAlias, addedTableName)
|
statement.unscoped, statement.mustColumnMap, statement.TableName(), statement.TableAlias, addedTableName)
|
||||||
|
@ -1213,7 +1200,8 @@ func (statement *Statement) genCountSql(bean interface{}) (string, []interface{}
|
||||||
id = ""
|
id = ""
|
||||||
}
|
}
|
||||||
statement.attachInSql()
|
statement.attachInSql()
|
||||||
return statement.genSelectSQL(fmt.Sprintf("count(%v)", id)), append(append(statement.joinArgs, statement.Params...), statement.BeanArgs...)
|
return statement.genSelectSQL(fmt.Sprintf("count(%v)", id)), append(append(append(statement.joinArgs, statement.Params...),
|
||||||
|
statement.BeanArgs...), statement.inParams...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) genSumSql(bean interface{}, columns ...string) (string, []interface{}) {
|
func (statement *Statement) genSumSql(bean interface{}, columns ...string) (string, []interface{}) {
|
||||||
|
@ -1233,7 +1221,8 @@ func (statement *Statement) genSumSql(bean interface{}, columns ...string) (stri
|
||||||
for _, colName := range columns {
|
for _, colName := range columns {
|
||||||
sumStrs = append(sumStrs, fmt.Sprintf("sum(%s)", colName))
|
sumStrs = append(sumStrs, fmt.Sprintf("sum(%s)", colName))
|
||||||
}
|
}
|
||||||
return statement.genSelectSQL(strings.Join(sumStrs, ", ")), append(append(statement.joinArgs, statement.Params...), statement.BeanArgs...)
|
return statement.genSelectSQL(strings.Join(sumStrs, ", ")), append(append(append(statement.joinArgs, statement.Params...),
|
||||||
|
statement.BeanArgs...), statement.inParams...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (statement *Statement) genSelectSQL(columnStr string) (a string) {
|
func (statement *Statement) genSelectSQL(columnStr string) (a string) {
|
||||||
|
|
Loading…
Reference in New Issue