//定义变量 // build database CEGUID m_ceguid; HANDLE m_hdb=0; CEOID m_ceoid=0; TCHAR DBFILENAME[20] = _T("\\abc.db"); TCHAR DBTABLENAME[20] = _T("\\wang");
//insert database CEOID ceoid =0; CEPROPVAL * pRorps; pRorps = new CEPROPVAL[2];
//read data int iRecordCount; CEOIDINFO oidinfo; DWORD dwIndex; DWORD dwRecSize; WORD wProps; PBYTE pBuff; PCEPROPVAL pRecord; int i; int k; //开始使用 case IDC_INSERT://CREATE DATABASE
//1. ¹ÒÔØÊý¾Ý¿â£¬²»´æÔÚÔò½¨Á¢ if (!CeMountDBVol(&m_ceguid,DBFILENAME,OPEN_ALWAYS)) { MessageBox(NULL,TEXT("faile"),NULL,MB_OK); return 0; } else MessageBox(NULL,TEXT("build DB success"),NULL,MB_OK); //2. ´ò¿ª±í£¬ m_hdb = CeOpenDatabaseEx(&m_ceguid,&m_ceoid,DBTABLENAME,NULL, CEDB_AUTOINCREMENT,NULL); if (m_hdb == INVALID_HANDLE_VALUE) { //3. ²»´æÔÚÔò½¨Á¢ if (GetLastError() == ERROR_FILE_NOT_FOUND) { CEDBASEINFO cedbaseinfo; cedbaseinfo.dwFlags = CEDB_VALIDNAME | CEDB_VALIDTYPE | CEDB_VALIDSORTSPEC; wcscpy(cedbaseinfo.szDbaseName,DBTABLENAME); cedbaseinfo.dwDbaseType = 0; cedbaseinfo.wNumSortOrder = 1 ;//ÅÅÐòÊýÄ¿ cedbaseinfo.rgSortSpecs[0].propid = pid_no; cedbaseinfo.rgSortSpecs[0].dwFlags = CEDB_SORT_CASEINSENSITIVE;
// m_ceoid = CeCreateDatabaseEx(&m_ceguid,&cedbaseinfo); if(m_ceoid==0) MessageBox(NULL,TEXT("faile"),NULL,MB_OK); else { m_hdb = CeOpenDatabaseEx(&m_ceguid,&m_ceoid,DBTABLENAME,NULL, CEDB_AUTOINCREMENT,NULL); MessageBox(NULL,TEXT("build table success"),NULL,MB_OK); } }
} else MessageBox(NULL,TEXT("open table success"),NULL,MB_OK);
///insert record
// memset(pRorps,0,LocalSize(pRorps)); pRorps->propid = pid_no; pRorps->val.lpwstr = TEXT("1"); // pRorps ++; //memset(pRorps,0,LocalSize(pRorps)); pRorps->propid = pid_name; pRorps->val.lpwstr = TEXT("wang");
pRorps --;
ceoid = CeWriteRecordProps(m_hdb,0,2,pRorps);
if (ceoid == 0) MessageBox(NULL,TEXT("insert failues"),NULL,MB_OK); else MessageBox(NULL,TEXT("insert success"),NULL,MB_OK);
//read record //iRecordCount = CeGetRecordCount(&m_ceguid,m_ceoid); CeOidGetInfoEx(&m_ceguid,m_ceoid,&oidinfo); iRecordCount = oidinfo.infDatabase.wNumRecords; wsprintf(DBTABLENAME,TEXT("RECORD IS %d"),iRecordCount); MessageBox(NULL,DBTABLENAME,NULL,NULL); // for( i=0;i { ceoid =CeSeekDatabase(m_hdb,CEDB_SEEK_BEGINNING,i,&dwIndex);
pBuff=0; ceoid=CeReadRecordProps(m_hdb, CEDB_ALLOWREALLOC, &wProps, NULL, & (LPBYTE)pBuff, &dwRecSize); pRecord =(PCEPROPVAL)pBuff; // for(k=0;k { switch(pRecord->propid) { case pid_no: wcscpy(DBTABLENAME,pRecord->val.lpwstr); MessageBox(NULL,DBTABLENAME,TEXT("NO"),NULL);
break; // case pid_name: wcscpy(DBTABLENAME,pRecord->val.lpwstr); MessageBox(NULL,DBTABLENAME,TEXT("NAME"),NULL);
break; } pRecord++; }//
LocalFree(pBuff); } //delete ceoid = CeSeekDatabase(m_hdb,CEDB_SEEK_BEGINNING,2,NULL); if( CeDeleteRecord(m_hdb,ceoid)) MessageBox(NULL,_T("DELE success"),NULL,NULL);
if(CloseHandle(m_hdb)) MessageBox(NULL,_T("close success"),NULL,NULL);
if(CeUnmountDBVol(&m_ceguid)) MessageBox(NULL,_T("unmount success"),NULL,NULL);
//search
break; |