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

Sqlite, databse is locked #636

Closed
forrackun opened this issue Aug 27, 2021 · 1 comment
Closed

Sqlite, databse is locked #636

forrackun opened this issue Aug 27, 2021 · 1 comment

Comments

@forrackun
Copy link

forrackun commented Aug 27, 2021

hello, i am having database is locked issue.
i can reproduce in below minimal example. as far as i know a constrain violation should not lock for subsequent operations
can you help me :) ?
thank you

// example.go

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/upper/db/v4"
	"github.com/upper/db/v4/adapter/sqlite"
)

var settings = sqlite.ConnectionURL{
	Database: `example.db`,
}

func main() {
	defer os.Remove(`example.db`)

	sess, err := sqlite.Open(settings)
	if err != nil {
		log.Fatalf("db.Open(): %q\n", err)
	}

	_, err = sess.SQL().Exec(`DROP TABLE IF EXISTS "example1";

	create table example1(
		id INTEGER PRIMARY KEY AUTOINCREMENT,
		slug text not null,
		subtype text not null,
		description text not null,
		group_id text not null,
		unique( slug, group_id)
	);`)

	if err != nil {
		log.Fatal(err)
	}

	//sess.SetMaxOpenConns(1)

	defer sess.Close()

	for range []int{1, 2, 3} {
		Insert(sess)
	}
}

func Insert(sess db.Session) {
	tbl := sess.Collection("example1")

	_, err := tbl.Insert(db.Cond{
		"slug":        "aa",
		"group_id":    "g1",
		"description": "asas",
		"subtype":     "asa",
	})
	fmt.Println(err)
}
<nil>
2021/08/27 11:00:55 upper/db: log_level=WARNING file=/home/madman/go/pkg/mod/github.com/upper/db/v4@v4.2.1/internal/sqladapter/session.go:646
        Session ID:     00001
        Query:          INSERT INTO "example1" ("description", "group_id", "slug", "subtype") VALUES (?, ?, ?, ?)
        Arguments:      []interface {}{"asas", "g1", "aa", "asa"}
        Error:          UNIQUE constraint failed: example1.slug, example1.group_id
        Time taken:     0.00055s
        Context:        context.Background

UNIQUE constraint failed: example1.slug, example1.group_id
2021/08/27 11:01:05 upper/db: log_level=WARNING file=/home/madman/go/pkg/mod/github.com/upper/db/v4@v4.2.1/internal/sqladapter/session.go:646
        Session ID:     00001
        Query:          INSERT INTO "example1" ("description", "group_id", "slug", "subtype") VALUES (?, ?, ?, ?)
        Arguments:      []interface {}{"asas", "g1", "aa", "asa"}
        Error:          upper: slow query
        Time taken:     10.01480s
        Context:        context.Background

database is locked

@forrackun
Copy link
Author

s.T().Skip(`Skipped due to a "database is locked" problem with concurrent transactions. See https://github.com/mattn/go-sqlite3/issues/274`)

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

1 participant