Alternative flags and encoding support#93
Conversation
| AUTO = SQLITE_ANY, | ||
| UTF8 = SQLITE_UTF8, | ||
| UTF16 = SQLITE_UTF16 | ||
| }; |
There was a problem hiding this comment.
@zauguin Use the same name as sqlite.
enum class Encoding {
ANY = SQLITE_ANY,
UTF8 = SQLITE_UTF8,
UTF16 = SQLITE_UTF16
};| UTF16 = SQLITE_UTF16 | ||
| }; | ||
| struct sqlite_config { | ||
| int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; |
There was a problem hiding this comment.
@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.
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.
@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.
@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.
Thanks, I integrated it.
| }; | ||
| struct sqlite_config { | ||
| int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; | ||
| const char *gVfs = nullptr; |
There was a problem hiding this comment.
@zauguin rename this to zVfs same as sqlite documentation.
| } | ||
|
|
||
| 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.
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.
I don't really understand this comment. By default the encoding is ANY, so in line 434 we select encoding UTF16.
|
@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. |
| OPEN_SHAREDCACHE = SQLITE_OPEN_SHAREDCACHE, | ||
| OPEN_PRIVATECACH = SQLITE_OPEN_PRIVATECACHE, | ||
| OPEN_URI = SQLITE_OPEN_URI | ||
| }; |
There was a problem hiding this comment.
@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.
@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.
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