-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathScriptComparerForm.cpp
More file actions
230 lines (207 loc) · 6.75 KB
/
ScriptComparerForm.cpp
File metadata and controls
230 lines (207 loc) · 6.75 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ScriptComparerForm.h"
#include <inifiles.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "dbcClasses"
#pragma link "dbcCustomScriptExtract"
#pragma link "dbcDBComparer"
#pragma link "dbcDBStructure"
#pragma link "dbcIBScriptExtract"
#pragma link "dbcMSSQLScriptExtract"
#pragma link "dbcMySQLScriptExtract"
#pragma link "dbcOracleScriptExtract"
#pragma link "dbcASAScriptExtract"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
UnicodeString __fastcall IniFileName()
{
return ExtractFilePath(ParamStr(0)) + "CompDemo.Ini";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnSelClick(TObject *Sender)
{
if ((Sender == BtnSelM) || (Sender == BtnSelT))
{
OpenDialog1->Filter = "SQL script (*.SQL)|*.sql|SQL script (*.DDL)|*.ddl|All files (*.*)|*.*";
}
if (OpenDialog1->Execute())
{
if (Sender == BtnSelM)
fnScriptM->Text = OpenDialog1->FileName;
if (Sender == BtnSelT)
FnScriptT->Text = OpenDialog1->FileName;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBComparerBeforeExtract(TObject *Sender)
{
switch (GetDbType())
{
case dbInterBase:
DBComparer->ExtractorMaster = IBScriptExtract;
DBComparer->ExtractorTarget = IBScriptExtract;
break;
case dbSybaseASA:
DBComparer->ExtractorMaster = SAWScriptExtract;
DBComparer->ExtractorTarget = SAWScriptExtract;
break;
case dbMySQL:
DBComparer->ExtractorMaster = MySQLScriptExtract;
DBComparer->ExtractorTarget = MySQLScriptExtract;
break;
case dbOracle:
DBComparer->ExtractorMaster = OracleScriptExtract;
DBComparer->ExtractorTarget = OracleScriptExtract;
break;
case dbMSSQL:
DBComparer->ExtractorMaster = MSSQLScriptExtract;
DBComparer->ExtractorTarget = MSSQLScriptExtract;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBComparerBeforeExtractMaster(TObject *Sender)
{
TCustomScriptExtract *extract = dynamic_cast<TCustomScriptExtract *>(DBComparer->ExtractorMaster);
extract->DBStructure = DBStructureMaster;
extract->ScriptFileNames->Text = fnScriptM->Text;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBComparerBeforeExtractTarget(TObject *Sender)
{
TCustomScriptExtract *extract = dynamic_cast<TCustomScriptExtract *>(DBComparer->ExtractorTarget);
extract->DBStructure = DBStructureTarget;
extract->ScriptFileNames->Text = FnScriptT->Text;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBComparerProgressUpdate(TObject *Sender, int Value, int MaxValue)
{
ProgressBar->Max = MaxValue;
ProgressBar->Position = Value;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnExtractClick(TObject *Sender)
{
// extract metadata
Screen->Cursor = crHourGlass;
DBComparer->ExtractDatabases();
MemoLog->SelAttributes->Color = clHotLight;
AddToLog("< Extracting finished... >");
if (DBComparer->MsgManager->IsErr)
{
MemoLog->SelAttributes->Color = clRed;
AddToLog("Errors:");
AddToLog(DBComparer->MsgManager->ErrSummary());
}
MemoLog->SelAttributes->Color = clWindowText;
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnCompareClick(TObject *Sender)
{
Screen->Cursor = crHourGlass;
DBComparer->CompareDatabases();
if (DBComparer->SQLExec)
{
MemoLog->SelAttributes->Color = clHotLight;
AddToLog("< Comparing finished. Loading script... >");
MemoScript->Lines->Clear();
DBComparer->SQLExec->GetScript(MemoScript->Lines);
AddToLog("< Process finished. >");
MemoLog->SelAttributes->Color = clWindowText;
}
Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBComparerLogNextLine(TObject *Sender, UnicodeString LogText)
{
AddToLog(LogText);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DBComparerErrorMessage(TObject *Sender, UnicodeString ErrText)
{
MemoLog->Perform(EM_SCROLLCARET, 0, 0);
MemoLog->SelAttributes->Color = clRed;
AddToLog(ErrText);
MemoLog->SelAttributes->Color = clWindowText;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TIniFile *ini = new TIniFile(IniFileName());
__try
{
fnScriptM->Text = ini->ReadString("Databases", "MasterScript", "");
FnScriptT->Text = ini->ReadString("Databases", "TargetScript", "");
try
{
int dbType = ini->ReadInteger("Databases", "DatabaseType", (int)dbInterBase);
SetDbType((TDatabaseType)dbType);
}
catch (...) {}
}
__finally
{
delete ini;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
TIniFile *ini = new TIniFile(IniFileName());
__try
{
ini->WriteString("Databases", "MasterScript", fnScriptM->Text);
ini->WriteString("Databases", "TargetScript", FnScriptT->Text);
try
{
ini->WriteInteger("Databases", "DatabaseType", (int)GetDbType());
}
catch (...) {}
}
__finally
{
delete ini;
}
}
//---------------------------------------------------------------------------
TDatabaseType __fastcall TForm1::GetDbType()
{
if (rbSAW->Checked)
return dbSybaseASA;
if (rbMy->Checked)
return dbMySQL;
if (rbOra->Checked)
return dbOracle;
if (rbMS->Checked)
return dbMSSQL;
return dbInterBase;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetDbType(TDatabaseType aType)
{
switch (aType)
{
case dbSybaseASA: rbSAW->Checked = true; break;
case dbMySQL: rbMy->Checked = true; break;
case dbOracle: rbOra->Checked = true; break;
case dbMSSQL: rbMS->Checked = true; break;
default: rbIB->Checked = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddToLog(UnicodeString aText)
{
MemoLog->Lines->Add(aText);
MemoLog->Perform(EM_SCROLLCARET, 0, 0);
}
//---------------------------------------------------------------------------