bug fixed

This commit is contained in:
Lunny Xiao 2016-03-16 23:05:25 +08:00
parent 9968697225
commit 769f6b3ae6
13 changed files with 70 additions and 16 deletions

View File

@ -1 +1 @@
xorm v0.5.2.0314 xorm v0.5.2.0316

5
examples/README.md Normal file
View File

@ -0,0 +1,5 @@
# Xorm Examples
Notice: all the examples will ask you install extra package `github.com/mattn/go-sqlite3`, since it depends on cgo. You have to compile it after you install a c++ compile. Please see [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3).
And then, you can run the examples via `go run xxx.go`. Every go file is a standalone example.

View File

@ -22,7 +22,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
return return
} }
Orm.ShowSQL = true Orm.ShowSQL(true)
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000) cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
Orm.SetDefaultCacher(cacher) Orm.SetDefaultCacher(cacher)

View File

@ -85,7 +85,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
return return
} }
engine.ShowSQL = true engine.ShowSQL(true)
cacher := xorm.NewLRUCacher2(xorm.NewMemoryStore(), time.Hour, 1000) cacher := xorm.NewLRUCacher2(xorm.NewMemoryStore(), time.Hour, 1000)
engine.SetDefaultCacher(cacher) engine.SetDefaultCacher(cacher)
fmt.Println(engine) fmt.Println(engine)
@ -95,7 +95,7 @@ func main() {
fmt.Println("-----start mysql go routines-----") fmt.Println("-----start mysql go routines-----")
engine, err = mysqlEngine() engine, err = mysqlEngine()
engine.ShowSQL = true engine.ShowSQL(true)
cacher = xorm.NewLRUCacher2(xorm.NewMemoryStore(), time.Hour, 1000) cacher = xorm.NewLRUCacher2(xorm.NewMemoryStore(), time.Hour, 1000)
engine.SetDefaultCacher(cacher) engine.SetDefaultCacher(cacher)
if err != nil { if err != nil {

View File

@ -53,7 +53,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
return return
} }
Orm.ShowSQL = true Orm.ShowSQL(true)
err = Orm.CreateTables(&User{}) err = Orm.CreateTables(&User{})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -34,7 +34,7 @@ func main() {
return return
} }
defer Orm.Close() defer Orm.Close()
Orm.ShowSQL = true Orm.ShowSQL(true)
err = Orm.CreateTables(&User{}, &LoginInfo{}) err = Orm.CreateTables(&User{}, &LoginInfo{})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -56,7 +56,7 @@ func main() {
fmt.Println(info) fmt.Println(info)
infos := make([]LoginInfo1, 0) infos := make([]LoginInfo1, 0)
err = Orm.Sql(`select *, (select name from user where id = login_info.user_id) as user_name from err = Orm.Sql(`select *, (select name from user where id = login_info.user_id) as user_name from
login_info limit 10`).Find(&infos) login_info limit 10`).Find(&infos)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

49
examples/find.go Normal file
View File

@ -0,0 +1,49 @@
package main
import (
"fmt"
"os"
"time"
"github.com/go-xorm/xorm"
)
type User struct {
Id int64
Name string
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
func main() {
f := "conversion.db"
os.Remove(f)
Orm, err := xorm.NewEngine("sqlite3", f)
if err != nil {
fmt.Println(err)
return
}
Orm.ShowSQL(true)
err = Orm.CreateTables(&User{})
if err != nil {
fmt.Println(err)
return
}
_, err = Orm.Insert(&User{Id: 1, Name: "xlw"})
if err != nil {
fmt.Println(err)
return
}
users := make([]User, 0)
err = Orm.Find(&users)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(users)
}

View File

@ -33,7 +33,7 @@ func test(engine *xorm.Engine) {
return return
} }
engine.ShowSQL = true engine.ShowSQL(true)
engine.SetMaxOpenConns(5) engine.SetMaxOpenConns(5)
size := 1000 size := 1000
@ -91,7 +91,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
return return
} }
engine.ShowSQL = true engine.ShowSQL(true)
fmt.Println(engine) fmt.Println(engine)
test(engine) test(engine)
fmt.Println("------------------------") fmt.Println("------------------------")

View File

@ -32,7 +32,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
return return
} }
Orm.ShowSQL = true Orm.ShowSQL(true)
err = Orm.CreateTables(&User{}, &LoginInfo{}) err = Orm.CreateTables(&User{}, &LoginInfo{})
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -65,7 +65,7 @@ func main() {
fmt.Println(err) fmt.Println(err)
return return
} }
Orm.ShowSQL = true Orm.ShowSQL(true)
err = sync(Orm) err = sync(Orm)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -20,7 +20,7 @@ func main() {
return return
} }
defer orm.Close() defer orm.Close()
orm.ShowSQL = true orm.ShowSQL(true)
tables, err := orm.DBMetas() tables, err := orm.DBMetas()
if err != nil { if err != nil {

View File

@ -457,7 +457,7 @@ func (session *Session) scanMapIntoStruct(obj interface{}, objMap map[string][]b
fieldValue = dataStruct.FieldByName(fieldName) fieldValue = dataStruct.FieldByName(fieldName)
} }
if !fieldValue.IsValid() || !fieldValue.CanSet() { if !fieldValue.IsValid() || !fieldValue.CanSet() {
session.Engine.LogWarn("table %v's column %v is not valid or cannot set", session.Engine.LogWarnf("table %v's column %v is not valid or cannot set",
table.Name, key) table.Name, key)
continue continue
} }
@ -1568,7 +1568,7 @@ func (session *Session) dropAll() error {
func (session *Session) getField(dataStruct *reflect.Value, key string, table *core.Table, idx int) *reflect.Value { func (session *Session) getField(dataStruct *reflect.Value, key string, table *core.Table, idx int) *reflect.Value {
var col *core.Column var col *core.Column
if col = table.GetColumnIdx(key, idx); col == nil { if col = table.GetColumnIdx(key, idx); col == nil {
session.Engine.LogWarn(fmt.Sprintf("table %v has no column %v. %v", table.Name, key, table.ColumnsSeq())) session.Engine.LogWarnf("table %v has no column %v. %v", table.Name, key, table.ColumnsSeq())
return nil return nil
} }
@ -1579,7 +1579,7 @@ func (session *Session) getField(dataStruct *reflect.Value, key string, table *c
} }
if !fieldValue.IsValid() || !fieldValue.CanSet() { if !fieldValue.IsValid() || !fieldValue.CanSet() {
session.Engine.LogWarn("table %v's column %v is not valid or cannot set", session.Engine.LogWarnf("table %v's column %v is not valid or cannot set",
table.Name, key) table.Name, key)
return nil return nil
} }

View File

@ -17,7 +17,7 @@ import (
) )
const ( const (
Version string = "0.5.2.0314" Version string = "0.5.2.0316"
) )
func regDrvsNDialects() bool { func regDrvsNDialects() bool {