From e8788d9d6fd0fb364cb0bc377dbecd1649f3f1f1 Mon Sep 17 00:00:00 2001 From: hofnarr Date: Fri, 20 Sep 2024 19:04:09 +0300 Subject: [PATCH] sqlite3: fix error when dropping db with sqlite_sequence table If column declaration uses `AUTOINCREMENT` keyword, a new column is created into table `sqlite_sequence` which can not be dropped. Currently, `sqlite3.Drop()` resolves tables to be dropped by querying table `sqlite_master` for all tables in the database. However, this query also returns aforementioned `sqlite_sequence` table. This commit adds a filter to the query resolving tables to be dropped. Filter removes `sqlite_sequence` from the query results. --- database/sqlite3/sqlite3.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/database/sqlite3/sqlite3.go b/database/sqlite3/sqlite3.go index 56bb23338..66af7ac9b 100644 --- a/database/sqlite3/sqlite3.go +++ b/database/sqlite3/sqlite3.go @@ -134,7 +134,13 @@ func (m *Sqlite) Close() error { } func (m *Sqlite) Drop() (err error) { - query := `SELECT name FROM sqlite_master WHERE type = 'table';` + query := ` + SELECT name FROM sqlite_master + WHERE type = 'table' + AND name NOT IN ( + 'sqlite_sequence' + );` + tables, err := m.db.Query(query) if err != nil { return &database.Error{OrigErr: err, Query: []byte(query)}