MCPcopy Create free account
hub / github.com/antirez/botlib / dbInit

Function dbInit

botlib.c:603–623  ·  view source on GitHub ↗

Create the SQLite tables if needed (if createdb is true), and return * the SQLite database handle. Return NULL on error. */

Source from the content-addressed store, hash-verified

601/* Create the SQLite tables if needed (if createdb is true), and return
602 * the SQLite database handle. Return NULL on error. */
603sqlite3 *dbInit(char *createdb_query) {
604 sqlite3 *db;
605 int rt = sqlite3_open(Bot.dbfile, &db);
606 if (rt != SQLITE_OK) {
607 fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
608 sqlite3_close(db);
609 return NULL;
610 }
611
612 if (createdb_query) {
613 char *errmsg;
614 int rc = sqlite3_exec(db, createdb_query, 0, 0, &errmsg);
615 if (rc != SQLITE_OK) {
616 fprintf(stderr, "SQL error [%d]: %s\n", rc, errmsg);
617 sqlite3_free(errmsg);
618 sqlite3_close(db);
619 return NULL;
620 }
621 }
622 return db;
623}
624
625/* Should be called every time a thread exits, so that if the thread has
626 * an SQLite thread-local handle, it gets closed. */

Callers 2

botHandleRequestFunction · 0.85
startBotFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected