Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Table Causes Hang #696

Open
Stoyvo opened this issue Feb 20, 2019 · 5 comments
Open

Rename Table Causes Hang #696

Stoyvo opened this issue Feb 20, 2019 · 5 comments
Assignees

Comments

@Stoyvo
Copy link

Stoyvo commented Feb 20, 2019

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

@rittneje
Copy link
Collaborator

@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?

@Stoyvo
Copy link
Author

Stoyvo commented Feb 21, 2019

@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
Copy link
Author

Stoyvo commented Feb 21, 2019

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)

@rittneje
Copy link
Collaborator

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?

@gjrtimmer
Copy link
Collaborator

Still active ?
Closable ?

@gjrtimmer gjrtimmer self-assigned this Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants