12
int mycmp(const DBT *, const DBT *);
23
printf("\tBtree...\n");
24
memset(&b_info, 0, sizeof(b_info));
26
b_info.cachesize = 100 * 1024;
29
b_info.compare = mycmp;
32
dbopen("a.db", O_CREAT | O_RDWR, 0664, DB_BTREE, &b_info)) == NULL)
36
printf("\tHash...\n");
37
memset(&h_info, 0, sizeof(h_info));
41
h_info.cachesize = 100 * 1024;
45
dbopen("a.db", O_CREAT | O_RDWR, 0664, DB_HASH, &h_info)) == NULL)
49
printf("\tRecno...\n");
50
memset(&r_info, 0, sizeof(r_info));
51
r_info.flags = R_FIXEDLEN;
52
r_info.cachesize = 100 * 1024;
57
dbopen("a.db", O_CREAT | O_RDWR, 0664, DB_RECNO, &r_info)) == NULL)
71
len = a->size > b->size ? b->size : a->size;
72
for (p1 = a->data, p2 = b->data; len--; ++p1, ++p2)
74
return ((long)*p1 - (long)*p2);
75
return ((long)a->size - (long)b->size);
89
memset(&key, 0, sizeof(key));
90
memset(&data, 0, sizeof(data));
92
for (i = 1; i < 100; ++i) { /* Test DB->put. */
93
sprintf(buf, "abc_%d_efg", i);
94
if (type == DB_RECNO) {
97
key.size = sizeof(recno);
99
key.data = data.data = buf;
100
key.size = data.size = strlen(buf);
104
data.size = strlen(buf);
105
if (dbp->put(dbp, &key, &data, 0))
109
if (type == DB_RECNO) { /* Test DB->get. */
112
key.size = sizeof(recno);
115
key.size = strlen(buf);
117
sprintf(buf, "abc_%d_efg", 97);
118
if (dbp->get(dbp, &key, &data, 0) != 0)
120
if (memcmp(data.data, buf, strlen(buf)))
121
err("DB->get: wrong data returned");
123
if (type == DB_RECNO) { /* Test DB->put no-overwrite. */
126
key.size = sizeof(recno);
129
key.size = strlen(buf);
131
sprintf(buf, "abc_%d_efg", 42);
132
if (dbp->put(dbp, &key, &data, R_NOOVERWRITE) == 0)
133
err("DB->put: no-overwrite succeeded");
135
if (type == DB_RECNO) { /* Test DB->del. */
138
key.size = sizeof(recno);
140
sprintf(buf, "abc_%d_efg", 35);
142
key.size = strlen(buf);
144
if (dbp->del(dbp, &key, 0))
148
if ((outfp = fopen("output", "w")) == NULL)
149
err("fopen: output");
150
while ((ret = dbp->seq(dbp, &key, &data, R_NEXT)) == 0) {
151
if (type == DB_RECNO)
152
fprintf(outfp, "%d\n", *(int *)key.data);
155
"%.*s\n", (int)key.size, (char *)key.data);
156
fprintf(outfp, "%.*s\n", (int)data.size, (char *)data.data);
163
ret = system("cmp output O.BH");
166
ret = system("sort output | cmp - O.BH");
169
ret = system("cmp output O.R");
173
err("output comparison failed");
175
if (dbp->sync(dbp, 0)) /* Test DB->sync. */
178
if (dbp->close(dbp)) /* Test DB->close. */
186
fprintf(stderr, "\t%s: %s\n", s, strerror(errno));