Exemple #1
0
static int
initialize()
{
    int rc;
    char *version;
    int major, minor, patch;
    rc = policy_initialize();
    if (rc)
        return rc;
    version = db_version(&major, &minor, &patch);
    if (DB_VERSION_MAJOR != major || DB_VERSION_MINOR != minor) {
        syslog(LOG_ERR,
               "This daemon was compiled with " DB_VERSION_STRING " (%d.%d.%d) definitions "
               "but it is using %s (%d.%d.%d).  This will not work!  "
               "Check that the version of the developpement files for Berkeley DB "
               "match the version that used.",
               DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
               version, major, minor, patch);
        abort();
    }
    if (DB_VERSION_PATCH != patch && (opt_verbose || debug_me))
        syslog(LOG_INFO,
               "Compiled with " DB_VERSION_STRING " (%d.%d.%d) definitions.  "
               "Running with %s (%d.%d.%d).",
               DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH,
               version, major, minor, patch);
    else if (debug_me)
        syslog(LOG_DEBUG,
               "This daemon was compiled with " DB_VERSION_STRING " (%d.%d.%d) definitions.",
               DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH);
    dbdata.data = &triplet_data;
    dbdata.size = sizeof triplet_data;
    dbdata.ulen = sizeof triplet_data;
    dbdata.flags = DB_DBT_USERMEM;
    rc = prepare_env();
    if (!rc)
        rc = prepare_db();
    return rc;
}
Exemple #2
0
int main(int argc, char **argv) {
	sqlite3 *db;
	sqlite3_stmt *pStmt;
	int rc;

	rc = sqlite3_open("example.db", &db);
	if (rc != SQLITE_OK) {
		printf("db open error\n");
		return -1;
	}

	sqlite3_enable_load_extension(db, 1);

	rc = sqlite3_load_extension(db, "libbfile_ext.so", NULL, NULL);
	if (rc != SQLITE_OK) {
		printf("load bfile extension error\n");
		return -1;
	}

	/* clean the database */
	cleandb(db);

	/* create table & directory, and insert data */
	rc = prepare_db(db);
	if (rc) return -1;

	/* query bfile data */
	rc = query_bfile(db);
	if (rc) return -1;

	/* replace directory alias */
	rc = change_dir(db);
	if (rc) return -1;

	sqlite3_close(db);
	return 0;
}