コード例 #1
0
ファイル: CP_Main.cpp プロジェクト: arefinsaaad/kupl09
BOOL CCP_MainApp::GetClipData(long lID, CClipFormat &Clip)
{
	BOOL bRet = FALSE;

	try
	{
		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT ooData FROM Data WHERE lParentID = %d AND strClipboardFormat = '%s'"), lID, GetFormatName(Clip.m_cfType));
		if(q.eof() == false)
		{
			int nDataLen = 0;
			const unsigned char *cData = q.getBlobField(_T("ooData"), nDataLen);
			if(cData != NULL)
			{
				Clip.m_hgData = NewGlobal(nDataLen);

				::CopyToGlobalHP(Clip.m_hgData, (LPVOID)cData, nDataLen);

				bRet = TRUE;
			}
		}
	}
	CATCH_SQLITE_EXCEPTION

	return bRet;
}
コード例 #2
0
bool CThumbIndex::AbstractFromGUID(const CString& guid, WIZABSTRACT &abstract,const CString& type)
{
    if(!m_dbThumb.IsOpened())
        return false;

    CString sql = CString("select ") + FIELD_LIST_ABSTRACT + " from " + TABLE_NAME_ABSTRACT +" where ABSTRACT_GUID='"
                    + guid + ("' AND ABSTRACT_TYPE=")
                    + STR2SQL(type)
                    + (";");
    try
    {
        CppSQLite3Query query = m_dbThumb.execQuery(sql);

        while (!query.eof())
        {
            abstract.guid = query.getStringField(0);
            abstract.text = query.getStringField(2);
            int length;
            const unsigned char * imageData = query.getBlobField(3, length);
            if (imageData && length)
            {
                abstract.image.loadFromData(imageData, length);
            }
            return true;
        }
		return false;
	}
	catch (const CppSQLite3Exception& e)
	{
		TOLOG(e.errorMessage());
        TOLOG(sql);
		return false;
	}
	catch (...) {
		TOLOG("Unknown exception while close DB");
		return false;
	}
}
コード例 #3
0
/** Message 조회
 *
 * @param szId target device id
 * @param nMessageType 0 이라면 Message 전체
 * @param pWrapper 응답을 전해 줄 IF4Wrapper
 */
