go-sqlite3
go-sqlite3 copied to clipboard
Rename Table Causes Hang
Requirements: SQLite - 3.26.0 go-sqlite3 - v1.10.0
Steps to reproduce:
- Create a table. Eg: "new_table"
- Rename table: Eg:
queryRenameTable := "ALTER TABLE new_table RENAME TO old_table;"
_, err := db.Exec(queryRenameTable)
if err != nil {
log.Println(err)
}
Expected Result: Table to rename to "old_table".
Actual Result: Breakpoint/code does not progress past db.Exec
@Stoyvo Can you post a full code sample, including the CREATE TABLE
command? Also, how did you open the database? Is it a file or an in-memory database?
@rittneje
var err error
db, _ = sql.Open("sqlite3", "file:testdb?cache=shared&mode=rwc")
db.SetMaxOpenConns(1)
db.Exec("PRAGMA temp_store = MEMORY;")
db.Exec("PRAGMA encoding=\"UTF-16\";")
The create table command is pretty standard.
sql_table := `
CREATE TABLE IF NOT EXISTS new_table (
id INTEGER NOT NULL PRIMARY KEY,
added INTEGER NOT NULL
);
`
db.Exec(sql_table)
Removed error checks for the sake of providing only code related to the issue
Current workaround:
// Create new table called "old_table" with all data and columns from "new_table"
queryCreateTable := "CREATE TABLE old_table AS SELECT * FROM new_table;"
db.Exec(queryCreateTable)
// Drop the previous table
queryDropTable := "DROP TABLE IF EXISTS new_table;"
db.Exec(queryDropTable)
// Create new table as per spec
queryCreateNewTable := `
CREATE TABLE IF NOT EXISTS new_table (
id INTEGER NOT NULL PRIMARY KEY,
added INTEGER NOT NULL
);
`
db.Exec(queryCreateNewTable)
// Import your data to new table from old table
// Clean up and remove old table
queryDropOldTable = "DROP TABLE IF EXISTS old_table;"
db.Exec(queryDropOldTable)
I am not yet able to reproduce this issue.
Your initial report mentions SQLite version 3.26.0. However, the version of this library you mention is packaged with SQLite version 3.25.2. How did you use that version of SQLite? What build tags are you using to compile the Go code? What operating system and architecture are you on?
Still active ? Closable ?