Skip to content
Browse files

Add CBIO_OPEN_CREATE

  • Loading branch information...
1 parent 3990d2f commit c5994e2712152501904c8a02a3d6826bf8b640b3 @trondn trondn committed Apr 20, 2012
Showing with 29 additions and 9 deletions.
  1. +19 −1 include/libcbio/types.h
  2. +3 −1 src/instance.c
  3. +7 −7 tests/testapp.c
View
20 include/libcbio/types.h
@@ -29,6 +29,23 @@
extern "C" {
#endif
+ /**< Document contents compressed via Snappy */
+#define CBIO_DOC_IS_COMPRESSED 128
+ /* Content Type Reasons (content_meta & 0x0F): */
+
+ /**< Document is valid JSON data */
+#define CBIO_DOC_IS_JSON 0
+
+ /**< Document was checked, and was not valid JSON */
+#define CBIO_DOC_INVALID_JSON 1
+
+ /**< Document was checked, and contained reserved keys,
+ was not inserted as JSON. */
+#define CBIO_DOC_INVALID_JSON_KEY 2
+
+ /**< Document was not checked (DB running in non-JSON mode) */
+#define CBIO_DOC_NON_JSON_MODE 3
+
struct libcbio_st;
typedef struct libcbio_st *libcbio_t;
@@ -37,7 +54,8 @@ extern "C" {
typedef enum {
CBIO_OPEN_RDONLY,
- CBIO_OPEN_RW
+ CBIO_OPEN_RW,
+ CBIO_OPEN_CREATE
} libcbio_open_mode_t;
typedef enum {
View
4 src/instance.c
@@ -35,8 +35,10 @@ cbio_error_t cbio_open_handle(const char *name,
ret->mode = mode;
if (mode == CBIO_OPEN_RDONLY) {
flags = COUCHSTORE_OPEN_FLAG_RDONLY;
- } else {
+ } else if (CBIO_OPEN_CREATE) {
flags = COUCHSTORE_OPEN_FLAG_CREATE;
+ } else {
+ flags = 0;
}
err = couchstore_open_db(name, flags, &ret->couchstore_handle);
View
14 tests/testapp.c
@@ -78,7 +78,7 @@ static int create_database(void)
return 1;
}
- err = cbio_open_handle(dbfile, CBIO_OPEN_RW, &handle);
+ err = cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle);
if (err != CBIO_SUCCESS) {
report("Expected open of \"%s\" to succeed, but it \"%s\"",
cbio_strerror(err));
@@ -103,7 +103,7 @@ static int get_miss(void)
libcbio_document_t doc;
cbio_error_t err;
- err = cbio_open_handle(dbfile, CBIO_OPEN_RW, &handle);
+ err = cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle);
if (err != CBIO_SUCCESS) {
report("Expected open of \"%s\" to succeed, but it \"%s\"",
cbio_strerror(err));
@@ -127,7 +127,7 @@ static int store_document(void)
libcbio_document_t doc;
cbio_error_t err;
- err = cbio_open_handle(dbfile, CBIO_OPEN_RW, &handle);
+ err = cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle);
if (err != CBIO_SUCCESS) {
report("Expected open of \"%s\" to succeed, but it \"%s\"",
cbio_strerror(err));
@@ -216,7 +216,7 @@ static int delete_document(void)
return 1;
}
- err = cbio_open_handle(dbfile, CBIO_OPEN_RW, &handle);
+ err = cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle);
if (err != CBIO_SUCCESS) {
report("Expected open of \"%s\" to succeed, but it \"%s\"",
cbio_strerror(err));
@@ -271,7 +271,7 @@ static int delete_nonexistent_document(void)
libcbio_document_t doc;
cbio_error_t err;
- err = cbio_open_handle(dbfile, CBIO_OPEN_RW, &handle);
+ err = cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle);
if (err != CBIO_SUCCESS) {
report("Expected open of \"%s\" to succeed, but it \"%s\"",
cbio_strerror(err));
@@ -378,7 +378,7 @@ static int bulk_store_documents(void)
}
libcbio_t handle;
- err = cbio_open_handle(dbfile, CBIO_OPEN_RW, &handle);
+ err = cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle);
if (err != CBIO_SUCCESS) {
report("Failed to open handle \"%s\"",
cbio_strerror(err));
@@ -458,7 +458,7 @@ static int test_changes_since(void)
{
libcbio_t handle;
cbio_error_t err;
- err = cbio_open_handle(dbfile, CBIO_OPEN_RW, &handle);
+ err = cbio_open_handle(dbfile, CBIO_OPEN_CREATE, &handle);
if (err != CBIO_SUCCESS) {
report("Failed to open handle \"%s\"",
cbio_strerror(err));

0 comments on commit c5994e2

Please sign in to comment.
Something went wrong with that request. Please try again.