Skip to content

Commit

Permalink
sqlite3: fix error when dropping db with sqlite_sequence table
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hofnarrr committed Sep 20, 2024
1 parent 4f3c203 commit e8788d9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion database/sqlite3/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down

0 comments on commit e8788d9

Please sign in to comment.