⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgloaddump.cpp

📁 sysbase 12 用程序实现加卸载数据。
💻 CPP
字号:
// DlgLoadDump.cpp : implementation file
//

#include "stdafx.h"
#include "dump.h"
#include "DlgLoadDump.h"
#include "Common.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgLoadDump dialog
extern  _ConnectionPtr	g_pCN;
extern  _RecordsetPtr	g_pRS;

CDlgLoadDump::CDlgLoadDump(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgLoadDump::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgLoadDump)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDlgLoadDump::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgLoadDump)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgLoadDump, CDialog)
	//{{AFX_MSG_MAP(CDlgLoadDump)
	ON_BN_CLICKED(IDC_BUTTON_DUMP, OnButtonDump)
	ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
	ON_CBN_SELCHANGE(IDC_COMBO_DataBase, OnSelchangeCOMBODataBase)
	ON_CBN_SELCHANGE(IDC_COMBO_DataBResume, OnSelchangeCOMBODataBResume)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgLoadDump message handlers

BOOL CDlgLoadDump::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	if (FALSE == CreateCN(g_pCN, "master")) 
	{
		ShowError(ERROR_DDL);
		return FALSE;
	}
	
	CString strError, strName, strSql;
	strSql = "select name from master..sysdatabases where name != 'master' and name !='model' and name != 'tempdb' and name != 'sybsystemdb' and name != 'sybsystemprocs'";
	//将数据库信息加入控件

	if(FALSE != ExecuteSql(strSql, DB_COMMAND_RESULT_READONLY, g_pRS, &strError))
	{
		while (FALSE == g_pRS->EndOfFile)
		{
			GetFieldString("Name", &strName);
			((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->InsertString(-1, strName);
			((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->InsertString(-1, strName);
			g_pRS->MoveNext();
		}
		((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->SetCurSel(0);
		((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->SetCurSel(0);
	}
	
	OnSelchangeCOMBODataBase();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgLoadDump::OnButtonDump() 
{
	// TODO: Add your control notification handler code here
	((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(false);

	CString strDataName, strError, strSQL = "";
	((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetCurSel(), strDataName);

	//先切换到Master数据库
	strSQL = "use master";
	if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
	{
		MessageBox(strError);
		((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(true);
		return;
	}
	//数据库
	strSQL = "dump database " + strDataName + " to \"" + "f:\\" + strDataName + ".dat " + "\" ";
	if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
	{
		MessageBox(strError);
		((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(true);
		return;
	}
	((this->GetDlgItem (IDC_BUTTON_DUMP)))->EnableWindow(true);   
}

void CDlgLoadDump::OnButtonLoad() 
{
	// TODO: Add your control notification handler code here

	
	((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(false);

	CString strDataName,strError, strSQL = "";

	//取得数据库名称
	((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetCurSel(), strDataName);

	// 1,设置当前数据库的no chkpt on recover, dbo use only, read only 为TRUE
	strSQL = "use master";
	if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
	{
		((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(true);
		return;
	}

  //以下是修改数据库名称的程序
	CString  strNewName;
	strNewName = "dfg";
	
	strSQL = "use master";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	
	strSQL = "sp_dboption " + strDataName + ", \"single user\", \"true\"";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	
	strSQL = "use Dump_DB_CR";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);

	strSQL = "checkpoint";
	ExecuteSql(strSQL, DB_COMMAND_RESULT_READONLY, g_pRS, &strError);

	strSQL = "sp_renamedb Dump_DB_CR, " + strNewName;
    ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	
	strSQL = "use master";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	
	strSQL = "sp_dboption  dfg, \"single user\",\"false\" ";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	
	strSQL = "use dfg";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	
	strSQL = "checkpoint";
	ExecuteSql(strSQL, DB_COMMAND_RESULT_READONLY, g_pRS, &strError);

/*
	strSQL = "sp_dboption " + strDataName + ", \"no chkpt on recover\", \"true\"";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	strSQL = "sp_dboption " + strDataName + ", \"dbo use only\", \"true\"";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	strSQL = "sp_dboption " + strDataName + ", \"read only\", \"true\"";
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
	
	strSQL = "dbcc checkdb";
	ExecuteSql(strSQL, DB_COMMAND_RESULT_READONLY, g_pRS, &strError);

	//2,开始恢复数据库 
	strSQL = "load database " +  strDataName + " from \"" + "f:\\" + strDataName + ".dat" + "\" ";
	if(FALSE == ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError))
	{
		// 恢复初始设置
		strSQL = "sp_dboption " + strDataName + ", \"no chkpt on recover\", \"false\"";
		ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
		strSQL = "sp_dboption " + strDataName + ", \"dbo use only\", \"false\"";
		ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
		strSQL = "sp_dboption " + strDataName + ", \"read only\", \"false\"";
		ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);
		MessageBox(strError);
	
		((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(true);
		return;
	}
	//3,恢复数据库online
	strSQL = "online database " + strDataName;
	ExecuteSql(strSQL, DB_COMMAND_NORESULT, g_pRS, &strError);	
	((this->GetDlgItem (IDC_BUTTON_LOAD)))->EnableWindow(true);
*/
}

void CDlgLoadDump::OnSelchangeCOMBODataBase() 
{
	// TODO: Add your control notification handler code here
	CString strDataName;
	((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBase)))->GetCurSel(), strDataName);
}

void CDlgLoadDump::OnSelchangeCOMBODataBResume() 
{
	// TODO: Add your control notification handler code here
	CString strDataName;
	((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->GetLBText(((CComboBox*)(this->GetDlgItem (IDC_COMBO_DataBResume)))->GetCurSel(), strDataName);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -