-
Notifications
You must be signed in to change notification settings - Fork 1
/
CopyDatabase.cpp
3824 lines (3116 loc) · 109 KB
/
CopyDatabase.cpp
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (C) 2013 Webyog Inc
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
*/
#include "ExportMultiFormat.h"
#include "FrameWindowHelper.h"
#include "MySQLVersionHelper.h"
#include "ClientMySQLWrapper.h"
#include "Global.h"
#include "CopyDatabase.h"
#include "CommonHelper.h"
#include "SQLMaker.h"
#include "GUIHelper.h"
#include "DBListBuilder.h"
#define COPIED_STOREDPGRMS_MANUALADJUST _(L"One or more stored programs or views were copied.\
\r\nThey may contain SQL-referencing the <source> database name and will need to be adjusted manually.")
extern PGLOBALS pGlobals;
CopyDatabase::CopyDatabase()
{
// Initialize the critical section one time only.
InitializeCriticalSection(&m_cs);
m_dontnotify = wyFalse;
m_newtargetmysql = NULL;
m_targettunnel = NULL;
m_newtargettunnel = NULL;
m_newsrctunnel = NULL;
m_newsrcmysql = NULL;
m_srcprocess = INVALID_HANDLE_VALUE;
m_tgtprocess = INVALID_HANDLE_VALUE;
m_tgtinfo = NULL;
m_srcinfo = NULL;
m_p = new Persist;
m_stop = wyFalse;
m_hcopythread = NULL;
m_copyevent = NULL;
m_copying = wyFalse;
m_is5xobjects = wyFalse;
m_istrg5xobjects = wyFalse;
m_issrc5xobjects = wyFalse;
m_issrceventsupport = wyFalse;
m_istrgeventsupports = wyFalse;
m_bulkinsert = wyFalse;
m_maxallowedsize = 0;
m_isobjecttoexport = wyFalse;
m_isstoredpgrms = wyFalse;
m_ispromtstorepgrmmessage = wyFalse;
m_srcsshpipehandles.m_hreadpipe = INVALID_HANDLE_VALUE;
m_srcsshpipehandles.m_hreadpipe2 = INVALID_HANDLE_VALUE;
m_srcsshpipehandles.m_hwritepipe = INVALID_HANDLE_VALUE;
m_srcsshpipehandles.m_hwritepipe2 = INVALID_HANDLE_VALUE;
m_tgtsshpipehandles.m_hreadpipe= INVALID_HANDLE_VALUE;
m_tgtsshpipehandles.m_hreadpipe2 = INVALID_HANDLE_VALUE;
m_tgtsshpipehandles.m_hwritepipe = INVALID_HANDLE_VALUE;
m_tgtsshpipehandles.m_hwritepipe2 = INVALID_HANDLE_VALUE;
m_selalltables = wyFalse;
m_isremdefiner = wyFalse;
m_iscreatedb = wyFalse;
}
CopyDatabase::~CopyDatabase()
{
//delete the dialog control list
DlgControl* pdlgctrl;
while((pdlgctrl = (DlgControl*)m_controllist.GetFirst()))
{
m_controllist.Remove(pdlgctrl);
delete pdlgctrl;
}
// Release resources used by the critical section object.
DeleteCriticalSection(&m_cs);
}
// this function creates the actual dialog box and also initializes some values of the class
wyBool
CopyDatabase::Create(HWND hwndparent, Tunnel * tunnel, PMYSQL umysql, wyChar *db, wyChar *table, wyBool checktables)
{
wyInt32 ret;
m_srcmysql = umysql;
m_srctunnel = tunnel;
m_dontnotify = wyFalse;
//if table is valid, then set m_table
if(table)
m_table.SetAs(table);
//else if the the falg to set only the tables is there, then set the member variable
else if(checktables == wyTrue)
m_selalltables = wyTrue;
m_srcdb.SetAs(db);
//Post 8.01
//RepaintTabModule();
ret = DialogBoxParam(pGlobals->m_hinstance, MAKEINTRESOURCE(IDD_COPYDATABASE), hwndparent,
CopyDatabase::WndProc,(LPARAM)this);
return wyTrue;
}
// Callback dialog procedure for the window.
INT_PTR CALLBACK
CopyDatabase::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LPNMHDR lpnm = (LPNMHDR)lParam;
LPNMTVKEYDOWN ptvkd = (LPNMTVKEYDOWN) lParam ;
CopyDatabase * pcd =(CopyDatabase*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
LPNMTREEVIEW treeview = (LPNMTREEVIEW)lParam;
switch(message)
{
case WM_INITDIALOG:
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
LocalizeWindow(hwnd);
PostMessage(hwnd, WM_INITDLGVALUES, 0, 0);
return TRUE;
case WM_INITDLGVALUES:
// we set some initial value.
pcd->m_p->Create("COPYDATABASE");
VERIFY(pcd->m_hwnddlg = hwnd);
VERIFY(pcd->m_hwndcombo = GetDlgItem(hwnd, IDC_SOURCEDB));
VERIFY(pcd->m_hwndcombodb = GetDlgItem(hwnd, IDC_SOURCEDB2));
pcd->CreateImageList();
pcd->AddInitData();
break;
case WM_HELP:
ShowHelp("Copy%20Database%20to%20Different%20Host%20SQLyog%20MySQL%20GUI.htm");
return TRUE;
case UM_COPYDATABASE:
pcd->OnUmCopydatabase(hwnd);
break;
case WM_MOUSEMOVE:
pcd->OnMouseMove(hwnd, lParam);
break;
case WM_MEASUREITEM:
OnComboMeasureItem((LPMEASUREITEMSTRUCT)lParam);
break;
case WM_DRAWITEM:
//draw connection color with connection name
OnDrawConnNameCombo(GetDlgItem(hwnd, LOWORD(wParam)), (LPDRAWITEMSTRUCT)lParam, wyTrue);
break;
case WM_NOTIFY:
if(lpnm->idFrom == IDC_TREE && lpnm->code == NM_CLICK)
HandleTreeViewItem(lParam, wParam);
if((ptvkd->hdr.idFrom == IDC_TREE) && ptvkd->wVKey == VK_SPACE)
HandleTreeViewItem(lParam, wParam, wyTrue);
if(lpnm->code == TVN_ITEMEXPANDING )
{
if(treeview->itemNew.iImage == NTABLES)
{
if(pcd->m_dontnotify)
return wyFalse;
}
return pcd->OnItemExpandingHelper(lpnm->hwndFrom, (LPNMTREEVIEW)lParam);
}
break;
case WM_COMMAND:
pcd->OnWmCommand(hwnd, wParam);
break;
case WM_SIZE:
pcd->CopyDbResize(hwnd);
break;
case WM_GETMINMAXINFO:
pcd->OnWMSizeInfo(lParam);
break;
case WM_PAINT:
pcd->OnPaint(hwnd);
break;
case WM_ERASEBKGND:
//blocked for double buffering
return 1;
case WM_DESTROY:
SaveInitPos(hwnd, COPYDATABASE_SECTION);
if(pcd->m_himl)
{
ImageList_Destroy(pcd->m_himl);
}
pcd->FreeComboParam();
if(pcd->m_p)
{
delete pcd->m_p;
}
break;
}
return 0;
}
void
CopyDatabase::OnMouseMove(HWND hwnd, LPARAM lparam)
{
RECT rect;
POINT pt;
if(m_copying == wyTrue)
{
pt.x = GET_X_LPARAM(lparam);
pt.y = GET_Y_LPARAM(lparam);
GetWindowRect(GetDlgItem(hwnd, IDOK), &rect);
MapWindowPoints(hwnd, NULL, &pt, 1);
//Cursor shows wait on Stop button while copying
if( PtInRect(&rect, pt) && IsCopyStopped() == wyFalse)
SetCursor(LoadCursor(NULL, IDC_ARROW));
else
SetCursor(LoadCursor(NULL, IDC_WAIT));
}
return;
}
void
CopyDatabase::OnUmCopydatabase(HWND hwnd)
{
wyBool ret;
wyUInt32 thdid,index;
COPYDBPARAM copydbparam;
COPYDB evt;
HWND hwndtree;
MDIWindow *wnd = NULL;
wyString msg;
HWND hwndmsg = NULL;
wyWChar buffer[SIZE_128];
VERIFY(wnd = GetActiveWin());
LPDIFFCOMBOITEM lpdiff;
m_ispromtstorepgrmmessage = wyFalse;
m_isstoredpgrms = wyFalse;
SetFocus(GetDlgItem(m_hwnddlg, IDC_CHECK1));
EnableDlgWindows(wyFalse);
EnableWindow(GetDlgItem(hwnd, IDDONE ), false);
EnableWindow(GetDlgItem(m_hwnddlg, IDC_SUMMARY), wyFalse);
m_summary.Clear();
VERIFY(hwndtree = GetDlgItem(m_hwnddlg, IDC_TREE));
// first see if any objects are selected.
if(IsObjectsSelected(hwndtree) == wyFalse)
{
yog_message(hwndtree, _(L"Please select atleast one object"), pGlobals->m_appname.GetAsWideChar(),MB_OK|MB_ICONINFORMATION | MB_HELP);
EnableDlgWindows(wyTrue);
m_copying = wyFalse;
return;
}
else
{
GetDlgItemText(m_hwnddlg, IDC_SOURCEDB2, buffer, SIZE_128 - 1);
m_targetdb.SetAs(buffer);
m_targetdb.RTrim();
index = SendMessage(m_hwndcombodb, CB_FINDSTRINGEXACT, -1,(LPARAM)m_targetdb.GetAsWideChar());
if(index != CB_ERR)
{
m_iscreatedb = wyFalse;
}
else
{
m_iscreatedb = wyTrue;
}
if(m_targetdb.GetLength() == 0)
{
yog_message(hwndtree, _(L"Please select a database or enter the name for new database"), pGlobals->m_appname.GetAsWideChar(),MB_OK|MB_ICONINFORMATION | MB_HELP);
EnableDlgWindows(wyTrue);
m_copying = wyFalse;
return;
}
}
ret = GetTargetDatabase();
if(ret == wyFalse)
{
EnableDlgWindows(wyTrue);
m_copying = wyFalse;
return;
}
hwndmsg = GetDlgItem(m_hwnddlg, IDC_MESSAGE);
if(hwndmsg)
{
msg.Sprintf(_("Connecting to source server "));
SendMessage(hwndmsg, WM_SETTEXT, 0, (LPARAM)msg.GetAsWideChar());
}
ret = pGlobals->m_pcmainwin->m_connection->CreateSourceInstance(this);
if(ret == wyFalse)
{
EnableDlgWindows(wyTrue);
m_copying = wyFalse;
return;
}
if(hwndmsg)
{
msg.Sprintf(_("Connecting to target server "));
SendMessage(hwndmsg, WM_SETTEXT, 0, (LPARAM)msg.GetAsWideChar());
}
ret = pGlobals->m_pcmainwin->m_connection->CreateTargetInstance(this);
if(ret == wyFalse)
{
EnableDlgWindows(wyTrue);
m_copying = wyFalse;
RemoveSourceInstances();
return;
}
ret = InitExportData(hwndtree);
if(ret == wyFalse)
{
Delete(&m_seltables);
EnableDlgWindows(wyTrue);
m_copying = wyFalse;
RemoveInstances();
return;
}
SetGroupProcess(wnd, wyTrue);
copydbparam.m_hwndmsg = GetDlgItem(m_hwnddlg, IDC_MESSAGE);
copydbparam.m_hwnddlg = m_hwnddlg;
copydbparam.m_summary = &m_summary;
m_copydbparam = ©dbparam;
evt.m_copydbevent = CreateEvent(NULL, TRUE, FALSE, NULL);
evt.m_copydb = this;
evt.m_lpParam = ©dbparam;
m_stopcopying = wyFalse;
m_isobjecttoexport = wyFalse;
VERIFY(m_hcopythread = (HANDLE)_beginthreadex(NULL, 0,
CopyDatabase::ExecuteCopyThread, &evt, 0, &thdid));
if(!m_hcopythread)
goto cleanup;
HandleMsgs(evt.m_copydbevent, wyFalse,m_hwnddlg);
cleanup:
if(evt.m_copydbevent)
VERIFY(CloseHandle(evt.m_copydbevent));
if(m_hcopythread)
VERIFY(CloseHandle(m_hcopythread));
//rebuilding Target DB to which Db is copyied
//SpecificDBRebuild((wyChar*)evt.m_copydb->m_targetdb.GetString());
//wnd = GetActiveWin();
SetGroupProcess(wnd, wyFalse);
if(pGlobals->m_isautocomplete == wyTrue)
RebuildACTags_SpecificDB(*m_tgtinfo, (wyChar*)m_targetdb.GetString());
FreeExportData();
EnableDlgWindows(wyTrue);
m_copying = wyFalse;
EnableDisable(IDC_STRUC);
//set the focus for 'Escape' key to cancel the dialog
SetFocus(m_hwnddlg);
SetCursor(LoadCursor(NULL, IDC_ARROW));
return;
}
unsigned __stdcall
CopyDatabase::ExecuteCopyThread(LPVOID lpparam)
{
wyBool ret;
COPYDB *copydb = (COPYDB*)lpparam;
wyBool flag = wyFalse, isdone = wyFalse;
wyString msg;
ret = copydb->m_copydb->ChangeTargetDB();
if(ret == wyFalse)
{
copydb->m_copydb->RemoveInstances();
goto close;
}
// if enable Transaction support (preference option)is selected and if it is not HTTP tunnel then execute
// start transaction by setting autocommit = 0
if(IsStartTransactionEnable() == wyTrue && copydb->m_copydb->m_newtargettunnel->IsTunnel() == wyFalse)
{
StartTransaction(copydb->m_copydb->m_newtargettunnel, copydb->m_copydb->m_newtargetmysql);
flag = wyTrue;
}
ret = copydb->m_copydb->ExportData(CopyDatabase::UpdateGui, (void*)copydb->m_lpParam);
//For working 'cancel'
//SetFocus(copydb->m_copydb->m_hwnddlg);
//if enable Transaction support (preference option)is selected then execute commit query
if(flag == wyTrue)
EndTransaction(copydb->m_copydb->m_newtargettunnel, copydb->m_copydb->m_newtargetmysql);
copydb->m_copydb->RemoveInstances();
//If user pressed on 'Stop'
if(ret == wyTrue && copydb->m_copydb && copydb->m_copydb->IsCopyStopped() == wyTrue)
{
//Shows number of rows copied
msg.Sprintf(_("Aborted by user "));
SendMessage(copydb->m_lpParam->m_hwndmsg, WM_SETTEXT, 0, (LPARAM)msg.GetAsWideChar());
}
else if(ret == wyTrue && copydb->m_copydb && copydb->m_copydb->m_isobjecttoexport == wyTrue)
{
//Shows number of rows copied
msg.Sprintf(_("Copied successfully "));
SendMessage(copydb->m_lpParam->m_hwndmsg, WM_SETTEXT, 0, (LPARAM)msg.GetAsWideChar());
isdone = wyTrue;
}
//if parent folder selected and press copy but if folder doesn;t have any child
else if(ret == wyTrue && copydb->m_copydb && copydb->m_copydb->m_isobjecttoexport == wyFalse)
{
SendMessage(copydb->m_lpParam->m_hwndmsg, WM_SETTEXT, 0,
(LPARAM)_(L"There was nothing to be copied"));
isdone = wyTrue;
}
else
{
//Shows number of rows copied
msg.Sprintf(_("Error occured while copying "));
SendMessage(copydb->m_lpParam->m_hwndmsg, WM_SETTEXT, 0, (LPARAM)msg.GetAsWideChar());
//SetFocus(copydb->m_copydb->m_hwnddlg);
}
if(copydb->m_copydb->m_summary.GetLength())
EnableWindow(GetDlgItem(copydb->m_lpParam->m_hwnddlg, IDC_SUMMARY), wyTrue);
//If it is succesful then Close button is changed to Done
ShowWindow(GetDlgItem(copydb->m_lpParam->m_hwnddlg, IDCANCEL), !isdone);
ShowWindow(GetDlgItem(copydb->m_lpParam->m_hwnddlg, IDDONE ), isdone);
EnableWindow(GetDlgItem(copydb->m_lpParam->m_hwnddlg, IDDONE ), isdone);
//Flag sets for prompting the Message box.
if(isdone == wyTrue && copydb->m_copydb)
{
if(copydb->m_copydb->m_isstoredpgrms == wyTrue && copydb->m_copydb->m_srcdb.Compare(copydb->m_copydb->m_targetdb) != 0)
copydb->m_copydb->m_ispromtstorepgrmmessage = wyTrue;
}
close:
SetEvent(copydb->m_copydbevent);
return 1;
}
void
CopyDatabase::RemoveInstances()
{
RemoveSourceInstances();
RemoveTargetInstances();
}
void
CopyDatabase::RemoveSourceInstances()
{
if(m_newsrcmysql)
m_newsrctunnel->mysql_close(m_newsrcmysql);
if(m_srcprocess != INVALID_HANDLE_VALUE)
{
//If SSH connection then close handles at end
if(m_srcinfo->m_isssh == wyTrue)
OnExitSSHConnection(&m_srcsshpipehandles);
if(m_srcinfo->m_sshsocket)
closesocket(m_srcinfo->m_sshsocket);
m_srcinfo->m_sshsocket = NULL;
VERIFY(TerminateProcess(m_srcprocess, 1));
}
if(m_newsrctunnel)
delete m_newsrctunnel;
}
void
CopyDatabase::RemoveTargetInstances()
{
if(m_newtargetmysql)
m_newtargettunnel->mysql_close(m_newtargetmysql);
if(m_tgtprocess != INVALID_HANDLE_VALUE)
{
//If SSH connection then close handles at end
if(m_tgtinfo->m_isssh == wyTrue)
OnExitSSHConnection(&m_tgtsshpipehandles);
if(m_tgtinfo->m_sshsocket)
closesocket(m_tgtinfo->m_sshsocket);
m_tgtinfo->m_sshsocket = NULL;
VERIFY(TerminateProcess(m_tgtprocess, 1));
}
if(m_newtargettunnel)
delete m_newtargettunnel;
}
void
CopyDatabase::OnWmCommand(HWND hwnd, WPARAM wparam)
{
CShowInfo csi;
switch(LOWORD(wparam))
{
case IDOK:
if(m_copying == wyTrue)
{
StopCopy();
SetWindowText(GetDlgItem(m_hwnddlg, IDC_MESSAGE), _(L"Aborting copy..."));
EnableWindow(GetDlgItem(m_hwnddlg, IDOK), FALSE);
SetFocus(m_hwnddlg);
}
else
{
m_copying = wyTrue;
UpdateWindow(hwnd);
PostMessage(hwnd, UM_COPYDATABASE, NULL, NULL);
}
break;
case IDC_SELALL2:
SendMessage(GetDlgItem(hwnd,IDC_TABLES),LB_SETSEL,TRUE,-1);
break;
case IDC_UNSELALL2:
SendMessage(GetDlgItem(hwnd,IDC_TABLES),LB_SETSEL,FALSE,-1);
break;
case IDDONE:
case IDCANCEL:
yog_enddialog(hwnd, 0);
break;
case IDC_CPY_DEFINER:
if(SendMessage(GetDlgItem(hwnd, IDC_CPY_DEFINER), BM_GETCHECK, 0, 0) == BST_CHECKED)
m_isremdefiner = wyTrue;
else
m_isremdefiner = wyFalse;
//m_isremdefiner = m_isremdefiner?wyFalse:wyTrue;
break;
case IDC_SOURCEDB:
if(HIWORD(wparam) == CBN_SELCHANGE)
OnCBSelChange(hwnd);
break;
// To disable bulkinsert when only structure is checked.
case IDC_STRUC:
case IDC_STRUCDATA:
EnableDisable(LOWORD(wparam));
break;
case IDC_SUMMARY:
csi.ShowInfo(hwnd, NULL, NULL, _(" Copy Database Summary"), (wyChar *)m_summary.GetString());
break;
}
return;
}
void
CopyDatabase::OnCBSelChange(HWND hwnd)
{
HWND treehandle;
if(m_table.GetLength())
m_table.Clear();
treehandle = GetDlgItem(hwnd, IDC_TREE);
if(treehandle == NULL)
return;
CheckTargetDB(hwnd);
VERIFY(SendMessage(treehandle, WM_SETREDRAW, FALSE, 0));
SetCursor(LoadCursor(NULL, IDC_WAIT));
HandleTreeviewOnComboChange(wyFalse, wyTrue);
//SelectTreeviewParentItems(treehandle);
SetCursor(LoadCursor(NULL, IDC_ARROW));
VERIFY(SendMessage(GetDlgItem(hwnd, IDC_TREE), WM_SETREDRAW, TRUE, 0));
}
// Function fills up the combo with diff database from diff connection.
wyBool
CopyDatabase::AddInitData()
{
HWND hwndtree = NULL;
DBListBuilder cdb;
wyInt32 ret,ncursel;
MDIWindow *wnd = GetActiveWin();
wyString activevalue,activevalue2, srcdetail;
wyBool flag = wyFalse;
LPDIFFCOMBOITEM lpdiff;
srcdetail.Sprintf("%s - %s", wnd->m_title.GetString(), m_srcdb.GetString());
cdb.GetSVs(m_hwndcombo);
SendMessage(GetDlgItem(m_hwnddlg, IDC_TARGETDB), WM_SETTEXT, 0,(LPARAM)srcdetail.GetAsWideChar());
m_p->Add(m_hwnddlg, IDC_DROP, "DropTable", "0", CHECKBOX);
m_p->Add(m_hwnddlg, IDC_STRUCDATA, "StrucData", "1", CHECKBOX);
m_p->Add(m_hwnddlg, IDC_STRUC, "StrucOnly", "0", CHECKBOX);
m_p->Add(m_hwnddlg, IDC_CPY_BULKINSERT, "CpyBulkInsert", "1", CHECKBOX);
m_p->Add(m_hwnddlg, IDC_CPY_DEFINER, "RemoveDefiner", "0", CHECKBOX);
if(wnd)
m_srcinfo = &wnd->m_conninfo;
m_issrc5xobjects = IsMySQL5010(m_srctunnel, m_srcmysql);
m_issrceventsupport = IsMySQL516(m_srctunnel, m_srcmysql);
/* now we remove the the current db that is being exported from combobox so that we dont accidently
drop the data */
/* starting from 4.1 BETA 4 we use connection name for unique values */
//if active connection is same as source connection then remove source db from databases combo
activevalue.Sprintf("%s", wnd->m_title.GetString());
activevalue2.Sprintf("%s", m_srcdb.GetString());
//populate dbs for first connection in the list
//ncursel = SendMessage(m_hwndcombo, CB_GETCURSEL, 0, 0);
ncursel = 0;
VERIFY(lpdiff =(LPDIFFCOMBOITEM)SendMessage(m_hwndcombo, CB_GETITEMDATA, ncursel, 0));
DBListBuilder::GetDBFromActiveWinscopydb(lpdiff->wnd->m_hwnd, (LPARAM)m_hwndcombodb);
if(lpdiff->wnd == wnd )
{
ret = SendMessage(m_hwndcombodb, CB_FINDSTRINGEXACT, -1,(LPARAM)activevalue2.GetAsWideChar());
if(ret != CB_ERR)
SendMessage(m_hwndcombodb, CB_DELETESTRING, ret, 0);
}
//delete lpdiff;
///If combo list is empty then disable the combo box
//11.52 we do not disable combo box on single connection since user can create a new db
ret = SendMessage(m_hwndcombo, CB_GETCOUNT, (WPARAM)0,(LPARAM)0);
if(!ret)
{
EnableWindow(m_hwndcombo, FALSE);
EnableWindow(m_hwndcombodb, FALSE);
}
else
{
EnableWindow(m_hwndcombo, TRUE);
EnableWindow(m_hwndcombodb, TRUE);
}
m_p->Add(m_hwnddlg, IDC_SOURCEDB, "Target", "", COMBOBOX_P);
// if user has only one connection and having only one db
if(CheckTargetDB(m_hwnddlg) == wyFalse)
flag = wyTrue;
// now add all the tables to the tree.
VERIFY(hwndtree = GetDlgItem(m_hwnddlg, IDC_TREE));
if(!hwndtree)
return wyFalse;
// To disable bulkinsert when only structure is checked.
EnableDisable(IDC_STRUC);
EnableWindow(GetDlgItem(m_hwnddlg, IDC_SUMMARY), wyFalse);
if(SendMessage(GetDlgItem(m_hwnddlg, IDC_CPY_DEFINER), BM_GETCHECK, 0, 0) == BST_CHECKED)
m_isremdefiner = wyTrue;
else
m_isremdefiner = wyFalse;
//Initialise the treeview
InitializeTree(m_hwnddlg, m_srcdb.GetString(), flag);
GetClientRect(m_hwnddlg, &m_dlgrect);
GetWindowRect(m_hwnddlg, &m_wndrect);
//set the initial position of the dialog
SetWindowPositionFromINI(m_hwnddlg, COPYDATABASE_SECTION,
m_wndrect.right - m_wndrect.left,
m_wndrect.bottom - m_wndrect.top);
GetCtrlRects();
PositionCtrls();
return wyTrue;
}
//Function adds table(s), view(s), procedure(s), function(s) and trigger(s)of the selected database to the tree control.
wyBool
CopyDatabase::InitializeTree(HWND hwnd, const wyChar * dbname, wyBool issingledb)
{
HWND hwndtree, hobtree;
MDIWindow *wnd;
HTREEITEM root, temp, hti;
wyInt32 image;
TVITEM tviOB;
VERIFY(wnd = GetActiveWin());
if(!wnd)
return wyFalse;
VERIFY(hwndtree = GetDlgItem(hwnd, IDC_TREE));
InsertTableParent(hwndtree, TVI_ROOT);
HandleTreeviewOnComboChange(issingledb);
//for copying single table
if(m_table.GetLength())// && cbselchange == wyFalse)
{
root = TreeView_GetRoot(hwndtree);
SelectTreeviewParentItems(hwndtree, root);
TreeView_Expand(hwndtree, root, TVE_EXPAND);
}
//select the table objects only
else if(m_selalltables == wyTrue)
{
root = TreeView_GetRoot(hwndtree);
SelectTreeviewParentItems(hwndtree, root);
TreeView_Expand(hwndtree, root, TVE_EXPAND);
}
//Selects parent for all objects
else
{
root = TreeView_GetRoot(hwndtree);
temp = root;
SelectTreeviewParentItems(hwndtree);
hobtree = wnd->m_pcqueryobject->m_hwnd;
if(hobtree)
{
hti = TreeView_GetSelection(hobtree);
image = wnd->m_pcqueryobject->GetSelectionImage();
while(image != NDATABASE)
{
hti = TreeView_GetParent(hobtree, hti);
image = GetItemImage(hobtree, hti);
}
hti = TreeView_GetChild(hobtree, hti);
while(root && hti)
{
tviOB.hItem = hti;
tviOB.mask = TVIF_PARAM;
TreeView_GetItem(hobtree, &tviOB);
if(tviOB.lParam && wcslen(((OBDltElementParam *)tviOB.lParam)->m_filterText))
{
TreeView_Expand(hwndtree, root, TVE_EXPAND);
}
root = TreeView_GetNextSibling(hwndtree, root);
hti = TreeView_GetNextSibling(hobtree, hti);
}
}
TreeView_SelectItem(hwndtree, temp);
}
return wyTrue;
}
///When expands treeview node
wyBool
CopyDatabase::OnItemExpandingHelper(HWND hwnd , LPNMTREEVIEW pnmtv)
{
TVITEM tvi, tviOB;
TREEVIEWPARAMS treeviewparam = {0};
MDIWindow *wnd = GetActiveWin();
HWND hobtree = wnd->m_pcqueryobject->m_hwnd;
wyInt32 image = 0, image1 = 0;
HTREEITEM hti = NULL,selected_hti = NULL;
wyWChar filterText[70], str[70];
wyBool atleastOneItemChecked = wyFalse;
tvi = pnmtv->itemNew;
treeviewparam.database = m_srcdb.GetAsWideChar();
treeviewparam.hwnd = hwnd;
treeviewparam.isopentables = wyFalse;
treeviewparam.isrefresh = wyTrue;
treeviewparam.issingletable = wyFalse;
treeviewparam.mysql = m_srcmysql;
treeviewparam.tunnel = m_srctunnel;
treeviewparam.tvi = &tvi;
treeviewparam.checkboxstate = wyTrue;
OnItemExpanding(treeviewparam);
image = wnd->m_pcqueryobject->GetSelectionImage();
image1 = GetItemImage(hwnd, tvi.hItem);
if(!(tvi.state & TVIS_EXPANDEDONCE) && ((m_selalltables == wyTrue && image1 == NTABLES) || (m_selalltables == wyFalse)))
{
if(!m_table.GetLength())
{
hti = TreeView_GetSelection(hobtree);
switch(image)
{
case NTABLES:
case NEVENTS:
case NSP:
case NFUNC:
case NTRIGGER:
case NVIEWS:
hti = TreeView_GetParent(hobtree, hti);
break;
case NTABLE:
case NSPITEM:
case NEVENTITEM:
case NFUNCITEM:
case NTRIGGERITEM:
case NVIEWSITEM:
hti = TreeView_GetParent(hobtree, hti);
hti = TreeView_GetParent(hobtree, hti);
break;
case NFOLDER:
hti = TreeView_GetParent(hobtree, hti);
hti = TreeView_GetParent(hobtree, hti);
hti = TreeView_GetParent(hobtree, hti);
break;
case NPRIMARYKEY:
case NCOLUMN:
case NPRIMARYINDEX:
case NINDEX:
hti = TreeView_GetParent(hobtree, hti);
hti = TreeView_GetParent(hobtree, hti);
hti = TreeView_GetParent(hobtree, hti);
hti = TreeView_GetParent(hobtree, hti);
break;
}
hti = TreeView_GetChild(hobtree, hti);
if(hti)
{
for(;hti;hti = TreeView_GetNextSibling(hobtree, hti))
{
image = GetItemImage(hobtree, hti);
if(image == image1)
break;
}
if(hti)
{
tviOB.hItem = hti;
tviOB.mask = TVIF_PARAM;
TreeView_GetItem(hobtree, &tviOB);
if(tviOB.lParam && wcslen(((OBDltElementParam *)tviOB.lParam)->m_filterText))
{
wcscpy(filterText, ((OBDltElementParam *)tviOB.lParam)->m_filterText);
_wcslwr_s(filterText, 65);
for(hti = TreeView_GetChild(hwnd, tvi.hItem); hti; hti = TreeView_GetNextSibling(hwnd, hti))
{
tviOB.hItem = hti;
tviOB.mask = TVIF_TEXT;
tviOB.pszText = str;
tviOB.cchTextMax = 65;
TreeView_GetItem(hwnd, &tviOB);
_wcslwr_s(tviOB.pszText, 65);
if(wcsstr(tviOB.pszText, filterText))
{
TreeView_SetCheckState(hwnd, hti, 1);
atleastOneItemChecked = wyTrue;
}
else
{
TreeView_SetCheckState(hwnd, hti, 0);
}
}
if(atleastOneItemChecked)
{
TreeView_SetCheckState(hwnd, tvi.hItem, 1);
}
else
{
TreeView_SetCheckState(hwnd, tvi.hItem, 0);
}
}
}
}
}
else
{
hti = TreeView_GetRoot(hwnd);
hti = TreeView_GetChild(hwnd, hti);
for(;hti; hti = TreeView_GetNextSibling(hwnd, hti))
{
tviOB.hItem = hti;
tviOB.mask = TVIF_TEXT;
tviOB.cchTextMax = 70;
tviOB.pszText = str;
TreeView_GetItem(hwnd, &tviOB);
if(!wcsicmp(tviOB.pszText, m_table.GetAsWideChar()))
{
TreeView_SetCheckState(hwnd, hti, 1);
selected_hti=hti;
atleastOneItemChecked = wyTrue;
}
else
{
TreeView_SetCheckState(hwnd, hti, 0);
}
}
if(atleastOneItemChecked)
{
if(image1 == NTABLES)
{
m_dontnotify = wyTrue;
//Fixed:http://code.google.com/p/sqlyog/issues/detail?id=1919
//TreeView_SelectItem(hwnd,selected_hti);
TreeView_SelectSetFirstVisible(hwnd,selected_hti);
}
TreeView_SetCheckState(hwnd, tvi.hItem, 1);
}
else
{
TreeView_SetCheckState(hwnd, tvi.hItem, 0);
}
}
}
return wyFalse;
}
wyBool
CopyDatabase::HandleTreeviewOnComboChange(wyBool issinglesrcdb, wyBool cbselchange)
{
HWND hwndtree = NULL;
HTREEITEM htreeitem = NULL;
wyBool iscopytable = wyFalse;
wyString query;
VERIFY(hwndtree = GetDlgItem(m_hwnddlg, IDC_TREE));
if(!hwndtree)
return wyFalse;
// if we have only one connection and connection having single db
if(issinglesrcdb == wyTrue)
{
m_istrg5xobjects = wyTrue;
m_istrgeventsupports = wyTrue;
}
//For versions less tahn 5.1, delete all parent folders from view,(view, sp, fun, trig, etc)
if(m_issrc5xobjects == wyFalse || m_istrg5xobjects == wyFalse)
{