some fixed for mssql support
This commit is contained in:
parent
06a1b9da56
commit
7222d6d7b3
27
session.go
27
session.go
|
@ -684,6 +684,7 @@ func (session *Session) canCache() bool {
|
||||||
session.Statement.JoinStr != "" ||
|
session.Statement.JoinStr != "" ||
|
||||||
session.Statement.RawSQL != "" ||
|
session.Statement.RawSQL != "" ||
|
||||||
!session.Statement.UseCache ||
|
!session.Statement.UseCache ||
|
||||||
|
session.Statement.IsForUpdate ||
|
||||||
session.Tx != nil ||
|
session.Tx != nil ||
|
||||||
len(session.Statement.selectStr) > 0 {
|
len(session.Statement.selectStr) > 0 {
|
||||||
return false
|
return false
|
||||||
|
@ -1332,7 +1333,11 @@ func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{})
|
||||||
}
|
}
|
||||||
colName = session.Engine.Quote(nm) + "." + colName
|
colName = session.Engine.Quote(nm) + "." + colName
|
||||||
}
|
}
|
||||||
autoCond = builder.IsNull{colName}.Or(builder.Eq{colName: "0001-01-01 00:00:00"})
|
if session.Engine.dialect.DBType() == core.MSSQL {
|
||||||
|
autoCond = builder.IsNull{colName}
|
||||||
|
} else {
|
||||||
|
autoCond = builder.IsNull{colName}.Or(builder.Eq{colName: "0001-01-01 00:00:00"})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1839,16 +1844,24 @@ func (session *Session) _row2Bean(rows *core.Rows, fields []string, fieldsCount
|
||||||
hasAssigned = true
|
hasAssigned = true
|
||||||
|
|
||||||
t := vv.Convert(core.TimeType).Interface().(time.Time)
|
t := vv.Convert(core.TimeType).Interface().(time.Time)
|
||||||
|
|
||||||
z, _ := t.Zone()
|
z, _ := t.Zone()
|
||||||
if len(z) == 0 || t.Year() == 0 { // !nashtsai! HACK tmp work around for lib/pq doesn't properly time with location
|
dbTZ := session.Engine.DatabaseTZ
|
||||||
dbTZ := session.Engine.DatabaseTZ
|
if dbTZ == nil {
|
||||||
if dbTZ == nil {
|
if session.Engine.dialect.DBType() == core.SQLITE {
|
||||||
|
dbTZ = time.UTC
|
||||||
|
} else {
|
||||||
dbTZ = time.Local
|
dbTZ = time.Local
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set new location if database don't save timezone or give an incorrect timezone
|
||||||
|
if len(z) == 0 || t.Year() == 0 || t.Location().String() != dbTZ.String() { // !nashtsai! HACK tmp work around for lib/pq doesn't properly time with location
|
||||||
session.Engine.logger.Debugf("empty zone key[%v] : %v | zone: %v | location: %+v\n", key, t, z, *t.Location())
|
session.Engine.logger.Debugf("empty zone key[%v] : %v | zone: %v | location: %+v\n", key, t, z, *t.Location())
|
||||||
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
|
||||||
t.Minute(), t.Second(), t.Nanosecond(), dbTZ)
|
t.Minute(), t.Second(), t.Nanosecond(), dbTZ)
|
||||||
}
|
}
|
||||||
|
|
||||||
// !nashtsai! convert to engine location
|
// !nashtsai! convert to engine location
|
||||||
if col.TimeZone == nil {
|
if col.TimeZone == nil {
|
||||||
t = t.In(session.Engine.TZLocation)
|
t = t.In(session.Engine.TZLocation)
|
||||||
|
@ -3011,6 +3024,9 @@ func (session *Session) value2Interface(col *core.Column, fieldValue reflect.Val
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
if col.SQLType.IsBlob() {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
return string(data), nil
|
return string(data), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3020,6 +3036,9 @@ func (session *Session) value2Interface(col *core.Column, fieldValue reflect.Val
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
if col.SQLType.IsBlob() {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
return string(data), nil
|
return string(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
statement.go
15
statement.go
|
@ -497,7 +497,7 @@ func buildConds(engine *Engine, table *core.Table, bean interface{},
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if engine.dialect.DBType() == core.MSSQL && col.SQLType.Name == core.Text {
|
if engine.dialect.DBType() == core.MSSQL && (col.SQLType.Name == core.Text || col.SQLType.IsBlob() || col.SQLType.Name == core.TimeStampz) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if col.SQLType.IsJson() {
|
if col.SQLType.IsJson() {
|
||||||
|
@ -522,7 +522,11 @@ func buildConds(engine *Engine, table *core.Table, bean interface{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if col.IsDeleted && !unscoped { // tag "deleted" is enabled
|
if col.IsDeleted && !unscoped { // tag "deleted" is enabled
|
||||||
conds = append(conds, builder.IsNull{colName}.Or(builder.Eq{colName: "0001-01-01 00:00:00"}))
|
if engine.dialect.DBType() == core.MSSQL {
|
||||||
|
conds = append(conds, builder.IsNull{colName})
|
||||||
|
} else {
|
||||||
|
conds = append(conds, builder.IsNull{colName}.Or(builder.Eq{colName: "0001-01-01 00:00:00"}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldValue := *fieldValuePtr
|
fieldValue := *fieldValuePtr
|
||||||
|
@ -1316,7 +1320,12 @@ func (statement *Statement) convertIDSQL(sqlStr string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("SELECT %s FROM %v", colstrs, sqls[1])
|
var top string
|
||||||
|
if statement.LimitN > 0 && statement.Engine.dialect.DBType() == core.MSSQL {
|
||||||
|
top = fmt.Sprintf("TOP %d ", statement.LimitN)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("SELECT %s%s FROM %v", top, colstrs, sqls[1])
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue