Skip to content

Update NewPool logic in regards to poolsize > 1 with inmemory set #125

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

element-of-surprise
Copy link

This addressed Issue: #124

if poolSize != 1 {
uriLower := strings.ToLower(uri)
inMemory := uri == ":memory:" || opts.Flags&sqlite.OpenMemory != 0
sharedCache := strings.Contains(uriLower, "cache=shared") || opts.Flags&sqlite.OpenSharedCache != 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although unlikely, the cache=shared string could appear in the file name. I think we need to do some minimal parsing of the URI (and ensure that the URI is, in fact, being parsed as a URI). Off-hand, you might be able to get away with splitting on the ? and doing url.ParseQuery, but double-check the docs to make sure there isn't some subtlety that I haven't thought of.

case err != nil && !test.wantErr:
t.Errorf("TestInvalidPoolOptions(%s): got err == %s, want err == nil", test.name, err)
continue
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For error tests like these, I like including a case that logs the error message in successful cases without failing. This allows manual inspection to see whether there's a case that's failing for an unrelated error cause.

for _, test := range tests {
dbpool, err := sqlitex.NewPool(test.uri, sqlitex.PoolOptions{
Flags: test.flags,
PoolSize: 2,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should vary the pool size for some of these tests.

dbFileShared := filepath.Join(dir, "awal.db?cache=shared")

tests := []struct {
name string
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Names aren't being used and aren't helpful here. Remove, please.


if poolSize != 1 {
uriLower := strings.ToLower(uri)
inMemory := uri == ":memory:" || opts.Flags&sqlite.OpenMemory != 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode=memory is another way this condition can be triggered.

@element-of-surprise
Copy link
Author

For whatever reason I don't seem to get emails for comments any longer (I should fix that). I'll have a look at these in the next few days as time allows and make the changes.

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

Successfully merging this pull request may close these issues.

2 participants