bug fixed for #208
This commit is contained in:
parent
897fef0bde
commit
f2d3be988e
|
@ -1,6 +1,7 @@
|
||||||
package xorm
|
package xorm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -297,6 +298,7 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu
|
||||||
col := new(core.Column)
|
col := new(core.Column)
|
||||||
col.Indexes = make(map[string]bool)
|
col.Indexes = make(map[string]bool)
|
||||||
col.Nullable = true
|
col.Nullable = true
|
||||||
|
col.DefaultIsEmpty = true
|
||||||
for idx, field := range fields {
|
for idx, field := range fields {
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
col.Name = strings.Trim(field, "`[] ")
|
col.Name = strings.Trim(field, "`[] ")
|
||||||
|
@ -315,8 +317,14 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu
|
||||||
} else {
|
} else {
|
||||||
col.Nullable = true
|
col.Nullable = true
|
||||||
}
|
}
|
||||||
|
case "DEFAULT":
|
||||||
|
col.Default = fields[idx+1]
|
||||||
|
col.DefaultIsEmpty = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !col.SQLType.IsNumeric() && !col.DefaultIsEmpty {
|
||||||
|
col.Default = "'" + col.Default + "'"
|
||||||
|
}
|
||||||
cols[col.Name] = col
|
cols[col.Name] = col
|
||||||
colSeq = append(colSeq, col.Name)
|
colSeq = append(colSeq, col.Name)
|
||||||
}
|
}
|
||||||
|
@ -366,15 +374,16 @@ func (db *sqlite3) GetIndexes(tableName string) (map[string]*core.Index, error)
|
||||||
|
|
||||||
indexes := make(map[string]*core.Index, 0)
|
indexes := make(map[string]*core.Index, 0)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var sql string
|
var tmpSql sql.NullString
|
||||||
err = rows.Scan(&sql)
|
err = rows.Scan(&tmpSql)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if sql == "" {
|
if !tmpSql.Valid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
sql := tmpSql.String
|
||||||
|
|
||||||
index := new(core.Index)
|
index := new(core.Index)
|
||||||
nNStart := strings.Index(sql, "INDEX")
|
nNStart := strings.Index(sql, "INDEX")
|
||||||
|
@ -384,7 +393,6 @@ func (db *sqlite3) GetIndexes(tableName string) (map[string]*core.Index, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []")
|
indexName := strings.Trim(sql[nNStart+6:nNEnd], "` []")
|
||||||
//fmt.Println(indexName)
|
|
||||||
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) {
|
||||||
index.Name = indexName[5+len(tableName) : len(indexName)]
|
index.Name = indexName[5+len(tableName) : len(indexName)]
|
||||||
} else {
|
} else {
|
||||||
|
|
2
xorm.go
2
xorm.go
|
@ -84,6 +84,8 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
||||||
TZLocation: time.Local,
|
TZLocation: time.Local,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
engine.dialect.SetLogger(engine.Logger)
|
||||||
|
|
||||||
engine.SetMapper(core.NewCacheMapper(new(core.SnakeMapper)))
|
engine.SetMapper(core.NewCacheMapper(new(core.SnakeMapper)))
|
||||||
|
|
||||||
runtime.SetFinalizer(engine, close)
|
runtime.SetFinalizer(engine, close)
|
||||||
|
|
Loading…
Reference in New Issue