m4_comment([$Id: data_open.so,v 1.13 2004/04/28 13:15:29 bostic Exp $]) m4_ref_title(m4_tam Applications, Opening the databases,, transapp/env_open, transapp/put) m4_p([dnl Next, we open three databases ("color" and "fruit" and "cats"), in the database environment. Again, our m4_ref(Db) database handles are declared to be free-threaded using the m4_ref(DB_THREAD) flag, and so may be used by any number of threads we subsequently create.]) include(ref/transapp/data_open.cs) m4_p([dnl After opening the database, we can use the m4_ref(db_stat) utility to display information about a database we have created:]) m4_indent([dnl prompt__GT__ db_stat -h TXNAPP -d color 53162 Btree magic number. 8 Btree version number. Flags: 2 Minimum keys per-page. 8192 Underlying database page size. 1 Number of levels in the tree. 0 Number of unique keys in the tree. 0 Number of data items in the tree. 0 Number of tree internal pages. 0 Number of bytes free in tree internal pages (0% ff). 1 Number of tree leaf pages. 8166 Number of bytes free in tree leaf pages (0.% ff). 0 Number of tree duplicate pages. 0 Number of bytes free in tree duplicate pages (0% ff). 0 Number of tree overflow pages. 0 Number of bytes free in tree overflow pages (0% ff). 0 Number of pages on the free list.]) m4_p([dnl The database open must be enclosed within a transaction in order to be recoverable. The transaction will ensure that created files are re-created in recovered environments (or do not appear at all). Additional database operations or operations on other databases can be included in the same transaction, of course. In the simple case, where the open is the only operation in the transaction, an application can set the m4_ref(DB_AUTO_COMMIT) flag instead of creating and managing its own transaction handle. The m4_ref(DB_AUTO_COMMIT) flag will internally wrap the operation in a transaction, simplifying application code.]) m4_p([dnl The previous example is the simplest case of transaction protection for database open. Obviously, additional database operations can be done in the scope of the same transaction. For example, an application maintaining a list of the databases in a database environment in a well-known file might include an update of the list in the same transaction in which the database is created. Or, an application might create both a primary and secondary database in a single transaction.]) m4_p([dnl m4_ref(Db) handles that will later be used for transactionally protected database operations must be opened within a transaction. Specifying a transaction handle to database operations using m4_ref(Db) handles not opened within a transaction will return an error. Similarly, not specifying a transaction handle to database operations that will modify the database, using handles that were opened within a transaction, will also return an error.]) m4_page_footer