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