DBInterface.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*************************************************************
  2. /* Copyright (C), 2008-2010, StoneU Tech. Co., Ltd.
  3. /* 文件名: DBInterface.h
  4. /* 作者: Jesse
  5. /* 创建日期: 2010-08-02
  6. /* 版本号: V1.0
  7. /* 描述: 实现多种数据库的支持
  8. /* 其它:
  9. /* 主要类模块: CDBInterface
  10. /* 历史修改记录:
  11. 作者 时间 版本 描述
  12. Jesse 10/08/02 1.0 创建这个模块
  13. ***************************************************************/
  14. #include "stdafx.h"
  15. #include "DBInterface.h"
  16. namespace DBInterface
  17. {
  18. CDBInterface* CDBInterface::m_pDBInterface = NULL;
  19. // 静态成员函数,提供全局访问的接口
  20. CDBInterface* CDBInterface::GetInstancePtr()
  21. {
  22. if( NULL == m_pDBInterface )
  23. {
  24. m_pDBInterface = new CDBInterface();
  25. }
  26. return m_pDBInterface;
  27. }
  28. // 释放资源
  29. void CDBInterface::Release()
  30. {
  31. if( m_pDBInterface )
  32. delete m_pDBInterface;
  33. m_pDBInterface = NULL;
  34. }
  35. // 设置数据库类型
  36. void CDBInterface::SetDBType(char *pDBType)
  37. {
  38. strcpy(m_chDBType, pDBType);
  39. }
  40. //得到时间计划
  41. INT CDBInterface::GetDatePlan( int nPlanType, CHAR *pPlanID, unsigned char nBufDate[7][24] )
  42. {//0:星期一 1:星期二 6:星期天
  43. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  44. list<string> list1, list2, list3, list4;
  45. list<string>::iterator it_list1, it_list2, it_list3, it_list4;
  46. sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
  47. "from t_plan_info where planid=\'%s\' and plantype = %d",
  48. pPlanID, nPlanType);
  49. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
  50. if( list1.size() == 0 || list2.size() == 0 || list3.size() == 0 || list4.size() == 0 )
  51. {
  52. return 0;
  53. }
  54. if( nRet != -1 )
  55. {
  56. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  57. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
  58. it_list1++, it_list2++, it_list3++, it_list4++)
  59. {
  60. for( int i = atoi((*it_list3).c_str()); i < atoi((*it_list4).c_str()) + 1; i++ )
  61. {
  62. for( int j = atoi((*it_list1).c_str()); j < atoi((*it_list2).c_str()) + 1; j++ )
  63. {
  64. nBufDate[i][j] = 15;
  65. }
  66. }
  67. }
  68. }
  69. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  70. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
  71. {
  72. list1.erase(it_list1++);
  73. list2.erase(it_list2++);
  74. list3.erase(it_list3++);
  75. list4.erase(it_list4++);
  76. }
  77. return nRet;
  78. }
  79. //得到时间计划
  80. INT CDBInterface::GetDatePlan( int nPlanType, CHAR *pUid, int nVarID, unsigned char nBufDate[7][24] )
  81. {
  82. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  83. list<string> list1, list2, list3, list4;
  84. list<string>::iterator it_list1, it_list2, it_list3, it_list4;
  85. sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
  86. "from t_plan_info where uid=\'%s\' and varid = %d and plantype = %d",
  87. pUid, nVarID, nPlanType);
  88. int nRet = CDBConnection::GetInstancePtr()->GetFieldValueList4(strSQLText, list1, list2, list3, list4);
  89. if( list1.size() == 0 || list2.size() == 0 || list3.size() == 0 || list4.size() == 0 )
  90. {
  91. return 0;
  92. }
  93. if( nRet != -1 )
  94. {
  95. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  96. it_list1 != list1.end() && it_list2 != list2.end() && it_list3 != list3.end() && it_list4 != list4.end();
  97. it_list1++, it_list2++, it_list3++, it_list4++ )
  98. {
  99. for( int i = atoi((*it_list3).c_str()); i < atoi((*it_list4).c_str()) + 1; i++ )
  100. {
  101. for( int j = atoi((*it_list1).c_str()); j < atoi((*it_list2).c_str()) + 1; j++ )
  102. {
  103. nBufDate[i][j] = 15;
  104. }
  105. }
  106. }
  107. }
  108. for( it_list1 = list1.begin(), it_list2 = list2.begin(), it_list3 = list3.begin(), it_list4 = list4.begin();
  109. it_list1 != list1.end(), it_list2 != list2.end(), it_list3 != list3.end(), it_list4 != list4.end(); )
  110. {
  111. list1.erase(it_list1++);
  112. list2.erase(it_list2++);
  113. list3.erase(it_list3++);
  114. list4.erase(it_list4++);
  115. }
  116. return nRet;
  117. }
  118. };