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

In-memory: no such table #677

Closed
pupizoid opened this issue Dec 27, 2018 · 2 comments
Closed

In-memory: no such table #677

pupizoid opened this issue Dec 27, 2018 · 2 comments

Comments

@pupizoid
Copy link

pupizoid commented Dec 27, 2018

Hi! I've faced strange behavior, working with in-memory sqlite3 database with go-sqlite3. I initialize a connection, create database and insert some data into it in the single Exec.

After that I perform a select query to set to zero last inserted rowid (thats important to me). And then when i'm trying to perform an insert query I get the "no such table" error.

This behavior is reproduced only when I create an in-memory database from go, if I create database file everything runs as expected. Moreover when I exec same queries on a in-memory database using sqlite3 cmd binary everything works fine too.

Here is a simple code that panics, but should not...

package main

import (
	"database/sql"

	_ "github.com/mattn/go-sqlite3"
)

func main() {
	db, err := sql.Open("sqlite3", ":memory:")
	if err != nil {
		panic(err)
	}

	db.Exec(`
		create table test(field text);
		insert into test(field) values ('test 1'), ('test 2'), ('test 3');
	`)

	_, err = db.Query("select count(*) from test;")
	if err != nil {
		panic(err)
	}

	_, err = db.Exec("insert into test(field) values ('test 4')")
	if err != nil {
		panic(err)  // panics here!
	}
}

I'm using go-sqlite3 1.10.0 with go1.11.2 darwin/amd64

@pupizoid pupizoid changed the title In memory: no such table In-memory: no such table Dec 27, 2018
@rittneje
Copy link
Collaborator

Try sql.Open("sqlite3", "file::memory:?cache=shared"). See "Why I'm getting no such table error?" in the FAQ.

@pupizoid
Copy link
Author

Thank you for the answer, that helped!

mihaitodor added a commit to mihaitodor/benthos that referenced this issue Oct 11, 2022
- Use in-memory SQLite database to avoid file locking issues
during integration tests as suggested here: mattn/go-sqlite3#677 (comment)
- The modernc.org/sqlite FreeBSD build was fixed: https://gitlab.com/cznic/sqlite/-/commit/fd7b2cc5b3b1be8d962638485629a39431cac462#bb99b1baec3b0c8f02dc4e87b04926bc377fd8db
- github.com/ClickHouse/clickhouse-go now supports ARM: ClickHouse/clickhouse-go#519
- Run `go fix ./...` to switch to `//go:build` across the codebase
since we're on Go 1.18+: https://stackoverflow.com/questions/68360688/whats-the-difference-between-gobuild-and-build-directives
mihaitodor added a commit to mihaitodor/benthos that referenced this issue Oct 11, 2022
- Use in-memory SQLite database to avoid file locking issues
during integration tests as suggested here: mattn/go-sqlite3#677 (comment)
- The modernc.org/sqlite FreeBSD build was fixed: https://gitlab.com/cznic/sqlite/-/commit/fd7b2cc5b3b1be8d962638485629a39431cac462#bb99b1baec3b0c8f02dc4e87b04926bc377fd8db
- github.com/ClickHouse/clickhouse-go now supports ARM: ClickHouse/clickhouse-go#519
- Run `go fix ./...` to switch to `//go:build` across the codebase
since we're on Go 1.18+: https://stackoverflow.com/questions/68360688/whats-the-difference-between-gobuild-and-build-directives
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

2 participants