当前位置: 首页>>代码示例>>C++>>正文


C++ db_open函数代码示例

本文整理汇总了C++中db_open函数的典型用法代码示例。如果您正苦于以下问题:C++ db_open函数的具体用法?C++ db_open怎么用?C++ db_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了db_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: talloc_free

/*
  Open up the notify.tdb database. You should close it down using
  talloc_free(). We need the messaging_ctx to allow for notifications
  via internal messages
*/
struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, 
				   struct messaging_context *messaging_ctx,
				   struct event_context *ev,
				   connection_struct *conn)
{
	struct notify_context *notify;

	if (!lp_change_notify(conn->params)) {
		return NULL;
	}

	notify = talloc(mem_ctx, struct notify_context);
	if (notify == NULL) {
		return NULL;
	}

	notify->db_recursive = db_open(notify, lock_path("notify.tdb"),
				       0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
				       O_RDWR|O_CREAT, 0644,
				       DBWRAP_LOCK_ORDER_2);
	if (notify->db_recursive == NULL) {
		talloc_free(notify);
		return NULL;
	}

	notify->db_onelevel = db_open(notify, lock_path("notify_onelevel.tdb"),
				      0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
				      O_RDWR|O_CREAT, 0644,
				      DBWRAP_LOCK_ORDER_2);
	if (notify->db_onelevel == NULL) {
		talloc_free(notify);
		return NULL;
	}

	notify->server = server;
	notify->messaging_ctx = messaging_ctx;
	notify->list = NULL;
	notify->array = NULL;
	notify->seqnum = dbwrap_get_seqnum(notify->db_recursive);
	notify->key = string_term_tdb_data(NOTIFY_KEY);

	talloc_set_destructor(notify, notify_destructor);

	/* register with the messaging subsystem for the notify
	   message type */
	messaging_register(notify->messaging_ctx, notify, 
			   MSG_PVFS_NOTIFY, notify_handler);

	notify->sys_notify_ctx = sys_notify_context_create(conn, notify, ev);

	return notify;
}
开发者ID:srimalik,项目名称:samba,代码行数:57,代码来源:notify_internal.c

示例2: main

int main(int argc,char **argv)
{
	static GDBM_FILE gdbm_stotest = NULL;
	datum key,data;
	int i;
	for(i = 1;i<argc;i++)
	{
		key.dptr = "store test1!";
		key.dsize = strlen("store test1")+1;
		data = key;
		gdbm_stotest = db_open(argv[i]);
		printf("\n--------open dbm id:%d-----------\n",gdbm_stotest);
		if(db_store(gdbm_stotest,key,data) < 0) {
			printf("\n---------store err-----------\n");
			db_close(gdbm_stotest);
			break;
		}
		else {
			printf("\n---------store successfully!-----------\n");
			db_close(gdbm_stotest);
		}
		printf("\n--------close dbm id:%d-----------\n",gdbm_stotest);
		key.dptr = "store test2!";
		key.dsize = strlen("store test1")+1;
		data = key;
		gdbm_stotest = db_open(argv[i]);
		printf("\n--------open dbm id:%d-----------\n",gdbm_stotest);
		if(db_store(gdbm_stotest,key,data) < 0) {
			printf("\n---------store err-----------\n");
			db_close(gdbm_stotest);
			break;
		}
		else {
			printf("\n---------store successfully!-----------\n");
			db_close(gdbm_stotest);
		}
		printf("\n--------close dbm id:%d-----------\n",gdbm_stotest);
		
		gdbm_stotest = db_open(argv[i]);
		key.dptr = "store test1!";
		key.dsize = strlen("store test1!")+1;

		data = key;
		if(gdbm_exists(gdbm_stotest,key) != 0){
			printf("-------really exist here!-----");
		}
		else {
			printf("-------not exist here!-------");		
		}
	}
}
开发者ID:yst1571661,项目名称:EquipSharedSystem,代码行数:51,代码来源:db_store_test.c

示例3: locking_init_internal

static bool locking_init_internal(bool read_only)
{
	brl_init(read_only);

	if (lock_db)
		return True;

	lock_db = db_open(NULL, lock_path("locking.tdb"),
			  SMB_OPEN_DATABASE_TDB_HASH_SIZE,
			  TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
			  read_only?O_RDONLY:O_RDWR|O_CREAT, 0644,
			  DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);

	if (!lock_db) {
		DEBUG(0,("ERROR: Failed to initialise locking database\n"));
		return False;
	}

	if (!posix_locking_init(read_only))
		return False;

	dbwrap_watch_db(lock_db, server_messaging_context());

	return True;
}
开发者ID:dmitry-shavyrin,项目名称:samba4_embedded_build,代码行数:25,代码来源:share_mode_lock.c

示例4: smbXsrv_session_global_init

NTSTATUS smbXsrv_session_global_init(void)
{
	const char *global_path = NULL;
	struct db_context *db_ctx = NULL;

	if (smbXsrv_session_global_db_ctx != NULL) {
		return NT_STATUS_OK;
	}

	/*
	 * This contains secret information like session keys!
	 */
	global_path = lock_path("smbXsrv_session_global.tdb");

	db_ctx = db_open(NULL, global_path,
			 0, /* hash_size */
			 TDB_DEFAULT |
			 TDB_CLEAR_IF_FIRST |
			 TDB_INCOMPATIBLE_HASH,
			 O_RDWR | O_CREAT, 0600,
			 DBWRAP_LOCK_ORDER_1);
	if (db_ctx == NULL) {
		NTSTATUS status;

		status = map_nt_error_from_unix_common(errno);

		return status;
	}

	smbXsrv_session_global_db_ctx = db_ctx;

	return NT_STATUS_OK;
}
开发者ID:ebrainte,项目名称:Samba,代码行数:33,代码来源:smbXsrv_session.c

示例5: db_locate

/* Match pattern against files in locate.db file */
static int
db_locate(
    const wchar_t *pattern)
{
    int count = 0;

#ifdef WIN32
    wchar_t buffer[PATH_MAX + 1];

    /* Open locate.db for read */
    db_open ();
    
    /* Read one directory and file name at a time from database file */
    while (db_read (buffer, PATH_MAX)) {
        /* See if file name in buffer matches the search pattern */
        if (db_match (buffer, pattern)) {
            /* Match found => output file name and path */
            wprintf (L"%s\n", buffer);
            count++;
        }

    }

    db_close ();
#endif

    return count;
}
开发者ID:apache,项目名称:nifi-minifi-cpp,代码行数:29,代码来源:locate.c

示例6: es_sqlite_create

static int
es_sqlite_create(duk_context *ctx)
{
    char path[PATH_MAX];
    char errbuf[512];
    es_context_t *ec = es_get(ctx);
    const char *name = duk_safe_to_string(ctx, 0);

    // Create the db-dir for this plugin

    snprintf(path, sizeof(path), "%s/databases", ec->ec_storage);

    if(fa_makedirs(path, errbuf, sizeof(errbuf)))
        duk_error(ctx, DUK_ERR_ERROR, "Unable to create directory %s -- %s",
                  path, errbuf);

    snprintf(path, sizeof(path), "%s/databases/%s", ec->ec_storage, name);

    sqlite3 *db = db_open(path, 0);
    if(db == NULL)
        duk_error(ctx, DUK_ERR_ERROR, "Unable to open database -- check logs");


    es_sqlite_t *es = es_resource_create(ec, &es_resource_sqlite, 0);

    es->es_db = db;
    es->es_name = strdup(name);

    es_resource_push(ctx, &es->super);
    return 1;
}
开发者ID:bguerreiro,项目名称:movian,代码行数:31,代码来源:es_sqlite.c

示例7: secrets_init_path

