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

Running PRAGMA statments in sqlitex.OpenInit script #131

Open
boutros opened this issue Dec 9, 2021 · 0 comments
Open

Running PRAGMA statments in sqlitex.OpenInit script #131

boutros opened this issue Dec 9, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@boutros
Copy link

boutros commented Dec 9, 2021

I'm trying to activate FOREIGN KEYS on all connections, but setting it in sqlitex.OpenInit does not seem to work for me. Are there any limitations on issuing PRAGMA statements in OpenInit?

Here is a failing testcase which proves it does not work:

t.Run("pragma", func(t *testing.T) {
	ctx := context.Background()
	initScript := `PRAGMA foreign_keys=ON;`
	dbpool, err := sqlitex.OpenInit(ctx, poolURI, poolFlags, poolSize, initScript)
	if err != nil {
		t.Fatal(err)
	}
	defer func() {
		if err := dbpool.Close(); err != nil {
			t.Error(err)
		}
	}()

	checkFn := func(stmt *sqlite.Stmt) error {
		if fk := stmt.ColumnInt(0); fk != 1 {
			t.Fatalf("initScript not run: PRAGMA foreign_keys returns %d, expected 1", fk)
		}
		return nil
	}

	for i := 0; i < poolSize; i++ {
		conn := dbpool.Get(ctx)
		defer dbpool.Put(conn)
		if err := sqlitex.ExecTransient(conn, "PRAGMA foreign_keys;", checkFn); err != nil {
			t.Error(err)
		}
	}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants