1打开数据库
BOOL playDlg::openData()
{
WCHAR a[100];
CString path;
path = m_exePath+L"sentence_making\\FROG.db";
memcpy(a,path,sizeof(a));
int nRet = sqlite3_open16((const char *)a,&psqlite); // 链接到数据库,如果成功,数据库句柄指针存储于psqlite 中
// 函数返回sqlITE_OK 表示连接成功,否则直接退出连接
if (nRet != sqlITE_OK)
{
AfxMessageBox(L"open DataBase Failed");
}
return TRUE;
}
CString playDlg::selData(UINT num)
{
CString sentence;
sqlite3_stmt * stat;
CString sql2;
sql2.Format(L"select * from zao_ju_lian_xi where [index] = %d",num);
//sql2.Format(L"select * from zao_ju_lian_xi where [index] =");
sqlite3_prepare16(psqlite,sql2,-1,&stat,0);
if(sqlite3_step(stat)==sqlITE_ROW )
sentence = (CString)sqlite3_column_text(stat,1);
sqlite3_finalize(stat);
sence[senNum] = sentence;
return sentence;
}
3、
BOOL playDlg::closeData()
{
if (psqlite)
{
sqlite3_close(psqlite); // 关闭sqlite 数据库连接
psqlite = NULL;
return TRUE;
}
else
{
return FALSE;
}
}