// ================================================================================
// FUNCTION		: OpenChangeDb
// DESCRIPTION	: open changes database.
// ================================================================================
bool CDbHandler::OpenChangeDb(IDatabase ** pDatabase)
{

	//If the change Db already exist we want to close it. and stop the process of
	//making it again.
	if ( OpenDatabase(pDatabase, SM_CHANGEDB, FALSE) )
	{
		IDATABASE_Release(*pDatabase);
		return true;
	}
	else
		return ( !OpenDatabase(pDatabase, SM_CHANGEDB, TRUE) );

}
示例#2
0
void Database::BackupFile(const QString& filename) {
    qLog(Debug) << "Starting database backup";
    QString dest_filename = QString("%1.bak").arg(filename);
    const int task_id =
        app_->task_manager()->StartTask(tr("Backing up database"));

    sqlite3* source_connection = nullptr;
    sqlite3* dest_connection = nullptr;

    BOOST_SCOPE_EXIT((source_connection)(dest_connection)(task_id)(app_)) {
        // Harmless to call sqlite3_close() with a nullptr pointer.
        sqlite3_close(source_connection);
        sqlite3_close(dest_connection);
        app_->task_manager()->SetTaskFinished(task_id);
    }
    BOOST_SCOPE_EXIT_END

    bool success = OpenDatabase(filename, &source_connection);
    if (!success) {
        return;
    }

    success = OpenDatabase(dest_filename, &dest_connection);
    if (!success) {
        return;
    }

    sqlite3_backup* backup =
        sqlite3_backup_init(dest_connection, "main", source_connection, "main");
    if (!backup) {
        const char* error_message = sqlite3_errmsg(dest_connection);
        qLog(Error) << "Failed to start database backup:" << error_message;
        return;
    }

    int ret = SQLITE_OK;
    do {
        ret = sqlite3_backup_step(backup, 16);
        const int page_count = sqlite3_backup_pagecount(backup);
        app_->task_manager()->SetTaskProgress(
            task_id, page_count - sqlite3_backup_remaining(backup), page_count);
    } while (ret == SQLITE_OK);

    if (ret != SQLITE_DONE) {
        qLog(Error) << "Database backup failed";
    }

    sqlite3_backup_finish(backup);
}
示例#3
0
EXPORT_C gint32 CContactDb::SearchContactsByName(guint32 nTagId, gchar* name, gboolean onlyPref, 
											CContactIterator ** ppContactIterator)
	{
	char sql[512] = {0};
	OpenDatabase();
	
	if (nTagId != ContactType_Phone)
		sprintf(sql, "select * from contact where nickname_spell like '%%%s%%'and type = %d order by nickname_spell asc;", name, nTagId);
	else if (onlyPref)
		sprintf(sql, "select * from contact where name_spell like '%%%s%%'and type = %d order by name_spell asc;", name, nTagId);
	else
		sprintf(sql, "select c.*, ext.* from contact c "\
					"left join (select ce.cid ,ce.comm_key, ce.comm_value, a.* from contact_ext ce "\
					"left join address a on ce.comm_value = a.aid) ext "\
					"on c.cid = ext.cid where name_spell like '%%%s%%'and type = %d order by name_spell asc;", name, nTagId);
							
	m_dbQuery = m_dbBeluga.execQuery(sql);
	*ppContactIterator = NULL;
	*ppContactIterator = new CContactIterator(this, onlyPref);
	if (NULL == *ppContactIterator)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}

	CloseDatabase();
	return 0;	
	}
bool CEOSSDbAccess::OpenTheDatabase(short sFacNum, CString* pstrErrorMsg,const CString& csFacDir)
{
	CString strFacilityDirectory = csFacDir;// ((BSTR) g_pIFacMgr->GetFacilityDirectory(sFacNum));
	mstrDatabaseRootPath = csFacDir;/*strFacilityDirectory;*/
	strFacilityDirectory = m_Dir.AppendPath(strFacilityDirectory, mstrComponentName);
	msFacNum = sFacNum;

	BOOL bStatus = false;
	CString strErrorMsg;
	
	//If the datastore doesn't exist, create it and try again. 
	if (!m_Dir.FileExists (strFacilityDirectory, mstrDatabaseName)) {
		//Create the data store if it doesn't exist.
		if (!CreateDataStore (sFacNum))
		{
			//We still didn't create the datastore.
			bStatus = false;
			strErrorMsg.Format("Database could not be created at %s.", strFacilityDirectory);
			MessageBox(NULL, strErrorMsg, "Database Creation Error", MB_OK|MB_ICONWARNING);
			pstrErrorMsg->Format("%s", strErrorMsg);
		}
		else
		{
			bStatus = true;
		}
	}

	return(OpenDatabase(strFacilityDirectory, mstrDatabaseName));
	return true;
}
示例#5
0
/***********************************************************************
 * function is called at program start
 * you can put your own initialization jobs there
 ***********************************************************************/
static UInt16
StartApplication(void)
{
  Err err = 0;

  // Initialize the random number seed;
  SysRandom( TimGetSeconds() );

  // Load prefs
  PrefLoadPrefs(&gPrefs);

  // Initialize TNglue
  err = TNGlueColorInit();

  // Initialize Cache
  CacheInit();

  // Open Database
  if (err == errNone)  err = OpenDatabase();
  if (err == errNone)  DatabaseSetCat(gPrefs.curCat);

  // Set Alarms
  if (err == errNone)  AlarmReset(DatabaseGetRefN(DB_MAIN));


  return (err);
}
示例#6
0
文件: symref.c 项目: mingpen/OpenNT
/*  SRSendSymLocate - send a locate-symbol message to the server
 *
 *  Send request to server, display all responses until
 *  !EOM is seen.
 *
 *  psz 	symbol to find
 *  fFilesOnly	TRUE => just list filenames
 *  pszScope	scope of search
 */
void SRSendSymLocate (PSZ psz, BOOL fFilesOnly, PSZ pszScope)
{
    char sz[CBMSG];
    char *p;
    char szFile[MAX_PATH];
    HANDLE hServer;

    sprintf (sz, "%s %s %s %s", CMD_LOCATE, psz, fFilesOnly ? "-f" : "-a", pszScope);

    hServer = OpenDatabase (FALSE);

    SendSz (hServer, sz);

    while (ReceiveSz (hServer, sz)) {
	if (!strcmp (sz, RSP_EOD))
	    break;
	p = strbscan (sz, " ");
	*p++ = 0;

	GetLocalName (sz, szFile);

	if (fFilesOnly)
	    printf ("%s\n", szFile);
	else
	    printf ("%s %s\n", szFile, p);
	}

    CloseDatabase (hServer);
}
示例#7
0
INT_PTR CALLBACK OpenErrorDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	INT_PTR bReturn;
	if (DoMyControlProcessing(hdlg, message, wParam, lParam, &bReturn))
		return bReturn;

	switch (message) {
	case WM_INITDIALOG:
	{
		TCHAR szError[256];
		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, opts.error, 0, szError, SIZEOF(szError), NULL);
		SetDlgItemText(hdlg, IDC_ERRORTEXT, szError);
	}
	if (opts.error == ERROR_SHARING_VIOLATION) ShowWindow(GetDlgItem(hdlg, IDC_INUSE), SW_SHOW);
	SetWindowLongPtr(GetDlgItem(hdlg, IDC_FILE), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hdlg, IDC_FILE), GWL_STYLE) | SS_PATHELLIPSIS);
	TranslateDialogDefault(hdlg);
	SetDlgItemText(hdlg, IDC_FILE, opts.filename);
	return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_BACK:
			PostMessage(GetParent(hdlg), WZM_GOTOPAGE, IDD_SELECTDB, (LPARAM)SelectDbDlgProc);
			break;

		case IDOK:
			OpenDatabase(hdlg, IDD_FILEACCESS);
			break;
		}
		break;
	}
	return FALSE;
}
示例#8
0
文件: symref.c 项目: mingpen/OpenNT
/*  SRSendAddDirectory - send an index-file request to server
 *
 *  psz     name of file to be indexed. This name is rootpath'd as the
 *          server may be operating on a different directory/drive
 */
void SRSendAddDirectory (PSZ psz)
{
    char szFile[MAX_PATH];

    {
	char szTmp[MAX_PATH];

	rootpath (psz, szTmp);

	GetGlobalName (szTmp, szFile);
    }

    {
	HANDLE hServer;
	char sz[CBMSG];

	sprintf (sz, "%s %s", CMD_ADD_DIRECTORY, szFile);

	printf ("%s", szFile);

	hServer = OpenDatabase (TRUE);

	SendSz (hServer, sz);

	CloseDatabase (hServer);

	printf ("\n");
    }

}
示例#9
0
文件: symref.c 项目: mingpen/OpenNT
/*  SRSendNewDatabase - send a change-database request to server
 *
 *  psz     name of new database.  This name is rootpath'd as the
 *          server may be operating on a different directory/drive
 */
void SRSendNewDatabase (PSZ psz)
{
    char szFile[MAX_PATH];

    {
	char szTmp[MAX_PATH];

	rootpath (psz, szTmp);

	GetGlobalName (szTmp, szFile);
    }

    {
	HANDLE hServer;
	char sz[CBMSG];

	sprintf (sz, "%s %s", CMD_SET_DATABASE, szFile);

	hServer = OpenDatabase (FALSE);

	SendSz (hServer, sz);

	CloseDatabase (hServer);
    }
}
示例#10
0
/**
@SYMTestCaseID          SYSLIB-DBMS-CT-0637
@SYMTestCaseDesc        Streaming conversions test
@SYMTestPriority        Medium
@SYMTestActions         Test the database definition and enquiry functions 
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
LOCAL_C void Test()
	{
	test.Start(_L(" @SYMTestCaseID:SYSLIB-DBMS-CT-0637 Build without transactions "));
	CreateDatabaseL();
	TUint time1,size1;
	BuildTable(KRecords,EFalse,time1,size1);
	CloseDatabaseL();
	test.Next(_L("Build with transactions"));
	CreateDatabaseL();
	TUint time2,size2;
	BuildTable(KRecords,ETrue,time2,size2);
	test.Printf(_L("Transaction performance: time %4.2f, size %4.2f\n"),TReal(time1)/TReal(time2),TReal(size1)/TReal(size2));
	test.Next(_L("Build Int index"));
	Execute(_L("create unique index int on table (int)"));
	test.Next(_L("Break index"));
	BreakIndex();
	test.Next(_L("Build Text index"));
	Execute(_L("create unique index text on table (text)"));
	test.Next(_L("Recover"));
	test (TheDatabase.IsDamaged());
	CloseDatabaseL();
	OpenDatabase();
	test (TheDatabase.IsDamaged());
	Recover();
	test.Next(_L("Drop table"));
	Execute(_L("drop table table"));
	CloseDatabaseL();
	}
示例#11
0
EXPORT_C gint32 CContactDb::SearchPhoneContactsByPhoneOrEmail(gchar * commValue, 
							gboolean onlyPref, CContactIterator ** ppContactIterator)
	{
	char sql[512] = {0};
	OpenDatabase();
	
	if (onlyPref)
		strcpy(sql, "select * from contact c where cid in (select cid from contact_ext where comm_value like '%");
	else
		strcpy(sql, "select c.*, ext.* from contact c "\
					"left join (select ce.cid ,ce.comm_key, ce.comm_value, a.* from contact_ext ce "\
					"left join address a on ce.comm_value = a.aid) ext "\
					"on c.cid = ext.cid where c.cid in (select cid from contact_ext where comm_value like '%");
	
	strcat(sql, commValue);
	strcat(sql, "%') order by c.name_spell asc;");				
		
	m_dbQuery = m_dbBeluga.execQuery(sql);
	*ppContactIterator = NULL;
	*ppContactIterator = new CContactIterator(this, onlyPref);
	if (NULL == *ppContactIterator)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}

	CloseDatabase();
	return 0;
	}
示例#12
0
EXPORT_C gint32 CContactDb::GetMaxId(guint32 * nMaxId)
	{
	OpenDatabase();
	*nMaxId = m_dbBeluga.execScalar("select max(cid) from contact;");
	CloseDatabase();
	return 0;
	}
示例#13
0
///////////////////////////////////////////////////////////////////////////
//	Name:	SaveDatabaseNow
//
//	Description:
//	Remember the name and path of the currently open database.  Close the database
//	to flush all buffers, then reopen it.
//	
//	Declaration:
//	bool CDbVista::SaveDatabaseNow();
//
//	Input:	none
//
//	Output:	none
//
//	Return:	true (db saved) / false (error when reopening)
//	
//  date    /	author	revision
//  -----------------	--------
//	03-Dec-2001	SFK		Created from SaveDatabaseNow in DbGeneralDbSupport.cpp
//////////////////////////////////////////////////////////////////
bool CDbVista::SaveDatabaseNow()
{

//	SetCurrentDrive();		// implement in new version?? SFK
	CloseDatabase();
	return (OpenDatabase(mstrDatabasePath, mstrDatabaseName));
}
示例#14
0
EXPORT_C gint32 CContactDb::GetAllContactsByGroup(guint32 nGroupId, gboolean onlyPref, CContactIterator ** ppContactIterator)
	{
	char sql[512] = {0};
	OpenDatabase();
	
	if (onlyPref || !CheckGroupInTag(nGroupId, ContactType_Phone))
		sprintf(sql, "select * from contact c, r_contact_group r where r.gid = %d and ", nGroupId);
	else
		sprintf(sql, "select c.*, ext.* from contact c, r_contact_group r "\
					"left join (select ce.cid ,ce.comm_key, ce.comm_value, a.* from contact_ext ce "\
					"left join address a on ce.comm_value = a.aid) ext "\
					"on c.cid = ext.cid where r.gid = %d and ", nGroupId);
	
	strcat(sql, "c.cid = r.cid ");
	if (-1 != m_nSortFieldIndex)
		{
		strcat(sql, "order by c.");
		strcat(sql, ((GString*)g_ptr_array_index(m_pFieldsName, m_nSortFieldIndex))->str);
		strcat(sql, " asc;");
		}
		
	m_dbQuery = m_dbBeluga.execQuery(sql);
	*ppContactIterator = NULL;
	*ppContactIterator = new CContactIterator(this, onlyPref);
	if (NULL == *ppContactIterator)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}

	CloseDatabase();
	return 0;
	}
示例#15
0
EXPORT_C gint32 CContactDb::GetEntityById(guint32 nId, CDbEntity** ppEntity)
	{
	char sql[128] = {0};
	*ppEntity = NULL;
	
	OpenDatabase();
	sprintf(sql, "select * from contact where cid = %d;", nId);
	CppSQLite3Query query = m_dbBeluga.execQuery(sql);
	
	if (query.eof())
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_Not_Exist);
		}
	
	if (ContactType_Phone == query.getIntField(ContactField_Type))
		*ppEntity = new CPhoneContact(this, FALSE);
	else
		*ppEntity = new CIMContact(this);
	if (NULL == *ppEntity)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}
	
	for (int i=0; i<query.numFields(); i++)
		{
		GString * fieldValue = g_string_new(query.fieldValue(i));
		(*ppEntity)->SetFieldValue(i, fieldValue);
		g_string_free(fieldValue, TRUE);
		}
		
	CloseDatabase();
	return 0;
	}
示例#16
0
EXPORT_C gint32 CContactDb::SaveRecentContact(stRecentContact * contact)
	{
	char sql[256] = {0};
	OpenDatabase();
	if (m_dbBeluga.execScalar("select count(*) from recent_contact;") > MAX_RECENT_CONTACT_NUM)
		{
		m_dbBeluga.execDML("delete from recent_contact where time = (select min(time) from recent_contact);");
		}
	
	sprintf(sql, "select count(*) from recent_contact where cid = %d;", contact->nContactId);
	if (m_dbBeluga.execScalar(sql) != 0)
		{
		memset(sql, 0, 256);
		sprintf(sql, "update recent_contact set event = %d, event_comm = '%s', time = '%d-%d-%d %02d:%02d:%02d' where cid = %d;", 
			contact->event, contact->eventCommInfo,
			contact->time.tm_year, contact->time.tm_mon, contact->time.tm_mday,
			contact->time.tm_hour, contact->time.tm_min, contact->time.tm_sec, contact->nContactId);
		}
		else
		{
		memset(sql, 0, 256);
		sprintf(sql, "insert into recent_contact values(null, %d, %d, '%s', %d-%d-%d %02d:%02d:%02d);", 
			contact->nContactId, contact->event, contact->eventCommInfo,
			contact->time.tm_year, contact->time.tm_mon, contact->time.tm_mday,
			contact->time.tm_hour, contact->time.tm_min, contact->time.tm_sec);
		}

	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
示例#17
0
BOOL CXmasterApp::InitInstance()
{
	CWaitCursor pCursor;
	
#ifndef _DEBUG
	if ( SetFirstInstance() == FALSE ) return FALSE;
#endif

#ifdef _AFXDLL
	Enable3dControls();
#else
	Enable3dControlsStatic();
#endif

	SetRegistryKey( gcszCopyright );
	GetVersionNumber();

	AfxOleInit();
	AfxEnableControlContainer();
	
	CSplashDlg* dlgSplash = new CSplashDlg;
		dlgSplash->Topmost();
	
	dlgSplash->Step( _T("Winsock") );
		WSADATA wsaData;
		if ( WSAStartup( 0x0101, &wsaData ) ) return FALSE;

	dlgSplash->Step( _T("注册表") );
		Settings.Load();
		Profiles.Setup();
		Skin.Apply();
	
	dlgSplash->Step( _T("数据库") );
		m_bInitialized = OpenDatabase();

	dlgSplash->Step( _T(" 图形用户界面") );

		m_pMainWnd = new CMainWnd();
		CoolMenu.EnableHook();

		CString strCaption;
		strCaption.LoadString( AFX_IDS_APP_TITLE );
		m_pMainWnd->SetWindowText( (LPCTSTR)strCaption );

		dlgSplash->Topmost();
		m_pMainWnd->ShowWindow( SW_SHOWMAXIMIZED );
		m_pMainWnd->UpdateWindow();
	
	dlgSplash->Step( _T("网络") );
		m_pMainWnd->SendMessage( WM_COMMAND, ID_NETWORK_CONNECT );

	pCursor.Restore();
	
	dlgSplash->Hide();
	
	LogMessage( "程序启动", TRUE );

	return TRUE;
}
示例#18
0
gint32 CContactDb::GetMaxContactCommId(guint32 * pMaxCommId)
	{
	*pMaxCommId = 0;
	OpenDatabase();
	*pMaxCommId = m_dbBeluga.execScalar("select max(ce_id) from contact_ext;");
	CloseDatabase();
	return 0;
	}
示例#19
0
OGRLayer *OGRCouchDBDataSource::GetLayerByName(const char * pszLayerName)
{
    OGRLayer* poLayer = OGRDataSource::GetLayerByName(pszLayerName);
    if (poLayer)
        return poLayer;

    return OpenDatabase(pszLayerName);
}
示例#20
0
EXPORT_C gint32 CContactDb::DeleteEntity(guint32 nEntityId)
	{
	char sql[128] = {0};
	OpenDatabase();
	sprintf(sql, "delete from contact where cid = %d;", nEntityId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
示例#21
0
EXPORT_C gint32 CContactDb::ReleaseContactAllRelations(guint32 nContactId)
	{
	char sql[128] = {0};
	OpenDatabase();
	sprintf(sql, "delete from r_contact_group where cid = %d;", nContactId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
示例#22
0
EXPORT_C gint32 CContactDb::CreateContactGroupRelation(guint32 nContactId, guint32 nGroupId)
	{
	char sql[128] = {0};
	OpenDatabase();
	sprintf(sql, "insert into r_contact_group values(%d, %d);", nContactId, nGroupId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
示例#23
0
文件: symref.c 项目: mingpen/OpenNT
/*  SRSendSync - send a sync request to server
 */
