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

"no such table" error #223

Closed
hallyn opened this issue Jul 30, 2015 · 11 comments
Closed

"no such table" error #223

hallyn opened this issue Jul 30, 2015 · 11 comments

Comments

@hallyn
Copy link
Contributor

hallyn commented Jul 30, 2015

Hi,

when doing some heavy stress-testing of our application which imports go-sqlite3, during one failure case I saw:

error: no such table: containers

This was in the middle of a run, sandwiched between many successful queries and actions on the containers table.

This was on a brand new built vm, using go-sqlite commit b4142c4.

Do you have any particular suggestions for figuring out what may have gone wrong?

Thanks!

@mattn
Copy link
Owner

mattn commented Jul 31, 2015

Because connection doesn't have exclusion.
https://github.com/mattn/go-sqlite3/blob/master/sqlite3_test.go#L772

@mattn
Copy link
Owner

mattn commented Jul 31, 2015

dup #216

@mattn mattn closed this as completed Jul 31, 2015
@hallyn
Copy link
Contributor Author

hallyn commented Jul 31, 2015

Hi, sorry, either I'm misunderstanding or I wasn't clear in the description. This is about our own testcase of an application built on go-sqlite3, not the go-sqlite3 testcaess. In our application testcase, the db is opened with the _txlock=exclusive option. It mostly runs correctly, but with a very massive concurrent testcase I got this case where my db query claimed that a table didn't exist.

@Higan
Copy link

Higan commented Sep 22, 2019

@hallyn Have you found the root cause of this issue? I'm facing a pretty similar error; the table should have been create, with lots of queries been executed successfully, but later an error was thrown claiming no such table.

@rittneje
Copy link
Collaborator

@Higan Do you have an example of your code that is having a problem? Are you using an actual database file, or an in-memory database? Are you using any temporary tables?

@eehsiao
Copy link

eehsiao commented Jan 13, 2020

@Higan @relud
if you open in :memory: , must be ":memory:?cache=shared"

@ko80
Copy link

ko80 commented Apr 21, 2020

Maybe this would help someone

I had the same issue with 'no such table' and found an exact explanation:

If sql.Rows is not closed before next query then driver returns no such table on next query. Issue exists only for in-memory storage, same test for file backed db runs fine.
#511 (comment)

After that, I found the part of code where I had forgotten to do rows.Close(), fixed that and now it works with no issues.

@luckydenis
Copy link

@Higan Do you have an example of your code that is having a problem? Are you using an actual database file, or an in-memory database? Are you using any temporary tables?

setup: Ubuntu 20.04.1 LTS
go: go1.15 linux/amd64
sqlite3: SQLite version 3.31.1 2020-01-27 19:55:54

database:
CRATE TABLE data (
uid INTEGER PRIMARY KEY
);

package main

import (
	"database/sql"
	"fmt"
	_ "github.com/mattn/go-sqlite3"
)


func main() {
	database := "./foo.db"

	db, err := sql.Open("sqlite3", database)
	if err != nil {
		fmt.Println(nil)
		return
	}
	defer db.Close()

	_, err = db.Exec("SELECT * FROM data;")
	if err != nil {
		fmt.Println(err)
		return
	}
}

stdout: no such table: data

@mrbardia72
Copy link

@mattn
How can I solve the following problem?
no such table: users

@rittneje
Copy link
Collaborator

@mrbardia72 Please open a new issue, with sufficient detail to diagnose your error.

@DANCANKARANI
Copy link

@mattn add table users, try this
db.CreateTable(&User{}).AutoMigrate(&Users{})

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

9 participants