-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTableCompareABC.h
88 lines (64 loc) · 2.42 KB
/
TableCompareABC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*----------------------------------------------------------------------
Copyright (c) Dan Petitt, http://www.coderanger.com
All Rights Reserved.
Please see the file "licence.txt" for licencing details.
File: TableCompareABC.h
Owner: [email protected]
Purpose: Abstract class for database syncronisation.
Override OnProcessTable to perform different algorithms for
generating differences SQL scripts
----------------------------------------------------------------------*/
#pragma once
class CTableCompareABC
{
public:
CTableCompareABC(void);
~CTableCompareABC(void);
void SetSourceDatabase( LPCTSTR pcszHost, LPCTSTR pcszUser, LPCTSTR pcszPassword, LPCTSTR pcszDatabase, UINT uPort = 3306 );
void SetTargetDatabase( LPCTSTR pcszHost, LPCTSTR pcszUser, LPCTSTR pcszPassword, LPCTSTR pcszDatabase, UINT uPort = 3306 );
void Start( LPCTSTR pcszExportFilePath, bool bDisplayProgress, bool bUseBulkInserts = true );
struct Field
{
Field() : bIsNull( false ), uType( 0 ), bIsPrimaryKey( false ), bIsUniqueKey( false ), bIsDifferent( true ) {};
std::string strName;
std::string strValue;
bool bIsNull;
DWORD uType;
bool bIsPrimaryKey, bIsUniqueKey;
bool bIsDifferent;
};
struct Record
{
std::string strHash;
std::vector< Field > arrFields;
};
protected:
virtual void OnProcessTable( const XMySQL::CConnection::Table &tbl ) = 0;
bool FieldIsQuoted( UINT uFieldType ); // Returns true if field values should be surrounded by quotes and escaped where necessary (i.e. strings, dates etc)
XMySQL::CConnection m_mySource;
XMySQL::CConnection m_myTarget;
FILE *m_pFile;
bool m_bDisplayProgress;
bool m_bUseBulkInserts;
UINT m_uTotalIdentical;
UINT m_uTotalDifferent;
UINT m_uTotalInserted;
UINT m_uTotalDeleted;
UINT m_uRecordsIdentical;
UINT m_uRecordsDifferent;
UINT m_uRecordsInserted;
UINT m_uRecordsDeleted;
std::vector< std::string > m_arrInsert, m_arrDelete, m_arrUpdate;
private:
void ProcessTable( const XMySQL::CConnection::Table &tbl );
UINT GetIdenticalCount() const { return m_uRecordsIdentical; }
UINT GetDifferentCount() const { return m_uRecordsDifferent; }
UINT GetDeletedCount() const { return m_uRecordsDeleted; }
UINT GetInsertedCount() const { return m_uRecordsInserted; }
void WriteOutStatements( const std::vector< std::string > &arr );
private:
time_t m_tStart;
private:
CTableCompareABC( const CTableCompareABC & );
CTableCompareABC & operator = ( const CTableCompareABC & );
};