1 /* chkseq.c Check sequential read and write */
5 #include <errno.h> /* Error numbers */
6 #include <fcntl.h> /* O_CREAT, O_RDWR */
12 void main(int argc, char *argv[]) {
13 char id1[] = {" "}, id2[] = {" "};
15 long in = 0L, out = 0L;
17 DBT key, data, keyo, datao;
21 if ((fin = fopen("data","r")) == NULL) {
22 printf("Unable to open %s\n","data");
25 if ((dbp = dbopen("test.db",O_RDWR | O_CREAT | O_BINARY, 0664
26 , DB_BTREE, NULL )) == NULL) {
27 printf("\n Open error on test.db %d %s\n",errno,strerror(errno));
31 while (fscanf(fin," %10s%10s",id1,id2) > 0) {
36 printf("%10s %10s\n",key.data,data.data);
37 if (dbp->put(dbp, &key, &data,R_NOOVERWRITE) != 0) {
38 printf("Error writing output\n");
42 printf("%d Records in\n",out);
45 if ((dbp = dbopen("test.db", O_RDWR | O_BINARY, 0664
46 , DB_BTREE, NULL )) == NULL) {
47 printf("\n Error on dbopen %d %s\n",errno,strerror(errno));
51 while (dbp->seq(dbp, &key, &data,R_NEXT) == 0) {
56 strcpy(id2,data.data);
59 printf("%10s %10s\n",key.data,data.data);
63 if (dbp->put(dbp, &keyo, &datao,0) != 0) {
64 printf("Write failed at %d\n",in);
68 if (dbp->put(dbp, &keyo, &datao,R_CURSOR) != 0) {
69 printf("Write failed at %d\n",in);
74 printf("%d Records copied\n",in);
76 dbp->seq(dbp, &key, &data,R_FIRST);
77 printf("%10s %10s\n",key.data,data.data);
79 while (dbp->seq(dbp, &key, &data,R_NEXT) == 0) {
81 printf("%10s %10s\n",key.data,data.data);
83 printf("%d Records read\n",in);