?? demo2dlg.cpp
字號:
// Demo2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "Demo2.h"
#include "Demo2Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "CppSQLite3U.h"
/////////////////////////////////////////////////////////////////////////////
// CDemo2Dlg dialog
CDemo2Dlg::CDemo2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CDemo2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDemo2Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDemo2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDemo2Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDemo2Dlg, CDialog)
//{{AFX_MSG_MAP(CDemo2Dlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDemo2Dlg message handlers
BOOL CDemo2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
#define FILE_DB_NAME TEXT("\\Storage Card\\unitechchen.db")
//獲取程序當(dāng)前路徑
void GetCurrentDirectory(CString &szPath)
{
wchar_t pBuf[256];
GetModuleFileName(NULL,pBuf,sizeof(pBuf)/sizeof(wchar_t));
szPath=pBuf;
szPath = szPath.Left(szPath.ReverseFind('\\')+1);
}
void CDemo2Dlg::OnButton1()
{
CString strDbPath;
GetCurrentDirectory(strDbPath);
strDbPath = FILE_DB_NAME;
CppSQLite3DB db;
try
{
//打開或新建一個(gè)數(shù)據(jù)庫
db.open(strDbPath);
//判斷表名是否存在
if(db.tableExists(L"tblTest"))
{
AfxMessageBox(L"Table: tblTest is existed!");
}
else //不存在
{
AfxMessageBox(L"Table: tblTest not existed!");
//新建表
db.execDML(L"create table tblTest(empno varchar(20), empname varchar(20))");
}
//插入一筆記錄
db.execDML(L"insert into tblTest values('編號', '姓名')");
//插入一筆記錄
db.execDML(L"insert into tblTest values('精瑞電腦', 'Answer')");
//刪除一筆記錄
db.execDML(L"delete from tblTest where empno='編號'");
//插入10筆記錄(使用事務(wù))
TCHAR buf[256];
db.execDML(L"begin transaction;");
for (int i = 0; i < 10; i++)
{
memset(buf, 0, sizeof(buf));
wsprintf(buf, L"insert into tblTest values ('no%d', 'name%d');", i, i);
db.execDML(buf);
}
db.execDML(L"commit transaction;");
//更新一筆記錄
db.execDML(L"update tblTest set empname='answer' where empno='no1'");
//獲取總筆數(shù)
int count = db.execScalar(L"select count(*) from tblTest;");
TCHAR szCount[50];
memset(szCount, 0, sizeof(szCount));
wsprintf(szCount, L"Count:%d", count);
AfxMessageBox(szCount);
//獲取每一筆
CppSQLite3Query q = db.execQuery(L"select * from tblTest");
while (!q.eof())
{
AfxMessageBox(q.fieldValue(0));
q.nextRow();
}
q.finalize();
db.close();
AfxMessageBox(L"OK");
}
catch(CppSQLite3Exception ex)
{
AfxMessageBox(ex.errorMessage());
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -