BOOL InformationTable::PHtoGMDSqlite(const CString &strPHSqlPath,const CString &strGMDsqlPath)
{
string strPHSelect ="select * from caseitem";
string strGMDInsert = L"insert into _InformationTable(UID,AppId,State,Item,Contents,App) values(?,?,?,?,?,?)";
try
{
CppSQLite3Query QueryContact = m_pPHSqlite->execQuery(strPHSelect);
CppSQLite3Statement stmtSearchWord = m_pGMDSqlite->compileStatement(strGMDInsert);
m_pGMDSqlite->execDML("begin transaction");
CString strID;
CString strName;
for (int Flag = 0; !QueryContact.eof(); QueryContact.nextRow(),++Flag)
{
//结构体每个元素赋值
InformationTableFieldName.strApp = QueryContact.getStringField("display_name");
CString strTableName=L"_InformationTable";
InformationTableFieldName.nUID=GetNextID(strTableName,"UID");
InformationTableFieldName.nAppID = atoi(strID);
InformationTableFieldName.strState =QueryContact.getStringField("deleted");
InformationTableFieldName.strItem=L"IMEI";
InformationTableFieldName.strContents = QueryContact.getStringField("item");
//进行绑定
stmtSearchWord.bind(1,InformationTableFieldName.nUID);
stmtSearchWord.bind(2,InformationTableFieldName.nAppID);
stmtSearchWord.bind(3,InformationTableFieldName.strState);
stmtSearchWord.bind(4,InformationTableFieldName.strItem)
stmtSearchWord.bind(5,InformationTableFieldName.strContents);
stmtSearchWord.bind(6,InformationTableFieldName.strApp);
stmtSearchWord.execDML();
stmtSearchWord.reset();
}
m_pGMDSqlite->execDML("commit transaction");//提交
QueryContact.finalize();//释放
}
catch (CppSQLite3Exception* e)
{
InsertDebugLog("CSearchWordTable::PHtoGMDSqlite数据库打开失败");
return FALSE;
}
catch (CException* e)
{
InsertDebugLog("CSearchWordTable::PHtoGMDSqlite内存错误");
return FALSE;
}
return TRUE;
}
//得到数据库中一张表某个字段的最大值或者这张表数据的条数(如果这张表中某一个 字段是0或1顺序排下来则这张表的数据条数为返回的值即strkeyName传入该字段)
strTable 表名 strKeyName 字段名
int CbaseSql::GetNextID(const CString & strTableName, const CString & strKeyName)
{
try
{
int nID = -1;
string strSQL = L"select max(" + strKeyName + L") as Id from " + strTableName;
CppSQLite3Query query = m_pGMDSqlite->execQuery(strSQL);
if(query.fieldIsNull("Id"))
return nID;
nID = query.getIntField("Id") + 1;
query.finalize();
return nID;
}
catch (CppSQLite3Exception & e)
{
InsertDebugLog("CbaseSql::GetNextID");
return -1;
}
catch (CException* e)
{
InsertDebugLog("CbaseSql::GetNextID");
return -1;
}
}