/* mdb_load.c - memory-mapped database load tool */
/*
- * Copyright 2011-2015 Howard Chu, Symas Corp.
+ * Copyright 2011-2018 Howard Chu, Symas Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
c2 += 2;
}
} else {
- c1++; c2++;
+ /* copies are redundant when no escapes were used */
+ *c1++ = *c2++;
}
}
} else {
static void usage(void)
{
- fprintf(stderr, "usage: %s dbpath [-V] [-f input] [-n] [-s name] [-N] [-T]\n", prog);
+ fprintf(stderr, "usage: %s [-V] [-f input] [-n] [-s name] [-N] [-T] dbpath\n", prog);
exit(EXIT_FAILURE);
}
putflags = MDB_NOOVERWRITE|MDB_NODUPDATA;
break;
case 'T':
- mode |= NOHDR;
+ mode |= NOHDR | PRINT;
break;
default:
usage();
while(1) {
rc = readline(&key, &kbuf);
- if (rc == EOF)
+ if (rc) /* rc == EOF */
break;
- if (rc)
- goto txn_abort;
rc = readline(&data, &dbuf);
- if (rc)
+ if (rc) {
+ fprintf(stderr, "%s: line %" Z "d: failed to read key value\n", prog, lineno);
goto txn_abort;
-
+ }
+
rc = mdb_cursor_put(mc, &key, &data, putflags);
if (rc == MDB_KEYEXIST && putflags)
continue;
- if (rc)
+ if (rc) {
+ fprintf(stderr, "mdb_cursor_put failed, error %d %s\n", rc, mdb_strerror(rc));
goto txn_abort;
+ }
batch++;
if (batch == 100) {
rc = mdb_txn_commit(txn);