/* open up the secrets database with specified private_dir path */
bool secrets_init_path(const char *private_dir)
{
	char *fname = NULL;
	TALLOC_CTX *frame;

	if (db_ctx != NULL) {
		return True;
	}

	if (private_dir == NULL) {
		return False;
	}

	frame = talloc_stackframe();
	fname = talloc_asprintf(frame, "%s/secrets.tdb", private_dir);
	if (fname == NULL) {
		TALLOC_FREE(frame);
		return False;
	}

	db_ctx = db_open(NULL, fname, 0,
			 TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
			 DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);

	if (db_ctx == NULL) {
		DEBUG(0,("Failed to open %s\n", fname));
		TALLOC_FREE(frame);
		return False;
	}

	TALLOC_FREE(frame);
	return True;
}
开发者ID:Alexander--,项目名称:samba,代码行数:34,代码来源:secrets.c

示例8: initDB

void 
initDB(/*DB_ENV ** dbenv, */pthread_attr_t * attr, int type)  
{

	pthread_t ptid;

	env_dir_create();
	env_open(&dbenv);
	int ret;
	/*
	///Start a checkpoint thread.
	if ((ret = pthread_create(
	    &ptid, attr, checkpoint_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning checkpoint thread: %s\n",
		    strerror(ret));
		exit (1);
	}

	/// Start a logfile removal thread. 
	if ((ret = pthread_create(
	    &ptid, attr, logfile_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning log file removal thread: %s\n",
		    strerror(ret));
		exit (1);
	}
	*/
	db_open(dbenv, &db_cats, "cats", type);



}
开发者ID:DreamtoucherN01,项目名称:stasis,代码行数:33,代码来源:genericBerkeleyDBCode.c

示例9: main

int main(int argc, char **argv)
{
  int dev_cnt;
  if(argc>1 && (strcmp(argv[1], "-d")==0) )
    demonize(argv[0]);

  while(1)
  {
    db_open();
    dev_cnt = 0;
    receive_history = true;
    frame_id = 0;
    printf("Wait for cm160 device to be connected\n");
    while((dev_cnt = scan_usb()) == 0)
      sleep(2);
    printf("Found %d compatible device%s\n", dev_cnt, dev_cnt>1?"s":"");

    // Only 1 device supported
    if(!(g_devices[0].hdev = usb_open(g_devices[0].usb_dev)))
    {
      fprintf(stderr, "failed to open device\n");
      db_close();
      break;
    }
    handle_device(0); 
    usb_close(g_devices[0].hdev);
    db_close();
  }

  return 0;
}
开发者ID:aziraphale,项目名称:eagle-owl,代码行数:31,代码来源:cm160.c

示例10: idmap_tdb2_open_db

/*
  open the permanent tdb
 */
