Merge branch 'sunfmin-master'

Conflicts:
	main.go
This commit is contained in:
Jinzhu 2014-04-25 07:23:26 +08:00
commit 288c8e37af
2 changed files with 5 additions and 3 deletions

View File

@ -16,11 +16,12 @@ type DB struct {
dialect Dialect
tagIdentifier string
singularTable bool
source string
}
func Open(driver, source string) (DB, error) {
var err error
db := DB{dialect: NewDialect(driver), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback}
db := DB{dialect: NewDialect(driver), tagIdentifier: "sql", logger: defaultLogger, callback: DefaultCallback, source: source}
db.db, err = sql.Open(driver, source)
db.parent = &db
return db, err

View File

@ -448,7 +448,8 @@ func (scope *Scope) removeIndex(indexName string) {
func (scope *Scope) autoMigrate() *Scope {
var tableName string
scope.Raw(fmt.Sprintf("SELECT table_name FROM INFORMATION_SCHEMA.tables where table_name = %v", scope.AddToVars(scope.TableName())))
scope.Raw(fmt.Sprintf("SELECT table_name FROM INFORMATION_SCHEMA.tables where table_name = %v",
scope.AddToVars(scope.TableName())))
scope.DB().QueryRow(scope.Sql, scope.SqlVars...).Scan(&tableName)
scope.SqlVars = []interface{}{}
@ -458,7 +459,7 @@ func (scope *Scope) autoMigrate() *Scope {
} else {
for _, field := range scope.Fields() {
var column, data string
scope.Raw(fmt.Sprintf("SELECT column_name, data_type FROM information_schema.columns WHERE table_name = %v and column_name = %v",
scope.Raw(fmt.Sprintf("SELECT column_name, data_type FROM information_schema.columns WHERE table_name = %v AND column_name = %v",
scope.AddToVars(scope.TableName()),
scope.AddToVars(field.DBName),
))