From edd80e23e55345080040f0d8c54a7bb85f9d0b6a 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 system tables In some cases SQLite creates new tables for internal use. The names of these internal schema objects[0] always begin with `sqlite_` and are not to be touched by applications. Example case: 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 tables starting with `sqlite_` from the query results. [0]: https://www.sqlite.org/fileformat2.html#intschema --- database/sqlite3/sqlite3.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/database/sqlite3/sqlite3.go b/database/sqlite3/sqlite3.go index 56bb23338..8bd70c952 100644 --- a/database/sqlite3/sqlite3.go +++ b/database/sqlite3/sqlite3.go @@ -134,7 +134,11 @@ 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 LIKE 'sqlite_%';` + tables, err := m.db.Query(query) if err != nil { return &database.Error{OrigErr: err, Query: []byte(query)}