static NTSTATUS idmap_tdb2_open_db(void)
{
	char *db_path;
	
	if (idmap_tdb2) {
		/* its already open */
		return NT_STATUS_OK;
	}

	db_path = lp_parm_talloc_string(-1, "tdb", "idmap2.tdb", NULL);
	if (db_path == NULL) {
		/* fall back to the private directory, which, despite
		   its name, is usually on shared storage */
		db_path = talloc_asprintf(NULL, "%s/idmap2.tdb", lp_private_dir());
	}
	NT_STATUS_HAVE_NO_MEMORY(db_path);

	/* Open idmap repository */
	idmap_tdb2 = db_open(NULL, db_path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
	TALLOC_FREE(db_path);

	if (idmap_tdb2 == NULL) {
		DEBUG(0, ("Unable to open idmap_tdb2 database '%s'\n",
			  db_path));
		return NT_STATUS_UNSUCCESSFUL;
	}

	/* load the ranges and high/low water marks */
	return idmap_tdb2_alloc_load();
}
开发者ID:berte,项目名称:mediaplayer,代码行数:33,代码来源:idmap_tdb2.c

示例11: doit

void doit(char *pathname)
{
	DB		*db;
	char	key[IDXLEN_MAX], *ptr;
	hash_t	hash;
	int		i, nrec;

	if ( (db = db_open(pathname, O_RDONLY, 0)) == NULL)
		err_sys("db_open error");

	nrec = 0;
	while ( (ptr = db_nextrec(db, key)) != NULL) {
		nrec++;
		hash = _db_hash(db, key);
		cntr[hash]++;
	}

	printf("total #records = %d\n", nrec);
	for (i = 0; i < NHASH_DEF; i++) {
		printf("%3d: %6ld\n", i, cntr[i]);
	}

	if ( (i = _db_checkfree(db)) < 0)
		printf("corrupted free list\n");
	else
		printf("%d records on free list\n", i);

	exit(0);
}
开发者ID:crazyleen,项目名称:apue,代码行数:29,代码来源:tstats.c

示例12: rt_dirbuild

/**
 * Builds a directory of the object names.
 *
 * Allocate and initialize information for this instance of an RT
 * model database.
 *
 * Returns -
 * (struct rt_i *) Success
 * RTI_NULL Fatal Error
 */
struct rt_i *
rt_dirbuild(const char *filename, char *buf, int len)
{
    register struct rt_i *rtip;
    register struct db_i *dbip;		/* Database instance ptr */

    if (rt_uniresource.re_magic == 0)
	rt_init_resource(&rt_uniresource, 0, NULL);

    if ((dbip = db_open(filename, DB_OPEN_READONLY)) == DBI_NULL)
	return RTI_NULL;		/* FAIL */
    RT_CK_DBI(dbip);

    if (db_dirbuild(dbip) < 0) {
	db_close(dbip);
	return RTI_NULL;		/* FAIL */
    }

    rtip = rt_new_rti(dbip);		/* clones dbip */
    db_close(dbip);				/* releases original dbip */

    if (buf != (char *)NULL)
	bu_strlcpy(buf, dbip->dbi_title, len);

    return rtip;				/* OK */
}
开发者ID:behollis,项目名称:brlcad-svn-rev65072-gsoc2015,代码行数:36,代码来源:dir.c

示例13: backend_get_packages_thread

static gboolean
backend_get_packages_thread (PkBackend *backend)
{
	PkBitfield filters;
	GList *list = NULL;
	sqlite3 *db = NULL;

	filters = pk_backend_get_uint (backend, "filters");

	pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);

	pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);

	db = db_open();

	if ((pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) &&
	     pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) ||
	    (!pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED) &&
	     !pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED))) {
		list = box_db_repos_packages_search_all (db, NULL, 0);
	} else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
		list = box_db_repos_packages_search_installed (db, NULL, 0);
	} else if (pk_bitfield_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
		list = box_db_repos_packages_search_available (db, NULL, 0);
	}

	add_packages_from_list (backend, list, FALSE);
	box_db_repos_package_list_free (list);

	db_close(db);
	pk_backend_finished (backend);
	return TRUE;
}
开发者ID:AlfredArouna,项目名称:packagekit,代码行数:33,代码来源:pk-backend-box.c

示例14: main

int main() {
    table *tab;
    field **defs;

    if(db_open("db")) {
        g_error("db_open");
        return 1;
    }

    tab = table_open("test");
    if(!tab) {
        g_error("table_open");
        return 1;
    }

    defs = table_get_field_defs(tab);
    while(!table_end(tab)) {

    }

    if(db_close()) {
        g_error("db_clos ");
        return 1;
    }

    return 0;
}
开发者ID:BackupTheBerlios,项目名称:geekbase,代码行数:27,代码来源:test.c

示例15: regdb_open

WERROR regdb_open( void )
{
	WERROR result = WERR_OK;

	if ( regdb ) {
		DEBUG(10, ("regdb_open: incrementing refcount (%d->%d)\n",
			   regdb_refcount, regdb_refcount+1));
		regdb_refcount++;
		return WERR_OK;
	}

	become_root();

	regdb = db_open(NULL, state_path("registry.tdb"), 0,
			REG_TDB_FLAGS, O_RDWR, 0600,
			DBWRAP_LOCK_ORDER_1);
	if ( !regdb ) {
		result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
		DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
			state_path("registry.tdb"), strerror(errno) ));
	}

	unbecome_root();

	regdb_refcount = 1;
	DEBUG(10, ("regdb_open: registry db opened. refcount reset (%d)\n",
		   regdb_refcount));

	return result;
}
开发者ID:ekohl,项目名称:samba,代码行数:30,代码来源:reg_backend_db.c


注:本文中的db_open函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。