diff --git a/examples/cachegoroutine.go b/examples/cachegoroutine.go index 6e2028b6..175d74e8 100644 --- a/examples/cachegoroutine.go +++ b/examples/cachegoroutine.go @@ -24,7 +24,7 @@ func mysqlEngine() (*xorm.Engine, error) { return xorm.NewEngine("mysql", "root:@/test?charset=utf8") } -var u *User = &User{} +var u = &User{} func test(engine *xorm.Engine) { err := engine.CreateTables(u) diff --git a/examples/conversion.go b/examples/conversion.go index 95736d0d..7797e7f4 100644 --- a/examples/conversion.go +++ b/examples/conversion.go @@ -15,10 +15,10 @@ type Status struct { } var ( - Registed Status = Status{"Registed", "white"} - Approved Status = Status{"Approved", "green"} - Removed Status = Status{"Removed", "red"} - Statuses map[string]Status = map[string]Status{ + Registed = Status{"Registed", "white"} + Approved = Status{"Approved", "green"} + Removed = Status{"Removed", "red"} + Statuses = map[string]Status{ Registed.Name: Registed, Approved.Name: Approved, Removed.Name: Removed, diff --git a/examples/goroutine.go b/examples/goroutine.go index f99c9fbe..4ba05c04 100644 --- a/examples/goroutine.go +++ b/examples/goroutine.go @@ -24,7 +24,7 @@ func mysqlEngine() (*xorm.Engine, error) { return xorm.NewEngine("mysql", "root:@/test?charset=utf8") } -var u *User = &User{} +var u = &User{} func test(engine *xorm.Engine) { err := engine.CreateTables(u) diff --git a/examples/maxconnect.go b/examples/maxconnect.go index 4fdfdf78..82d2f49a 100644 --- a/examples/maxconnect.go +++ b/examples/maxconnect.go @@ -24,7 +24,7 @@ func mysqlEngine() (*xorm.Engine, error) { return xorm.NewEngine("mysql", "root:@/test?charset=utf8") } -var u *User = &User{} +var u = &User{} func test(engine *xorm.Engine) { err := engine.CreateTables(u) diff --git a/mssql_dialect.go b/mssql_dialect.go index 2c6fede4..023f4de8 100644 --- a/mssql_dialect.go +++ b/mssql_dialect.go @@ -257,8 +257,9 @@ func (db *mssql) SqlType(c *core.Column) string { return core.Int } - var hasLen1 bool = (c.Length > 0) - var hasLen2 bool = (c.Length2 > 0) + hasLen1 := (c.Length > 0) + hasLen2 := (c.Length2 > 0) + if hasLen2 { res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")" } else if hasLen1 { diff --git a/mysql_dialect.go b/mysql_dialect.go index 0ac5bad8..ac5174fa 100644 --- a/mysql_dialect.go +++ b/mysql_dialect.go @@ -201,7 +201,7 @@ func (db *mysql) SqlType(c *core.Column) string { res = core.Enum res += "(" opts := "" - for v, _ := range c.EnumOptions { + for v := range c.EnumOptions { opts += fmt.Sprintf(",'%v'", v) } res += strings.TrimLeft(opts, ",") @@ -210,7 +210,7 @@ func (db *mysql) SqlType(c *core.Column) string { res = core.Set res += "(" opts := "" - for v, _ := range c.SetOptions { + for v := range c.SetOptions { opts += fmt.Sprintf(",'%v'", v) } res += strings.TrimLeft(opts, ",") @@ -226,8 +226,8 @@ func (db *mysql) SqlType(c *core.Column) string { res = t } - var hasLen1 bool = (c.Length > 0) - var hasLen2 bool = (c.Length2 > 0) + hasLen1 := (c.Length > 0) + hasLen2 := (c.Length2 > 0) if res == core.BigInt && !hasLen1 && !hasLen2 { c.Length = 20 diff --git a/oracle_dialect.go b/oracle_dialect.go index d4aee930..94e71afc 100644 --- a/oracle_dialect.go +++ b/oracle_dialect.go @@ -525,8 +525,9 @@ func (db *oracle) SqlType(c *core.Column) string { res = t } - var hasLen1 bool = (c.Length > 0) - var hasLen2 bool = (c.Length2 > 0) + hasLen1 := (c.Length > 0) + hasLen2 := (c.Length2 > 0) + if hasLen2 { res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")" } else if hasLen1 { diff --git a/postgres_dialect.go b/postgres_dialect.go index 27daabc6..2edc07cc 100644 --- a/postgres_dialect.go +++ b/postgres_dialect.go @@ -812,8 +812,9 @@ func (db *postgres) SqlType(c *core.Column) string { res = t } - var hasLen1 bool = (c.Length > 0) - var hasLen2 bool = (c.Length2 > 0) + hasLen1 := (c.Length > 0) + hasLen2 := (c.Length2 > 0) + if hasLen2 { res += "(" + strconv.Itoa(c.Length) + "," + strconv.Itoa(c.Length2) + ")" } else if hasLen1 { @@ -879,9 +880,10 @@ func (db *postgres) ModifyColumnSql(tableName string, col *core.Column) string { } func (db *postgres) DropIndexSql(tableName string, index *core.Index) string { - quote := db.Quote //var unique string - var idxName string = index.Name + quote := db.Quote + idxName := index.Name + if !strings.HasPrefix(idxName, "UQE_") && !strings.HasPrefix(idxName, "IDX_") { if index.Type == core.UniqueType { diff --git a/sqlite3_dialect.go b/sqlite3_dialect.go index 1217e868..afc51b84 100644 --- a/sqlite3_dialect.go +++ b/sqlite3_dialect.go @@ -237,9 +237,10 @@ func (db *sqlite3) TableCheckSql(tableName string) (string, []interface{}) { } func (db *sqlite3) DropIndexSql(tableName string, index *core.Index) string { - quote := db.Quote //var unique string - var idxName string = index.Name + quote := db.Quote + idxName := index.Name + if !strings.HasPrefix(idxName, "UQE_") && !strings.HasPrefix(idxName, "IDX_") { if index.Type == core.UniqueType {