diff options
author | Michael Cahill <michael.cahill@mongodb.com> | 2015-09-22 15:59:09 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@mongodb.com> | 2015-09-22 15:59:09 +1000 |
commit | 959376c602c664dd13ffdd8e59931ae1aa4c89f0 (patch) | |
tree | 9da677c175bacb2770cbfe5e23d5bccdca60697f /examples | |
parent | 752b2b20d05197edc789b38aefbb72bb9c2fdd02 (diff) | |
parent | 402d1271741e7ac312c947cf67c798990b61a040 (diff) | |
download | mongo-959376c602c664dd13ffdd8e59931ae1aa4c89f0.tar.gz |
Merge pull request #2189 from wiredtiger/index-create-lsm3
WT-147: Dynamic Index creation. Use bulk=unordered
Diffstat (limited to 'examples')
-rw-r--r-- | examples/c/ex_extractor.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/examples/c/ex_extractor.c b/examples/c/ex_extractor.c index 2d985fddd44..68906bcc743 100644 --- a/examples/c/ex_extractor.c +++ b/examples/c/ex_extractor.c @@ -37,6 +37,8 @@ #include <wiredtiger.h> +#define RET_OK(ret) ((ret) == 0 || (ret) == WT_NOTFOUND) + int add_extractor(WT_CONNECTION *conn); static const char *home; @@ -144,28 +146,43 @@ read_index(WT_SESSION *session) WT_CURSOR *cursor; int i, ret; char *first_name, *last_name; - uint16_t term_end, term_start, year; + uint16_t rec_year, term_end, term_start, year; + year = 0; srand((unsigned int)getpid()); ret = session->open_cursor( session, "index:presidents:term", NULL, NULL, &cursor); /* * Pick 10 random years and read the data. */ - for (i = 0; i < 10; i++) { + for (i = 0; i < 10 && RET_OK(ret); i++) { year = (uint16_t)((rand() % YEAR_SPAN) + YEAR_BASE); + printf("Year %d:\n", year); cursor->set_key(cursor, year); - if ((ret = cursor->search(cursor)) == 0) { + if ((ret = cursor->search(cursor)) != 0) + break; + if ((ret = cursor->get_key(cursor, &rec_year)) != 0) + break; + if ((ret = cursor->get_value(cursor, + &last_name, &first_name, &term_start, &term_end)) != 0) + break; + + /* Report all presidents that served during the chosen year */ + while (term_start <= year && + year <= term_end && year == rec_year) { + printf("\t%s %s\n", first_name, last_name); + if ((ret = cursor->next(cursor)) != 0) + break; + if ((ret = cursor->get_key(cursor, &rec_year)) != 0) + break; if ((ret = cursor->get_value(cursor, &last_name, &first_name, &term_start, &term_end)) != 0) break; - printf("Year %d: %s %s\n", year, first_name, last_name); - continue; } - - fprintf(stderr, "Error %d for year %d\n", ret, year); - break; } + if (!RET_OK(ret)) + fprintf(stderr, "Error %d for year %d\n", ret, year); + ret = cursor->close(cursor); return (ret); } |