PageRenderTime 26ms CodeModel.GetById 8ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/TGame/TUtil/Config/ConfigLoaderSqlite.cpp

http://awoe.googlecode.com/
C++ | 86 lines | 76 code | 7 blank | 3 comment | 9 complexity | 206a7c3141407a40ddda3dbbfd53006b MD5 | raw file
 1#include "stdafx.h"
 2#include "ConfigLoaderSqlite.h"
 3#include "SQLite\DB_SQLite.h"
 4#include "Log\Log.h"
 5
 6namespace woe
 7{
 8	ConfigLoaderSqlite::ConfigLoaderSqlite()
 9		:m_pSQLiteBase( NULL )
10	{
11
12	}
13
14	ConfigLoaderSqlite::~ConfigLoaderSqlite()
15	{
16		if ( m_pSQLiteBase )
17		{
18			m_pSQLiteBase->Close();
19			delete m_pSQLiteBase;
20			m_pSQLiteBase = NULL;
21		}
22	}
23
24	bool ConfigLoaderSqlite::DoLoad(const std::string& strDBName,  IConfigOperator* config)
25	{	
26		if ( !config )
27		{
28			LOG_DEBUG("Failed to , ConfigLoaderSqlite::DoLoad, the param config is NULL\n");
29			return false;
30		}
31		if ( m_pSQLiteBase )
32		{
33			m_pSQLiteBase->Close();
34			delete m_pSQLiteBase;
35			m_pSQLiteBase = NULL;
36		}
37		m_pSQLiteBase = new CSQLiteBase;
38		if ( !m_pSQLiteBase )
39		{
40			LOG_DEBUG("Failed to , ConfigLoaderSqlite::DoLoad, new CSQLiteBase failed\n");
41			delete m_pSQLiteBase;
42			m_pSQLiteBase = NULL;
43			return false;
44		}
45
46		if ( !m_pSQLiteBase->Open( strDBName.c_str() ) )
47		{
48			LOG_DEBUG_V("Failed to Open db %s ,ConfigLoaderSqlite::DoLoad\n",strDBName.c_str());
49			delete m_pSQLiteBase;
50			m_pSQLiteBase = NULL;
51			return false;	
52		}
53		CppSQLite3DB* db = m_pSQLiteBase->GetDB();
54		if ( NULL == db )
55		{
56			LOG_DEBUG("Failed to Get DB ,ConfigLoaderSqlite::DoLoad\n");
57			delete m_pSQLiteBase;
58			m_pSQLiteBase = NULL;
59			return false;
60		}
61
62		char szSQL[128] = "select name from sqlite_master where type = 'table' order by name";
63		CppSQLite3Query query = db->execQuery(szSQL);
64
65		while ( !query.eof() )
66		{
67			const char* szTblName = query.fieldValue(0);
68			strcpy( szSQL, "select * from " );
69			strcat_s( szSQL, szTblName );
70			CppSQLite3Query query1 = db->execQuery(szSQL);
71			while ( !query1.eof() )
72			{
73				//const char* sz1 = query1.fieldValue(0);
74				//const char* sz2 = query1.fieldValue(1);
75				CString strRet1, strRet2;
76				m_pSQLiteBase->Transcode( query1.fieldValue( 0 ), strRet1 );
77				m_pSQLiteBase->Transcode( query1.fieldValue( 1 ), strRet2 );
78				//config->Set( sz1, sz2 );
79				config->Set( strRet1.GetString(), strRet2.GetString() );
80				query1.nextRow();
81			}
82			query.nextRow();	
83		}
84		return true;
85	}
86}