bug fixed

This commit is contained in:
Lunny Xiao 2013-12-12 14:33:26 +08:00
parent bb6a9c24fa
commit 98d4c0e000
17 changed files with 5594 additions and 5558 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
. "xorm"
) )
type User struct { type User struct {
@ -16,13 +16,13 @@ func main() {
f := "cache.db" f := "cache.db"
os.Remove(f) os.Remove(f)
Orm, err := NewEngine("sqlite3", f) Orm, err := xorm.NewEngine("sqlite3", f)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
return return
} }
Orm.ShowSQL = true Orm.ShowSQL = true
cacher := NewLRUCacher(NewMemoryStore(), 1000) cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
Orm.SetDefaultCacher(cacher) Orm.SetDefaultCacher(cacher)
err = Orm.CreateTables(&User{}) err = Orm.CreateTables(&User{})

View File

@ -1,14 +1,11 @@
package main package main
import ( import (
//xorm "github.com/lunny/xorm"
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
//"time"
//"sync/atomic"
xorm "xorm"
) )
type User struct { type User struct {
@ -40,36 +37,31 @@ func test(engine *xorm.Engine) {
for i := 0; i < size; i++ { for i := 0; i < size; i++ {
go func(x int) { go func(x int) {
//x := i //x := i
err := engine.Test() err := engine.Ping()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} else { } else {
err = engine.Map(u) for j := 0; j < 10; j++ {
if err != nil { if x+j < 2 {
fmt.Println("Map user failed") _, err = engine.Get(u)
} else { } else if x+j < 4 {
for j := 0; j < 10; j++ { users := make([]User, 0)
if x+j < 2 { err = engine.Find(&users)
_, err = engine.Get(u) } else if x+j < 8 {
} else if x+j < 4 { _, err = engine.Count(u)
users := make([]User, 0) } else if x+j < 16 {
err = engine.Find(&users) _, err = engine.Insert(&User{Name: "xlw"})
} else if x+j < 8 { } else if x+j < 32 {
_, err = engine.Count(u) //_, err = engine.Id(1).Delete(u)
} else if x+j < 16 { _, err = engine.Delete(u)
_, err = engine.Insert(&User{Name: "xlw"}) }
} else if x+j < 32 { if err != nil {
//_, err = engine.Id(1).Delete(u) fmt.Println(err)
_, err = engine.Delete(u) queue <- x
} return
if err != nil {
fmt.Println(err)
queue <- x
return
}
} }
fmt.Printf("%v success!\n", x)
} }
fmt.Printf("%v success!\n", x)
} }
queue <- x queue <- x
}(i) }(i)

View File

@ -3,9 +3,9 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
. "xorm"
) )
type Status struct { type Status struct {

View File

@ -2,9 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
. "xorm"
) )
type User struct { type User struct {

View File

@ -1,15 +1,12 @@
package main package main
import ( import (
//xorm "github.com/lunny/xorm"
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
//"time"
//"sync/atomic"
"runtime" "runtime"
xorm "xorm"
) )
type User struct { type User struct {

View File

@ -3,13 +3,11 @@ package main
import ( import (
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm"
xorm "github.com/lunny/xorm" xorm "github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
//"time"
//"sync/atomic"
"runtime" "runtime"
//xorm "xorm"
) )
type User struct { type User struct {

View File

@ -2,9 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
. "xorm"
) )
type User struct { type User struct {

View File

@ -2,9 +2,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
. "xorm"
) )
type User struct { type User struct {

View File

@ -4,8 +4,8 @@ import (
"fmt" "fmt"
_ "github.com/bylevel/pq" _ "github.com/bylevel/pq"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/lunny/xorm"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"xorm"
) )
type SyncUser2 struct { type SyncUser2 struct {

View File

@ -1,8 +1,7 @@
package xorm package xorm
import ( import (
//"reflect" "strings"
//"strings"
) )
// name translation between struct, fields names and table, column names // name translation between struct, fields names and table, column names
@ -71,6 +70,8 @@ func titleCasedName(name string) string {
newstr := make([]rune, 0) newstr := make([]rune, 0)
upNextChar := true upNextChar := true
name = strings.ToLower(name)
for _, chr := range name { for _, chr := range name {
switch { switch {
case upNextChar: case upNextChar:

4483
session.go

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

2
xorm/.gopmfile Normal file
View File

@ -0,0 +1,2 @@
[deps]
github.com/lunny/xorm=../

View File

@ -184,9 +184,9 @@ func genGoImports(tables []*xorm.Table) map[string]string {
func typestring(col *xorm.Column) string { func typestring(col *xorm.Column) string {
st := col.SQLType st := col.SQLType
if col.IsPrimaryKey { /*if col.IsPrimaryKey {
return "int64" return "int64"
} }*/
t := xorm.SQLType2Type(st) t := xorm.SQLType2Type(st)
s := t.String() s := t.String()
if s == "[]uint8" { if s == "[]uint8" {
@ -197,14 +197,16 @@ func typestring(col *xorm.Column) string {
func tag(table *xorm.Table, col *xorm.Column) string { func tag(table *xorm.Table, col *xorm.Column) string {
isNameId := (mapper.Table2Obj(col.Name) == "Id") isNameId := (mapper.Table2Obj(col.Name) == "Id")
isIdPk := isNameId && typestring(col) == "int64"
res := make([]string, 0) res := make([]string, 0)
if !col.Nullable { if !col.Nullable {
if !isNameId { if !isIdPk {
res = append(res, "not null") res = append(res, "not null")
} }
} }
if col.IsPrimaryKey { if col.IsPrimaryKey {
if !isNameId { if !isIdPk {
res = append(res, "pk") res = append(res, "pk")
} }
} }
@ -212,7 +214,7 @@ func tag(table *xorm.Table, col *xorm.Column) string {
res = append(res, "default "+col.Default) res = append(res, "default "+col.Default)
} }
if col.IsAutoIncrement { if col.IsAutoIncrement {
if !isNameId { if !isIdPk {
res = append(res, "autoincr") res = append(res, "autoincr")
} }
} }

View File

@ -24,7 +24,7 @@ func init() {
var engine *xorm.Engine var engine *xorm.Engine
func help() { func shellHelp() {
fmt.Println(` fmt.Println(`
show tables show all tables show tables show all tables
columns <table_name> show table's column info columns <table_name> show table's column info
@ -127,12 +127,12 @@ func runShell(cmd *Command, args []string) {
} }
} }
} else if lcmd == "show tables;" { } else if lcmd == "show tables;" {
tables, err := engine.DBMetas() /*tables, err := engine.DBMetas()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} else { } else {
} }*/
} else { } else {
cnt, err := engine.Exec(scmd) cnt, err := engine.Exec(scmd)
if err != nil { if err != nil {

View File

@ -18,6 +18,8 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition. // Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true const go11tag = true
const version = "0.1"
// Commands lists the available commands and help topics. // Commands lists the available commands and help topics.
// The order here is the order in which they are printed by 'gopm help'. // The order here is the order in which they are printed by 'gopm help'.
var commands = []*Command{ var commands = []*Command{
@ -70,7 +72,6 @@ func setExitStatus(n int) {
} }
var usageTemplate = `xorm is a database tool based xorm package. var usageTemplate = `xorm is a database tool based xorm package.
Usage: Usage:
xorm command [arguments] xorm command [arguments]