BOOL CMessageHelper::Select(const char *szId, BYTE nMessageType, IF4Wrapper *pWrapper)
{
    if(!CheckDB()) return FALSE;

    CppSQLite3Query result;
    char timeString[32];
    TIMESTAMP issueTime;
    unsigned char * pPayload;
    int idx=0, nPayloadLen;
    int year, mon, day, hour, min, sec;

    if(pWrapper == NULL) return FALSE;

    if(!Open()) return FALSE;
    try
    {
        CppSQLite3Statement stmt;
        
        if (nMessageType > 0) {
            stmt = m_SqliteHelper.compileStatement(
                "SELECT "
                "messageId, issueTime, userData, payload, "
                "duration, errorHandler, preHandler, postHandler "
                "FROM MessageTbl "
                "WHERE targetId = ? and messageType = ? ; ");

            stmt.bind(1, szId);
            stmt.bind(2, nMessageType);
        } else {
            stmt = m_SqliteHelper.compileStatement(
                "SELECT "
                "messageId, issueTime, userData, payload, "
                "duration, errorHandler, preHandler, postHandler "
                "FROM MessageTbl "
                "WHERE targetId = ? ; ");

            stmt.bind(1, szId);
        }

        result = stmt.execQuery();
        while(!result.eof())
        {
            memset(timeString, 0, sizeof(timeString));
            memset(&issueTime, 0, sizeof(TIMESTAMP));
            pPayload = NULL; nPayloadLen = 0; idx = 0;

            IF4API_AddResultNumber(pWrapper, "1.6", VARSMI_UINT, result.getIntField(idx));  idx++;
            strcat(timeString, result.getStringField(idx));                                 idx++;
            sscanf(timeString,"%04d-%02d-%02d %02d:%02d:%02d",
                    &year, &mon, &day, &hour, &min, &sec);
            issueTime.year = year; issueTime.mon = mon;
            issueTime.day = day; issueTime.hour = hour;
            issueTime.min = min; issueTime.sec = sec;
            /*
            XDEBUG(" %04d/%02d/%02d %02d:%02d:%02d\r\n",
                    issueTime.year, issueTime.mon, issueTime.day, issueTime.hour, issueTime.min, issueTime.sec);
                    */
	        IF4API_AddResultFormat(pWrapper, "1.16", VARSMI_TIMESTAMP, &issueTime, sizeof(TIMESTAMP));
            IF4API_AddResultNumber(pWrapper, "1.6", VARSMI_UINT, result.getIntField(idx));  idx++;
            pPayload = const_cast<unsigned char *>(result.getBlobField(idx, nPayloadLen));  idx++;
	        IF4API_AddResultFormat(pWrapper, "1.12", VARSMI_STREAM, pPayload, nPayloadLen);

            result.nextRow();
        }
        stmt.finalize();
        Close();
    }
	catch ( CppSQLite3Exception& e )
	{
        Close();
		XDEBUG(ANSI_COLOR_RED "MessageTbl DB ERROR SELECT: %d %s\r\n" ANSI_NORMAL, e.errorCode(), e.errorMessage());
        return FALSE;
	}
    return TRUE;
}
コード例 #4
0
ファイル: PersistencManager.cpp プロジェクト: trimpsyw/crack
//必须在task 加载之后
int CPersistencManager::LoadBlockMap(CB_MAP &block_map,CT_MAP &task_map){
	
	if(m_useLevelDB)
	{
		for(CT_MAP::iterator it = task_map.begin(); it != task_map.end(); it++)
		{
			const char* guid = it->first.c_str();
			CCrackTask* pCT = it->second;
			leveldb::ReadOptions ro;
			leveldb::Status s;
			string value;
			int actual_num = 0;
			//连在一起申请,不然在deleteTask函数释放时会出错
			CCrackBlock* pCBs = new (std::nothrow)CCrackBlock[pCT->m_split_num];
			if (!pCBs){
				CLog::Log(LOG_LEVEL_ERROR, "Alloc object %d CCrackBlock Error\n", pCT->m_split_num);
				return -2;
			}

			for(int i = 0; i < pCT->m_split_num; i++)
			{
				s = m_LevelDB->Get(ro, BLOCK_IDX(guid, i), &value);
				if(!s.ok()) continue;

				s = m_LevelDB->Get(ro, value, &value);
				if(!s.ok()) continue;

				actual_num ++;
				CCrackBlock* item = (CCrackBlock*) value.data();
				CCrackBlock *pCB = pCBs + i;
				*pCB = *item;
				pCB->task = pCT;
	
				pCT->m_crackblock_map.insert(CB_MAP::value_type(pCB->guid,pCB));
				block_map.insert(CB_MAP::value_type(pCB->guid, pCB));
			}

			pCT->m_split_num = actual_num;
		}

		return 0;
	}
	
	int ret = 0;

	CT_MAP::iterator cur_iter ;
	CT_MAP::iterator end_iter  = task_map.end();
	CCrackTask *pCT = NULL;

	for(cur_iter = task_map.begin(); cur_iter != end_iter; cur_iter++)
	{
		const char* guid = cur_iter->first.c_str();
		pCT = cur_iter->second;
		
		//连在一起申请,不然在deleteTask函数释放时会出错
		CCrackBlock* pCBs = new (std::nothrow)CCrackBlock[pCT->m_split_num];
		if (!pCBs){
			CLog::Log(LOG_LEVEL_ERROR, "Alloc object %d CCrackBlock Error\n", pCT->m_split_num);
			return -2;
		}

		char cmd[1024];
		_snprintf(cmd, sizeof(cmd), "select * from Block where taskid='%s'", guid);
		CppSQLite3Query query = m_SQLite3DB.execQuery(cmd);
		int idx = 0;
		while (!query.eof())
		{
			CCrackBlock *pCB = pCBs + idx;
			idx ++;

			memset(pCB->john,0,sizeof(pCB->john));
			memset(pCB->m_comp_guid,0,sizeof(pCB->m_comp_guid));
			memset(pCB->guid,0,sizeof(pCB->guid));
		
			memcpy(pCB->m_comp_guid,query.fieldValue("compip"),strlen(query.fieldValue("compip")));
			memcpy(pCB->guid,query.fieldValue("blockid"),strlen(query.fieldValue("blockid")));
					
			pCB->algo = pCT->algo;
			pCB->charset = pCT->charset;
			pCB->type = query.getIntField("type");
			int len;
			const unsigned char* info = query.getBlobField("info", len);
			memcpy(&(pCB->start), info, len);

			int tmpIndex = query.getIntField("index0");
			pCB->hash_idx = tmpIndex;
			memcpy(pCB->john,pCT->m_crackhash_list[pCB->hash_idx]->m_john,sizeof(pCT->m_crackhash_list[pCB->hash_idx]->m_john));

			pCB->special = pCT->special;
			pCB->task = pCT;
			pCB->m_progress = query.getFloatField("progress");
			pCB->m_speed = query.getFloatField("speed");

			pCB->m_status = query.getIntField("status");
			pCB->m_remaintime = query.getIntField("remaintime");

			
			cur_iter->second->m_crackblock_map.insert(CB_MAP::value_type(pCB->guid,pCB));		
					
			block_map.insert(CB_MAP::value_type(pCB->guid,pCB));
		       
			query.nextRow();
		}
	}

	return ret;
}
コード例 #5
0
ファイル: PersistencManager.cpp プロジェクト: trimpsyw/crack
int CPersistencManager::LoadTaskMap(CT_MAP &task_map){

	if(m_useLevelDB)
	{
		string value;
		vector<string> allguids;
		leveldb::ReadOptions ro;
		leveldb::Status s;
		int task_count = 0;

		s = m_LevelDB->Get(ro, TASK_COUNT, &value);
		if(s.ok())
			task_count = *(int*)value.data();
		CLog::Log(LOG_LEVEL_DEBUG, "LoadTaskMap: count=%d\n", task_count);

		for(int i = 1; i <= task_count; i++)
		{
			s = m_LevelDB->Get(ro, TASK_IDX(TASK_KEY, i), &value);
			if(s.ok())
			{
				allguids.push_back(value);
			}
		}

		for(int i = 0; i < allguids.size(); i++)
		{
			s = m_LevelDB->Get(ro, allguids[i], &value);
			if(!s.ok()) continue;

			//CCrackTask类里面有类,不能直接拷贝构造函数将内存按字节拷贝,咳!
			CCrackTask* task = (CCrackTask*)value.data();
			CCrackTask* pCT = new CCrackTask();

#ifndef USE_PLACEMANT_NEW
			memcpy(pCT, (crack_task*)task, sizeof(crack_task));
			memcpy(pCT->m_owner, task->m_owner, sizeof(task->m_owner));
			int len = (char*)&task->m_filelen - (char*)&task->m_status + sizeof(task->m_filelen);
			memcpy(&pCT->m_status, &task->m_status, len);
#else
			memcpy(pCT, task, sizeof(CCrackTask));
			//调用placement new对类成员进行初始化
			new (&pCT->m_crackblock_map) CB_MAP();
			new (&pCT->cur_crack_block) CB_MAP::iterator();
			new (&pCT->m_crackhash_list) CRACK_HASH_LIST();
#endif

			task_map.insert(CT_MAP::value_type(pCT->guid,pCT));
		}

		return 0;
	}

	int ret = 0;
	
	CppSQLite3Query query = m_SQLite3DB.execQuery("select * from Task order by 1;");

    while (!query.eof())
    {
        CCrackTask *pCT = new CCrackTask();
		if (!pCT){

			CLog::Log(LOG_LEVEL_ERROR,"Alloc object CCrackTask Error\n");
			return -1;
		}

		memset(pCT->guid,0,sizeof(pCT->guid));
		memcpy(pCT->guid,query.fieldValue("taskid"),strlen(query.fieldValue("taskid")));


		pCT->algo = query.getIntField("algo");
		pCT->charset = query.getIntField("charset");
		pCT->type = query.getIntField("type");
		pCT->special = query.getIntField("filetag");
		pCT->single = query.getIntField("single");
		int len;
		const unsigned char* info = query.getBlobField("info", len);
		memcpy(&(pCT->startLength), info, len);
		memset(pCT->m_owner,0,sizeof(pCT->m_owner));
		memcpy(pCT->m_owner,query.fieldValue("owner"),strlen(query.fieldValue("owner")));

		pCT->m_status = query.getIntField("status");
		pCT->m_split_num = query.getIntField("splitnum");
		pCT->m_finish_num = query.getIntField("finishnum");
		pCT->m_bsuccess = (strcmp(query.fieldValue("success"),"1") == 0)? true : false;
		pCT->m_progress = query.getFloatField("progress");

		pCT->m_speed = query.getFloatField("speed");
		pCT->m_start_time = query.getIntField("starttime");
		pCT->m_running_time = query.getIntField("runtime");
		pCT->m_remain_time = query.getIntField("remaintime");

		pCT->count = query.getIntField("count");

		if(pCT->type == bruteforce)
			CLog::Log(LOG_LEVEL_NOMAL, "[%d %d] %d\n", pCT->startLength, pCT->endLength, pCT->count);
		else if(pCT->type == dict)
			CLog::Log(LOG_LEVEL_NOMAL, "[dict=%d] %d\n", pCT->dict_idx, pCT->count);
		else if(pCT->type == mask)
			CLog::Log(LOG_LEVEL_NOMAL, "[mask=%s] %d\n", pCT->masks, pCT->count);
		
		task_map.insert(CT_MAP::value_type(pCT->guid,pCT));

        query.nextRow();
    }

	return ret;
}
コード例 #6
0
ファイル: CppSQLite3DemoExt.cpp プロジェクト: Omgan/CppSQLite
int main(int argc, char** argv)
{
    try
    {
		int row;
        CppSQLite3DB db;

        cout << "SQLite Header Version: " << CppSQLite3DB::SQLiteHeaderVersion() << endl;
        cout << "SQLite Library Version: " << CppSQLite3DB::SQLiteLibraryVersion() << endl;
        cout << "SQLite Library Version Number: " << CppSQLite3DB::SQLiteLibraryVersionNumber() << endl;

        remove(gszFile);
        db.open(gszFile);

        ////////////////////////////////////////////////////////////////////////////////
        // Demonstrate getStringField(), getIntField(), getFloatField()
        ////////////////////////////////////////////////////////////////////////////////
        db.execDML("create table parts(no int, name char(20), qty int, cost number);");
        db.execDML("insert into parts values(1, 'part1', 100, 1.11);");
        db.execDML("insert into parts values(2, null, 200, 2.22);");
        db.execDML("insert into parts values(3, 'part3', null, 3.33);");
        db.execDML("insert into parts values(4, 'part4', 400, null);");

        cout << endl << "CppSQLite3Query getStringField(), getIntField(), getFloatField() tests" << endl;
        CppSQLite3Query q = db.execQuery("select * from parts;");
        while (!q.eof())
        {
            cout << q.getIntField(0) << "|";
            cout << q.getStringField(1) << "|";
            cout << q.getInt64Field(2) << "|";
            cout << q.getFloatField(3) << "|" << endl;
            q.nextRow();
        }

        cout << endl << "specify NULL values tests" << endl;
        q = db.execQuery("select * from parts;");
        while (!q.eof())
        {
            cout << q.getIntField(0) << "|";
            cout << q.getStringField(1, "NULL") << "|";
            cout << q.getIntField(2, -1) << "|";
            cout << q.getFloatField(3, -3.33) << "|" << endl;
            q.nextRow();
        }

        cout << endl << "Specify fields by name" << endl;
        q = db.execQuery("select * from parts;");
        while (!q.eof())
        {
            cout << q.getIntField("no") << "|";
            cout << q.getStringField("name") << "|";
            cout << q.getInt64Field("qty") << "|";
            cout << q.getFloatField("cost") << "|" << endl;
            q.nextRow();
        }

        cout << endl << "specify NULL values tests" << endl;
        q = db.execQuery("select * from parts;");
        while (!q.eof())
        {
            cout << q.getIntField("no") << "|";
            cout << q.getStringField("name", "NULL") << "|";
            cout << q.getIntField("qty", -1) << "|";
            cout << q.getFloatField("cost", -3.33) << "|" << endl;
            q.nextRow();
        }
		q.finalize();

		////////////////////////////////////////////////////////////////////////////////
        // Demonstrate getStringField(), getIntField(), getFloatField()
		// But this time on CppSQLite3Table
        ////////////////////////////////////////////////////////////////////////////////
        cout << endl << "CppSQLite3Table getStringField(), getIntField(), getFloatField() tests" << endl;
        CppSQLite3Table t = db.getTable("select * from parts;");
        for (row = 0; row < t.numRows(); row++)
        {
            t.setRow(row);
            cout << t.getIntField(0) << "|";
            cout << t.getStringField(1) << "|";
            cout << t.getIntField(2) << "|";
            cout << t.getFloatField(3) << "|" << endl;
        }

        cout << endl << "specify NULL values tests" << endl;
        for (row = 0; row < t.numRows(); row++)
        {
            t.setRow(row);
            cout << t.getIntField(0, -1) << "|";
            cout << t.getStringField(1, "NULL") << "|";
            cout << t.getIntField(2, -1) << "|";
            cout << t.getFloatField(3, -3.33) << "|" << endl;
        }

        cout << endl << "Specify fields by name" << endl;
        for (row = 0; row < t.numRows(); row++)
        {
            t.setRow(row);
            cout << t.getIntField("no") << "|";
            cout << t.getStringField("name") << "|";
            cout << t.getIntField("qty") << "|";
            cout << t.getFloatField("cost") << "|" << endl;
        }

        cout << endl << "specify NULL values tests" << endl;
        for (row = 0; row < t.numRows(); row++)
        {
            t.setRow(row);
            cout << t.getIntField("no") << "|";
            cout << t.getStringField("name", "NULL") << "|";
            cout << t.getIntField("qty", -1) << "|";
            cout << t.getFloatField("cost", -3.33) << "|" << endl;
        }


		////////////////////////////////////////////////////////////////////////////////
		// Demonstrate multi-statement DML
		// Note that number of rows affected is only from the last statement
		// when multiple statements are used
		////////////////////////////////////////////////////////////////////////////////
        cout << endl << "Multi-Statement execDML()" << endl;
		const char* szDML = "insert into parts values(5, 'part5', 500, 5.55);"
							"insert into parts values(6, 'part6', 600, 6.66);"
							"insert into parts values(7, 'part7', 700, 7.77);";
		int nRows = db.execDML(szDML);
		cout << endl << nRows << " rows affected" << endl;
        cout << db.execScalar("select count(*) from parts;") << " rows in parts table" << endl;
		            szDML = "delete from parts where no = 2;"
							"delete from parts where no = 3;";
		nRows = db.execDML(szDML);
        cout << endl << nRows << " rows affected" << endl;
        cout << db.execScalar("select count(*) from parts;") << " rows in parts table" << endl;


		////////////////////////////////////////////////////////////////////////////////
		// Demonstrate new typing system & BLOBS
		// ANy data can be stored in any column
		////////////////////////////////////////////////////////////////////////////////
        cout << endl << "Data types and BLOBs()" << endl;
        db.execDML("create table types(no int, "
				"name char(20), qty float, dat blob);");
        db.execDML("insert into types values(null, null, null, null);");
        db.execDML("insert into types values(1, 2, 3, 4);");
        db.execDML("insert into types values(1.1, 2.2, 3.3, 4.4);");
        db.execDML("insert into types values('a', 'b', 'c', 'd');");

        CppSQLite3Statement stmt = db.compileStatement("insert into types values(?,?,?,?);");
        unsigned char buf[256];
		memset(buf, 1, 1); stmt.bind(1, buf, 1);
		memset(buf, 2, 2); stmt.bind(2, buf, 2);
		memset(buf, 3, 3); stmt.bind(3, buf, 3);
		memset(buf, 4, 4); stmt.bind(4, buf, 4);
		stmt.execDML();
        cout << db.execScalar("select count(*) from types;") << " rows in types table" << endl;

        q = db.execQuery("select * from types;");
        while (!q.eof())
        {
			for (int i = 0; i < q.numFields(); i++)
			{
				switch (q.fieldDataType(i))
				{
				case SQLITE_INTEGER  : cout << "SQLITE_INTEGER|"; break;
				case SQLITE_FLOAT    : cout << "SQLITE_FLOAT  |"; break;
				case SQLITE_TEXT     : cout << "SQLITE_TEXT   |"; break;
				case SQLITE_BLOB     : cout << "SQLITE_BLOB   |"; break;
				case SQLITE_NULL     : cout << "SQLITE_NULL   |"; break;
				default: cout << "***UNKNOWN TYPE***"; break;
				}
			}
            q.nextRow();
			cout << endl;
        }

        nRows = db.execDML("delete from types where no = 1 or no = 1.1 or no = 'a' or no is null;");
		cout << endl << nRows << " rows deleted, leaving binary row only" << endl;

        q = db.execQuery("select * from types;");
		const unsigned char* pBlob;
		int nLen;
		pBlob = q.getBlobField(0, nLen);
		cout << "Field 1 BLOB length: " << nLen << endl;
		pBlob = q.getBlobField(1, nLen);
		cout << "Field 2 BLOB length: " << nLen << endl;
		pBlob = q.getBlobField(2, nLen);
		cout << "Field 3 BLOB length: " << nLen << endl;
		pBlob = q.getBlobField(3, nLen);
		cout << "Field 4 BLOB length: " << nLen << endl;

		q.finalize();

        nRows = db.execDML("delete from types;");
		cout << endl << nRows << " rows deleted, leaving empty table" << endl;
        unsigned char bin[256];

        for (int i = 0; i < sizeof bin; i++)
        {
            bin[i] = i;
        }

        stmt = db.compileStatement("insert into types values(?,0,0,0);");
		stmt.bind(1, bin, sizeof bin);
		stmt.execDML();

        cout << "Stored binary Length: " << sizeof bin << endl;

        q = db.execQuery("select * from types;");

		pBlob = q.getBlobField(0, nLen);
		cout << "Field 1 BLOB length: " << nLen << endl;

        for (i = 0; i < sizeof bin; i++)
        {
            if (pBlob[i] != i)
            {
				cout << "Problem: i: ," << i << " BLOB[i]: " << pBlob[i] << endl;
            }
        }
	}
    catch (CppSQLite3Exception& e)
    {
        cerr << e.errorCode() << ":" << e.errorMessage() << endl;
    }

	////////////////////////////////////////////////////////////////////////////////
    // Loop until user enters q or Q
    ////////////////////////////////////////////////////////////////////////////////
    char c(' ');

    while (c != 'q' && c != 'Q')
    {
        cout << "Press q then enter to quit: ";
        cin >> c;
    }
    return 0;
}
コード例 #7
0
BOOL Maxthon3PlugIn::ExportFavoriteData( PFAVORITELINEDATA pData, int32& nDataNum )
{
	CCRCHash ojbCrcHash;

	if (pData == NULL || nDataNum == 0)
	{
		return FALSE;
	}

	if (m_pMemFavoriteDB != NULL)
	{
		CppSQLite3DB  m_SqliteDatabase;

		m_SqliteDatabase.openmem(m_pMemFavoriteDB, "");
		CppSQLite3Query Query = m_SqliteDatabase.execQuery("select * from MyFavNodes where parent_id <> ''");
		int i = 0;
		unsigned char szParentNode[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		unsigned char szRecycle[16] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		unsigned char szGroup[16] = {2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		unsigned char szStartPageFav[16] = {3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

		while(!Query.eof() && i < nDataNum)
		{
			const unsigned char *pTemp = NULL;
			int nBlobLen = 0;
			pTemp = Query.getBlobField("parent_id", nBlobLen);

			if (memcmp(pTemp, szParentNode, 16) == 0)
			{
				pData[i].nPid = 0;
			}
			else if(memcmp(pTemp, szRecycle, 16) == 0)
			{
				int i = 0;
			}
			else if(memcmp(pTemp, szGroup, 16) == 0)
			{
				int j = 0;
			}
			else if(memcmp(pTemp, szStartPageFav, 16) == 0)
			{
				pData[i].nPid = 0;
				int m = 0;
			}
			else
			{
				ojbCrcHash.GetHash((BYTE *)pTemp, nBlobLen, (BYTE *)&pData[i].nPid, sizeof(uint32));
			}
			

			pTemp = Query.getBlobField("id", nBlobLen);

			if (pTemp == NULL)
			{
				continue;
			}

			ojbCrcHash.GetHash((BYTE *)pTemp, nBlobLen, (BYTE *)&pData[i].nId, sizeof(uint32));

			pTemp = Query.getBlobField("title", nBlobLen);

			if (nBlobLen != 0)
			{
				memcpy(pData[i].szTitle, pTemp, nBlobLen);

				ojbCrcHash.GetHash((BYTE *)pData[i].szTitle, wcslen(pData[i].szTitle) * sizeof(wchar_t), (BYTE *)&pData[i].nHashId, sizeof(uint32));
			}
			else
			{
				pData[i].szTitle[0] = 0;
			}

			pTemp = Query.getBlobField("url", nBlobLen);

			if (nBlobLen != 0)
			{
				memcpy(pData[i].szUrl, pTemp, nBlobLen);
			}
			else
			{
				pData[i].szUrl[0] = 0;
			}

			pData[i].bFolder = Query.getIntField("type", 1) == IT_FOLDER ? true : false;

			pData[i].nAddTimes = Query.getIntField("add_date", 0);
			pData[i].nClickTimes = Query.getIntField("visit_count", 0);
			pData[i].nLastModifyTime = Query.getIntField("last_modified", 0);
			pData[i].bDelete = false;
			pData[i].nOrder = Query.getIntField("norder", 0);

			Query.nextRow();
			i++;
		}

		nDataNum = i;

		for (int i = 0; i < nDataNum; i++)
		{
			//如果该结点的nId不是数组下标+1,则需要修正
			if ((pData[i].nId != i + 1 + ID_VALUE_MAXTHON2_BEGIN))
			{
				//扫描所有以该结点为父结点的结点,并修正这些结点的nPid
				for (int j = 0; j < nDataNum; j++)
				{
					if (pData[j].nPid == pData[i].nId)
					{
						pData[j].nPid = i + 1 + ID_VALUE_MAXTHON2_BEGIN;
					}
				}

				pData[i].nId = i + 1 + ID_VALUE_MAXTHON2_BEGIN;
			}
		}

		return TRUE;
	}

	return FALSE;
}
コード例 #8
0
//##ModelId=474D307602FF
bool CClip_ImportExport::ImportFromSqliteV1(CppSQLite3DB &db, CppSQLite3Query &qMain)
{
	try
	{
		//Load the Main Table
		m_Desc = qMain.getStringField(_T("mText"));
		long lID = qMain.getIntField(_T("lID"));

		//Load the data Table
		CClipFormat cf;
		HGLOBAL hGlobal = 0;
		m_Formats.RemoveAll();

		CString csSQL;
		csSQL.Format(
			_T("SELECT Data.* FROM Data ")
			_T("INNER JOIN Main ON Main.lID = Data.lParentID ")
			_T("WHERE Main.lID = %d ORDER BY Data.lID desc"), lID);

		CppSQLite3Query qData = db.execQuery(csSQL);
		while(qData.eof() == false)
		{
			cf.m_cfType = GetFormatID(qData.getStringField(_T("strClipBoardFormat")));
			long lOriginalSize = qData.getIntField(_T("lOriginalSize"));

			int nDataLen = 0;
			const unsigned char *cData = qData.getBlobField(_T("ooData"), nDataLen);
			if(cData != NULL)
			{
				Bytef *pUnZippedData = new Bytef[lOriginalSize];
				if(pUnZippedData)
				{
					//the data in the exported file is compressed so uncompress it now
					int nRet = uncompress(pUnZippedData, (uLongf *)&lOriginalSize, (Bytef *)cData, nDataLen);
					if(nRet == Z_OK)
					{
						cf.m_hgData = NewGlobalP(pUnZippedData, lOriginalSize);
						if(cf.m_hgData)
						{
							m_Formats.Add(cf);
							cf.m_hgData = NULL; //m_format owns m_hgData now
						}
						else
						{
							Log(StrF(_T("Error allocating NewGlobalP size = %d"), lOriginalSize));
							ASSERT(FALSE);
						}
					}
					else
					{
						Log(_T("Error uncompressing data from zlib"));
						ASSERT(FALSE);
					}

					delete []pUnZippedData;
					pUnZippedData = NULL;
				}
				else
				{
					Log(StrF(_T("Error allocating memory to unzip size = %d"), lOriginalSize));
					ASSERT(FALSE);
				}
			}

			qData.nextRow();
		}
	}
	CATCH_SQLITE_EXCEPTION_AND_RETURN(false)

	return m_Formats.GetSize() > 0;
}