示例#1
0
int SM_Manager::ShowDb() {
	CloseDb();
	if (OpenDb(DataName) != 0)
		return -1;
	rmm.OpenFile("tablelist", tablefh);
	RM_FileScan rfs = RM_FileScan(rmm.getFileManager(), rmm.getBufPageManager());
	 RM_Record rec;
	rfs.OpenScan(tablefh, STRING, 0, 0, NO_OP, NULL);
	cout << "----- begin -----" << endl;
	while (rfs.GetNextRec(rec) != -1) {
		cout << rec.rid << " , " << rec.data << endl;
	}
	cout << "----- end -----" << endl;
	rmm.CloseFile(tablefh);
	return 0;
}
示例#2
0
文件: db.cpp 项目: AltJ/ECCoin
void CDBEnv::Flush(bool fShutdown)
{
    int64_t nStart = GetTimeMillis();
    // Flush log data to the actual data file on all files that are not in use
    LogPrint(
        "db", "CDBEnv::Flush: Flush(%s)%s\n", fShutdown ? "true" : "false", fDbEnvInit ? "" : " database not started");
    if (!fDbEnvInit)
        return;
    {
        LOCK(cs_db);
        std::map<std::string, int>::iterator mi = mapFileUseCount.begin();
        while (mi != mapFileUseCount.end())
        {
            std::string strFile = (*mi).first;
            int nRefCount = (*mi).second;
            LogPrint("db", "CDBEnv::Flush: Flushing %s (refcount = %d)...\n", strFile, nRefCount);
            if (nRefCount == 0)
            {
                // Move log data to the dat file
                CloseDb(strFile);
                LogPrint("db", "CDBEnv::Flush: %s checkpoint\n", strFile);
                dbenv->txn_checkpoint(0, 0, 0);
                LogPrint("db", "CDBEnv::Flush: %s detach\n", strFile);
                if (!fMockDb)
                    dbenv->lsn_reset(strFile.c_str(), 0);
                LogPrint("db", "CDBEnv::Flush: %s closed\n", strFile);
                mapFileUseCount.erase(mi++);
            }
            else
                mi++;
        }
        LogPrint("db", "CDBEnv::Flush: Flush(%s)%s took %15dms\n", fShutdown ? "true" : "false",
            fDbEnvInit ? "" : " database not started", GetTimeMillis() - nStart);
        if (fShutdown)
        {
            char **listp;
            if (mapFileUseCount.empty())
            {
                dbenv->log_archive(&listp, DB_ARCH_REMOVE);
                Close();
                if (!fMockDb)
                    fs::remove_all(fs::path(strPath) / "database");
            }
        }
    }
}
示例#3
0
bool recDb::OpenDb( const wxString& fname )
{
    if( IsOpen() ) {
        recMessage( _("Database already open."), _("Open Database") );
        return false;
    }

    try {
        s_db->Open( fname, wxEmptyString, WXSQLITE_OPEN_READWRITE );
    } catch( wxSQLite3Exception& e ) {
        recDb::ErrorMessage( e );
        return false;
    }
    if( !IsOpen() ) {
        recMessage( _("Unable to open Database."), _("Open Database") );
        return false;
    }

    bool success = recVersion::Manage();
    if( success == false ) {
        CloseDb();
    }
    return success;
}
// -----------------------------------------------------------------------------
// CUpnpSecurityDbConnection::~CUpnpSecurityDbConnection
// Destructor.
// -----------------------------------------------------------------------------
//
CUpnpSecurityDbConnection::~CUpnpSecurityDbConnection()
    {
    CloseDb();
    iFs.Close();
    }
// -----------------------------------------------------------------------------
// CUpnpSecurityDbConnection::OpenDb
// Opens database connection and sets Cache size. 
// -----------------------------------------------------------------------------
//
TInt CUpnpSecurityDbConnection::OpenDb( const TDesC& aDb )
    {
    CloseDb();
    return iDatabase.Open( aDb, &KUpnpSecuritySqlPragmaCacheSize );
    }
示例#6
0
int SM_Manager::Exec(const char *instr) {
	vector<string> argv;
	string cur;
	cout << instr << endl;
	for (int i = 0; ; i++) {
		if (instr[i] == ' ' || instr[i] == '(' || instr[i] == ')' || instr[i] == ',' || instr[i] == 0) {
			if (cur.length() > 0) {
				argv.push_back(cur);
				cur = "";
			}
			if (instr[i] == 0){
				break;
			}
		}
		else {
			cur = cur + instr[i];
		}
	}
	if (argv.size() < 3)
		return -1;
	if (argv[0] == "CREATE" && argv[1] =="DATABASE") {
		CreateDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "DROP" && argv[1] == "DATABASE") {
		DropDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "USE" && argv[1] == "DATABASE") {
		CloseDb();
		OpenDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "SHOW" && argv[1] == "DATABASE") {
		ShowDb(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "CREATE" && argv[1] == "TABLE") {
		string tablename = argv[2];
		vector<AttrInfo> attrs;
		for (int i = 3; i < argv.size();) {
			AttrInfo attr;
			if (argv[i] == "PRIMARY" && argv[i + 1] == "KEY") {
				attr.primaryKey = true;
				i += 2;
			}
			cout << argv[i] << endl;
			strcpy(attr.attrName, argv[i].c_str());
			i += 1;
			if (argv[i] == "int") {
				attr.attrType = MyINT;
				attr.attrLength = 4;
				i += 1;
				cout << "lala" << endl;
			} else if (argv[i] == "float") {
				attr.attrType = FLOAT;
				attr.attrLength = 4;
				i += 1;
			} else if (argv[i] == "char") {
				attr.attrType = STRING;
				attr.attrLength = atoi(argv[i + 1].c_str());
				i += 2;
			}
			if (i + 1 < argv.size() && argv[i] == "NOT" && argv[i + 1] == "NULL") {
				attr.notNull = true;
				i += 2;
			}
			attrs.push_back(attr);
		}
		AttrInfo *x = new AttrInfo[attrs.size()];
		for (int i = 0; i < attrs.size(); i++)
			x[i] = attrs[i];
		CreateTable(tablename.c_str(), attrs.size(), x);
		delete x;
		return 0;
	}
	if (argv[0] == "DROP" && argv[1] == "TABLE") {
		DropTable(argv[2].c_str());
		return 0;
	}
	if (argv[0] == "SHOW" && argv[1] == "TABLE") {
		ShowTable(argv[2].c_str());
		return 0;
	}
	return 0;
}
// ---------------------------------------------------------------------------
// CIRNmsLogDb:AddNmsLogStartL()
// adds the NmsLog log entry into data base
// ---------------------------------------------------------------------------
//
void CIRNmsLogDb::AddNmsLogStartL( CIRNmsLogger& aNmsLog )
    {
    IRLOG_DEBUG( "CIRNmsLogDb::AddNmsLogStartL" );
    OpenDbL();
    RDbTable nmsLogtable;
    TInt error=nmsLogtable.Open( iNmsLogDb, KNmsLogTable, nmsLogtable.
        EUpdatable );
    CleanupClosePushL( nmsLogtable );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    
    //! arrange the presets in incresing order of index
    nmsLogtable.SetIndex( KNmsLogIndex );
    nmsLogtable.Reset();

    //if NmsLog log is greater or equal to than 5
    if ( nmsLogtable.CountL() >= KMaxNoNmsLog )
        {
        //first row is selected
        nmsLogtable.FirstL();
        //the current row is selected
        nmsLogtable.GetL();
        //delete that entry
        nmsLogtable.DeleteL();
        }    
    CleanupStack::PopAndDestroy( &nmsLogtable );
    //Algorithm : else condition need not handle seperatly
    //Algorithm : add NmsLogid and informations like
    //starttime,connectedfrom,NmsLogid,connectiontype,channelid
    //currentnetwork,homenetwork,NmsLogtable 
    //Algorithm: if no. of NmsLog is greater than 5

    _LIT( query, "SELECT * FROM %S" );    
    HBufC* sqlStr=HBufC::NewLC( query().Length() + KNmsLogTable().Length() );
    sqlStr->Des().Format( query, &KNmsLogTable );
    
    // Create a view on the database
    RDbView view;     
    error = view.Prepare( iNmsLogDb, *sqlStr );
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CleanupStack::PopAndDestroy( sqlStr );     
    CleanupClosePushL( view );
    error = view.EvaluateAll();
    if ( error )
        {
        CloseDb();
        User::LeaveIfError( error );    
        }
    CDbColSet* columns = view.ColSetL();
    CleanupStack::PushL( columns );
    
    RDbColWriteStream writeStream;
    TRAP( error, //trap start
       // Insert a row. Column order matches sql select statement
        view.InsertL();
        //get index
        view.SetColL( columns->ColNo( KID ), aNmsLog.NmsLogId() );    
        //!open stream
        writeStream.OpenLC( view, columns->ColNo( KNmsLogCol ) );
        aNmsLog.ExternalizeL( writeStream );
        writeStream.CommitL();
        CleanupStack::PopAndDestroy( &writeStream );
         );
示例#8
0
CBmTests::~CBmTests ()
{
    CloseDb ();
}
示例#9
0
文件: db.cpp 项目: adocode/GameServer
  Db::~Db(){
	  CloseDb();
  }
/**
Destructor
Closes the database tables, the database and the database session
@internalTechnology
*/
CTzLocalizationDbAccessor::~CTzLocalizationDbAccessor()
	{
    CloseDb();
    iDbsSession.Close();
    }