-
Notifications
You must be signed in to change notification settings - Fork 156
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
Alternative flags and encoding support #93
Conversation
hdr/sqlite_modern_cpp.h
Outdated
AUTO = SQLITE_ANY, | ||
UTF8 = SQLITE_UTF8, | ||
UTF16 = SQLITE_UTF16 | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zauguin Use the same name as sqlite.
enum class Encoding {
ANY = SQLITE_ANY,
UTF8 = SQLITE_UTF8,
UTF16 = SQLITE_UTF16
};
hdr/sqlite_modern_cpp.h
Outdated
struct sqlite_config { | ||
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zauguin Use an enum for flags instead of int
.
enum class Flags {
OPEN_READONLY = SQLITE_OPEN_READONLY,
OPEN_READWRITE = SQLITE_OPEN_READWRITE,
OPEN_CREATE = SQLITE_OPEN_CREATE,
OPEN_NOMUTEX = SQLITE_OPEN_NOMUTEX,
OPEN_FULLMUTEX = SQLITE_OPEN_FULLMUTEX,
OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE,
OPEN_PRIVATECACH = SQLITE_OPEN_PRIVATECACH,
OPEN_URI = SQLITE_OPEN_URI
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a enum class
operator |
isn't defined, so this leads to quite some boilerplate. Do need operator&
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zauguin I didn't know that, Is there a workaround for this limitation?
No we don't need operator &
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zauguin I just tested a hackish way, let me know what you think
enum class test { A = 1, B = 2, C = 4 };
test operator|(const test& a, const test& b) {
test ret;
ret = static_cast<test>(static_cast<int>(a) | static_cast<int>(b));
return ret;
};
int main() {
test c = test::A | test::B;
cout << static_cast<int>(c) << endl; // prints 3 as expected :-)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I integrated it.
hdr/sqlite_modern_cpp.h
Outdated
struct sqlite_config { | ||
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; | ||
const char *gVfs = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zauguin rename this to zVfs
same as sqlite documentation.
hdr/sqlite_modern_cpp.h
Outdated
} | ||
|
||
database(std::string const & db_name): _db(nullptr) { | ||
database(const std::u16string &db_name, const sqlite_config &config = {}): _db(nullptr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the default encoding for this constructor UTF16
, this changes the behavior we had in previous versions.
@zauguin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand this comment. By default the encoding is ANY, so in line 434 we select encoding UTF16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zauguin You are right, my mistake :-)
@zauguin Looks very good to me, please add a unit test and update documentation. |
904f1b9
to
6ec8e43
Compare
This will hit the same Visual C++ bug as #94. |
@zauguin I thinks its better to keep it simple, |
I only add tests for read-only, I don't know anything about the other ones, but there is no reason why they shouldn't work. |
hdr/sqlite_modern_cpp.h
Outdated
OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE, | ||
OPEN_PRIVATECACH = SQLITE_OPEN_PRIVATECACHE, | ||
OPEN_URI = SQLITE_OPEN_URI | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aminroosta What do you think about omitting OPEN_? It looks a bit redundant. If you prefer to keep it we might move it to the class name: OpenFlags::READONLY
looks better than Flags::OPEN_READONLY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zauguin OpenFlags::READONLY
looks better, I'm for it 😉
BTW do you think we should make a new release after this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now I'm working on std::variant
support and I would really like to see this in the next release, especially for supporting functions with different argument types, but apart from that, go for it.
Provides the functionality of #72 with the sqlite_config interface.
Fixes #71