symisc / unqlite

An Embedded NoSQL, Transactional Database Engine
https://unqlite.symisc.net
Other
2.11k stars 164 forks source link

unqlite_open behaviour on UNQLITE_OPEN_READWRITE and UNQLITE_OPEN_READONLY modes #25

Closed woldendans closed 8 years ago

woldendans commented 8 years ago

Hello,

In the unqlite_open documentation page, it is specified that, if UNQLITE_OPEN_READWRITE is used:

Open the database with read+write privileges. If the database does not exists, an error code is returned.

I would expect this behaviour to be true for UNQLITE_OPEN_READONLY too.

Yet, what I observe is that even if the DB does not exists, the return code is _UNQLITEOK. But if you call any funtion using the returned handle (like a store instruction), you will get a _UNQLITEIOERR return code.

What is the real expected behaviour? The one specified is appealing because it allow us to check immediatly if the DB exists instead of waiting for a first instruction to be made.

symisc commented 8 years ago

The reason for that is that unqlite_open() does not deal with disk operation at all. That is, it merely prepare the db handle, allocate the internal stuff and so forth. Disk operation starts with the first call to unqllte_kv_store(), unqlite_kv_fetch(), etc.

The function should be named unqlite_initi() instead of unqlite_open().