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

Add Serialize and Deserialize support #1089

Merged
merged 38 commits into from
Nov 17, 2022

Conversation

otoolep
Copy link
Contributor

@otoolep otoolep commented Sep 6, 2022

No description provided.

@otoolep
Copy link
Contributor Author

otoolep commented Sep 6, 2022

It's not clear to me why the build is failing because:

  • sqlite3_serialize() is available in the C source.
  • SQLITE_OMIT_DESERIALIZE is not defined anywhere that I can see so the C function should be available.

What am I missing?

@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2022

Codecov Report

Base: 46.09% // Head: 46.80% // Increases project coverage by +0.70% 🎉

Coverage data is based on head (9ec6bc6) compared to base (7476442).
Patch coverage: 82.85% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1089      +/-   ##
==========================================
+ Coverage   46.09%   46.80%   +0.70%     
==========================================
  Files          11       12       +1     
  Lines        1499     1534      +35     
==========================================
+ Hits          691      718      +27     
- Misses        669      673       +4     
- Partials      139      143       +4     
Impacted Files Coverage Δ
sqlite3_opt_serialize.go 82.85% <82.85%> (ø)
sqlite3.go 52.64% <0.00%> (-0.23%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rittneje
Copy link
Collaborator

rittneje commented Sep 6, 2022

@otoolep Prior to v3.36.0, sqlite3_serialize and sqlite3_deserialize were opt in via -DSQLITE_ENABLE_DESERIALIZE. This is why the libsqlite3 tests are failing. Also now they are opt out via -DSQLITE_OMIT_DESERIALIZE, which we should support.

We will either need a Go build tag to enable these new methods, or a tag to disable them. Personally, my preference would be to make it opt out so things "just work" by default, but technically that could be a breaking change for anyone currently using the libsqlite3 tag. @mattn what do you think?

@mattn
Copy link
Owner

mattn commented Sep 6, 2022

Personally, my preference would be to make it opt out so things "just work" by default

Do you mean that the functions return like ErrNotImplemented?

@rittneje
Copy link
Collaborator

rittneje commented Sep 6, 2022

@mattn Historically this library has been inconsistent between having alternate version of the Go methods that return errors, or simply not defining the Go methods at all. I don't care which one we do here. The important part is that if you opt out (or don't opt in, depending on our approach), we never attempt to reference the C functions.

@otoolep
Copy link
Contributor Author

otoolep commented Sep 6, 2022

I can add a build tag for either option (opt-in or opt-out), I forgot about the libsqlite3 tests. The lack of this patch is the only thing forcing rqlite to use a fork of this repo.

@mattn
Copy link
Owner

mattn commented Sep 6, 2022

type Serializable interface {
  Serialize(schema string) []byte
}
if ser, ok := conn.(Serializable); ok {
  b = ser.Serialize(name)
  // blah
} else {
  // not implemented
}

We can do check whether the SQLiteConn has methods like above, I think. @rittneje what do you think?

@rittneje
Copy link
Collaborator

rittneje commented Sep 6, 2022

@mattn The underlying problem is we cannot reference the sqlite3_serialize or sqlite3_deserialize C functions if SQLite itself was compiled without them. For the statically compiled version this is simple because we control the build options, but for someone linking against their system version we have no way of knowing unless they tell us. These are the choices I can see:

  1. We make our references to those two C functions opt out. This means anyone using libsqlite3 today could be broken (if their system version was compiled without support) and will have to add an additional Go build tag so we don't attempt to reference those functions.
  2. We make our references to those C functions opt in. This preserves backwards compatibility for anyone using libsqlite3 today, but in exchange anyone that wants to use these new Go methods is required to pass an additional tag to go build, which is annoying.
  3. We always exclude these new methods if libsqlite3 is defined.
  4. We make these new methods opt in if you are using libsqlite3. Otherwise they are always defined.
  5. We make these new methods opt in if you are using libsqlite3, and opt out if you aren't.

Us dynamically checking what methods SQLiteConn has does not help, since we are the ones that have to define those very methods in the first place.

@mattn
Copy link
Owner

mattn commented Sep 6, 2022

Thanks your explaining. As you mentioned above, let's add sqlite_omit_deserialize.

@rittneje
Copy link
Collaborator

rittneje commented Sep 7, 2022

To be clear, you are saying to do option 1 from my list?

@mattn
Copy link
Owner

mattn commented Sep 7, 2022

I have thought about this for a little while and I expect the following.

  1. opt-in if using libsqlite3, default is undefined
  2. always enabled if libsqlite3 is not used

@mattn
Copy link
Owner

mattn commented Sep 7, 2022

I assume that people who use libsqlite3 are expecting minimalism and they does not want these functions. I guess.

@rittneje
Copy link
Collaborator

rittneje commented Sep 7, 2022

I assume that people who use libsqlite3 are expecting minimalism and they does not want these functions. I guess.

Depends on their use case. They could also just want consistency across applications written in multiple languages.

@otoolep
Copy link
Contributor Author

otoolep commented Sep 11, 2022

@rittneje @mattn -- does this look like what you had in mind?

I also don't understand the "dockerfile" CI failure. Can you help?

@rittneje
Copy link
Collaborator

I also don't understand the "dockerfile" CI failure. Can you help?

Seems that #1085 changed the output of the sample program, but did not change the expectation in the GitHub action, so it fails.

docker run simple | grep 99\ こんにちわ世界099

That said, I don't know why the output is checked in both the Dockerfile itself as well as the GitHub action. @mattn Can one of them be removed?

sqlite3_opt_serialize.go Outdated Show resolved Hide resolved
sqlite3_opt_serialize.go Outdated Show resolved Hide resolved
sqlite3_opt_serialize.go Outdated Show resolved Hide resolved
sqlite3_opt_serialize.go Outdated Show resolved Hide resolved
@otoolep
Copy link
Contributor Author

otoolep commented Sep 14, 2022

I think we're good now. Let me know there are more required changes.

@otoolep
Copy link
Contributor Author

otoolep commented Sep 16, 2022

What do you guys think, ready to merge?

sqlite3_opt_serialize.go Outdated Show resolved Hide resolved
sqlite3_opt_serialize.go Outdated Show resolved Hide resolved
@otoolep
Copy link
Contributor Author

otoolep commented Oct 3, 2022

I think we're good to merge this?

@otoolep
Copy link
Contributor Author

otoolep commented Nov 11, 2022

@rittneje -- I think we're good to merge this? Anything else need doing? The test has been updated, and all tests pass.

With this merged I can return to using this repo, and dump my fork.

@rittneje rittneje merged commit 1603038 into mattn:master Nov 17, 2022
@otoolep
Copy link
Contributor Author

otoolep commented Nov 17, 2022

Thank you! Looking forward to moving back to this repo, and away from my fork.

@mattn
Copy link
Owner

mattn commented Dec 25, 2022

@otoolep Thank you.

jensMF pushed a commit to jensMF/go-sqlite3 that referenced this pull request Jan 31, 2023
Add support for Serialize and Deserialize, which wrap sqlite3_serialize and sqlite3_deserialize.
meiyang1123 pushed a commit to meiyang1123/go-sqlite3 that referenced this pull request Aug 28, 2024
Add support for Serialize and Deserialize, which wrap sqlite3_serialize and sqlite3_deserialize.
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.

4 participants