Shows how to extend WiredTiger with application-specific collations, extractors and cursor types.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wiredtiger.h>
#ifdef _WIN32
#define strcasecmp stricmp
#endif
static const char *home;
static int
{
const char *s1 = (
const char *)v1->
data;
const char *s2 = (
const char *)v2->
data;
(void)session;
(void)collator;
*cmp = strcasecmp(s1, s2);
return (0);
}
static WT_COLLATOR nocasecoll = { __compare_nocase, NULL, NULL };
typedef struct {
uint32_t maxlen;
} PREFIX_COLLATOR;
static int
{
PREFIX_COLLATOR *pcoll = (PREFIX_COLLATOR *)collator;
const char *s1 = (
const char *)v1->
data;
const char *s2 = (
const char *)v2->
data;
(void)session;
*cmp = strncmp(s1, s2, pcoll->maxlen);
return (0);
}
static PREFIX_COLLATOR pcoll10 = { {__compare_prefixes, NULL, NULL}, 10 };
int
main(void)
{
int ret;
if (getenv("WIREDTIGER_HOME") == NULL) {
home = "WT_HOME";
ret = system("rm -rf WT_HOME && mkdir WT_HOME");
} else
home = NULL;
fprintf(stderr, "Error connecting to %s: %s\n",
ret = conn->
add_collator(conn,
"nocase", &nocasecoll, NULL);
ret = conn->
add_collator(conn,
"prefix10", &pcoll10.iface, NULL);
if ((ret = conn->
open_session(conn, NULL, NULL, &session)) != 0)
fprintf(stderr, "Error opening a session on %s: %s\n",
if ((ret = conn->
close(conn, NULL)) != 0)
fprintf(stderr, "Error closing %s: %s\n",
return (ret);
}