//----------------------------------------------------------------------- // This method opens or creates the sample database. //----------------------------------------------------------------------- static Db createOrOpenDatabase(DbSystem dbSystem, out bool bCreatedDatabase) { Db db; string sDbName = "sample.db"; // Try to open a database. If that fails, create it. The following // example creates the database in the current directory. However, // a full or partial file name may be specified. // NOTE: Multiple threads should each do their own open of the // database and get back their own Db object. try { db = dbSystem.dbOpen(sDbName, null, null, null, false); } catch (XFlaimException ex) { if (ex.getRCode() != RCODE.NE_XFLM_IO_PATH_NOT_FOUND) { throw ex; } db = dbSystem.dbCreate(sDbName, null, null, null, null, null); bCreatedDatabase = true; } return(db); }
public bool createDbTest( string sDbName, DbSystem dbSystem) { Db db = null; RCODE rc; beginTest("Create Database Test (" + sDbName + ")"); for (;;) { rc = RCODE.NE_XFLM_OK; try { XFLM_CREATE_OPTS createOpts = new XFLM_CREATE_OPTS(); createOpts.uiBlockSize = 8192; createOpts.uiVersionNum = (uint)DBVersions.XFLM_CURRENT_VERSION_NUM; createOpts.uiMinRflFileSize = 2000000; createOpts.uiMaxRflFileSize = 20000000; createOpts.bKeepRflFiles = 1; createOpts.bLogAbortedTransToRfl = 1; createOpts.eDefaultLanguage = Languages.FLM_DE_LANG; db = dbSystem.dbCreate(sDbName, null, null, null, null, createOpts); } catch (XFlaimException ex) { rc = ex.getRCode(); if (rc != RCODE.NE_XFLM_FILE_EXISTS) { endTest(false, ex, "creating database"); return(false); } } if (rc == RCODE.NE_XFLM_OK) { break; } // rc better be NE_XFLM_FILE_EXISTS - try to delete the file try { dbSystem.dbRemove(sDbName, null, null, true); } catch (XFlaimException ex) { endTest(false, ex, "removing database"); return(false); } } if (db != null) { db.close(); db = null; } endTest(false, true); return(true); }
public bool importTests( string sDbName, DbSystem dbSystem) { bool bOk = false; Db db = null; bool bStartedTrans = false; RCODE rc; // Create the database beginTest("Create database \"" + sDbName + "\""); for (;;) { rc = RCODE.NE_XFLM_OK; try { XFLM_CREATE_OPTS createOpts = new XFLM_CREATE_OPTS(); createOpts.uiBlockSize = 8192; createOpts.uiVersionNum = (uint)DBVersions.XFLM_CURRENT_VERSION_NUM; createOpts.uiMinRflFileSize = 2000000; createOpts.uiMaxRflFileSize = 20000000; createOpts.bKeepRflFiles = 1; createOpts.bLogAbortedTransToRfl = 1; createOpts.eDefaultLanguage = Languages.FLM_DE_LANG; db = dbSystem.dbCreate(sDbName, null, null, null, null, createOpts); } catch (XFlaimException ex) { rc = ex.getRCode(); if (rc != RCODE.NE_XFLM_FILE_EXISTS) { endTest(false, ex, "creating database"); return(false); } } if (rc == RCODE.NE_XFLM_OK) { break; } // rc better be NE_XFLM_FILE_EXISTS - try to delete the file try { dbSystem.dbRemove(sDbName, null, null, true); } catch (XFlaimException ex) { endTest(false, ex, "removing database"); return(false); } } endTest(false, true); // Start a transaction beginTest("Start Update Transaction Test"); try { db.transBegin(eDbTransType.XFLM_UPDATE_TRANS, 255, 0); } catch (XFlaimException ex) { endTest(false, ex, "starting update transaction"); goto Exit; } endTest(false, true); bStartedTrans = true; // Create a document if (!importTests(db, dbSystem)) { goto Exit; } // Commit the transaction beginTest("Commit Update Transaction Test"); try { bStartedTrans = false; db.transCommit(); } catch (XFlaimException ex) { endTest(false, ex, "committing update transaction"); goto Exit; } endTest(false, true); bOk = true; Exit: if (bStartedTrans) { db.transAbort(); } if (db != null) { db.close(); db = null; } return(bOk); }