Пример #1
0
BOOL CMLogin::DoSaveADImages(sqlite3* db, TADImages& img, const char* sID){
    BOOL ret = FALSE;
    
    if (strcmp(m_sADImagesTableName, "") == 0) {
		return TRUE;
	}
    
    CHAR sql[1024];
	sqlite3_stmt *stmt;
	snprintf(sql,1024,
             "REPLACE INTO  %s(id,imageurl) values (?,?)",
             m_sADImagesTableName);
    
	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
        BindParam(stmt, 1, sID);
        BindParam(stmt, 2, img.sImage);
        
		if (sqlite3_step(stmt) == SQLITE_DONE) {
            
			ret = TRUE;
		} else {
			CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
		}
        
		sqlite3_finalize(stmt);
	} else {
		CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
	}
    
	return ret;
}
Пример #2
0
BOOL CMMyInfo::GetPushInfo(const char* tags, const char* alias, sqlite3* db)
{
    
    
    
    if (db == NULL || strlen(m_tagsandaliastablename) == 0) {
        return false;
    }
    
    bool ret = false;
    
    sUid = alias;
    sTags = tags;
    
    //拿到之前保存的tags和alias
    GetPreviousTagsAndAlias(db);
    
    //清空数据表
    ClearTagsAlias();
    
    
    CHAR sql[1024];
	sqlite3_stmt *stmt;
    snprintf(sql, 1024,"INSERT INTO %s(uid,tags) VALUES (?,?)",  m_tagsandaliastablename);
    
	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
        BindParam(stmt, 1, sUid.c_str());
        BindParam(stmt, 2, sTags.c_str());
        
		if (sqlite3_step(stmt) == SQLITE_DONE) {
            
			ret = TRUE;
            
		} else {
			CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
		}
        
		sqlite3_finalize(stmt);
	} else {
		CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
	}
    if(ret)
        GetTagsAliasCacheItems(db);

	return ret;

    
    
    
}
Пример #3
0
BOOL CMMyInfo::GetTagsAliasItem(TiXmlElement *pItem, sqlite3 *db, TDummyItem &item){
    BOOL ret = FALSE;
	const CHAR* pStr = NULL;
    pStr = pItem->Attribute("uid");
	if (pStr)
        sUid = pStr;
    
    pStr = pItem->Attribute("tags");
	if (pStr){
        sTags = pStr;
    }
   
    if (strcmp(m_tagsandaliastablename, "") == 0) {
		return TRUE;
	}
    
    //拿到之前保存的tags和alias
    GetPreviousTagsAndAlias(db);
    
    //清空数据表
    ClearTagsAlias();
    
	CHAR sql[1024];
	sqlite3_stmt *stmt;
    snprintf(sql, 1024,"INSERT INTO %s(uid,tags) VALUES (?,?)",  m_tagsandaliastablename);
    
	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
        BindParam(stmt, 1, sUid.c_str());
        BindParam(stmt, 2, sTags.c_str());
        
		if (sqlite3_step(stmt) == SQLITE_DONE) {
            
			ret = TRUE;
            
		} else {
			CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
		}
   
		sqlite3_finalize(stmt);
	} else {
		CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
	}
    if(ret)
        GetTagsAliasCacheItems(db);
    
	return ret;

}
void CMQuestionDetail::DoClear() {
	m_mutex.Lock();
	if (m_lstItem)
		m_lstItem->clear();
	m_mutex.UnLock();

	sqlite3* db = CheckTable(m_tablename);
	if (db != NULL) {

		CHAR sql[1024];
		sql[0] = '\0';
		sqlite3_stmt *stmt;

		snprintf(sql,sizeof(sql),"DELETE FROM %s WHERE questionid = ? ", m_tablename);

		if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
			BindParam(stmt, 1, sQuestionID);

			if (sqlite3_step(stmt) != SQLITE_DONE) {
				CM_ERRP("exec %s failed.", sql);
			}


		}

	}
}
Пример #5
0
void CMBrowser::DoClear()
{

    DoClearList();

    sqlite3* db = CheckTable();

    if(strlen(m_tablename)<=0)
        return;


    if(db != NULL)
    {
        CHAR sql[1024];
        sql[0] = '\0';
        sqlite3_stmt *stmt;

        snprintf(sql,1024,"DELETE FROM %s WHERE categoryid = ? ", m_tablename);

        if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
        {
            BindParam(stmt,1, sCategoryID);

            if (sqlite3_step(stmt) != SQLITE_DONE)
            {
                CM_ERRP("exec %s failed.", sql);
            }
            sqlite3_finalize(stmt);
        }
    }

}
Пример #6
0
BOOL CMExerciseList::CheckExerciseListIsExit(const char *sID)
{
    BOOL ret = FALSE;
    if(strlen(m_tablename)==0)
        return ret;
    
	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';
    
    sqlite3*db=CheckTable(m_tablename);
	if (db == NULL)
		return FALSE;
    
    int nCount = 0;
    
    snprintf(sql, 1024,"SELECT COUNT(*) FROM %s WHERE id=?", m_tablename);
    if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
    {
        BindParam(stmt, 1, sID);
        if (sqlite3_step(stmt) == SQLITE_ROW)
        {
            nCount = sqlite3_column_int(stmt, 0);
            if (nCount > 0)
                ret = TRUE;
        }
        
        sqlite3_finalize(stmt);
    }
    else
	{
		CM_ERRP("sqlite3_step %s failed.error:%s", sql, sqlite3_errmsg(db));
	}
    return ret;
}
Пример #7
0
void CMSpecialTopic::DoClear()
{
    m_mutex.Lock();
    if(m_lstHeadItem)
    {
        
        for(int i = 0; i < m_lstHeadItem->size(); i++)
        {
            TBrowserItem* ptr = m_lstHeadItem->at(i);
            SAFEDELETE(ptr);
        }
        
        m_lstHeadItem->clear();
    }
	m_mutex.UnLock();
    
	m_mutex.Lock();
    if(m_lstItem)
    {
        for(int i = 0; i < m_lstItem->size(); i++)
        {
            TBrowserItem* ptr = m_lstItem->at(i);
            SAFEDELETE(ptr);
        }
        
        m_lstItem->clear();
    }
    m_mutex.UnLock();

    
    sqlite3* db = CheckTable();
    
    if(db != NULL)
    {
        CHAR sql[1024];
        sql[0] = '\0';
        sqlite3_stmt *stmt;
        
        snprintf(sql, sizeof(sql),"DELETE FROM %s WHERE parentspecid = ? ", m_tablename);
        
        if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
        {
            BindParam(stmt, 1, sParentSpecId);
            
            
            if (sqlite3_step(stmt) != SQLITE_DONE)
            {
                CM_ERRP("exec %s failed.", sql);
            }
        }
    }
}
BOOL TTrainSignInItem::Refresh()
{
	BOOL ret = FALSE;

	if(strlen(TABLE_TRAINSIGNIN) == 0)
		return FALSE;


	if(strlen(sID.c_str()) == 0)
		return FALSE;

	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';

	sqlite3*db = CMDBHelper::GetInstance(1)->GetConnection();

	if (db == NULL)
		return FALSE;

	snprintf(sql,1024,"SELECT * FROM %s WHERE id = ?", TABLE_TRAINSIGNIN);

	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
	{
		BindParam(stmt, 1, sID.c_str());
		int i = sqlite3_step(stmt);
		if (i == SQLITE_ROW)
		{
			fetchItem(stmt);
			ret = TRUE;
		}
		else if (i == SQLITE_DONE)
		{
			ret = TRUE;
		}
		else
		{
			if (i != SQLITE_DONE) {
			CM_ERRP("sqlite3_prepare_refresh %s failed.error:%s sid:%s", sql, sqlite3_errmsg(db),sID.c_str());
			}
		}

		sqlite3_finalize(stmt);
	}
	else
	{
		CM_ERRP("sqlite3_step %s failed.error:%s", sql, sqlite3_errmsg(db));
	}
	return ret;
}
Пример #9
0
BOOL CMSpecialTopic::DoGetCacheItems(sqlite3* db)
{
	BOOL ret = FALSE;
	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';
    
    snprintf(sql,sizeof(sql),"SELECT main.*, sub.stitle , sub.simage , sub.parentspecid FROM %s AS sub  LEFT JOIN %s AS main ON sub.id = main.id WHERE sub.parentspecid = ? ",m_tablename,m_tablename );
    
    if (m_bPaging)
    {
        snprintf(sql,sizeof(sql),"%s LIMIT %d OFFSET %d", sql, m_nPageSize, (m_nPageNo - 1)*m_nPageSize);
    }
    
    // printf("error:%d \n",sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) );
    
	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
	{
        BindParam(stmt, 1, sParentSpecId);
        if ( m_nPageNo == 1)
        {
            m_mutex.Lock();
            m_lstItem->clear();
            m_mutex.UnLock();
            
            m_mutex.Lock();
            m_lstHeadItem->clear();
            m_mutex.UnLock();
            
        }
        
        while(sqlite3_step(stmt)==SQLITE_ROW)
        {
        	TClassItem* item= new TClassItem();
            
            item->fetchItem(stmt);
            
//            utf8ncpy(item.sID, (const char*)sqlite3_column_text(stmt, 1), 63);
//            
//            utf8ncpy(item.sFlag, (const char*)sqlite3_column_text(stmt, 2), 15);
//            
//            utf8ncpy(item.sTitle, (const char*)sqlite3_column_text(stmt, 3), 99);
//            
//            utf8ncpy(item.sBrief, (const char*)sqlite3_column_text(stmt, 4), 99);
//
//            
//            utf8ncpy(item.sLargeimage, (const char*)sqlite3_column_text(stmt, 5) ,299);
//            
//            utf8ncpy(item.sImage, (const char*)sqlite3_column_text(stmt, 6) ,299);
//            
//            utf8ncpy(item.sThumbs, (const char*)sqlite3_column_text(stmt, 7) ,299);
//            
//            utf8ncpy(item.sType , (const char*)sqlite3_column_text(stmt, 8) ,63);
//            
//            item.nCoursewarecount = sqlite3_column_int(stmt, 9);
//            
//            utf8ncpy(item.sUrl, (const char*)sqlite3_column_text(stmt, 10) ,299);
//            
//            utf8ncpy(item.sPubdate, (const char*)sqlite3_column_text(stmt, 11) ,19);
//            
//            item.nVC = sqlite3_column_int(stmt, 12);
//            
//            item.nPV = sqlite3_column_int(stmt, 13);
//            
//            item.nCommentcount = sqlite3_column_int(stmt, 14);
//            
//            item.bEnablecomment = sqlite3_column_int(stmt, 15);
//            
//            item.bEnabledownload = sqlite3_column_int(stmt, 16);
//            
//            item.bEnablerating = sqlite3_column_int(stmt, 17);
//            
//            utf8ncpy(item.sDescription,  (const char*)sqlite3_column_text(stmt, 18) , 449);
//            
//            
//            utf8ncpy(item.sTag,  (const char*)sqlite3_column_text(stmt, 19) , 63);
//            
//            utf8ncpy(item.sSpecialtopic,  (const char*)sqlite3_column_text(stmt, 20) , 63);
//            
//            utf8ncpy(item.sCredit,  (const char*)sqlite3_column_text(stmt, 21) , 31);
//            
//            item.nStudyduration = sqlite3_column_int(stmt, 22);
//            
//            item.nStudyprogress = sqlite3_column_int(stmt, 23);
//            
//            utf8ncpy(item.sLaststudydate,  (const char*)sqlite3_column_text(stmt, 24) , 31);
//            
//            
//            utf8ncpy(item.sFavoritedate,  (const char*)sqlite3_column_text(stmt, 25) , 19);
//            
//            item.bMyCompany = sqlite3_column_int(stmt, 26);
//            
//            item.bIsRated = sqlite3_column_int(stmt, 27);


            utf8ncpy(m_sTitle,  (const char*)sqlite3_column_text(stmt, 28) , 99);
            
            utf8ncpy(m_sImage,  (const char*)sqlite3_column_text(stmt, 29) , 299);
            utf8ncpy(sParentSpecId,  (const char*)sqlite3_column_text(stmt, 30) , 63);
            
            
            m_mutex.Lock();
            
            if(m_lstItem)
                m_lstItem->push_back(item);
            m_mutex.UnLock();
            
            
        }
        ret=TRUE;
        
        if (ret)
        {
            //计算总数
            m_nTotalCount = 0;
            snprintf(sql,sizeof(sql),"SELECT COUNT(*) FROM %s WHERE parentspecid = ? ", m_tablename);
            if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
            {
                BindParam(stmt, 1, sParentSpecId);

                
                if (sqlite3_step(stmt) == SQLITE_ROW)
                {
                    
                    m_nTotalCount = sqlite3_column_int(stmt, 0);
                }
                
                sqlite3_finalize(stmt);
            }
        }
        
        
        sqlite3_finalize(stmt);
        
        ret = TRUE;
	}
    
	return ret;
}
Пример #10
0
BOOL CMSpecialTopic::DoPutItem(TiXmlElement* pItem, sqlite3* db, TBrowserItem*& item)
{
    const CHAR* pid = NULL;
    
	pid = pItem->Attribute("id");

    
    //存入数据库
    if(!db)
        return FALSE;
    
    if(strlen(m_tablename)==0)
        return FALSE;
    
    CHAR sql[1024];
    
    BOOL ret = FALSE;
    
	sqlite3_stmt *stmt;
    
    snprintf(sql,sizeof(sql), "INSERT INTO %s(id,stitle,simage,parentspecid) VALUES (?,?,?,?)", m_tablename);
    
    if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
        BindParam(stmt, 1, pid);
        
        BindParam(stmt,2, m_sTitle);
        BindParam(stmt, 3, m_sImage);
        BindParam(stmt, 4, sParentSpecId);
        
        if(sqlite3_step(stmt) == SQLITE_DONE)
        {
        	ret = TRUE;
        }
        else
        {
        	CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
        }
        
        sqlite3_finalize(stmt);
    }
    else {
    	CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
    }
    
    if( CMContenthandler::DoPutItem(pItem, db, item)==FALSE)
        ret= FALSE;
    
    char* errorMsg;
    
    //发生错误则回滚
    if (ret == FALSE) {
        
        if (db != NULL && sqlite3_exec(db, "ROLLBACK TRANSACTION;", 0,0, &errorMsg) != SQLITE_OK)
        {
            CM_ERRP("ROLLBACK TRANSACTION failed.error:%s", errorMsg);
        }
        
    }
    
    return ret;
}
BOOL CMQuestionDetail::DoUpdate(const TAnswerItem& obj) {
    BOOL ret = FALSE;

    //更新对象
    m_mutex.Lock();
    for (int i = 0; i < m_lstItem->size(); i++) {
        TAnswerItem& item = m_lstItem->at(i);
        
        if (strcmp(item.sID.c_str(), obj.sID.c_str()) == 0) {
            item = obj;
            //若设了最佳答案,踢出链表
            if(item.nAnswerflag!=0)
            {
                
                if(m_lstItem)
                {
                    m_hasFlagAnswerItem=item;

                    m_lstItem->removeAt(i);
                }
                
            }
            ret = TRUE;
            break;
        }
    }
    m_mutex.UnLock();
	if (strlen(sQuestionID) == 0)
		return FALSE;

	if (strcmp(m_tablename, "") == 0) {
		//表名为空表示不需同步数据库,直接返回成功。
		return TRUE;
	}

	//保存入数据库
	sqlite3*db = CheckTable(m_tablename);
	if (db) {
		sqlite3_stmt *stmt;
		CHAR sql[512];
		snprintf(sql,sizeof(sql),"UPDATE %s SET id=?, answer=?, answer_username=?, answer_fullname=?, answer_icon=?, pubdate=?, answerflag=?, pv=?, questionid=?, isliked=?, pic_url=?, thumburl=? WHERE id=? ",
				m_tablename);

		if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
			BindParam(stmt, 1, obj.sID.c_str());
			BindParam(stmt, 2, obj.sAnswer.c_str());
			BindParam(stmt, 3, obj.sAnswerer_username.c_str());
			BindParam(stmt, 4, obj.sAnswerer_fullname.c_str());
			BindParam(stmt, 5, obj.sAnswerer_icon.c_str());
			BindParam(stmt, 6, obj.sPubdate.c_str());
			BindParam(stmt, 7, obj.nAnswerflag);
			BindParam(stmt, 8, obj.nPV);
			BindParam(stmt, 9, sQuestionID);
			BindParam(stmt, 10, obj.nIsliked);
			BindParam(stmt, 11, obj.sPic_url.c_str());
            BindParam(stmt, 12, obj.sThumburl.c_str());

            BindParam(stmt, 13,obj.sID.c_str());

			if (sqlite3_step(stmt) == SQLITE_DONE) {
			
			} else {
				CM_ERRP("sqlite3_step %s failed.error:%s",
						sql, sqlite3_errmsg(db));
			}
		} else {
			CM_ERRP("prepare %s failed.error:%s", sql, sqlite3_errmsg(db));
		}

		sqlite3_finalize(stmt);
	}

	return ret;
}
BOOL CMQuestionDetail::DoRefresh(TAnswerItem& obj) {
    BOOL ret = FALSE;

    
    m_mutex.Lock();
    for (int i = 0; i < m_lstItem->size(); i++) {
        TAnswerItem& item = m_lstItem->at(i);
        
        if (strcmp(item.sID.c_str(), obj.sID.c_str()) == 0) {
            obj=item;
            ret = TRUE;
            break;
        }
    }
    m_mutex.UnLock();
    
    
	if (strcmp(m_tablename, "") == 0)
		return FALSE;

	//根据obj的sID属性更新
	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';

	sqlite3*db = CheckTable(m_tablename);
	if (db == NULL)
		return FALSE;

	snprintf(sql,sizeof(sql),"SELECT  * FROM %s WHERE id = ? ", m_tablename);

	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
		BindParam(stmt, 1, obj.sID.c_str());

		if (sqlite3_step(stmt) == SQLITE_ROW) {

			TAnswerItem item;

            item.sID =  (const char*) sqlite3_column_text(stmt, 1);

            item.sAnswer = (const char*) sqlite3_column_text(stmt, 2);

            item.sAnswerer_username =(const char*) sqlite3_column_text(stmt, 3);

            item.sAnswerer_fullname =(const char*) sqlite3_column_text(stmt, 4);

            item.sAnswerer_icon = (const char*) sqlite3_column_text(stmt, 5);

            item.sPubdate = (const char*) sqlite3_column_text(stmt, 6);

			item.nAnswerflag = sqlite3_column_int(stmt, 7);

			item.nPV = sqlite3_column_int(stmt, 8);

			//strcpy(sQuestionID, (const char*)sqlite3_column_text(stmt, 9));

			utf8ncpy(sQuestionID, (const char*) sqlite3_column_text(stmt, 9),
					63);

			item.nIsliked = sqlite3_column_int(stmt, 10);

	
            item.sPic_url =  (const char*) sqlite3_column_text(stmt, 11);
            
            item.sThumburl =(const char*) sqlite3_column_text(stmt, 12);

	
		} else {
			CM_ERRP("sqlite3_prepare_v2 %s failed.error:%s",
					sql, sqlite3_errmsg(db));
		}

		sqlite3_finalize(stmt);
	} else {
		CM_ERRP("sqlite3_step %s failed.error:%s", sql, sqlite3_errmsg(db));
	}
	return ret;

}
Пример #13
0
void TExerciseListItem::bindItem(sqlite3_stmt* stmt) const
{
    BindParam(stmt, 1, sID.c_str());
    BindParam(stmt, 2, sTitle.c_str());
    BindParam(stmt, 3, nQuestioncount);
    BindParam(stmt, 4, nUncompletecount);
    BindParam(stmt, 5, sDesc.c_str());
    BindParam(stmt, 6, sCategory.c_str());
    BindParam(stmt, 7, nUsercompletecount);
    BindParam(stmt, 8, sPubdate.c_str());
    BindParam(stmt, 9, nCurIndex);
    BindParam(stmt, 10, nWrongCount);
    BindParam(stmt, 11, nRightCount);
    BindParam(stmt,12,sTrainID.c_str());
}
Пример #14
0
BOOL CMExerciseList::DoRefresh(TExerciseListItem& obj)
{
	BOOL ret = FALSE;

    
	if (strcmp(m_tablename, "") == 0)
        return FALSE;

	//根据obj的sID属性更新
	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';
    
	sqlite3*db=CheckTable(m_tablename);

	if (db == NULL)
		return FALSE;


	snprintf(sql,sizeof(sql),"SELECT id,title,questioncount,uncompletecount,desc,category,usercompletecount,pubdate,curindex,nwrongcount,rightcount,trainid FROM %s WHERE id = ?", m_tablename);
    
	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
	{
		BindParam(stmt, 1, obj.sID.c_str());
        
        if (sqlite3_step(stmt) == SQLITE_ROW)
        {
            
            obj.sID = (const char*)sqlite3_column_text(stmt, 0);
            
            obj.sTitle = (const char*)sqlite3_column_text(stmt, 1);
            
            obj.nQuestioncount = sqlite3_column_int(stmt, 2);
            
            obj.nUncompletecount = sqlite3_column_int(stmt, 3);
            
            obj.sDesc = (const char*)sqlite3_column_text(stmt, 4);
            
            obj.sCategory = (const char*)sqlite3_column_text(stmt, 5);
            
            obj.nUsercompletecount = sqlite3_column_int(stmt, 6);
            
            obj.sPubdate = (const char*)sqlite3_column_text(stmt, 7);
            
            obj.nCurIndex = sqlite3_column_int(stmt, 8);
            
            obj.nWrongCount = sqlite3_column_int(stmt, 9);
            
            obj.nRightCount = sqlite3_column_int(stmt, 10);
            
            obj.sTrainID = (const char*)sqlite3_column_text(stmt,11);

            m_mutex.Lock();
            
            for (int i = 0; i < m_lstItem->size(); i++) {
                TExerciseListItem& item = m_lstItem->at(i);
                
                if (strcmp(item.sID.c_str(), obj.sID.c_str()) == 0) {
                    item = obj;
                    ret = TRUE;
                    break;
                }
            }
            m_mutex.UnLock();

        }
        else
        {
        	CM_ERRP("sqlite3_prepare_v2 %s failed.error:%s", sql, sqlite3_errmsg(db));
        }
        
        sqlite3_finalize(stmt);
	}
	else
	{
		CM_ERRP("sqlite3_step %s failed.error:%s", sql, sqlite3_errmsg(db));
	}
    
	return ret;
}
Пример #15
0
BOOL CMBrowser::DoPutItem(TiXmlElement* pItem, sqlite3* db, TBrowserItem*& item)
{
    const CHAR* pid = NULL;

    pid = pItem->Attribute("id");

    if(!db)
        return FALSE;

    BOOL ret = FALSE;

    if(strlen(m_tablename)>0)
    {
        CHAR sql[1024];

        sqlite3_stmt *stmt;

        snprintf(sql,1024,"INSERT INTO %s(id,isheaditem,categoryid) VALUES (?,?,?)", m_tablename);

        if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
            BindParam(stmt, 1, pid);

            BindParam(stmt, 2, item->bIsHeadItem);

            BindParam(stmt, 3, sCategoryID);

            if(sqlite3_step(stmt) == SQLITE_DONE)
            {
                ret = TRUE;
            }
            else
            {
                CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
            }

            sqlite3_finalize(stmt);
        }
        else {
            CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
        }
    }
    else
        ret=TRUE;


    if(!pItem || !db)
        return FALSE;

    *item=pItem;

    if (item->bIsHeadItem)
    {
        if(m_lstHeadItem)
            m_lstHeadItem->push_back(item);
    }
    else
    {
        if(m_lstItem)
            m_lstItem->push_back(item);
    }

    if(DoSaveTBrowseitem(db, *item))
        ret= TRUE;


    char* errorMsg;

    if (ret == FALSE) {
        if (db != NULL && sqlite3_exec(db, "ROLLBACK TRANSACTION;", 0,0, &errorMsg) != SQLITE_OK)
        {
            CM_ERRP("ROLLBACK TRANSACTION failed.error:%s", errorMsg);
        }
    }

    return ret;

}
Пример #16
0
bool Sqlite3Connection::Execute() {
	Cancel();
	if(statement.GetLength() == 0) {
		session.SetError("Empty statement", String("Preparing: ") + statement);
		return false;
	}
	String utf8_stmt = ToCharset(CHARSET_UTF8, statement, CHARSET_DEFAULT);
	if (SQLITE_OK != sqlite3_prepare(db,utf8_stmt,utf8_stmt.GetLength(),&current_stmt,NULL)) {
		LLOG("Sqlite3Connection::Compile(" << statement << ") -> error");
		session.SetError(sqlite3_errmsg(db), String("Preparing: ") + statement);
		return false;
	}
	current_stmt_string = statement;
	int nparams = ParseForArgs(current_stmt_string);
	ASSERT(nparams == param.GetCount());
	for (int i = 0; i < nparams; ++i)
		BindParam(i+1,param[i]);
	param.Clear();
	// Make sure that compiling the statement never fails.
	ASSERT(NULL != current_stmt);
	int retcode;
	dword ticks_start = GetTickCount();
	int sleep_ms = 1;
	do{
		retcode = sqlite3_step(current_stmt);
		if(retcode!=SQLITE_BUSY && retcode!=SQLITE_LOCKED) break;
		if(session.busy_timeout == 0) break;
		if(session.busy_timeout>0){
			if((int)(GetTickCount()-ticks_start)>session.busy_timeout){
				break;
			}
		}//else infinite retry
		if(retcode==SQLITE_LOCKED) sqlite3_reset(current_stmt);
		Sleep(sleep_ms);
		if(sleep_ms<128) sleep_ms += sleep_ms;
	}while(1);
	if ((retcode != SQLITE_DONE) && (retcode != SQLITE_ROW)) {
		session.SetError(sqlite3_errmsg(db), current_stmt_string);
		return false;
	}
	got_first_row = got_row_data = (retcode==SQLITE_ROW);
//	if (got_row_data) { // By WebChaot, 2009-01-15
		int numfields = sqlite3_column_count(current_stmt);
		info.SetCount(numfields);
		for (int i = 0; i < numfields; ++i) {
			SqlColumnInfo& field = info[i];
			field.name = sqlite3_column_name(current_stmt,i);
			field.binary = false;
			String coltype = sqlite3_column_decltype(current_stmt,i);
			switch (sqlite3_column_type(current_stmt,i)) {
				case SQLITE_INTEGER:
					field.type = INT_V;
					break;
				case SQLITE_FLOAT:
					field.type = DOUBLE_V;
					break;
				case SQLITE_TEXT:
					if(coltype == "date")
						field.type = DATE_V;
					else
					if(coltype == "datetime")
						field.type = TIME_V;
					else
						field.type = WSTRING_V;
					break;
				case SQLITE_NULL:
					if(coltype == "date")
						field.type = DATE_V;
					else
					if(coltype == "datetime")
						field.type = TIME_V;
					else
					if(coltype.Find("char") >= 0 || coltype.Find("text") >= 0 )
						field.type = WSTRING_V;
					else
					if(coltype.Find("integer") >= 0)
						field.type = INT_V;
					else
					if(coltype.Find("real") >= 0)
						field.type = DOUBLE_V;
					else
						field.type = VOID_V;
					break;
				case SQLITE_BLOB:
					field.type = STRING_V;
					field.binary = true;
					break;
				default:
					NEVER();
					break;
			}
		}
//	}
	return true;
}
Пример #17
0
BOOL CMMyInfo::DoUpdate(const TDummyItem& obj) {
    
    BOOL ret = FALSE;
    
    sqlite3* db = CheckTable(m_tablename);
    
    if (db)
    {
        m_mutex.Lock();
        
        CHAR sql[1024];
        sqlite3_stmt *stmt;
        snprintf(sql,1024, "UPDATE %s SET jobnumber=?, headimage=?, fullname=?, organization=?, department=?, position=?, title=?, rankurl=?, detailurl=?, level=?, value=?, credit=?, studyrecord=?, positioncoursecount=?, currentminvalue=?, nextvalue=?, undoexam=?, wrongqa=?,contributevalue=?", m_tablename);
        
        if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
        {
            BindParam(stmt, 1, sJobnumber.c_str());
            BindParam(stmt, 2, sHeadimage.c_str());
            BindParam(stmt, 3, sWorkname.c_str());
            BindParam(stmt, 4, sOrg.c_str());
            BindParam(stmt, 5, sDevelopment.c_str());
            BindParam(stmt, 6, sPosition.c_str());
            BindParam(stmt, 7, sTitle.c_str());
            BindParam(stmt, 8, sRankurl.c_str());
            BindParam(stmt, 9, sDetailurl.c_str());
            
            BindParam(stmt, 10, nLevel);
            BindParam(stmt, 11, nValue);
            BindParam(stmt, 12, nCredit);
            BindParam(stmt, 13, nStudycount);
            
            BindParam(stmt, 14, nPositionCourseCount);
            BindParam(stmt, 15, nCurrentminvalue);
            BindParam(stmt, 16, nNextvalue);
            BindParam(stmt, 17, nUndoExam);
            BindParam(stmt, 18, nWrongQa);
            
            BindParam(stmt,19,nContributeValue);
            
            if (sqlite3_step(stmt) == SQLITE_DONE)
            {
                ret = TRUE;
            }
            else
            {
                CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
            }
        }
        else
        {
            CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
        }
        
        m_mutex.UnLock();
        
        sqlite3_finalize(stmt);
    }
	return ret;
}
Пример #18
0
BOOL CMExerciseList::DoPutItem(TiXmlElement* pItem, sqlite3* db, TExerciseListItem& item)
{
	BOOL ret = FALSE;
	const CHAR* pStr = NULL;

	pStr = pItem->Attribute("id");
	if(pStr)
        item.sID = pStr;
    
	pStr = pItem->Attribute("title");
	if(pStr)
        item.sTitle = pStr;
    
    pItem->QueryIntAttribute("questioncount", &item.nQuestioncount);
    
    pItem->QueryIntAttribute("uncompletecount", &item.nUncompletecount);
    
	pStr = pItem->Attribute("desc");
	if(pStr)
        item.sDesc = pStr;
    
	pStr = pItem->Attribute("category");
	if(pStr)
        item.sCategory = pStr;
    
    pItem->QueryIntAttribute("usercompletecount", &item.nUsercompletecount);
    
	pStr = pItem->Attribute("pubdate");
	if(pStr)
        item.sPubdate = pStr;
    
    int temp = 0;
    item.nCurIndex = temp;
    item.nWrongCount = 0;
    item.nRightCount = 0;

    item.sTrainID = n_sTrainID;

	if (strcmp(m_tablename, "") == 0)
	{
		//表名为空,不入库,返回成功
		return TRUE;
	}
    
    if (CheckExerciseListIsExit(item.sID.c_str())) {
        //该练习存在,无需更新表,直接从表里读数据
        Refresh(item);
        return TRUE;
    }
    else
    {
        GetExerciseData(item.sID.c_str(), item);
    }
    
	CHAR sql[1024];
	sqlite3_stmt *stmt;
    snprintf(sql,sizeof(sql),"REPLACE INTO %s(id,title,questioncount,uncompletecount,desc,category,usercompletecount,pubdate,curindex,nwrongcount,rightcount,trainid) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", m_tablename);
    if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
        BindParam(stmt, 1, item.sID.c_str());
        BindParam(stmt, 2, item.sTitle.c_str());
        BindParam(stmt, 3, item.nQuestioncount);
        BindParam(stmt, 4, item.nUncompletecount);
        BindParam(stmt, 5, item.sDesc.c_str());
        BindParam(stmt, 6, item.sCategory.c_str());
        BindParam(stmt, 7, item.nUsercompletecount);
        BindParam(stmt, 8, item.sPubdate.c_str());
        BindParam(stmt, 9, item.nCurIndex);
        BindParam(stmt, 10, item.nWrongCount);
        BindParam(stmt, 11, item.nRightCount);
        BindParam(stmt, 12, item.sTrainID.c_str());
        if(sqlite3_step(stmt) == SQLITE_DONE)
        {
        	ret = TRUE;
        }
        else
        {
        	CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
        }
        
        sqlite3_finalize(stmt);
    }
    else
    {
    	CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
    }
    
    return  ret;
}
Пример #19
0
BOOL CMMyInfo::DoPutItem(TiXmlElement* pItem, sqlite3* db, TDummyItem& item) {
	BOOL ret = FALSE;
	const CHAR* pStr = NULL;
	 pStr= pItem->Attribute("jobnumber");

	if (pStr)
        sJobnumber = pStr;

	pStr = pItem->Attribute("headimage");
	if (pStr)
        sHeadimage = pStr;

	pStr = pItem->Attribute("fullname");
	if (pStr)
        sWorkname = pStr;

	pStr = pItem->Attribute("organization");
	if (pStr)
        sOrg = pStr;

	pStr = pItem->Attribute("department");
	if (pStr)
        sDevelopment = pStr;

	pStr = pItem->Attribute("position");
	if (pStr)
        sPosition = pStr;

	pStr = pItem->Attribute("title");
	if (pStr)
        sTitle = pStr;

	pStr = pItem->Attribute("rankurl");
	if (pStr)
        sRankurl = pStr;
    
	pStr = pItem->Attribute("detailurl");
	if (pStr)
        sDetailurl = pStr;
    
    pItem->QueryIntAttribute("sex",&nSex);

	pItem->QueryIntAttribute("level", &nLevel);
    
	pItem->QueryIntAttribute("value", &nValue);

	pItem->QueryIntAttribute("credit", &nCredit);

    pItem->QueryIntAttribute("studyrecord", &nStudycount);

    pItem->QueryIntAttribute("positioncoursecount", &nPositionCourseCount);

    pItem->QueryIntAttribute("currentminvalue", &nCurrentminvalue);

    pItem->QueryIntAttribute("nextvalue", &nNextvalue);
    
    pItem->QueryIntAttribute("undoexam", &nUndoExam);

    
    pItem->QueryIntAttribute("wrongqa", &nWrongQa);

    pItem->QueryIntAttribute("contributevalue",&nContributeValue);

	if (strcmp(m_tablename, "") == 0) {
		return TRUE;
	}
    

	CHAR sql[1024];
	sqlite3_stmt *stmt;
	snprintf(sql,1024,
			"INSERT INTO %s(jobnumber,headimage,fullname,organization,department,position,title,rankurl,detailurl,level,value,credit,studyrecord,positioncoursecount,currentminvalue,nextvalue,undoexam,wrongqa,sex,contributevalue) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
			m_tablename);
    

	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {

		BindParam(stmt, 1, sJobnumber.c_str());
		BindParam(stmt, 2, sHeadimage.c_str());
		BindParam(stmt, 3, sWorkname.c_str());
		BindParam(stmt, 4, sOrg.c_str());
		BindParam(stmt, 5, sDevelopment.c_str());
		BindParam(stmt, 6, sPosition.c_str());
		BindParam(stmt, 7, sTitle.c_str());
		BindParam(stmt, 8, sRankurl.c_str());
		BindParam(stmt, 9, sDetailurl.c_str());

		BindParam(stmt, 10, nLevel);
		BindParam(stmt, 11, nValue);
		BindParam(stmt, 12, nCredit);
		BindParam(stmt, 13, nStudycount);
        
        BindParam(stmt, 14, nPositionCourseCount);
        BindParam(stmt, 15, nCurrentminvalue);
	    BindParam(stmt, 16, nNextvalue);
        BindParam(stmt, 17, nUndoExam);
        BindParam(stmt, 18, nWrongQa);
        BindParam(stmt, 19, nSex);
        BindParam(stmt,20,nContributeValue);


		if (sqlite3_step(stmt) == SQLITE_DONE) {

			ret = TRUE;
		} else {
			CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
		}

		sqlite3_finalize(stmt);
	} else {
		CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
	}

	return ret;
}
Пример #20
0
BOOL CMExerciseList::DoUpdate(const TExerciseListItem& obj)
{
    BOOL ret = FALSE;
    
    //更新对象
    m_mutex.Lock();
    
    for (int i = 0; i < m_lstItem->size(); i++)
    {
        TExerciseListItem& item = m_lstItem->at(i);
        
        if (strcmp(item.sID.c_str(), obj.sID.c_str()) == 0) {
            item = obj;
            ret = TRUE;
            break;
        }
    }
    m_mutex.UnLock();
    
	if (strcmp(m_tablename, "") == 0)
        return FALSE;
    
    //保存入数据库
    sqlite3*db=CheckTable(m_tablename);
    
    if(db)
    {
		sqlite3_stmt *stmt;
		CHAR sql[512];
		snprintf(sql,sizeof(sql),"UPDATE %s SET id=?, title=?, questioncount=?, uncompletecount=?, desc=?, category=?, usercompletecount=?, pubdate=?,curindex=?,nwrongcount=?,rightcount=?,trainid=? WHERE id=? ", m_tablename);
        
        if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
            BindParam(stmt, 1, obj.sID.c_str());
            BindParam(stmt, 2, obj.sTitle.c_str());
            BindParam(stmt, 3, obj.nQuestioncount);
            BindParam(stmt, 4, obj.nUncompletecount);
            BindParam(stmt, 5, obj.sDesc.c_str());
            BindParam(stmt, 6, obj.sCategory.c_str());
            BindParam(stmt, 7, obj.nUsercompletecount);
            BindParam(stmt, 8, obj.sPubdate.c_str());
            BindParam(stmt, 9, obj.nCurIndex);
            BindParam(stmt, 10, obj.nWrongCount);
            BindParam(stmt, 11, obj.nRightCount);
            BindParam(stmt, 12, obj.sTrainID.c_str());
            if(sqlite3_step(stmt)==SQLITE_DONE)
            {
                ret = TRUE;
            }
            else
            {
            	CM_ERRP("sqlite3_step %s failed.error:%s", sql, sqlite3_errmsg(db));
            }
        }
        else
        {
        	CM_ERRP("prepare %s failed.error:%s", sql, sqlite3_errmsg(db));
        }
        
        sqlite3_finalize(stmt);
    }
    
    return ret;
}
BOOL CMQuestionDetail::DoGetCacheItems(sqlite3* db) {
	BOOL ret = FALSE;
	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';

	//	sprintf(sql, "SELECT id,flag,title,largeimage,image,thumb,type,coursewarecount,url,pubdate,vc,pv,commentcount,enablecomment,enabledownload,enablerating,description,category,tag,specialtopic,credit,studyduration,studyprogress,laststudydate,favoritedate,mycompany,isheaditem FROM %s ORDER BY _id ASC", m_tablename);

	snprintf(sql,sizeof(sql),"SELECT * FROM %s WHERE questionid = ? ORDER BY _id ASC ",
			m_tablename);

	if (m_bPaging) {
		snprintf(sql,sizeof(sql),"%s LIMIT %d OFFSET %d", sql, m_nPageSize,
				(m_nPageNo - 1) * m_nPageSize);
	}

	// printf("error:%d \n",sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) );

	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
    
		BindParam(stmt, 1, sQuestionID);

		while (sqlite3_step(stmt) == SQLITE_ROW) {
			TAnswerItem item;

            item.sID =(const char*) sqlite3_column_text(stmt, 1);

            item.sAnswer = (const char*) sqlite3_column_text(stmt, 2);

            item.sAnswerer_username =(const char*) sqlite3_column_text(stmt, 3);

            item.sAnswerer_fullname =(const char*) sqlite3_column_text(stmt, 4);

            item.sAnswerer_icon =(const char*) sqlite3_column_text(stmt, 5);

            item.sPubdate = (const char*) sqlite3_column_text(stmt, 6);

			item.nAnswerflag = sqlite3_column_int(stmt, 7);

			item.nPV = sqlite3_column_int(stmt, 8);
            
            //9 IS QUESTIONID

			item.nIsliked = sqlite3_column_int(stmt, 10);

            item.sPic_url = (const char*) sqlite3_column_text(stmt, 11);
            
            item.sThumburl = (const char*) sqlite3_column_text(stmt, 12);

			m_mutex.Lock();

			if (m_lstItem)
				m_lstItem->push_back(item);
			m_mutex.UnLock();

			if (item.nAnswerflag != 0) {
				m_hasFlagAnswerItem = item;
			}

		}

		if (ret) {
			//计算总数
			m_nTotalCount = 0;
			snprintf(sql,sizeof(sql),"SELECT COUNT(*) FROM %s WHERE questionid = ? ",
					m_tablename);
			if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
				if (sqlite3_step(stmt) == SQLITE_ROW) {
					BindParam(stmt, 1, sQuestionID);

					m_nTotalCount = sqlite3_column_int(stmt, 0);
				}

				sqlite3_finalize(stmt);
			}
		}

		sqlite3_finalize(stmt);

		ret = TRUE;
	}

	return ret;
}
Пример #22
0
BOOL CMExerciseList::DoGetCacheItems(sqlite3* db)
{
	if (strcmp(m_tablename, "") == 0)
        return FALSE;
    
	BOOL ret = FALSE;
	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';

	snprintf(sql,sizeof(sql),"SELECT id,title,questioncount,uncompletecount,desc,category,usercompletecount,pubdate,curindex,nwrongcount,rightcount,trainid FROM %s WHERE trainid=? ORDER BY _id ASC", m_tablename);

	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
	{
		BindParam(stmt,1,n_sTrainID.c_str());
        m_mutex.Lock();
        while(sqlite3_step(stmt) == SQLITE_ROW)
        {
        	TExerciseListItem item;
            
            item.sID = (const char*)sqlite3_column_text(stmt, 0);
            
            item.sTitle = (const char*)sqlite3_column_text(stmt, 1);
            
            item.nQuestioncount = sqlite3_column_int(stmt, 2);
            
            item.nUncompletecount = sqlite3_column_int(stmt, 3);
            
            item.sDesc = (const char*)sqlite3_column_text(stmt, 4);
            
            item.sCategory = (const char*)sqlite3_column_text(stmt, 5);
            
            item.nUsercompletecount = sqlite3_column_int(stmt, 6);
            
            item.sPubdate = (const char*)sqlite3_column_text(stmt, 7);
            
            item.nCurIndex = sqlite3_column_int(stmt, 8);
            
            item.nWrongCount = sqlite3_column_int(stmt, 9);
            
            item.nRightCount = sqlite3_column_int(stmt, 10);
            
            item.sTrainID = (const char*)sqlite3_column_text(stmt, 11);

        	m_lstItem->push_back(item);
            
            ret = TRUE;

        }
        m_mutex.UnLock();
        
        sqlite3_finalize(stmt);
        
	}
    
	if (ret)
	{
		//计算总数
		m_nTotalCount = 0;
		snprintf(sql,sizeof(sql),"SELECT COUNT(*) FROM %s", m_tablename);
		if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
		{
	        if (sqlite3_step(stmt) == SQLITE_ROW)
	        {
	        	m_nTotalCount = sqlite3_column_int(stmt, 0);
	        }
            
	        sqlite3_finalize(stmt);
		}
	}
    
	return ret;
}
Пример #23
0
BOOL CMBrowser::DoGetCacheItems(sqlite3* db)
{
	BOOL ret = FALSE;
	sqlite3_stmt *stmt;
	CHAR sql[1024];
	sql[0] = '\0';

    if(strlen(m_tablename)<=0)
        return FALSE;


    snprintf(sql,1024,"SELECT main.*,  sub.isheaditem , sub.categoryid   FROM %s AS sub  LEFT JOIN %s AS main ON sub.id = main.id WHERE sub.categoryid = ? ",m_tablename,kCourseTable);
    if (m_bPaging)
    {
        snprintf(sql,1024,"%s LIMIT %d OFFSET %d", sql, m_nPageSize, (m_nPageNo - 1)*m_nPageSize);
    }

//    CM_ERRP("CMBrowser DoGetCacheItems %s", sql);
//    CM_ERRP("CMBrowser DoGetCacheItems categoryid %s", sCategoryID);

	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
	{
        BindParam(stmt, 1, sCategoryID);
        if ( m_nPageNo == 1)
        {

            DoClearList();

        }

        while(sqlite3_step(stmt)==SQLITE_ROW)
        {

            if (sqlite3_column_int(stmt, 30)==0)
            {
                TClassItem* item= new TClassItem();
                item->fetchItem(stmt);

                if(sqlite3_column_int(stmt, kDbColumnIndex+1)==0)
                    item->bIsHeadItem=FALSE;
                else
                    item->bIsHeadItem=TRUE;

                if(item->bIsHeadItem)
                {
                    m_mutex.Lock();
                    m_lstHeadItem->push_back(item);
                    m_mutex.UnLock();
                }
                else
                {
                    m_mutex.Lock();

                    if(m_lstItem)
                        m_lstItem->push_back(item);

                    m_mutex.UnLock();

                }
            }
            else
            {
                TCoursewareItem* item=new TCoursewareItem();
                item->fetchItem(stmt);


                if(strlen(m_tablename)<=0)
                    item->bIsHeadItem=FALSE;
                else
                    item->bIsHeadItem=sqlite3_column_int(stmt, kDbColumnIndex+1);

                if(item->bIsHeadItem)
                {
                    m_mutex.Lock();
                    m_lstHeadItem->push_back(item);
                    m_mutex.UnLock();
                }
                else
                {
                    m_mutex.Lock();

                    if(m_lstItem)
                        m_lstItem->push_back(item);

                    m_mutex.UnLock();

                }
            }

        }

        sqlite3_finalize(stmt);

		m_nTotalCount = 0;
		if(strlen(m_tablename)<=0)
			snprintf(sql,1024,"SELECT COUNT(*) FROM %s ", m_tablename);
		else
			snprintf(sql,1024,"SELECT COUNT(*) FROM %s WHERE categoryid = ? ", m_tablename);

//		CM_ERRP("CMBrowser DoGetCacheItems %s", sql);

		if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK)
		{
			if(strlen(m_tablename)>0)
				BindParam(stmt, 1, sCategoryID);

			if (sqlite3_step(stmt) == SQLITE_ROW)
			{
				m_nTotalCount = sqlite3_column_int(stmt, 0);
			}

		}

        sqlite3_finalize(stmt);

    	if (GetItemCount() > 0 || GetHeadItemCount() > 0) {
    		//如果缓存为空,返回false,触发远程请求
    		ret = TRUE;
    	}
	}
    
    int count = m_nTotalCount/m_nPageSize;
    if(m_nTotalCount%m_nPageSize > 0)
        count++;
    
    m_bEnd = (m_nPageNo >= count);

	if(m_pListener)
		m_pListener->OnUpdateDataFinish(m_UserData, TResult::ESuccess);
	return ret;
}
BOOL CMQuestionDetail::DoPutItem(TiXmlElement* pItem, sqlite3* db,
		TAnswerItem& item) {

	BOOL ret = FALSE;
	if (!pItem)
		return FALSE;
	const CHAR* pStr = NULL;

	pStr = pItem->Attribute("id");
	if (pStr)
        item.sID = pStr;

	pStr = pItem->Attribute("answer");
	if (pStr)
        item.sAnswer = pStr;

	pStr = pItem->Attribute("answerer_username");
	if (pStr)
        item.sAnswerer_username = pStr;

	pStr = pItem->Attribute("answerer_fullname");
	if (pStr)
        item.sAnswerer_fullname = pStr;
	if (strlen(item.sAnswerer_fullname.c_str()) <= 0)
        item.sAnswerer_fullname = item.sAnswerer_username;

	pStr = pItem->Attribute("answerer_icon");
	if (pStr)
        item.sAnswerer_icon = pStr;

	pStr = pItem->Attribute("pubdate");
	if (pStr)
        item.sPubdate = pStr;

	pItem->QueryIntAttribute("answerflag", &item.nAnswerflag);

	pItem->QueryIntAttribute("pv", &item.nPV);

	pItem->QueryIntAttribute("isliked", &item.nIsliked);

	//int tmp=0;
//	pItem->QueryIntAttribute("isliked",&  tmp);
	// item.bIsliked=tmp;
	TiXmlElement *pChildItem = pItem->FirstChildElement("pic");
	if (pChildItem) {
		pStr = pChildItem->Attribute("url");
        item.sPic_url = pStr;
        pStr=NULL;
        
        pStr = pChildItem->Attribute("thumburl");
        item.sThumburl = pStr;
        
	}

	if (item.nAnswerflag != 0) {
		m_hasFlagAnswerItem = item;
		ret = FALSE;
	} else
		ret = TRUE;

	if (!db)
		return FALSE;

	if (strlen(m_tablename) == 0)
		return FALSE;

	CHAR sql[2048];

	sqlite3_stmt *stmt;

	snprintf(sql,sizeof(sql),"INSERT INTO %s(id,answer,answer_username,answer_fullname,answer_icon,pubdate,answerflag,pv,questionid,isliked,pic_url,thumburl) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",
			m_tablename);

	if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
		BindParam(stmt, 1, item.sID.c_str());
		BindParam(stmt, 2, item.sAnswer.c_str());
		BindParam(stmt, 3, item.sAnswerer_username.c_str());
		BindParam(stmt, 4, item.sAnswerer_fullname.c_str());
		BindParam(stmt, 5, item.sAnswerer_icon.c_str());
		BindParam(stmt, 6, item.sPubdate.c_str());
		BindParam(stmt, 7, item.nAnswerflag);
		BindParam(stmt, 8, item.nPV);
		BindParam(stmt, 9, sQuestionID);
		BindParam(stmt, 10, item.nIsliked);
		BindParam(stmt, 11, item.sPic_url.c_str());
        BindParam(stmt, 12, item.sThumburl.c_str());


		if (sqlite3_step(stmt) == SQLITE_DONE) {
//            if(ret==TRUE)
//                ret = TRUE;
		} else {
			CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
		}

		sqlite3_finalize(stmt);
	} else {
		CM_ERRP("exec %s failed.error:%s", sql, sqlite3_errmsg(db));
	}

	return ret;

}