diff --git a/sqlite3_dialect.go b/sqlite3_dialect.go index 2295ce38..cb9e7f54 100644 --- a/sqlite3_dialect.go +++ b/sqlite3_dialect.go @@ -1,6 +1,7 @@ package xorm import ( + "database/sql" "errors" "fmt" "strings" @@ -297,6 +298,7 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu col := new(core.Column) col.Indexes = make(map[string]bool) col.Nullable = true + col.DefaultIsEmpty = true for idx, field := range fields { if idx == 0 { col.Name = strings.Trim(field, "`[] ") @@ -315,8 +317,14 @@ func (db *sqlite3) GetColumns(tableName string) ([]string, map[string]*core.Colu } else { 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 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) for rows.Next() { - var sql string - err = rows.Scan(&sql) + var tmpSql sql.NullString + err = rows.Scan(&tmpSql) if err != nil { return nil, err } - if sql == "" { + if !tmpSql.Valid { continue } + sql := tmpSql.String index := new(core.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], "` []") - //fmt.Println(indexName) if strings.HasPrefix(indexName, "IDX_"+tableName) || strings.HasPrefix(indexName, "UQE_"+tableName) { index.Name = indexName[5+len(tableName) : len(indexName)] } else { diff --git a/xorm.go b/xorm.go index 4673d783..b5121d52 100644 --- a/xorm.go +++ b/xorm.go @@ -84,6 +84,8 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) { TZLocation: time.Local, } + engine.dialect.SetLogger(engine.Logger) + engine.SetMapper(core.NewCacheMapper(new(core.SnakeMapper))) runtime.SetFinalizer(engine, close)