go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Rename Table Causes Hang

Open Stoyvo opened this issue 6 years ago • 5 comments

Requirements: SQLite - 3.26.0 go-sqlite3 - v1.10.0

Steps to reproduce:

  1. Create a table. Eg: "new_table"
  2. 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 avatar Feb 20 '19 23:02 Stoyvo

@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 avatar Feb 21 '19 00:02 rittneje

@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

Stoyvo avatar Feb 21 '19 12:02 Stoyvo

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)

Stoyvo avatar Feb 21 '19 13:02 Stoyvo

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?

rittneje avatar Feb 21 '19 23:02 rittneje

Still active ? Closable ?

gjrtimmer avatar Aug 22 '19 10:08 gjrtimmer