From 50e1d6526e8ca0da580bb56fe130d526ec4e648b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20B=C4=99dkowski?= Date: Sat, 24 Oct 2015 14:42:38 +0200 Subject: [PATCH] sqlite3: fix HasColumn - problem with detecting columns Handle table definitions like ", \"col"" and ",col". --- sqlite3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index 96d798a0..d052d2c1 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -51,7 +51,7 @@ func (s sqlite3) HasTable(scope *Scope, tableName string) bool { func (s sqlite3) HasColumn(scope *Scope, tableName string, columnName string) bool { 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 }