MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / bdblib_create_table

Function bdblib_create_table

modules/db_berkeley/bdb_lib.c:560–712  ·  view source on GitHub ↗

* The function is called to create a handle to a db table. * * On startup, we do not create any of the db handles. * Instead it is done on first-use (lazy-initialized) to only create handles to * files (db) that we require. * * There is one db file per opensips table (eg. acc), and they should exist * in your DB_PATH (refer to opensips-cli) directory. * * This function does _not_ create t

Source from the content-addressed store, hash-verified

558 *
559 */
560table_p bdblib_create_table(database_p _db, str *_s)
561{
562
563 int rc,i,flags;
564 DB *bdb = NULL;
565 table_p tp = NULL;
566 char tblname[MAX_TABLENAME_SIZE];
567
568 if(!_db || !_db->dbenv)
569 {
570 LM_ERR("no database_p or dbenv.\n");
571 return NULL;
572 }
573
574 tp = (table_p)pkg_malloc(sizeof(table_t));
575 if(!tp)
576 {
577 LM_ERR("no private memory for table_t.\n");
578 return NULL;
579 }
580
581 if ((rc = db_create(&bdb, _db->dbenv, 0)) != 0)
582 {
583 _db->dbenv->err(_db->dbenv, rc, "database create");
584 LM_ERR("error in db_create, bdb error: %s.\n",db_strerror(rc));
585 pkg_free(tp);
586 return NULL;
587 }
588
589 memset(tblname, 0, MAX_TABLENAME_SIZE);
590 memcpy(tblname, _s->s, _s->len);
591
592#ifdef BDB_EXTRA_DEBUG
593 LM_DBG("CREATE TABLE = %s\n", tblname);
594#endif
595
596 flags = DB_THREAD;
597
598 if ((rc = bdb->open(bdb, NULL, tblname, NULL, DB_HASH, flags, 0664)) != 0)
599 {
600 _db->dbenv->err(_db->dbenv, rc, "DB->open: %s", tblname);
601 LM_ERR("bdb open failed: %s.\n",db_strerror(rc));
602 pkg_free(tp);
603 return NULL;
604 }
605
606 if(!lock_init(&tp->sem))
607 {
608 goto error;
609 }
610
611 tp->name.s = (char*)pkg_malloc(_s->len*sizeof(char));
612 memcpy(tp->name.s, _s->s, _s->len);
613 tp->name.len = _s->len;
614 tp->db=bdb;
615 tp->ncols=0;
616 tp->nkeys=0;
617 tp->ro=0; /*0=ReadWrite ; 1=ReadOnly*/

Callers 1

bdblib_get_tableFunction · 0.85

Calls 7

lock_initFunction · 0.85
load_metadata_defaultsFunction · 0.85
load_metadata_keysFunction · 0.85
load_metadata_readonlyFunction · 0.85
load_metadata_logflagsFunction · 0.85
bdblib_create_journalFunction · 0.85
load_metadata_columnsFunction · 0.70

Tested by

no test coverage detected