void SRSendSync ()
{
    HANDLE hServer;

    hServer = OpenDatabase (FALSE);

    SendSz (hServer, CMD_SYNCHRONIZE);

    CloseDatabase (hServer);
}
示例#24
0
EXPORT_C gint32 CContactDb::DeleteAllContactsByTag(guint32 nTagId)
	{
	char sql[256] = {0};
	OpenDatabase();
	sprintf(sql, "delete from contact where cid in (select cid from r_contact_group where gid in "\
				 "(select gid from cgroup where tid= %d)); ", nTagId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
示例#25
0
rc_t KeyRingOpen(KKeyRing** self, const char* path, const struct KFile* pwd_in, struct KFile* pwd_out)
{
    rc_t rc; 
    assert(self && path && pwd_in && pwd_out);

    *self = (KKeyRing*) malloc(sizeof(**self));
    if (*self)
    { 
        rc = KeyRingInit(*self, path);
        if (rc == 0)
        {
            rc = KeyRingAddRef(*self);
            if (rc == 0)
            {
                KDirectory* wd; 
                rc = KDirectoryNativeDir(&wd);
                if (rc == 0)
                {   /* open the database */
                    if (KDirectoryPathType(wd, "%s", (*self)->path) == kptFile)
                        rc = GetPassword(pwd_in, pwd_out, (*self)->passwd);
                    else /* does not exist; create first */
                    {   
                        rc = GetNewPassword(pwd_in, pwd_out, (*self)->passwd);
                        if (rc == 0)
                            rc = CreateDatabase(*self);
                    }
                    if (rc == 0)
                        rc = OpenDatabase(*self);
                        
                    {
                        rc_t rc2;
                        rc2 = KDirectoryRelease(wd);
                        if (rc == 0)
                            rc = rc2;
                    }
                }
            }
            
            if (rc != 0)
            {
                KeyRingWhack(*self);
                *self = NULL;
            }
        }
        else
        {
            free(*self);
            *self = NULL;
        }
    }
    else
        rc = RC ( rcApp, rcDatabase, rcOpening, rcMemory, rcExhausted );

    return rc;
}
wxSQLite3ResultSet TagsDatabase::SelectTagsByFile(const wxString& file, const wxFileName& path)
{
	// Incase empty file path is provided, use the current file name
	wxFileName databaseFileName(path);
	path.IsOk() == false ? databaseFileName = m_fileName : databaseFileName = path;
	OpenDatabase(databaseFileName);

	wxString query;
	query = wxString::Format(_T("select * from tags where file='%s';"), file.GetData());
	return m_db->ExecuteQuery(query.GetData());
}
示例#27
0
///////////////////////////////////////////////////////////////////////////
//	Name:	InitializeDatabase
//
//	Description:
//	If a database does not exist at the specified directory, copy an empty one
//	to it from the default directory location.  Clear all information from the
//	database at the specified directory.
//	
//	Declaration:
//	bool CDbVista::InitializeDatabase(CString &strDbBasePath)
//
//	Input:	none
//			mstrComponentName	name of the subpath where this instrument's data is kept
//			mstrMyDbFilename	name of file that indicates a database is present
//			mstrDefaultPath		directory where an empty database is found (under mstrComponentName)
//			mstrDatabaseName	name of the database that is thought to exist at the specified dir (under mstrComponentName)
//
//	Output:	none
//
//	Return:	true (db exists and initialized) / false (error in operation)
//	
//  date    /	author	revision
//  -----------------	--------
//	28-Jan-2002	SFK		Created
//////////////////////////////////////////////////////////////////
bool CDbVista::InitializeDatabase(const CString &strDbBasePath,const bool bPrompt)
{
	//CDirUtilities m_Dir;
	CString strError, strEmptyDbPath;
	
	if ((mstrComponentName.GetLength() == 0) || (mstrMyDbFilename.GetLength() == 0)) {
		strError.Format("Initialize Database: No component name or db filename set program error, cannot continue.");

		//WAS "NOT FOR NDAR".  Reenabled by pjm 11/27/2007 for B2R1
		if (!m_bQuietMode)
			MessageBox(NULL, strError, "Fatal Error", MB_OK|MB_ICONWARNING);

		return(false);
	}

	CString strTemp = m_Dir.AppendPath(strDbBasePath, mstrComponentName);	// create the instrument Com specific path
	
	bool bSuccess = m_Dir.FileExists(strTemp, mstrMyDbFilename);		// does a database exist there already?
	if (mbDatabaseOpen) CloseDatabase();							// close any database that might be open now

	if (!bSuccess) 
	{			// no database where we are to initialize one
		if (mstrDefaultPath.GetLength() == 0) 
		{
			strError.Format("Initialize Database: No Default Path Set program error, cannot continue.");

			//WAS "NOT FOR NDAR".  Reenabled by pjm 11/27/2007 for B2R1
			if (!m_bQuietMode)		
				MessageBox(NULL, strError, "Fatal Error", MB_OK|MB_ICONWARNING);

			return(false);
		}
		strEmptyDbPath = m_Dir.AppendPath(mstrDefaultPath, mstrComponentName);
		bSuccess = m_Dir.CopyDirectory(strEmptyDbPath, strTemp, true);	// copy an empty one over there
	}

	if (bSuccess) 		// database exists, open it and clear it
	{
		bSuccess = OpenDatabase(strTemp, mstrDatabaseName);

		//NDAR change so that ClearDatabase() will do the right thing.
		//Changed back PJM 11/27/2007 for B2R1
		bool b = bPrompt;

		if (m_bQuietMode)
			b = false;

		if (bSuccess) 
			bSuccess = ClearDatabase(mstrDatabaseName, b);
	}

	return (bSuccess);
}
示例#28
0
gboolean CContactDb::CheckGroupInTag(guint32 nGroupId, guint32 nTagId)
	{
	char sql[128] = {0};
	guint32 count = 0;
	OpenDatabase();
	
	sprintf(sql, "select count(*) from cgroup where tid = %d and gid = %d;", nTagId, nGroupId);
	count = m_dbBeluga.execScalar(sql);
	CloseDatabase();
	
	return (count ? TRUE : FALSE); 
	}
示例#29
0
EXPORT_C gint32 CContactDb::GetContactsTotalityByGroup(guint32 nGroupId, guint32 * totality)
	{
	char sql[128] = {0};
	*totality = 0;
	OpenDatabase();
	
	sprintf(sql, "select count(cid) from r_contact_group where gid = %d;", nGroupId);
	*totality = m_dbBeluga.execScalar(sql);
	CloseDatabase();
	
	return 0;
	}
示例#30
0
EXPORT_C gint32 CContactDb::GetContactsTotalityByTag(guint32 nTagId, guint32 * totality)
	{
	char sql[128] = {0};
	*totality = 0;
	OpenDatabase();
	
	sprintf(sql, "select count(*) from contact where type = %d;", nTagId);
	*totality = m_dbBeluga.execScalar(sql);
	CloseDatabase();
	
	return 0;
	}