go-xorm / cmd

Command line tools for database operation written by Go, moved to https://gitea.com/xorm/cmd
BSD 3-Clause "New" or "Revised" License
168 stars 77 forks source link

reverse Sqlite3 error , reverse.go:179 Unknown col "GroupGID" in index "IX_..." #41

Open zwq000 opened 6 years ago

zwq000 commented 6 years ago

use a exist sqlite database, index sql like

CREATE  INDEX "IX_Users_GroupGID" ON "Users" ("GroupGID")

DbMetas() func throw a error Unknown col "GroupGID", because at dialect_sqlite3.go func GetIndexes() get column name is "GroupGID" ,it's include quotation.

索引定义中表名和字段名包含引号,这个数据库是其他程序生成的,所以 在获取数据库元数据时发生了异常. 无法找到对应的字段名.

目前的解决办法是 在 dialect_sqlite3.go 中增加一个 normalizeName 方法,去掉两边的引号和中间的空格

//normalize tabale/index/col name remove quotation
func normalizeName(name string) string {
    if name[0] == '"' {
        name = name[1:]
    }
    l := len(name)
    if name[l-1] == '"' {
        name = name[:l-1]
    }
    spaceIndex := strings.Index(name, " ")
    if spaceIndex > 1 { //name include space,Use firse token
        return name[:spaceIndex]
    }
    return name
}