1
0

CDBHelper.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "CDBHelper.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. namespace YADB
  5. {
  6. CDBHelper::CDBHelper()
  7. {
  8. }
  9. CDBHelper::~CDBHelper()
  10. {
  11. }
  12. void CDBHelper::String2DateTime( const char* szString, MYSQL_TIME & value )
  13. {
  14. sscanf( szString, "%d-%d-%d %d:%d:%d", &value.year, &value.month, &value.day, &value.hour, &value.minute, &value.second );
  15. value.second_part = 0;//microseconds
  16. value.neg = false;
  17. value.time_type = MYSQL_TIMESTAMP_DATE;
  18. }
  19. void CDBHelper::DateTime2String( const MYSQL_TIME & value, char * szString, int Length )
  20. {
  21. char szTemp[20] = { 0 };
  22. sprintf( szTemp, "%d-%d-%d %02d:%02d:%02d", \
  23. value.year, value.month, value.day, value.hour, value.minute, value.second );
  24. strncpy( szString, szTemp, Length );
  25. }
  26. void CDBHelper::InitMySQLTime( MYSQL_TIME & value )
  27. {
  28. value.year = 0;
  29. value.month = 0;
  30. value.day = 0;
  31. value.hour = 0;
  32. value.minute = 0;
  33. value.second = 0;
  34. value.neg = false;
  35. value.second_part = 0;
  36. value.time_type = MYSQL_TIMESTAMP_DATETIME;
  37. }
  38. }