forked from mirror/gorm
sqlite3: fix HasColumn - problem with detecting columns
Handle table definitions like ", \"col"" and ",col".
This commit is contained in:
parent
484fb30089
commit
50e1d6526e
|
@ -51,7 +51,7 @@ func (s sqlite3) HasTable(scope *Scope, tableName string) bool {
|
||||||
|
|
||||||
func (s sqlite3) HasColumn(scope *Scope, tableName string, columnName string) bool {
|
func (s sqlite3) HasColumn(scope *Scope, tableName string, columnName string) bool {
|
||||||
var count int
|
var count int
|
||||||
s.RawScanInt(scope, &count, fmt.Sprintf("SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND (sql LIKE '%%(\"%v\" %%' OR sql LIKE '%%,\"%v\" %%' OR sql LIKE '%%( %v %%' OR sql LIKE '%%, %v %%');\n", columnName, columnName, columnName, columnName), tableName)
|
s.RawScanInt(scope, &count, fmt.Sprintf("SELECT count(*) FROM sqlite_master WHERE tbl_name = ? AND (sql LIKE '%%(\"%v\" %%' OR sql LIKE '%%,\"%v\" %%' OR sql LIKE '%%, \"%v\" %%' OR sql LIKE '%%( %v %%' OR sql LIKE '%%, %v %%' OR sql LIKE '%%,%v %%');\n", columnName, columnName, columnName, columnName, columnName, columnName), tableName)
|
||||||
return count > 0
|
return count > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue