Logo Search packages:      
Sourcecode: qdbm version File versions  Download package

Villa::Villa ( const char *  name,
int  omode = Villa::OREADER,
VLCFUNC  cmp = Villa::cmplex 
) throw (Villa_error)

Get the database handle.

Parameters:
name the name of a database file.
omode the connection mode: `VillaOWRITER' as a writer, `VillaOREADER' as a reader. If the mode is `VillaOWRITER', the following may be added by bitwise or: `VillaOCREAT', which means it creates a new database if not exist, `VillaOTRUNC', which means it creates a new database regardless if one exists, `VillaOZCOMP', which means leaves in the database are compressed. Both of `VillaOREADER' and `VillaOWRITER' can be added to by bitwise or: `VillaONOLCK', which means it opens a database file without file locking, or `VillaOLCKNB', which means locking is performed without blocking.
cmp the comparing function: `Villacmplex' comparing keys in lexical order, `Villacmpint' comparing keys as objects of `int' in native byte order, `Villacmpnum' comparing keys as numbers of big endian, `Villacmpdec' comparing keys as decimal strings. Any function compatible with them can be assigned to the comparing function. The comparing function should be kept same in the life of a database.
Exceptions:
Villa_error if an error occurs.
Note:
While connecting as a writer, an exclusive lock is invoked to the database file. While connecting as a reader, a shared lock is invoked to the database file. The thread blocks until the lock is achieved. `VillaOZCOMP' is available only if QDBM was built with ZLIB enabled. If `VillaONOLCK' is used, the application is responsible for exclusion control.

Definition at line 186 of file xvilla.cc.

References qdbm::mutex, name(), tranmutex, and villa.

  : ADBM(){
  if(pthread_mutex_lock(&mutex) != 0) throw Villa_error();
  if(!(villa = vlopen(name, omode, cmp))){
    pthread_mutex_unlock(&mutex);
    throw Villa_error(dpecode);
  }
  pthread_mutex_init(&tranmutex, NULL);
  pthread_mutex_unlock(&mutex);
}


Generated by  Doxygen 1.6.0   Back to index