4. Opening/Closing the database

If no filename is provided, the weewiki database is used. Otherwise, a new SQLite database is opened.

<<open_the_db>>=
if (argc == 2) {
    wiki = wmp_core_db(&core);
} else {
    rc = sqlite3_open(argv[2], &wiki);
    if (rc) {
        fprintf(stderr,
                "Could not open database: %s",
                sqlite3_errmsg(wiki));
        sqlite3_close(wiki);
        return 0;
    }
}

At the end, this SQLite database is closed. If it's the same as the database (the same pointer), this does not happen.

<<close_the_db>>=
if (wiki != wmp_core_db(&core)) {
    printf("closing...\n");
    sqlite3_close(wiki);
    wiki = NULL;
}



prev | home | next