1 /*
2 / QueryViewComposer.cpp
3 / Query/View Composer
4 /
5 / version 1.7, 2013 May 8
6 /
7 / Author: Sandro Furieri a-furieri@lqt.it
8 /
9 / Copyright (C) 2009-2013 Alessandro Furieri
10 /
11 / This program is free software: you can redistribute it and/or modify
12 / it under the terms of the GNU General Public License as published by
13 / the Free Software Foundation, either version 3 of the License, or
14 / (at your option) any later version.
15 /
16 / This program is distributed in the hope that it will be useful,
17 / but WITHOUT ANY WARRANTY; without even the implied warranty of
18 / MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 / GNU General Public License for more details.
20 /
21 / You should have received a copy of the GNU General Public License
22 / along with this program. If not, see <http://www.gnu.org/licenses/>.
23 /
24 */
25
26 #include "Classdef.h"
27
QueryViewComposer()28 void MyFrame::QueryViewComposer()
29 {
30 //
31 // query/view composer invoked
32 //
33 int ret;
34 char *errMsg = NULL;
35 ComposerDialog dlg;
36 dlg.Create(this);
37 int metadataType = GetMetaDataType();
38 if (dlg.ShowModal() == wxID_OK)
39 {
40 if (dlg.IsSpatialView() == true)
41 {
42 // creating a Spatial View
43 ::wxBeginBusyCursor();
44 ret =
45 sqlite3_exec(GetSqlite(), dlg.GetSqlSample().ToUTF8(), NULL, NULL,
46 &errMsg);
47 if (ret != SQLITE_OK)
48 {
49 wxMessageBox(wxT("SQLite SQL error: ") +
50 wxString::FromUTF8(errMsg), wxT("spatialite_gui"),
51 wxOK | wxICON_ERROR, this);
52 sqlite3_free(errMsg);
53 ::wxEndBusyCursor();
54 return;
55 }
56 if (dlg.IsWritable1() == true)
57 {
58 // creating Triggers supporting RW operations on the Main Table
59 ret =
60 sqlite3_exec(GetSqlite(), dlg.GetSqlTriggerInsert().ToUTF8(),
61 NULL, NULL, &errMsg);
62 if (ret != SQLITE_OK)
63 {
64 wxMessageBox(wxT("SQLite SQL error: ") +
65 wxString::FromUTF8(errMsg),
66 wxT("spatialite_gui"), wxOK | wxICON_ERROR,
67 this);
68 sqlite3_free(errMsg);
69 ::wxEndBusyCursor();
70 return;
71 }
72 ret =
73 sqlite3_exec(GetSqlite(), dlg.GetSqlTriggerUpdate().ToUTF8(),
74 NULL, NULL, &errMsg);
75 if (ret != SQLITE_OK)
76 {
77 wxMessageBox(wxT("SQLite SQL error: ") +
78 wxString::FromUTF8(errMsg),
79 wxT("spatialite_gui"), wxOK | wxICON_ERROR,
80 this);
81 sqlite3_free(errMsg);
82 ::wxEndBusyCursor();
83 return;
84 }
85 ret =
86 sqlite3_exec(GetSqlite(), dlg.GetSqlTriggerDelete().ToUTF8(),
87 NULL, NULL, &errMsg);
88 if (ret != SQLITE_OK)
89 {
90 wxMessageBox(wxT("SQLite SQL error: ") +
91 wxString::FromUTF8(errMsg),
92 wxT("spatialite_gui"), wxOK | wxICON_ERROR,
93 this);
94 sqlite3_free(errMsg);
95 ::wxEndBusyCursor();
96 return;
97 }
98 }
99 wxString sql = wxT("INSERT INTO views_geometry_columns ");
100 if (metadataType == METADATA_CURRENT)
101 {
102 // current metadata style >= v.4.0.0
103 sql +=
104 wxT
105 ("(view_name, view_geometry, view_rowid, f_table_name, f_geometry_column, read_only)");
106 } else
107 {
108 // legacy metadata style <= v.3.1.0
109 sql +=
110 wxT
111 ("(view_name, view_geometry, view_rowid, f_table_name, f_geometry_column)");
112 }
113 sql += wxT(" VALUES (");
114 if (metadataType == METADATA_CURRENT)
115 {
116 // current metadata style >= v.4.0.0
117 sql += wxT("Lower('");
118 sql += dlg.GetViewName();
119 sql += wxT("'), Lower('");
120 sql += dlg.GetGeometryColumnAlias();
121 sql += wxT("'), Lower('");
122 sql += dlg.GetGeometryRowidAlias();
123 sql += wxT("'), Lower('");
124 if (dlg.IsViewGeomTable2() == true)
125 sql += dlg.GetTableName2();
126 else
127 sql += dlg.GetTableName1();
128 sql += wxT("'), Lower('");
129 sql += dlg.GetGeometryColumn();
130 if (metadataType == METADATA_CURRENT)
131 {
132 // current metadata style >= v.4.0.0
133 if (dlg.IsWritable1() == true)
134 sql += wxT("'), 0)");
135 else
136 sql += wxT("'), 1)");
137 }
138 } else
139 {
140 // legacy metadata style <= v.3.1.0
141 sql += wxT("'");
142 sql += dlg.GetViewName();
143 sql += wxT("', '");
144 sql += dlg.GetGeometryColumnAlias();
145 sql += wxT("', '");
146 sql += dlg.GetGeometryRowidAlias();
147 sql += wxT("', '");
148 if (dlg.IsViewGeomTable2() == true)
149 sql += dlg.GetTableName2();
150 else
151 sql += dlg.GetTableName1();
152 sql += wxT("', '");
153 sql += dlg.GetGeometryColumn();
154 sql += wxT("')");
155 }
156 ret = sqlite3_exec(GetSqlite(), sql.ToUTF8(), NULL, NULL, &errMsg);
157 if (ret != SQLITE_OK)
158 {
159 wxMessageBox(wxT("SQLite SQL error: ") +
160 wxString::FromUTF8(errMsg), wxT("spatialite_gui"),
161 wxOK | wxICON_ERROR, this);
162 sqlite3_free(errMsg);
163 ::wxEndBusyCursor();
164 return;
165 }
166 if (metadataType == METADATA_CURRENT)
167 {
168 // current metadata style >= v.4.0.0
169
170 // creating the Spatial View Auth row
171 sql = wxT("INSERT INTO views_geometry_columns_auth ");
172 sql += wxT("(view_name, view_geometry, hidden)");
173 sql += wxT(" VALUES (Lower('");
174 sql += dlg.GetViewName();
175 sql += wxT("'), Lower('");
176 sql += dlg.GetGeometryColumnAlias();
177 sql += wxT("'), 0)");
178 ret =
179 sqlite3_exec(GetSqlite(), sql.ToUTF8(), NULL, NULL, &errMsg);
180 if (ret != SQLITE_OK)
181 {
182 wxMessageBox(wxT("SQLite SQL error: ") +
183 wxString::FromUTF8(errMsg),
184 wxT("spatialite_gui"), wxOK | wxICON_ERROR,
185 this);
186 sqlite3_free(errMsg);
187 ::wxEndBusyCursor();
188 return;
189 }
190 // creating the Spatial View Statistics row
191 sql = wxT("INSERT INTO views_geometry_columns_statistics ");
192 sql += wxT("(view_name, view_geometry)");
193 sql += wxT(" VALUES (Lower('");
194 sql += dlg.GetViewName();
195 sql += wxT("'), Lower('");
196 sql += dlg.GetGeometryColumnAlias();
197 sql += wxT("'))");
198 ret =
199 sqlite3_exec(GetSqlite(), sql.ToUTF8(), NULL, NULL, &errMsg);
200 if (ret != SQLITE_OK)
201 {
202 wxMessageBox(wxT("SQLite SQL error: ") +
203 wxString::FromUTF8(errMsg),
204 wxT("spatialite_gui"), wxOK | wxICON_ERROR,
205 this);
206 sqlite3_free(errMsg);
207 ::wxEndBusyCursor();
208 return;
209 }
210 }
211 ::wxEndBusyCursor();
212 wxMessageBox(wxT("The Spatial View ") + dlg.GetViewName() +
213 wxT("\nwas successfully created"),
214 wxT("spatialite_gui"), wxOK | wxICON_INFORMATION, this);
215 InitTableTree();
216 return;
217 } else if (dlg.IsPlainView() == true)
218 {
219 // creating an ordinary View
220 ::wxBeginBusyCursor();
221 ret =
222 sqlite3_exec(GetSqlite(), dlg.GetSqlSample().ToUTF8(), NULL, NULL,
223 &errMsg);
224 if (ret != SQLITE_OK)
225 {
226 wxMessageBox(wxT("SQLite SQL error: ") +
227 wxString::FromUTF8(errMsg), wxT("spatialite_gui"),
228 wxOK | wxICON_ERROR, this);
229 sqlite3_free(errMsg);
230 ::wxEndBusyCursor();
231 return;
232 }
233 ::wxEndBusyCursor();
234 wxMessageBox(wxT("The View ") + dlg.GetViewName() +
235 wxT("\nwas successfully created"),
236 wxT("spatialite_gui"), wxOK | wxICON_INFORMATION, this);
237 InitTableTree();
238 return;
239 } else
240 {
241 // executing the SQL statement
242 SetSql(dlg.GetSqlSample(), true);
243 }
244 }
245 }
246
Create(MyFrame * parent)247 bool ComposerDialog::Create(MyFrame * parent)
248 {
249 //
250 // creating the dialog
251 //
252 MainFrame = parent;
253 IncompleteSql = true;
254 Table2Enabled = false;
255 TableAlias1 = wxT("a");
256 TableAlias2 = wxT("b");
257 LeftJoin = false;
258 Match2Enabled = false;
259 Match3Enabled = false;
260 Where1Enabled = false;
261 Where2Enabled = false;
262 Where3Enabled = false;
263 Where1Table2 = false;
264 Where2Table2 = false;
265 Where3Table2 = false;
266 AndOr12 = true;
267 AndOr23 = true;
268 Order1Enabled = false;
269 Order2Enabled = false;
270 Order3Enabled = false;
271 Order4Enabled = false;
272 Order1Table2 = false;
273 Order2Table2 = false;
274 Order3Table2 = false;
275 Order4Table2 = false;
276 Order1Desc = false;
277 Order2Desc = false;
278 Order3Desc = false;
279 Order4Desc = false;
280 ViewGeomTable2 = false;
281 PlainView = false;
282 SpatialView = false;
283 Writable1 = false;
284 Writable2 = false;
285 if (wxDialog::Create(parent, wxID_ANY, wxT("Query / View Composer")) == false)
286 return false;
287 // populates individual controls
288 TableList.Populate(MainFrame->GetSqlite());
289 CreateControls();
290 // sets dialog sizer
291 GetSizer()->Fit(this);
292 GetSizer()->SetSizeHints(this);
293 // centers the dialog window
294 Centre();
295 UpdateSqlSample();
296 return true;
297 }
298
CreateControls()299 void ComposerDialog::CreateControls()
300 {
301 //
302 // creating individual control and setting initial values
303 //
304 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
305 this->SetSizer(topSizer);
306 wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
307 topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
308 // the SQL sample row
309 wxBoxSizer *sqlBoxSizer = new wxBoxSizer(wxHORIZONTAL);
310 boxSizer->Add(sqlBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
311 wxStaticBox *sqlBox = new wxStaticBox(this, wxID_STATIC,
312 wxT("SQL statement"),
313 wxDefaultPosition,
314 wxDefaultSize);
315 wxBoxSizer *sqlSizer = new wxStaticBoxSizer(sqlBox, wxVERTICAL);
316 sqlBoxSizer->Add(sqlSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
317 SqlCtrl =
318 new wxTextCtrl(this, ID_QVC_SQL, wxT(""), wxDefaultPosition,
319 wxSize(600, 150),
320 wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL | wxTE_RICH);
321 sqlSizer->Add(SqlCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
322
323 // the tab control
324 TabCtrl =
325 new wxNotebook(this, ID_QVC_TAB, wxDefaultPosition, wxDefaultSize,
326 wxNB_TOP);
327 boxSizer->Add(TabCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
328 // tab - Page #1
329 Page1 = new ComposerMainPage();
330 Page1->Create(this);
331 TabCtrl->AddPage(Page1, wxT("Main"), true);
332 // tab - Page #2
333 Page2 = new ComposerFilterPage();
334 Page2->Create(this);
335 TabCtrl->AddPage(Page2, wxT("Filter"), true);
336 // tab - Page #3
337 Page3 = new ComposerOrderPage();
338 Page3->Create(this);
339 TabCtrl->AddPage(Page3, wxT("Order"), true);
340 // tab - Page #4
341 Page4 = new ComposerViewPage();
342 Page4->Create(this);
343 TabCtrl->AddPage(Page4, wxT("View"), true);
344
345 TabCtrl->ChangeSelection(0);
346
347 // appending the OK / CANCEL buttons
348 wxBoxSizer *btnSizer = new wxBoxSizer(wxHORIZONTAL);
349 boxSizer->Add(btnSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
350 wxButton *okBtn = new wxButton(this, wxID_OK, wxT("&Ok"));
351 btnSizer->Add(okBtn, 0, wxALIGN_LEFT | wxALL, 5);
352 wxButton *cancelBtn = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
353 btnSizer->Add(cancelBtn, 0, wxALIGN_LEFT | wxALL, 5);
354 // appending the event handlers
355 Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
356 (wxObjectEventFunction) & ComposerDialog::OnOk);
357 }
358
OnOk(wxCommandEvent & WXUNUSED (event))359 void ComposerDialog::OnOk(wxCommandEvent & WXUNUSED(event))
360 {
361 //
362 // all done:
363 //
364 if (IncompleteSql == true)
365 {
366 wxMessageBox(wxT
367 ("Your SQL statement isn't yet completed ...\n\nplease, check better and then retry"),
368 wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
369 return;
370 }
371 if (SpatialView == true && GeometryColumn.Len() == 0)
372 {
373 wxMessageBox(wxT
374 ("You MUST specify a Geometry Column to create a Spatial View ...\n\nplease, check better and then retry"),
375 wxT("spatialite_gui"), wxOK | wxICON_WARNING, this);
376 return;
377 }
378 PrepareSqlTriggers();
379 wxDialog::EndModal(wxID_OK);
380 }
381
Table1Status(bool ok)382 void ComposerDialog::Table1Status(bool ok)
383 {
384 //
385 // enabling/disabling dependent fields in following pages
386 //
387 Page2->Table1Status(ok);
388 Page3->Table1Status(ok);
389 Page4->Table1Status(ok);
390 UpdateSqlSample();
391 }
392
Table2Status(bool ok)393 void ComposerDialog::Table2Status(bool ok)
394 {
395 //
396 // enabling/disabling dependent fields in following pages
397 //
398 Page2->Table2Status(ok);
399 Page3->Table2Status(ok);
400 Page4->Table2Status(ok);
401 UpdateSqlSample();
402 }
403
SelectGeometryColumn()404 void ComposerDialog::SelectGeometryColumn()
405 {
406 //
407 // forcing the SpatialView Geometry Column to be selected anyway
408 //
409 wxString rowid = wxT("ROWID");
410 if (GeometryColumn.Len() > 0)
411 {
412 if (ViewGeomTable2 == true)
413 {
414 Column2List.SetState(GeometryColumn);
415 Page1->SelectGeometryColumn(GeometryColumn, true);
416 Column2List.SetState(rowid);
417 Page1->SelectGeometryColumn(rowid, true);
418 } else
419 {
420 Column1List.SetState(GeometryColumn);
421 Page1->SelectGeometryColumn(GeometryColumn, false);
422 Column1List.SetState(rowid);
423 Page1->SelectGeometryColumn(rowid, false);
424 }
425 }
426 }
427
IsDuplicateAlias(wxString & alias)428 bool ComposerDialog::IsDuplicateAlias(wxString & alias)
429 {
430 //
431 // checkink an alias name to be unique
432 //
433 AuxColumn *pC;
434 pC = Column1List.GetFirst();
435 while (pC)
436 {
437 if (pC->GetAliasName().CmpNoCase(alias) == 0)
438 return true;
439 pC = pC->GetNext();
440 }
441 pC = Column2List.GetFirst();
442 while (pC)
443 {
444 if (pC->GetAliasName().CmpNoCase(alias) == 0)
445 return true;
446 pC = pC->GetNext();
447 }
448 return false;
449 }
450
SetAliases()451 void ComposerDialog::SetAliases()
452 {
453 //
454 // setting up column alias names
455 //
456 AuxColumn *pC;
457 wxString alias;
458 int antiAlias;
459 char dummy[64];
460
461 // cleaning up the old alias names
462 pC = Column1List.GetFirst();
463 while (pC)
464 {
465 pC->SetAliasName(alias);
466 pC = pC->GetNext();
467 }
468 pC = Column2List.GetFirst();
469 while (pC)
470 {
471 pC->SetAliasName(alias);
472 pC = pC->GetNext();
473 }
474
475 // setting up the current alias names
476 pC = Column1List.GetFirst();
477 while (pC)
478 {
479 if (pC->IsSelected() == false)
480 {
481 pC = pC->GetNext();
482 continue;
483 }
484 alias = pC->GetName();
485 if (IsDuplicateAlias(alias) == true)
486 {
487 antiAlias = 1;
488 while (1)
489 {
490 sprintf(dummy, "_%d", antiAlias++);
491 alias = pC->GetName() + wxString::FromUTF8(dummy);
492 if (IsDuplicateAlias(alias) == false)
493 break;
494 }
495 }
496 pC->SetAliasName(alias);
497 if (ViewGeomTable2 == false)
498 {
499 if (pC->GetName().CmpNoCase(GeometryColumn) == 0)
500 GeometryColumnAlias = pC->GetAliasName();
501 if (pC->GetName() == wxString::FromUTF8("ROWID"))
502 GeometryRowidAlias = pC->GetAliasName();
503 }
504 pC = pC->GetNext();
505 }
506 pC = Column2List.GetFirst();
507 while (pC)
508 {
509 if (pC->IsSelected() == false)
510 {
511 pC = pC->GetNext();
512 continue;
513 }
514 alias = pC->GetName();
515 if (IsDuplicateAlias(alias) == true)
516 {
517 antiAlias = 1;
518 while (1)
519 {
520 sprintf(dummy, "_%d", antiAlias++);
521 alias = pC->GetName() + wxString::FromUTF8(dummy);
522 if (IsDuplicateAlias(alias) == false)
523 break;
524 }
525 }
526 pC->SetAliasName(alias);
527 if (ViewGeomTable2 == true)
528 {
529 if (pC->GetName().CmpNoCase(GeometryColumn) == 0)
530 GeometryColumnAlias = pC->GetAliasName();
531 if (pC->GetName() == wxString::FromUTF8("ROWID"))
532 GeometryRowidAlias = pC->GetAliasName();
533 }
534 pC = pC->GetNext();
535 }
536 }
537
UpdateSqlSample()538 void ComposerDialog::UpdateSqlSample()
539 {
540 //
541 // composing the SQL statement
542 //
543 AuxColumn *pCol;
544 bool comma;
545 int markStart[4192];
546 int markStop[4192];
547 int markStyle[4192];
548 int nextMark = 0;
549 int base;
550 char xname[1024];
551 wxString undefined = wxT("~???~");
552 wxString selectedColumns;
553 IncompleteSql = false;
554 SetAliases();
555 SqlSample = wxT("");
556
557 if (PlainView == true || SpatialView == true)
558 {
559 // CREATE VIEW ... AS
560 markStyle[nextMark] = 2;
561 markStart[nextMark] = 0;
562 SqlSample += wxT("CREATE VIEW");
563 markStop[nextMark++] = SqlSample.Len();
564 if (ViewName.Len() == 0)
565 {
566 SqlSample += wxT(" ");
567 markStyle[nextMark] = 1;
568 markStart[nextMark] = SqlSample.Len();
569 SqlSample += undefined;
570 IncompleteSql = true;
571 markStop[nextMark++] = SqlSample.Len();
572 SqlSample += wxT(" ");
573 } else
574 {
575 SqlSample += wxT(" ");
576 strcpy(xname, ViewName.ToUTF8());
577 MainFrame->DoubleQuotedSql(xname);
578 SqlSample += wxString::FromUTF8(xname);
579 SqlSample += wxT(" ");
580 }
581 markStyle[nextMark] = 2;
582 markStart[nextMark] = SqlSample.Len();
583 SqlSample += wxT("AS");
584 markStop[nextMark++] = SqlSample.Len();
585 SqlSample += wxT("\n");
586 }
587
588 markStyle[nextMark] = 2;
589 markStart[nextMark] = SqlSample.Len();
590 int startSelect = SqlSample.Len();
591 SqlSample += wxT("SELECT");
592 markStop[nextMark++] = SqlSample.Len();
593 SqlSample += wxT(" ");
594 base = SqlSample.Len();
595 // SELECT a,b,c [from the main table]
596 int selectCount = SqlSample.Len() - startSelect;
597 comma = false;
598 pCol = Column1List.GetFirst();
599 while (pCol)
600 {
601 if (pCol->IsSelected() == true)
602 {
603 if (comma)
604 {
605 markStyle[nextMark] = 2;
606 markStart[nextMark] = base + selectedColumns.Len();
607 selectedColumns += wxT(",");
608 markStop[nextMark++] = base + selectedColumns.Len();
609 if (selectCount > 50)
610 {
611 selectedColumns += wxT("\n ");
612 selectCount = 4;
613 } else
614 {
615 selectedColumns += wxT(" ");
616 selectCount += 2;
617 }
618 }
619 wxString col;
620 int baseCol = base + selectedColumns.Len();
621 if (Table2Enabled == false)
622 ;
623 else
624 {
625 if (TableAlias1.Len() == 0)
626 {
627 strcpy(xname, TableName1.ToUTF8());
628 MainFrame->DoubleQuotedSql(xname);
629 col += wxString::FromUTF8(xname);
630 col += wxT(".");
631 } else
632 {
633 strcpy(xname, TableAlias1.ToUTF8());
634 MainFrame->DoubleQuotedSql(xname);
635 col += wxString::FromUTF8(xname);
636 col += wxT(".");
637 }
638 }
639 strcpy(xname, pCol->GetName().ToUTF8());
640 MainFrame->DoubleQuotedSql(xname);
641 col += wxString::FromUTF8(xname);
642 col += wxT(" ");
643 markStyle[nextMark] = 2;
644 markStart[nextMark] = baseCol + col.Len();
645 col += wxT("AS");
646 markStop[nextMark++] = baseCol + col.Len();
647 col += wxT(" ");
648 strcpy(xname, pCol->GetAliasName().ToUTF8());
649 MainFrame->DoubleQuotedSql(xname);
650 col += wxString::FromUTF8(xname);
651 selectCount += col.Len();
652 selectedColumns += col;
653 comma = true;
654 }
655 pCol = pCol->GetNext();
656 }
657 if (Table2Enabled == true && Column2List.HasSelectedColumns() == true)
658 {
659 // SELECT a,b,c [from Table#2]
660 pCol = Column2List.GetFirst();
661 while (pCol)
662 {
663 if (pCol->IsSelected() == true)
664 {
665 if (comma)
666 {
667 markStyle[nextMark] = 2;
668 markStart[nextMark] = base + selectedColumns.Len();
669 selectedColumns += wxT(",");
670 markStop[nextMark++] = base + selectedColumns.Len();
671 }
672 wxString col;
673 int baseCol = base + selectedColumns.Len();
674 if (selectCount > 50)
675 {
676 col += wxT("\n ");
677 selectCount = 0;
678 } else
679 {
680 col += wxT(" ");
681 selectCount += 2;
682 }
683 if (TableAlias2.Len() == 0)
684 {
685 strcpy(xname, TableName2.ToUTF8());
686 MainFrame->DoubleQuotedSql(xname);
687 col += wxString::FromUTF8(xname);
688 col += wxT(".");
689 } else
690 {
691 strcpy(xname, TableAlias2.ToUTF8());
692 MainFrame->DoubleQuotedSql(xname);
693 col += wxString::FromUTF8(xname);
694 col += wxT(".");
695 }
696 strcpy(xname, pCol->GetName().ToUTF8());
697 MainFrame->DoubleQuotedSql(xname);
698 col += wxString::FromUTF8(xname);
699 col += wxT(" ");
700 markStyle[nextMark] = 2;
701 markStart[nextMark] = baseCol + col.Len();
702 col += wxT("AS");
703 markStop[nextMark++] = baseCol + col.Len();
704 col += wxT(" ");
705 strcpy(xname, pCol->GetAliasName().ToUTF8());
706 MainFrame->DoubleQuotedSql(xname);
707 col += wxString::FromUTF8(xname);
708 selectCount += col.Len();
709 selectedColumns += col;
710 comma = true;
711 }
712 pCol = pCol->GetNext();
713 }
714 }
715 if (selectedColumns.Len() == 0)
716 {
717 markStyle[nextMark] = 1;
718 markStart[nextMark] = SqlSample.Len();
719 SqlSample += undefined;
720 IncompleteSql = true;
721 markStop[nextMark++] = SqlSample.Len();
722 } else
723 SqlSample += selectedColumns;
724
725 // the FROM clause
726 SqlSample += wxT("\n");
727 markStyle[nextMark] = 2;
728 markStart[nextMark] = SqlSample.Len();
729 SqlSample += wxT("FROM");
730 markStop[nextMark++] = SqlSample.Len();
731 SqlSample += wxT(" ");
732 if (TableName1.Len() == 0)
733 {
734 markStyle[nextMark] = 1;
735 markStart[nextMark] = SqlSample.Len();
736 SqlSample += undefined;
737 IncompleteSql = true;
738 markStop[nextMark++] = SqlSample.Len();
739 } else
740 {
741 base = SqlSample.Len();
742 strcpy(xname, TableName1.ToUTF8());
743 MainFrame->DoubleQuotedSql(xname);
744 wxString from = wxString::FromUTF8(xname);
745 if (Table2Enabled == false)
746 ;
747 else
748 {
749 if (TableAlias1.Len() == 0)
750 ;
751 else
752 {
753 from += wxT(" ");
754 markStyle[nextMark] = 2;
755 markStart[nextMark] = base + from.Len();
756 from += wxT("AS");
757 markStop[nextMark++] = base + from.Len();
758 from += wxT(" ");
759 strcpy(xname, TableAlias1.ToUTF8());
760 MainFrame->DoubleQuotedSql(xname);
761 from += wxString::FromUTF8(xname);
762 }
763 }
764 SqlSample += from;
765 }
766 if (Table2Enabled == true)
767 {
768 SqlSample += wxT("\n");
769 int onIniJoin = SqlSample.Len();
770 if (LeftJoin == true)
771 {
772 markStyle[nextMark] = 2;
773 markStart[nextMark] = SqlSample.Len();
774 SqlSample += wxT("LEFT JOIN");
775 markStop[nextMark++] = SqlSample.Len();
776 } else
777 {
778 markStyle[nextMark] = 2;
779 markStart[nextMark] = SqlSample.Len();
780 SqlSample += wxT("JOIN");
781 markStop[nextMark++] = SqlSample.Len();
782 }
783 SqlSample += wxT(" ");
784 if (TableName2.Len() == 0)
785 {
786 markStyle[nextMark] = 1;
787 markStart[nextMark] = SqlSample.Len();
788 SqlSample += undefined;
789 IncompleteSql = true;
790 markStop[nextMark++] = SqlSample.Len();
791 } else
792 {
793 base = SqlSample.Len();
794 strcpy(xname, TableName2.ToUTF8());
795 MainFrame->DoubleQuotedSql(xname);
796 wxString join = wxString::FromUTF8(xname);
797 if (TableAlias2.Len() == 0)
798 ;
799 else
800 {
801 join += wxT(" ");
802 markStyle[nextMark] = 2;
803 markStart[nextMark] = base + join.Len();
804 join += wxT("AS");
805 markStop[nextMark++] = base + join.Len();
806 join += wxT(" ");
807 strcpy(xname, TableAlias2.ToUTF8());
808 MainFrame->DoubleQuotedSql(xname);
809 join += wxString::FromUTF8(xname);
810 }
811 int onCount = SqlSample.Len() - onIniJoin;
812 int baseMatch = join.Len();
813 wxString match;
814 bool isUsing = false;
815 if (Match2Enabled == false && Match3Enabled == false
816 && Match1Table1 == Match1Table2)
817 isUsing = true;
818 if (Match2Enabled == true && Match3Enabled == false
819 && Match1Table1 == Match1Table2 && Match2Table1 == Match2Table2)
820 isUsing = true;
821 if (Match2Enabled == false && Match3Enabled == true
822 && Match1Table1 == Match1Table2 && Match3Table1 == Match3Table2)
823 isUsing = true;
824 if (Match2Enabled == true && Match3Enabled == true
825 && Match1Table1 == Match1Table2 && Match2Table1 == Match2Table2
826 && Match3Table1 == Match3Table2)
827 isUsing = true;
828 if (isUsing == true)
829 {
830 match = wxT(" ");
831 markStyle[nextMark] = 2;
832 markStart[nextMark] = base + baseMatch + match.Len();
833 match += wxT("USING (");
834 markStop[nextMark++] = base + baseMatch + match.Len();
835 if (Match1Table1.Len() == 0)
836 {
837 markStyle[nextMark] = 1;
838 markStart[nextMark] = base + baseMatch + match.Len();
839 match += undefined;
840 IncompleteSql = true;
841 markStop[nextMark++] = base + baseMatch + match.Len();
842 } else
843 {
844 strcpy(xname, Match1Table1.ToUTF8());
845 MainFrame->DoubleQuotedSql(xname);
846 match += wxString::FromUTF8(xname);
847 }
848 if (Match2Enabled == true)
849 {
850 markStyle[nextMark] = 2;
851 markStart[nextMark] = base + baseMatch + match.Len();
852 match += wxT(", ");
853 markStop[nextMark++] = base + baseMatch + match.Len();
854 if (Match2Table1.Len() == 0)
855 {
856 markStyle[nextMark] = 1;
857 markStart[nextMark] = base + baseMatch + match.Len();
858 match += undefined;
859 IncompleteSql = true;
860 markStop[nextMark++] = base + baseMatch + match.Len();
861 } else
862 {
863 strcpy(xname, Match2Table1.ToUTF8());
864 MainFrame->DoubleQuotedSql(xname);
865 match += wxString::FromUTF8(xname);
866 }
867 }
868 if (Match3Enabled == true)
869 {
870 markStyle[nextMark] = 2;
871 markStart[nextMark] = base + baseMatch + match.Len();
872 match += wxT(", ");
873 markStop[nextMark++] = base + baseMatch + match.Len();
874 if (Match3Table1.Len() == 0)
875 {
876 markStyle[nextMark] = 1;
877 markStart[nextMark] = base + baseMatch + match.Len();
878 match += undefined;
879 IncompleteSql = true;
880 markStop[nextMark++] = base + baseMatch + match.Len();
881 } else
882 {
883 strcpy(xname, Match3Table1.ToUTF8());
884 MainFrame->DoubleQuotedSql(xname);
885 match += wxString::FromUTF8(xname);
886 }
887 }
888 markStyle[nextMark] = 2;
889 markStart[nextMark] = base + baseMatch + match.Len();
890 match += wxT(")");
891 markStop[nextMark++] = base + baseMatch + match.Len();
892 } else
893 {
894 match = wxT(" ");
895 markStyle[nextMark] = 2;
896 markStart[nextMark] = base + baseMatch + match.Len();
897 match += wxT("ON (");
898 markStop[nextMark++] = base + baseMatch + match.Len();
899 int baseCondition = match.Len();
900 wxString condition;
901 if (Match1Table1.Len() > 0 || Match1Table2.Len() > 0)
902 {
903 if (Match1Table1.Len() == 0)
904 {
905 markStyle[nextMark] = 1;
906 markStart[nextMark] =
907 base + baseMatch + baseCondition + condition.Len();
908 condition += undefined;
909 IncompleteSql = true;
910 markStop[nextMark++] =
911 base + baseMatch + baseCondition + condition.Len();
912 } else
913 {
914 if (TableAlias1.Len() == 0)
915 {
916 strcpy(xname, TableName1.ToUTF8());
917 MainFrame->DoubleQuotedSql(xname);
918 condition += wxString::FromUTF8(xname);
919 } else
920 {
921 strcpy(xname, TableAlias1.ToUTF8());
922 MainFrame->DoubleQuotedSql(xname);
923 condition += wxString::FromUTF8(xname);
924 }
925 condition += wxT(".");
926 strcpy(xname, Match1Table1.ToUTF8());
927 MainFrame->DoubleQuotedSql(xname);
928 condition += wxString::FromUTF8(xname);
929 }
930 condition += wxT(" = ");
931 if (Match1Table2.Len() == 0)
932 {
933 markStyle[nextMark] = 1;
934 markStart[nextMark] =
935 base + baseMatch + baseCondition + condition.Len();
936 condition += undefined;
937 IncompleteSql = true;
938 markStop[nextMark++] =
939 base + baseMatch + baseCondition + condition.Len();
940 } else
941 {
942 if (TableAlias2.Len() == 0)
943 {
944 strcpy(xname, TableName2.ToUTF8());
945 MainFrame->DoubleQuotedSql(xname);
946 condition += wxString::FromUTF8(xname);
947 } else
948 {
949 strcpy(xname, TableAlias2.ToUTF8());
950 MainFrame->DoubleQuotedSql(xname);
951 condition += wxString::FromUTF8(xname);
952 }
953 condition += wxT(".");
954 strcpy(xname, Match1Table2.ToUTF8());
955 MainFrame->DoubleQuotedSql(xname);
956 condition += wxString::FromUTF8(xname);
957 }
958 onCount += condition.Len();
959 }
960 if (Match2Enabled
961 && (Match2Table1.Len() > 0 || Match2Table2.Len() > 0))
962 {
963 if (onCount > 30)
964 {
965 condition += wxT("\n ");
966 onCount = 4;
967 } else
968 condition += wxT(" ");
969 markStyle[nextMark] = 2;
970 markStart[nextMark] =
971 base + baseMatch + baseCondition + condition.Len();
972 condition += wxT("AND");
973 markStop[nextMark++] =
974 base + baseMatch + baseCondition + condition.Len();
975 condition += wxT(" ");
976 if (Match2Table1.Len() == 0)
977 {
978 markStyle[nextMark] = 1;
979 markStart[nextMark] =
980 base + baseMatch + baseCondition + condition.Len();
981 condition += undefined;
982 IncompleteSql = true;
983 markStop[nextMark++] =
984 base + baseMatch + baseCondition + condition.Len();
985 } else
986 {
987 if (TableAlias1.Len() == 0)
988 {
989 strcpy(xname, TableName1.ToUTF8());
990 MainFrame->DoubleQuotedSql(xname);
991 condition += wxString::FromUTF8(xname);
992 } else
993 {
994 strcpy(xname, TableAlias1.ToUTF8());
995 MainFrame->DoubleQuotedSql(xname);
996 condition += wxString::FromUTF8(xname);
997 }
998 condition += wxT(".");
999 strcpy(xname, Match2Table1.ToUTF8());
1000 MainFrame->DoubleQuotedSql(xname);
1001 condition += wxString::FromUTF8(xname);
1002 }
1003 condition += wxT(" = ");
1004 if (Match2Table2.Len() == 0)
1005 {
1006 markStyle[nextMark] = 1;
1007 markStart[nextMark] =
1008 base + baseMatch + baseCondition + condition.Len();
1009 condition += undefined;
1010 IncompleteSql = true;
1011 markStop[nextMark++] =
1012 base + baseMatch + baseCondition + condition.Len();
1013 } else
1014 {
1015 if (TableAlias2.Len() == 0)
1016 {
1017 strcpy(xname, TableName2.ToUTF8());
1018 MainFrame->DoubleQuotedSql(xname);
1019 condition += wxString::FromUTF8(xname);
1020 } else
1021 {
1022 strcpy(xname, TableAlias2.ToUTF8());
1023 MainFrame->DoubleQuotedSql(xname);
1024 condition += wxString::FromUTF8(xname);
1025 }
1026 condition += wxT(".");
1027 strcpy(xname, Match2Table2.ToUTF8());
1028 MainFrame->DoubleQuotedSql(xname);
1029 condition += wxString::FromUTF8(xname);
1030 }
1031 onCount += condition.Len();
1032 }
1033 if (Match3Enabled
1034 && (Match3Table1.Len() > 0 || Match3Table2.Len() > 0))
1035 {
1036 if (onCount > 30)
1037 {
1038 condition += wxT("\n ");
1039 onCount = 4;
1040 } else
1041 condition += wxT(" ");
1042 markStyle[nextMark] = 2;
1043 markStart[nextMark] =
1044 base + baseMatch + baseCondition + condition.Len();
1045 condition += wxT("AND");
1046 markStop[nextMark++] =
1047 base + baseMatch + baseCondition + condition.Len();
1048 condition += wxT(" ");
1049 if (Match3Table1.Len() == 0)
1050 {
1051 markStyle[nextMark] = 1;
1052 markStart[nextMark] =
1053 base + baseMatch + baseCondition + condition.Len();
1054 condition += undefined;
1055 IncompleteSql = true;
1056 markStop[nextMark++] =
1057 base + baseMatch + baseCondition + condition.Len();
1058 } else
1059 {
1060 if (TableAlias1.Len() == 0)
1061 {
1062 strcpy(xname, TableName1.ToUTF8());
1063 MainFrame->DoubleQuotedSql(xname);
1064 condition += wxString::FromUTF8(xname);
1065 } else
1066 {
1067 strcpy(xname, TableAlias1.ToUTF8());
1068 MainFrame->DoubleQuotedSql(xname);
1069 condition += wxString::FromUTF8(xname);
1070 }
1071 condition += wxT(".");
1072 strcpy(xname, Match3Table1.ToUTF8());
1073 MainFrame->DoubleQuotedSql(xname);
1074 condition += wxString::FromUTF8(xname);
1075 }
1076 condition += wxT(" = ");
1077 if (Match3Table2.Len() == 0)
1078 {
1079 markStyle[nextMark] = 1;
1080 markStart[nextMark] =
1081 base + baseMatch + baseCondition + condition.Len();
1082 condition += undefined;
1083 IncompleteSql = true;
1084 markStop[nextMark++] =
1085 base + baseMatch + baseCondition + condition.Len();
1086 } else
1087 {
1088 if (TableAlias2.Len() == 0)
1089 {
1090 strcpy(xname, TableName2.ToUTF8());
1091 MainFrame->DoubleQuotedSql(xname);
1092 condition += wxString::FromUTF8(xname);
1093 } else
1094 {
1095 strcpy(xname, TableAlias2.ToUTF8());
1096 MainFrame->DoubleQuotedSql(xname);
1097 condition += wxString::FromUTF8(xname);
1098 }
1099 condition += wxT(".");
1100 strcpy(xname, Match3Table2.ToUTF8());
1101 MainFrame->DoubleQuotedSql(xname);
1102 condition += wxString::FromUTF8(xname);
1103 }
1104 }
1105 if (condition.Len() == 0)
1106 {
1107 match += undefined;
1108 IncompleteSql = true;
1109 } else
1110 match += condition;
1111 markStyle[nextMark] = 2;
1112 markStart[nextMark] = base + baseMatch + match.Len();
1113 match += wxT(")");
1114 markStop[nextMark++] = base + baseMatch + match.Len();
1115 }
1116 if (match.Len() == 0)
1117 {
1118 markStyle[nextMark] = 1;
1119 markStart[nextMark] = base + join.Len();
1120 join += undefined;
1121 IncompleteSql = true;
1122 markStop[nextMark++] = base + join.Len();
1123 } else
1124 join += match;
1125 SqlSample += join;
1126 }
1127 }
1128 if (Where1Enabled == true || Where2Enabled == true || Where3Enabled == true)
1129 {
1130 // the WHERE clause
1131 bool openBraket1 = false;
1132 bool openBraket2 = false;
1133 bool closeBraket3 = false;
1134 bool closeBraket4 = false;
1135 SqlSample += wxT("\n");
1136 int whereStart = SqlSample.Len();
1137 markStyle[nextMark] = 2;
1138 markStart[nextMark] = SqlSample.Len();
1139 SqlSample += wxT("WHERE");
1140 markStop[nextMark++] = SqlSample.Len();
1141 SqlSample += wxT(" ");
1142 int whereCount = SqlSample.Len() - whereStart;
1143 if (Where1Enabled == true && Where2Enabled == true
1144 && Where3Enabled == true)
1145 {
1146 if (AndOr12 == false && AndOr23 == true)
1147 {
1148 openBraket1 = true;
1149 closeBraket3 = true;
1150 }
1151 if (AndOr12 == true && AndOr23 == false)
1152 {
1153 openBraket2 = true;
1154 closeBraket4 = true;
1155 }
1156 }
1157 if (Where1Enabled == true)
1158 {
1159 int clauseBase = SqlSample.Len();
1160 wxString clause;
1161 if (openBraket1 == true)
1162 {
1163 markStyle[nextMark] = 2;
1164 markStart[nextMark] = clauseBase + clause.Len();
1165 clause += wxT("(");
1166 markStop[nextMark++] = clauseBase + clause.Len();
1167 }
1168 if (Where1Column.Len() == 0)
1169 {
1170 markStyle[nextMark] = 1;
1171 markStart[nextMark] = clauseBase + clause.Len();
1172 clause += undefined;
1173 IncompleteSql = true;
1174 markStop[nextMark++] = clauseBase + clause.Len();
1175 } else
1176 {
1177 if (Table2Enabled == false)
1178 {
1179 strcpy(xname, Where1Column.ToUTF8());
1180 MainFrame->DoubleQuotedSql(xname);
1181 clause += wxString::FromUTF8(xname);
1182 } else
1183 {
1184 if (Where1Table2 == true)
1185 {
1186 if (TableAlias2.Len() == 0)
1187 {
1188 strcpy(xname, TableName2.ToUTF8());
1189 MainFrame->DoubleQuotedSql(xname);
1190 clause += wxString::FromUTF8(xname);
1191 } else
1192 {
1193 strcpy(xname, TableAlias2.ToUTF8());
1194 MainFrame->DoubleQuotedSql(xname);
1195 clause += wxString::FromUTF8(xname);
1196 }
1197 clause += wxT(".");
1198 clause += Where1Column;
1199 } else
1200 {
1201 if (TableAlias1.Len() == 0)
1202 clause += TableName1;
1203 else
1204 clause += TableAlias1;
1205 clause += wxT(".");
1206 clause += Where1Column;
1207 }
1208 }
1209 }
1210 clause += wxT(" ");
1211 if (Where1Operator.Len() == 0)
1212 {
1213 markStyle[nextMark] = 1;
1214 markStart[nextMark] = clauseBase + clause.Len();
1215 clause += undefined;
1216 IncompleteSql = true;
1217 markStop[nextMark++] = clauseBase + clause.Len();
1218 } else
1219 {
1220 markStyle[nextMark] = 2;
1221 markStart[nextMark] = clauseBase + clause.Len();
1222 clause += Where1Operator;
1223 markStop[nextMark++] = clauseBase + clause.Len();
1224 }
1225 if (Where1Operator == wxT("IS NULL")
1226 || Where1Operator == wxT("IS NOT NULL"))
1227 ;
1228 else if (Where1Operator == wxT("IN"))
1229 {
1230 clause += wxT(" ");
1231 markStyle[nextMark] = 2;
1232 markStart[nextMark] = clauseBase + clause.Len();
1233 clause += wxT("(");
1234 markStop[nextMark++] = clauseBase + clause.Len();
1235 int listBase = clauseBase + clause.Len();
1236 wxString cleanList;
1237 SqlCleanList(Where1Value, cleanList, markStyle, markStart,
1238 markStop, &nextMark, listBase);
1239 clause += cleanList;
1240 markStyle[nextMark] = 2;
1241 markStart[nextMark] = clauseBase + clause.Len();
1242 clause += wxT(")");
1243 markStop[nextMark++] = clauseBase + clause.Len();
1244 } else
1245 {
1246 clause += wxT(" ");
1247 bool isNumber = false;
1248 long lngTest;
1249 double dblTest;
1250 if (Where1Value.ToLong(&lngTest) == true)
1251 isNumber = true;
1252 if (Where1Value.ToDouble(&dblTest) == true)
1253 isNumber = true;
1254 bool noQuote;
1255 wxString cleanSql;
1256 if (isNumber == false)
1257 noQuote = SqlCleanString(Where1Value, cleanSql);
1258 else
1259 {
1260 noQuote = true;
1261 cleanSql = Where1Value;
1262 }
1263 if (noQuote == false)
1264 clause += wxT("'");
1265 clause += cleanSql;
1266 if (noQuote == false)
1267 clause += wxT("'");
1268 }
1269 whereCount += clause.Len();
1270 SqlSample += clause;
1271 }
1272 if (Where2Enabled == true)
1273 {
1274 int clauseBase = SqlSample.Len();
1275 wxString clause;
1276 if (whereCount > 30)
1277 {
1278 clause = wxT("\n ");
1279 whereCount = 4;
1280 } else
1281 clause = wxT(" ");
1282 markStyle[nextMark] = 2;
1283 markStart[nextMark] = clauseBase + clause.Len();
1284 if (AndOr12 == true)
1285 clause += wxT("AND");
1286 else
1287 clause += wxT("OR");
1288 markStop[nextMark++] = clauseBase + clause.Len();
1289 clause += wxT(" ");
1290 if (openBraket2 == true)
1291 {
1292 markStyle[nextMark] = 2;
1293 markStart[nextMark] = clauseBase + clause.Len();
1294 clause += wxT("(");
1295 markStop[nextMark++] = clauseBase + clause.Len();
1296 }
1297 if (Where2Column.Len() == 0)
1298 {
1299 markStyle[nextMark] = 1;
1300 markStart[nextMark] = clauseBase + clause.Len();
1301 clause += undefined;
1302 IncompleteSql = true;
1303 markStop[nextMark++] = clauseBase + clause.Len();
1304 } else
1305 {
1306 if (Table2Enabled == false)
1307 {
1308 strcpy(xname, Where2Column.ToUTF8());
1309 MainFrame->DoubleQuotedSql(xname);
1310 clause += wxString::FromUTF8(xname);
1311 } else
1312 {
1313 if (Where2Table2 == true)
1314 {
1315 if (TableAlias2.Len() == 0)
1316 {
1317 strcpy(xname, TableName2.ToUTF8());
1318 MainFrame->DoubleQuotedSql(xname);
1319 clause += wxString::FromUTF8(xname);
1320 } else
1321 {
1322 strcpy(xname, TableAlias2.ToUTF8());
1323 MainFrame->DoubleQuotedSql(xname);
1324 clause += wxString::FromUTF8(xname);
1325 }
1326 clause += wxT(".");
1327 strcpy(xname, Where2Column.ToUTF8());
1328 MainFrame->DoubleQuotedSql(xname);
1329 clause += wxString::FromUTF8(xname);
1330 } else
1331 {
1332 if (TableAlias1.Len() == 0)
1333 {
1334 strcpy(xname, TableName1.ToUTF8());
1335 MainFrame->DoubleQuotedSql(xname);
1336 clause += wxString::FromUTF8(xname);
1337 } else
1338 {
1339 strcpy(xname, TableAlias1.ToUTF8());
1340 MainFrame->DoubleQuotedSql(xname);
1341 clause += wxString::FromUTF8(xname);
1342 }
1343 clause += wxT(".");
1344 strcpy(xname, Where2Column.ToUTF8());
1345 MainFrame->DoubleQuotedSql(xname);
1346 clause += wxString::FromUTF8(xname);
1347 }
1348 }
1349 }
1350 clause += wxT(" ");
1351 if (Where2Operator.Len() == 0)
1352 {
1353 markStyle[nextMark] = 1;
1354 markStart[nextMark] = clauseBase + clause.Len();
1355 clause += undefined;
1356 IncompleteSql = true;
1357 markStop[nextMark++] = clauseBase + clause.Len();
1358 } else
1359 {
1360 markStyle[nextMark] = 2;
1361 markStart[nextMark] = clauseBase + clause.Len();
1362 clause += Where2Operator;
1363 markStop[nextMark++] = clauseBase + clause.Len();
1364 }
1365 if (Where2Operator == wxT("IS NULL")
1366 || Where2Operator == wxT("IS NOT NULL"))
1367 ;
1368 else
1369 {
1370 clause += wxT(" ");
1371 bool isNumber = false;
1372 long lngTest;
1373 double dblTest;
1374 if (Where2Value.ToLong(&lngTest) == true)
1375 isNumber = true;
1376 if (Where2Value.ToDouble(&dblTest) == true)
1377 isNumber = true;
1378 bool noQuote;
1379 wxString cleanSql;
1380 if (isNumber == false)
1381 noQuote = SqlCleanString(Where2Value, cleanSql);
1382 else
1383 {
1384 noQuote = true;
1385 cleanSql = Where2Value;
1386 }
1387 if (noQuote == false)
1388 clause += wxT("'");
1389 clause += cleanSql;
1390 if (noQuote == false)
1391 clause += wxT("'");
1392 }
1393 if (closeBraket3 == true)
1394 {
1395 markStyle[nextMark] = 2;
1396 markStart[nextMark] = clauseBase + clause.Len();
1397 clause += wxT(")");
1398 markStop[nextMark++] = clauseBase + clause.Len();
1399 }
1400 whereCount += clause.Len();
1401 SqlSample += clause;
1402 }
1403 if (Where3Enabled == true)
1404 {
1405 int clauseBase = SqlSample.Len();
1406 wxString clause;
1407 if (whereCount > 30)
1408 {
1409 clause = wxT("\n ");
1410 whereCount = 4;
1411 } else
1412 clause = wxT(" ");
1413 markStyle[nextMark] = 2;
1414 markStart[nextMark] = clauseBase + clause.Len();
1415 if (AndOr23 == true)
1416 clause += wxT("AND");
1417 else
1418 clause += wxT("OR");
1419 markStop[nextMark++] = clauseBase + clause.Len();
1420 clause += wxT(" ");
1421 if (Where3Column.Len() == 0)
1422 {
1423 markStyle[nextMark] = 1;
1424 markStart[nextMark] = clauseBase + clause.Len();
1425 clause += undefined;
1426 IncompleteSql = true;
1427 markStop[nextMark++] = clauseBase + clause.Len();
1428 } else
1429 {
1430 if (Table2Enabled == false)
1431 {
1432 strcpy(xname, Where3Column.ToUTF8());
1433 MainFrame->DoubleQuotedSql(xname);
1434 clause += wxString::FromUTF8(xname);
1435 } else
1436 {
1437 if (Where3Table2 == true)
1438 {
1439 if (TableAlias2.Len() == 0)
1440 {
1441 strcpy(xname, TableName2.ToUTF8());
1442 MainFrame->DoubleQuotedSql(xname);
1443 clause += wxString::FromUTF8(xname);
1444 } else
1445 {
1446 strcpy(xname, TableAlias2.ToUTF8());
1447 MainFrame->DoubleQuotedSql(xname);
1448 clause += wxString::FromUTF8(xname);
1449 }
1450 clause += wxT(".");
1451 strcpy(xname, Where3Column.ToUTF8());
1452 MainFrame->DoubleQuotedSql(xname);
1453 clause += wxString::FromUTF8(xname);
1454 } else
1455 {
1456 if (TableAlias1.Len() == 0)
1457 {
1458 strcpy(xname, TableName1.ToUTF8());
1459 MainFrame->DoubleQuotedSql(xname);
1460 clause += wxString::FromUTF8(xname);
1461 } else
1462 {
1463 strcpy(xname, TableAlias1.ToUTF8());
1464 MainFrame->DoubleQuotedSql(xname);
1465 clause += wxString::FromUTF8(xname);
1466 }
1467 clause += wxT(".");
1468 strcpy(xname, Where3Column.ToUTF8());
1469 MainFrame->DoubleQuotedSql(xname);
1470 clause += wxString::FromUTF8(xname);
1471 }
1472 }
1473 }
1474 clause += wxT(" ");
1475 if (Where3Operator.Len() == 0)
1476 {
1477 markStyle[nextMark] = 1;
1478 markStart[nextMark] = clauseBase + clause.Len();
1479 clause += undefined;
1480 IncompleteSql = true;
1481 markStop[nextMark++] = clauseBase + clause.Len();
1482 } else
1483 {
1484 markStyle[nextMark] = 2;
1485 markStart[nextMark] = clauseBase + clause.Len();
1486 clause += Where3Operator;
1487 markStop[nextMark++] = clauseBase + clause.Len();
1488 }
1489 if (Where3Operator == wxT("IS NULL")
1490 || Where3Operator == wxT("IS NOT NULL"))
1491 ;
1492 else
1493 {
1494 clause += wxT(" ");
1495 bool isNumber = false;
1496 long lngTest;
1497 double dblTest;
1498 if (Where3Value.ToLong(&lngTest) == true)
1499 isNumber = true;
1500 if (Where3Value.ToDouble(&dblTest) == true)
1501 isNumber = true;
1502 bool noQuote;
1503 wxString cleanSql;
1504 if (isNumber == false)
1505 noQuote = SqlCleanString(Where3Value, cleanSql);
1506 else
1507 {
1508 noQuote = true;
1509 cleanSql = Where3Value;
1510 }
1511 if (noQuote == false)
1512 clause += wxT("'");
1513 clause += cleanSql;
1514 if (noQuote == false)
1515 clause += wxT("'");
1516 }
1517 if (closeBraket4 == true)
1518 {
1519 markStyle[nextMark] = 2;
1520 markStart[nextMark] = clauseBase + clause.Len();
1521 clause += wxT(")");
1522 markStop[nextMark++] = clauseBase + clause.Len();
1523 }
1524 SqlSample += clause;
1525 }
1526 }
1527 if (Order1Enabled == true || Order2Enabled == true || Order3Enabled == true
1528 || Order4Enabled == true)
1529 {
1530 // the ORDER BY clause
1531 bool comma = false;
1532 SqlSample += wxT("\n");
1533 int orderStart = SqlSample.Len();
1534 markStyle[nextMark] = 2;
1535 markStart[nextMark] = SqlSample.Len();
1536 SqlSample += wxT("ORDER BY");
1537 markStop[nextMark++] = SqlSample.Len();
1538 SqlSample += wxT(" ");
1539 int orderCount = SqlSample.Len() - orderStart;
1540 if (Order1Enabled == true)
1541 {
1542 int orderBase = SqlSample.Len();
1543 wxString order;
1544 if (Order1Column.Len() == 0)
1545 {
1546 markStyle[nextMark] = 1;
1547 markStart[nextMark] = orderBase + order.Len();
1548 order += undefined;
1549 IncompleteSql = true;
1550 markStop[nextMark++] = orderBase + order.Len();
1551 } else
1552 {
1553 if (Table2Enabled == false)
1554 {
1555 strcpy(xname, Order1Column.ToUTF8());
1556 MainFrame->DoubleQuotedSql(xname);
1557 order += wxString::FromUTF8(xname);
1558 } else
1559 {
1560 if (Order1Table2 == true)
1561 {
1562 if (TableAlias2.Len() == 0)
1563 {
1564 strcpy(xname, TableName2.ToUTF8());
1565 MainFrame->DoubleQuotedSql(xname);
1566 order += wxString::FromUTF8(xname);
1567 } else
1568 {
1569 strcpy(xname, TableAlias2.ToUTF8());
1570 MainFrame->DoubleQuotedSql(xname);
1571 order += wxString::FromUTF8(xname);
1572 }
1573 order += wxT(".");
1574 strcpy(xname, Order1Column.ToUTF8());
1575 MainFrame->DoubleQuotedSql(xname);
1576 order += wxString::FromUTF8(xname);
1577 } else
1578 {
1579 if (TableAlias1.Len() == 0)
1580 {
1581 strcpy(xname, TableName1.ToUTF8());
1582 MainFrame->DoubleQuotedSql(xname);
1583 order += wxString::FromUTF8(xname);
1584 } else
1585 {
1586 strcpy(xname, TableAlias1.ToUTF8());
1587 MainFrame->DoubleQuotedSql(xname);
1588 order += wxString::FromUTF8(xname);
1589 }
1590 order += wxT(".");
1591 strcpy(xname, Order1Column.ToUTF8());
1592 MainFrame->DoubleQuotedSql(xname);
1593 order += wxString::FromUTF8(xname);
1594 }
1595 }
1596 }
1597 if (Order1Desc == true)
1598 {
1599 order += wxT(" ");
1600 markStyle[nextMark] = 2;
1601 markStart[nextMark] = orderBase + order.Len();
1602 order += wxT("DESC");
1603 markStop[nextMark++] = orderBase + order.Len();
1604 }
1605 orderCount += order.Len();
1606 SqlSample += order;
1607 comma = true;
1608 }
1609 if (Order2Enabled == true)
1610 {
1611 int orderBase = SqlSample.Len();
1612 wxString order;
1613 if (comma == true)
1614 {
1615 markStyle[nextMark] = 2;
1616 markStart[nextMark] = orderBase + order.Len();
1617 order += wxT(",");
1618 markStop[nextMark++] = orderBase + order.Len();
1619 }
1620 if (orderCount > 40)
1621 {
1622 order += wxT("\n ");
1623 orderCount = 4;
1624 } else
1625 order += wxT(" ");
1626 if (Order2Column.Len() == 0)
1627 {
1628 markStyle[nextMark] = 1;
1629 markStart[nextMark] = orderBase + order.Len();
1630 order += undefined;
1631 IncompleteSql = true;
1632 markStop[nextMark++] = orderBase + order.Len();
1633 } else
1634 {
1635 if (Table2Enabled == false)
1636 {
1637 strcpy(xname, Order2Column.ToUTF8());
1638 MainFrame->DoubleQuotedSql(xname);
1639 order += wxString::FromUTF8(xname);
1640 } else
1641 {
1642 if (Order2Table2 == true)
1643 {
1644 if (TableAlias2.Len() == 0)
1645 {
1646 strcpy(xname, TableName2.ToUTF8());
1647 MainFrame->DoubleQuotedSql(xname);
1648 order += wxString::FromUTF8(xname);
1649 } else
1650 {
1651 strcpy(xname, TableAlias2.ToUTF8());
1652 MainFrame->DoubleQuotedSql(xname);
1653 order += wxString::FromUTF8(xname);
1654 }
1655 order += wxT(".");
1656 strcpy(xname, Order2Column.ToUTF8());
1657 MainFrame->DoubleQuotedSql(xname);
1658 order += wxString::FromUTF8(xname);
1659 } else
1660 {
1661 if (TableAlias1.Len() == 0)
1662 {
1663 strcpy(xname, TableName1.ToUTF8());
1664 MainFrame->DoubleQuotedSql(xname);
1665 order += wxString::FromUTF8(xname);
1666 } else
1667 {
1668 strcpy(xname, TableAlias1.ToUTF8());
1669 MainFrame->DoubleQuotedSql(xname);
1670 order += wxString::FromUTF8(xname);
1671 }
1672 order += wxT(".");
1673 strcpy(xname, Order2Column.ToUTF8());
1674 MainFrame->DoubleQuotedSql(xname);
1675 order += wxString::FromUTF8(xname);
1676 }
1677 }
1678 }
1679 if (Order2Desc == true)
1680 {
1681 order += wxT(" ");
1682 markStyle[nextMark] = 2;
1683 markStart[nextMark] = orderBase + order.Len();
1684 order += wxT("DESC");
1685 markStop[nextMark++] = orderBase + order.Len();
1686 }
1687 orderCount += order.Len();
1688 SqlSample += order;
1689 comma = true;
1690 }
1691 if (Order3Enabled == true)
1692 {
1693 int orderBase = SqlSample.Len();
1694 wxString order;
1695 if (comma == true)
1696 {
1697 markStyle[nextMark] = 2;
1698 markStart[nextMark] = orderBase + order.Len();
1699 order += wxT(",");
1700 markStop[nextMark++] = orderBase + order.Len();
1701 }
1702 if (orderCount > 40)
1703 {
1704 order += wxT("\n ");
1705 orderCount = 4;
1706 } else
1707 order += wxT(" ");
1708 if (Order3Column.Len() == 0)
1709 {
1710 markStyle[nextMark] = 1;
1711 markStart[nextMark] = orderBase + order.Len();
1712 order += undefined;
1713 IncompleteSql = true;
1714 markStop[nextMark++] = orderBase + order.Len();
1715 } else
1716 {
1717 if (Table2Enabled == false)
1718 {
1719 strcpy(xname, Order1Column.ToUTF8());
1720 MainFrame->DoubleQuotedSql(xname);
1721 order += wxString::FromUTF8(xname);
1722 } else
1723 {
1724 if (Order3Table2 == true)
1725 {
1726 if (TableAlias2.Len() == 0)
1727 {
1728 strcpy(xname, TableName2.ToUTF8());
1729 MainFrame->DoubleQuotedSql(xname);
1730 order += wxString::FromUTF8(xname);
1731 } else
1732 {
1733 strcpy(xname, TableAlias2.ToUTF8());
1734 MainFrame->DoubleQuotedSql(xname);
1735 order += wxString::FromUTF8(xname);
1736 }
1737 order += wxT(".");
1738 strcpy(xname, Order3Column.ToUTF8());
1739 MainFrame->DoubleQuotedSql(xname);
1740 order += wxString::FromUTF8(xname);
1741 } else
1742 {
1743 if (TableAlias1.Len() == 0)
1744 {
1745 strcpy(xname, TableName1.ToUTF8());
1746 MainFrame->DoubleQuotedSql(xname);
1747 order += wxString::FromUTF8(xname);
1748 } else
1749 {
1750 strcpy(xname, TableAlias1.ToUTF8());
1751 MainFrame->DoubleQuotedSql(xname);
1752 order += wxString::FromUTF8(xname);
1753 }
1754 order += wxT(".");
1755 strcpy(xname, Order3Column.ToUTF8());
1756 MainFrame->DoubleQuotedSql(xname);
1757 order += wxString::FromUTF8(xname);
1758 }
1759 }
1760 }
1761 if (Order3Desc == true)
1762 {
1763 order += wxT(" ");
1764 markStyle[nextMark] = 2;
1765 markStart[nextMark] = orderBase + order.Len();
1766 order += wxT("DESC");
1767 markStop[nextMark++] = orderBase + order.Len();
1768 }
1769 orderCount += order.Len();
1770 SqlSample += order;
1771 comma = true;
1772 }
1773 if (Order4Enabled == true)
1774 {
1775 int orderBase = SqlSample.Len();
1776 wxString order;
1777 if (comma == true)
1778 {
1779 markStyle[nextMark] = 2;
1780 markStart[nextMark] = orderBase + order.Len();
1781 order += wxT(",");
1782 markStop[nextMark++] = orderBase + order.Len();
1783 }
1784 if (orderCount > 40)
1785 {
1786 order += wxT("\n ");
1787 orderCount = 4;
1788 } else
1789 order += wxT(" ");
1790 if (Order4Column.Len() == 0)
1791 {
1792 markStyle[nextMark] = 1;
1793 markStart[nextMark] = orderBase + order.Len();
1794 order += undefined;
1795 IncompleteSql = true;
1796 markStop[nextMark++] = orderBase + order.Len();
1797 } else
1798 {
1799 if (Table2Enabled == false)
1800 {
1801 strcpy(xname, Order1Column.ToUTF8());
1802 MainFrame->DoubleQuotedSql(xname);
1803 order += wxString::FromUTF8(xname);
1804 } else
1805 {
1806 if (Order4Table2 == true)
1807 {
1808 if (TableAlias2.Len() == 0)
1809 {
1810 strcpy(xname, TableName2.ToUTF8());
1811 MainFrame->DoubleQuotedSql(xname);
1812 order += wxString::FromUTF8(xname);
1813 } else
1814 {
1815 strcpy(xname, TableAlias2.ToUTF8());
1816 MainFrame->DoubleQuotedSql(xname);
1817 order += wxString::FromUTF8(xname);
1818 }
1819 order += wxT(".");
1820 strcpy(xname, Order4Column.ToUTF8());
1821 MainFrame->DoubleQuotedSql(xname);
1822 order += wxString::FromUTF8(xname);
1823 } else
1824 {
1825 if (TableAlias1.Len() == 0)
1826 {
1827 strcpy(xname, TableName1.ToUTF8());
1828 MainFrame->DoubleQuotedSql(xname);
1829 order += wxString::FromUTF8(xname);
1830 } else
1831 {
1832 strcpy(xname, TableAlias1.ToUTF8());
1833 MainFrame->DoubleQuotedSql(xname);
1834 order += wxString::FromUTF8(xname);
1835 }
1836 order += wxT(".");
1837 strcpy(xname, Order4Column.ToUTF8());
1838 MainFrame->DoubleQuotedSql(xname);
1839 order += wxString::FromUTF8(xname);
1840 }
1841 }
1842 }
1843 if (Order4Desc == true)
1844 {
1845 order += wxT(" ");
1846 markStyle[nextMark] = 2;
1847 markStart[nextMark] = orderBase + order.Len();
1848 order += wxT("DESC");
1849 markStop[nextMark++] = orderBase + order.Len();
1850 }
1851 SqlSample += order;
1852 }
1853 }
1854
1855 SqlCtrl->Hide();
1856 SqlCtrl->SetValue(SqlSample);
1857 wxColour bgColor(255, 255, 255);
1858 if (IncompleteSql == true
1859 || (SpatialView == true && GeometryColumn.Len() == 0))
1860 bgColor = wxColor(255, 255, 0);
1861 wxTextAttr style(wxColour(192, 0, 192), bgColor,
1862 wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
1863 wxFONTWEIGHT_NORMAL));
1864 wxTextAttr style2(wxColour(128, 0, 255), wxColour(255, 192, 0),
1865 wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
1866 wxFONTWEIGHT_NORMAL));
1867 wxTextAttr style3(wxColour(0, 0, 255), bgColor,
1868 wxFont(10, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL,
1869 wxFONTWEIGHT_BOLD));
1870 SqlCtrl->SetStyle(0, SqlSample.Len(), style);
1871 int i;
1872 for (i = 0; i < nextMark; i++)
1873 {
1874 if (markStyle[i] == 2)
1875 SqlCtrl->SetStyle(markStart[i], markStop[i], style3);
1876 else
1877 SqlCtrl->SetStyle(markStart[i], markStop[i], style2);
1878 }
1879 SqlCtrl->Show();
1880 }
1881
PrepareSqlTriggers()1882 void ComposerDialog::PrepareSqlTriggers()
1883 {
1884 //
1885 // preparing the SQL Triggers enabling a Writable View
1886 //
1887 AuxColumn *pCol;
1888 char dummy[8192];
1889 char xname[1024];
1890 char xname2[1024];
1891 char xview[1024];
1892 char xcol[1024];
1893 bool comma;
1894 SqlTriggerInsert = wxT("");
1895 SqlTriggerUpdate = wxT("");
1896 SqlTriggerDelete = wxT("");
1897 if (Writable1 == false)
1898 return;
1899
1900 // composing the INSERT trigger
1901 SqlTriggerInsert = wxT("CREATE TRIGGER ");
1902 strcpy(xview, ViewName.ToUTF8());
1903 sprintf(dummy, "vw_ins_%s", xview);
1904 MyFrame::DoubleQuotedSql(dummy);
1905 SqlTriggerInsert += wxString::FromUTF8(dummy);
1906 SqlTriggerInsert += wxT(" INSTEAD OF INSERT ON ");
1907 MyFrame::DoubleQuotedSql(xview);
1908 SqlTriggerInsert += wxString::FromUTF8(xview);
1909 SqlTriggerInsert += wxT("\nBEGIN\nINSERT OR REPLACE INTO ");
1910 if (Writable2 == true && Table2Enabled == true)
1911 {
1912 // supporting table #2
1913 strcpy(xname2, TableName2.ToUTF8());
1914 MyFrame::DoubleQuotedSql(xname2);
1915 SqlTriggerInsert += wxString::FromUTF8(xname2);
1916 SqlTriggerInsert += wxT(" (");
1917 comma = false;
1918 strcpy(xcol, Match1Table2.ToUTF8());
1919 MainFrame->DoubleQuotedSql(xcol);
1920 SqlTriggerInsert += wxString::FromUTF8(xcol);
1921 comma = true;
1922 if (Match2Enabled == true)
1923 {
1924 if (comma)
1925 SqlTriggerInsert += wxT(", ");
1926 strcpy(xcol, Match2Table2.ToUTF8());
1927 MainFrame->DoubleQuotedSql(xcol);
1928 SqlTriggerInsert += wxString::FromUTF8(xcol);
1929 }
1930 if (Match3Enabled == true)
1931 {
1932 if (comma)
1933 SqlTriggerInsert += wxT(", ");
1934 strcpy(xcol, Match3Table2.ToUTF8());
1935 MainFrame->DoubleQuotedSql(xcol);
1936 SqlTriggerInsert += wxString::FromUTF8(xcol);
1937 }
1938 pCol = Column2List.GetFirst();
1939 while (pCol)
1940 {
1941 if (pCol->IsSelected() == true)
1942 {
1943 if (pCol->GetName() == wxT("ROWID"))
1944 {
1945 pCol = pCol->GetNext();
1946 continue;
1947 }
1948 if (pCol->GetName() == Match1Table2)
1949 {
1950 pCol = pCol->GetNext();
1951 continue;
1952 }
1953 if (Match2Enabled == true)
1954 {
1955 if (pCol->GetName() == Match2Table2)
1956 {
1957 pCol = pCol->GetNext();
1958 continue;
1959 }
1960 }
1961 if (Match3Enabled == true)
1962 {
1963 if (pCol->GetName() == Match3Table2)
1964 {
1965 pCol = pCol->GetNext();
1966 continue;
1967 }
1968 }
1969 if (comma)
1970 SqlTriggerInsert += wxT(", ");
1971 strcpy(xcol, pCol->GetName().ToUTF8());
1972 MainFrame->DoubleQuotedSql(xcol);
1973 SqlTriggerInsert += wxString::FromUTF8(xcol);
1974 comma = true;
1975 }
1976 pCol = pCol->GetNext();
1977 }
1978 SqlTriggerInsert += wxT(")\n VALUES (");
1979 comma = false;
1980 strcpy(xcol, Match1Table1.ToUTF8());
1981 MainFrame->DoubleQuotedSql(xcol);
1982 SqlTriggerInsert += wxT("NEW.") + wxString::FromUTF8(xcol);
1983 comma = true;
1984 if (Match2Enabled == true)
1985 {
1986 if (comma)
1987 SqlTriggerInsert += wxT(", ");
1988 strcpy(xcol, Match2Table1.ToUTF8());
1989 MainFrame->DoubleQuotedSql(xcol);
1990 SqlTriggerInsert += wxT("NEW.") + wxString::FromUTF8(xcol);
1991 }
1992 if (Match3Enabled == true)
1993 {
1994 if (comma)
1995 SqlTriggerInsert += wxT(", ");
1996 strcpy(xcol, Match3Table1.ToUTF8());
1997 MainFrame->DoubleQuotedSql(xcol);
1998 SqlTriggerInsert += wxT("NEW.") + wxString::FromUTF8(xcol);
1999 }
2000 pCol = Column2List.GetFirst();
2001 while (pCol)
2002 {
2003 if (pCol->IsSelected() == true)
2004 {
2005 if (pCol->GetName() == wxT("ROWID"))
2006 {
2007 pCol = pCol->GetNext();
2008 continue;
2009 }
2010 if (pCol->GetName() == Match1Table2)
2011 {
2012 pCol = pCol->GetNext();
2013 continue;
2014 }
2015 if (Match2Enabled == true)
2016 {
2017 if (pCol->GetName() == Match2Table2)
2018 {
2019 pCol = pCol->GetNext();
2020 continue;
2021 }
2022 }
2023 if (Match3Enabled == true)
2024 {
2025 if (pCol->GetName() == Match3Table2)
2026 {
2027 pCol = pCol->GetNext();
2028 continue;
2029 }
2030 }
2031 if (comma)
2032 SqlTriggerInsert += wxT(", ");
2033 strcpy(xcol, pCol->GetName().ToUTF8());
2034 MainFrame->DoubleQuotedSql(xcol);
2035 SqlTriggerInsert += wxT("NEW.") + wxString::FromUTF8(xcol);
2036 comma = true;
2037 }
2038 pCol = pCol->GetNext();
2039 }
2040 SqlTriggerInsert += wxT(");\nINSERT INTO ");
2041 }
2042 strcpy(xname, TableName1.ToUTF8());
2043 MyFrame::DoubleQuotedSql(xname);
2044 SqlTriggerInsert += wxString::FromUTF8(xname);
2045 SqlTriggerInsert += wxT(" (");
2046 comma = false;
2047 pCol = Column1List.GetFirst();
2048 while (pCol)
2049 {
2050 if (pCol->IsSelected() == true)
2051 {
2052 if (pCol->GetName() == wxT("ROWID"))
2053 {
2054 pCol = pCol->GetNext();
2055 continue;
2056 }
2057 if (comma)
2058 SqlTriggerInsert += wxT(", ");
2059 strcpy(xcol, pCol->GetName().ToUTF8());
2060 MainFrame->DoubleQuotedSql(xcol);
2061 SqlTriggerInsert += wxString::FromUTF8(xcol);
2062 comma = true;
2063 }
2064 pCol = pCol->GetNext();
2065 }
2066 SqlTriggerInsert += wxT(")\n VALUES (");
2067 comma = false;
2068 pCol = Column1List.GetFirst();
2069 while (pCol)
2070 {
2071 if (pCol->IsSelected() == true)
2072 {
2073 if (pCol->GetName() == wxT("ROWID"))
2074 {
2075 pCol = pCol->GetNext();
2076 continue;
2077 }
2078 if (comma)
2079 SqlTriggerInsert += wxT(", ");
2080 strcpy(xcol, pCol->GetName().ToUTF8());
2081 MainFrame->DoubleQuotedSql(xcol);
2082 SqlTriggerInsert += wxT("NEW.") + wxString::FromUTF8(xcol);
2083 comma = true;
2084 }
2085 pCol = pCol->GetNext();
2086 }
2087 SqlTriggerInsert += wxT(");\nEND");
2088
2089 // composing the UPDATE trigger
2090 SqlTriggerUpdate = wxT("CREATE TRIGGER ");
2091 strcpy(xview, ViewName.ToUTF8());
2092 sprintf(dummy, "vw_upd_%s", xview);
2093 MyFrame::DoubleQuotedSql(dummy);
2094 SqlTriggerUpdate += wxString::FromUTF8(dummy);
2095 SqlTriggerUpdate += wxT(" INSTEAD OF UPDATE OF\n ");
2096 comma = false;
2097 pCol = Column1List.GetFirst();
2098 while (pCol)
2099 {
2100 if (pCol->IsSelected() == true)
2101 {
2102 if (pCol->GetName() == wxT("ROWID"))
2103 {
2104 pCol = pCol->GetNext();
2105 continue;
2106 }
2107 if (comma)
2108 SqlTriggerUpdate += wxT(", ");
2109 strcpy(xcol, pCol->GetName().ToUTF8());
2110 MainFrame->DoubleQuotedSql(xcol);
2111 SqlTriggerUpdate += wxString::FromUTF8(xcol);
2112 comma = true;
2113 }
2114 pCol = pCol->GetNext();
2115 }
2116 if (Writable2 == true && Table2Enabled == true)
2117 {
2118 // supporting table #2
2119 pCol = Column2List.GetFirst();
2120 while (pCol)
2121 {
2122 if (pCol->IsSelected() == true)
2123 {
2124 if (pCol->GetName() == wxT("ROWID"))
2125 {
2126 pCol = pCol->GetNext();
2127 continue;
2128 }
2129 if (comma)
2130 SqlTriggerUpdate += wxT(", ");
2131 strcpy(xcol, pCol->GetName().ToUTF8());
2132 MainFrame->DoubleQuotedSql(xcol);
2133 SqlTriggerUpdate += wxString::FromUTF8(xcol);
2134 comma = true;
2135 }
2136 pCol = pCol->GetNext();
2137 }
2138 }
2139 SqlTriggerUpdate += wxT("\n ON ");
2140 MyFrame::DoubleQuotedSql(xview);
2141 SqlTriggerUpdate += wxString::FromUTF8(xview);
2142 SqlTriggerUpdate += wxT("\nBEGIN\nUPDATE ");
2143 if (Writable2 == true && Table2Enabled == true)
2144 {
2145 // supporting table #2
2146 strcpy(xname, TableName2.ToUTF8());
2147 MyFrame::DoubleQuotedSql(xname);
2148 SqlTriggerUpdate += wxString::FromUTF8(xname);
2149 SqlTriggerUpdate += wxT(" SET ");
2150 comma = false;
2151 pCol = Column2List.GetFirst();
2152 while (pCol)
2153 {
2154 if (pCol->IsSelected() == true)
2155 {
2156 if (pCol->GetName() == wxT("ROWID"))
2157 {
2158 pCol = pCol->GetNext();
2159 continue;
2160 }
2161 if (pCol->GetName() == Match1Table2)
2162 {
2163 pCol = pCol->GetNext();
2164 continue;
2165 }
2166 if (Match2Enabled == true)
2167 {
2168 if (pCol->GetName() == Match2Table2)
2169 {
2170 pCol = pCol->GetNext();
2171 continue;
2172 }
2173 }
2174 if (Match3Enabled == true)
2175 {
2176 if (pCol->GetName() == Match3Table2)
2177 {
2178 pCol = pCol->GetNext();
2179 continue;
2180 }
2181 }
2182 if (comma)
2183 SqlTriggerUpdate += wxT(", ");
2184 strcpy(xcol, pCol->GetName().ToUTF8());
2185 MainFrame->DoubleQuotedSql(xcol);
2186 SqlTriggerUpdate +=
2187 wxString::FromUTF8(xcol) + wxT(" = NEW.") +
2188 wxString::FromUTF8(xcol);
2189 comma = true;
2190 }
2191 pCol = pCol->GetNext();
2192 }
2193 SqlTriggerUpdate += wxT("\nWHERE ");
2194 strcpy(xcol, Match1Table2.ToUTF8());
2195 MainFrame->DoubleQuotedSql(xcol);
2196 SqlTriggerUpdate += wxString::FromUTF8(xcol);
2197 strcpy(xcol, Match1Table1.ToUTF8());
2198 MainFrame->DoubleQuotedSql(xcol);
2199 SqlTriggerUpdate += wxT(" = NEW.") + wxString::FromUTF8(xcol);
2200 if (Match2Enabled == true)
2201 {
2202 if (AndOr12 == true)
2203 SqlTriggerUpdate += wxT(" AND ");
2204 else
2205 SqlTriggerUpdate += wxT(" OR ");
2206 strcpy(xcol, Match2Table2.ToUTF8());
2207 MainFrame->DoubleQuotedSql(xcol);
2208 SqlTriggerUpdate += wxT(" = NEW.") + wxString::FromUTF8(xcol);
2209 strcpy(xcol, Match2Table1.ToUTF8());
2210 MainFrame->DoubleQuotedSql(xcol);
2211 SqlTriggerUpdate += wxT("NEW.") + wxString::FromUTF8(xcol);
2212 }
2213 if (Match3Enabled == true)
2214 {
2215
2216 if (AndOr23 == true)
2217 SqlTriggerUpdate += wxT(" AND ");
2218 else
2219 SqlTriggerUpdate += wxT(" OR ");
2220 strcpy(xcol, Match3Table2.ToUTF8());
2221 MainFrame->DoubleQuotedSql(xcol);
2222 SqlTriggerUpdate += wxT(" = NEW.") + wxString::FromUTF8(xcol);
2223 strcpy(xcol, Match3Table1.ToUTF8());
2224 MainFrame->DoubleQuotedSql(xcol);
2225 SqlTriggerUpdate += wxT("NEW.") + wxString::FromUTF8(xcol);
2226 }
2227 SqlTriggerUpdate += wxT(";\nUPDATE");
2228 }
2229 strcpy(xname, TableName1.ToUTF8());
2230 MyFrame::DoubleQuotedSql(xname);
2231 SqlTriggerUpdate += wxString::FromUTF8(xname);
2232 SqlTriggerUpdate += wxT(" SET ");
2233 comma = false;
2234 pCol = Column1List.GetFirst();
2235 while (pCol)
2236 {
2237 if (pCol->IsSelected() == true)
2238 {
2239 if (pCol->GetName() == wxT("ROWID"))
2240 {
2241 pCol = pCol->GetNext();
2242 continue;
2243 }
2244 if (comma)
2245 SqlTriggerUpdate += wxT(", ");
2246 strcpy(xcol, pCol->GetName().ToUTF8());
2247 MainFrame->DoubleQuotedSql(xcol);
2248 SqlTriggerUpdate +=
2249 wxString::FromUTF8(xcol) + wxT(" = NEW.") +
2250 wxString::FromUTF8(xcol);
2251 comma = true;
2252 }
2253 pCol = pCol->GetNext();
2254 }
2255 SqlTriggerUpdate += wxT("\nWHERE ROWID = OLD.ROWID;\nEND");
2256
2257 // composing the DELETE trigger
2258 SqlTriggerDelete = wxT("CREATE TRIGGER ");
2259 strcpy(xview, ViewName.ToUTF8());
2260 sprintf(dummy, "vw_del_%s", xview);
2261 MyFrame::DoubleQuotedSql(dummy);
2262 SqlTriggerDelete += wxString::FromUTF8(dummy);
2263 SqlTriggerDelete += wxT(" INSTEAD OF DELETE ON ");
2264 MyFrame::DoubleQuotedSql(xview);
2265 SqlTriggerDelete += wxString::FromUTF8(xview);
2266 SqlTriggerDelete += wxT("\nBEGIN\nDELETE FROM ");
2267 strcpy(xname, TableName1.ToUTF8());
2268 MyFrame::DoubleQuotedSql(xname);
2269 SqlTriggerDelete += wxString::FromUTF8(xname);
2270 SqlTriggerDelete += wxT(" WHERE ROWID = OLD.ROWID;\nEND");
2271 }
2272
SqlCleanString(wxString & dirty,wxString & clean)2273 bool ComposerDialog::SqlCleanString(wxString & dirty, wxString & clean)
2274 {
2275 // well-formatting a string to be used as an SQL string
2276 char org[8192];
2277 char dst[8192];
2278 int len;
2279 char *in = org;
2280 char *out = dst;
2281 bool ret = false;
2282 strcpy(org, dirty.ToUTF8());
2283 len = strlen(org);
2284 if (len > 2 && *org == '\'' && *(org + (len - 1)) == '\'')
2285 {
2286 strcpy(dst, org);
2287 ret = true;
2288 } else
2289 {
2290 while (*in != '\0')
2291 {
2292 if (*in == '\'')
2293 *out++ = '\'';
2294 *out++ = *in++;
2295 }
2296 *out = '\0';
2297 }
2298 clean = wxString::FromUTF8(dst);
2299 return ret;
2300 }
2301
SqlCleanList(wxString & dirty,wxString & clean,int * style,int * start,int * stop,int * next,int base)2302 void ComposerDialog::SqlCleanList(wxString & dirty, wxString & clean,
2303 int *style, int *start, int *stop, int *next,
2304 int base)
2305 {
2306 // well-formatting a string to be used as an SQL values list [IN]
2307 wxString token[256];
2308 int nextToken = 0;
2309 int i;
2310 bool quotedList;
2311 char org[8192];
2312 char dst[8192];
2313 char *in = org;
2314 char *out = dst;
2315 strcpy(org, dirty.ToUTF8());
2316 while (1)
2317 {
2318 if (*in == '\0')
2319 {
2320 *out = '\0';
2321 token[nextToken++] = wxString::FromUTF8(dst);
2322 break;
2323 }
2324 if (*in == ',')
2325 {
2326 *out = '\0';
2327 token[nextToken++] = wxString::FromUTF8(dst);
2328 in++;
2329 out = dst;
2330 continue;
2331 }
2332 *out++ = *in++;
2333 }
2334 for (i = 0; i < nextToken; i++)
2335 {
2336 wxString str = token[i].Trim(false);
2337 token[i] = str.Trim(true);
2338 }
2339 quotedList = false;
2340 for (i = 0; i < nextToken; i++)
2341 {
2342 bool isNumber = false;
2343 long lngTest;
2344 double dblTest;
2345 if (token[i].Len() == 0)
2346 continue;
2347 if (token[i].ToLong(&lngTest) == true)
2348 isNumber = true;
2349 if (token[i].ToDouble(&dblTest) == true)
2350 isNumber = true;
2351 if (isNumber == false)
2352 quotedList = true;
2353 }
2354 if (quotedList == true)
2355 {
2356 for (i = 0; i < nextToken; i++)
2357 {
2358 if (token[i].Len() == 0)
2359 continue;
2360 wxString str;
2361 SqlCleanString(token[i], str);
2362 token[i] = str;
2363 }
2364 }
2365 clean = wxT("");
2366 bool comma = false;
2367 for (i = 0; i < nextToken; i++)
2368 {
2369 if (token[i].Len() == 0)
2370 continue;
2371 if (comma == true)
2372 {
2373 style[*next] = 2;
2374 start[*next] = base + clean.Len();
2375 clean += wxT(", ");
2376 stop[(*next)++] = base + clean.Len();
2377 }
2378 if (quotedList == true)
2379 clean += wxT("'");
2380 clean += token[i];
2381 if (quotedList == true)
2382 clean += wxT("'");
2383 comma = true;
2384 }
2385 }
2386
Create(ComposerDialog * parent)2387 bool ComposerMainPage::Create(ComposerDialog * parent)
2388 {
2389 //
2390 // creating the dialog
2391 //
2392 Parent = parent;
2393 if (wxPanel::Create(Parent->GetTabCtrl()) == false)
2394 return false;
2395 // populates individual controls
2396 CreateControls();
2397 // sets dialog sizer
2398 GetSizer()->Fit(this);
2399 GetSizer()->SetSizeHints(this);
2400 // centers the dialog window
2401 Centre();
2402 return true;
2403 }
2404
CreateControls()2405 void ComposerMainPage::CreateControls()
2406 {
2407 //
2408 // creating individual control and setting initial values
2409 //
2410 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
2411 this->SetSizer(topSizer);
2412 wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
2413 topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2414
2415 // the TABLES row
2416 wxBoxSizer *tablesSizer = new wxBoxSizer(wxHORIZONTAL);
2417 boxSizer->Add(tablesSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2418 // the MAIN TABLE pane
2419 wxBoxSizer *mainTblBoxSizer = new wxBoxSizer(wxVERTICAL);
2420 tablesSizer->Add(mainTblBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2421 wxStaticBox *mainTblBox = new wxStaticBox(this, wxID_STATIC,
2422 wxT("Main Table"),
2423 wxDefaultPosition,
2424 wxDefaultSize);
2425 wxBoxSizer *mainTblSizer = new wxStaticBoxSizer(mainTblBox, wxVERTICAL);
2426 mainTblBoxSizer->Add(mainTblSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2427 int count = Parent->GetTableList()->GetCount();
2428 wxString *tables = new wxString[count];
2429 int i = 0;
2430 AuxTable *pTable = Parent->GetTableList()->GetFirst();
2431 while (pTable)
2432 {
2433 tables[i] = pTable->GetTableName();
2434 i++;
2435 pTable = pTable->GetNext();
2436 }
2437 Table1NameCtrl =
2438 new wxComboBox(this, ID_QVC_TABLE_NAME_1, wxT(""), wxDefaultPosition,
2439 wxSize(130, 21), count, tables,
2440 wxCB_DROPDOWN | wxCB_READONLY);
2441 mainTblSizer->Add(Table1NameCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2442 wxBoxSizer *alias1Sizer = new wxBoxSizer(wxHORIZONTAL);
2443 mainTblSizer->Add(alias1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2444 wxStaticText *aliasTbl1 = new wxStaticText(this, wxID_STATIC, wxT("&Alias:"));
2445 alias1Sizer->Add(aliasTbl1, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
2446
2447 Table1AliasCtrl =
2448 new wxTextCtrl(this, ID_QVC_TABLE_ALIAS_1, Parent->GetTableAlias1(),
2449 wxDefaultPosition, wxDefaultSize);
2450 alias1Sizer->Add(Table1AliasCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2451 Table1ColumnsCtrl = new wxListBox(this, ID_QVC_COLUMNS_1,
2452 wxDefaultPosition, wxSize(130, 165),
2453 0, NULL,
2454 wxLB_HSCROLL | wxLB_NEEDED_SB |
2455 wxLB_EXTENDED);
2456 mainTblSizer->Add(Table1ColumnsCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2457
2458 // the TABLE#2 pane
2459 wxBoxSizer *tbl2BoxSizer = new wxBoxSizer(wxVERTICAL);
2460 tablesSizer->Add(tbl2BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2461 wxStaticBox *tbl2Box = new wxStaticBox(this, wxID_STATIC,
2462 wxT("Table #2"),
2463 wxDefaultPosition,
2464 wxDefaultSize);
2465 wxBoxSizer *tbl2Sizer = new wxStaticBoxSizer(tbl2Box, wxVERTICAL);
2466 tbl2BoxSizer->Add(tbl2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2467 Table2Ctrl = new wxCheckBox(this, ID_QVC_TABLE_2, wxT("Enable"));
2468 Table2Ctrl->SetValue(false);
2469 tbl2Sizer->Add(Table2Ctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3);
2470 count = Parent->GetTableList()->GetCount();
2471 wxString *tables2 = new wxString[count];
2472 i = 0;
2473 pTable = Parent->GetTableList()->GetFirst();
2474 while (pTable)
2475 {
2476 tables2[i] = pTable->GetTableName();
2477 i++;
2478 pTable = pTable->GetNext();
2479 }
2480 Table2NameCtrl =
2481 new wxComboBox(this, ID_QVC_TABLE_NAME_2, wxT(""), wxDefaultPosition,
2482 wxSize(130, 21), count, tables2,
2483 wxCB_DROPDOWN | wxCB_READONLY);
2484 Table2NameCtrl->Enable(false);
2485 tbl2Sizer->Add(Table2NameCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2486 wxBoxSizer *alias2Sizer = new wxBoxSizer(wxHORIZONTAL);
2487 tbl2Sizer->Add(alias2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2488 wxStaticText *aliasTbl2 = new wxStaticText(this, wxID_STATIC, wxT("&Alias:"));
2489 alias2Sizer->Add(aliasTbl2, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
2490 Table2AliasCtrl =
2491 new wxTextCtrl(this, ID_QVC_TABLE_ALIAS_2, Parent->GetTableAlias2(),
2492 wxDefaultPosition, wxDefaultSize);
2493 Table2AliasCtrl->Enable(false);
2494 alias2Sizer->Add(Table2AliasCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2495 Table2ColumnsCtrl = new wxListBox(this, ID_QVC_COLUMNS_2,
2496 wxDefaultPosition, wxSize(130, 80),
2497 0, NULL,
2498 wxLB_HSCROLL | wxLB_NEEDED_SB |
2499 wxLB_EXTENDED);
2500 Table2ColumnsCtrl->Enable(false);
2501 tbl2Sizer->Add(Table2ColumnsCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2502 wxString join1Modes[2];
2503 join1Modes[0] = wxT("[&Inner] Join");
2504 join1Modes[1] = wxT("&Left [Outer] Join");
2505 JoinModeCtrl = new wxRadioBox(this, ID_QVC_JOIN_MODE,
2506 wxT("Join mode"),
2507 wxDefaultPosition, wxDefaultSize, 2,
2508 join1Modes, 1, wxRA_SPECIFY_COLS);
2509 JoinModeCtrl->SetSelection(0);
2510 JoinModeCtrl->Enable(false);
2511 tbl2Sizer->Add(JoinModeCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2512
2513 // the JOIN condition pane
2514 wxBoxSizer *joinSizer = new wxBoxSizer(wxVERTICAL);
2515 tablesSizer->Add(joinSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2516
2517 // JOIN match #1
2518 wxStaticBox *match1Box = new wxStaticBox(this, wxID_STATIC,
2519 wxT("Join match #1"),
2520 wxDefaultPosition,
2521 wxDefaultSize);
2522 wxBoxSizer *match1Sizer = new wxStaticBoxSizer(match1Box, wxHORIZONTAL);
2523 joinSizer->Add(match1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2524 wxStaticBox *match1tbl1Box = new wxStaticBox(this, wxID_STATIC,
2525 wxT("Main Table column"),
2526 wxDefaultPosition,
2527 wxDefaultSize);
2528 wxBoxSizer *match1tbl1Sizer = new wxStaticBoxSizer(match1tbl1Box, wxVERTICAL);
2529 match1Sizer->Add(match1tbl1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2530 Match1Table1Ctrl =
2531 new wxComboBox(this, ID_QVC_MATCH_1_T1, wxT(""), wxDefaultPosition,
2532 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2533 Match1Table1Ctrl->Enable(false);
2534 match1tbl1Sizer->Add(Match1Table1Ctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL,
2535 0);
2536 wxStaticBox *match1tbl2Box = new wxStaticBox(this, wxID_STATIC,
2537 wxT("Table #2 column"),
2538 wxDefaultPosition,
2539 wxDefaultSize);
2540 wxBoxSizer *match1tbl2Sizer = new wxStaticBoxSizer(match1tbl2Box, wxVERTICAL);
2541 match1Sizer->Add(match1tbl2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2542 Match1Table2Ctrl =
2543 new wxComboBox(this, ID_QVC_MATCH_1_T2, wxT(""), wxDefaultPosition,
2544 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2545 Match1Table2Ctrl->Enable(false);
2546 match1tbl2Sizer->Add(Match1Table2Ctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL,
2547 0);
2548
2549 // JOIN match #2
2550 wxStaticBox *match2Box = new wxStaticBox(this, wxID_STATIC,
2551 wxT("Join match #2"),
2552 wxDefaultPosition,
2553 wxDefaultSize);
2554 wxBoxSizer *match20Sizer = new wxStaticBoxSizer(match2Box, wxVERTICAL);
2555 joinSizer->Add(match20Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2556 Match2Ctrl = new wxCheckBox(this, ID_QVC_MATCH_2_ENABLE, wxT("Enable"));
2557 Match2Ctrl->SetValue(false);
2558 Match2Ctrl->Enable(false);
2559 match20Sizer->Add(Match2Ctrl, 0, wxALIGN_LEFT | wxALL, 1);
2560 wxBoxSizer *match2Sizer = new wxBoxSizer(wxHORIZONTAL);
2561 match20Sizer->Add(match2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2562 wxStaticBox *match2tbl1Box = new wxStaticBox(this, wxID_STATIC,
2563 wxT("Main Table column"),
2564 wxDefaultPosition,
2565 wxDefaultSize);
2566 wxBoxSizer *match2tbl1Sizer = new wxStaticBoxSizer(match2tbl1Box, wxVERTICAL);
2567 match2Sizer->Add(match2tbl1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2568 Match2Table1Ctrl =
2569 new wxComboBox(this, ID_QVC_MATCH_2_T1, wxT(""), wxDefaultPosition,
2570 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2571 Match2Table1Ctrl->Enable(false);
2572 match2tbl1Sizer->Add(Match2Table1Ctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL,
2573 0);
2574 wxStaticBox *match2tbl2Box = new wxStaticBox(this, wxID_STATIC,
2575 wxT("Table #2 column"),
2576 wxDefaultPosition,
2577 wxDefaultSize);
2578 wxBoxSizer *match2tbl2Sizer = new wxStaticBoxSizer(match2tbl2Box, wxVERTICAL);
2579 match2Sizer->Add(match2tbl2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2580 Match2Table2Ctrl =
2581 new wxComboBox(this, ID_QVC_MATCH_2_T2, wxT(""), wxDefaultPosition,
2582 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2583 Match2Table2Ctrl->Enable(false);
2584 match2tbl2Sizer->Add(Match2Table2Ctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL,
2585 0);
2586
2587 // JOIN match #3
2588 wxStaticBox *match3Box = new wxStaticBox(this, wxID_STATIC,
2589 wxT("Join match #3"),
2590 wxDefaultPosition,
2591 wxDefaultSize);
2592 wxBoxSizer *match30Sizer = new wxStaticBoxSizer(match3Box, wxVERTICAL);
2593 joinSizer->Add(match30Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
2594 Match3Ctrl = new wxCheckBox(this, ID_QVC_MATCH_3_ENABLE, wxT("Enable"));
2595 Match3Ctrl->SetValue(false);
2596 Match3Ctrl->Enable(false);
2597 match30Sizer->Add(Match3Ctrl, 0, wxALIGN_LEFT | wxALL, 1);
2598 wxBoxSizer *match3Sizer = new wxBoxSizer(wxHORIZONTAL);
2599 match30Sizer->Add(match3Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
2600 wxStaticBox *match3tbl1Box = new wxStaticBox(this, wxID_STATIC,
2601 wxT("Main Table column"),
2602 wxDefaultPosition,
2603 wxDefaultSize);
2604 wxBoxSizer *match3tbl1Sizer = new wxStaticBoxSizer(match3tbl1Box, wxVERTICAL);
2605 match3Sizer->Add(match3tbl1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2606 Match3Table1Ctrl =
2607 new wxComboBox(this, ID_QVC_MATCH_3_T1, wxT(""), wxDefaultPosition,
2608 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2609 Match3Table1Ctrl->Enable(false);
2610 match3tbl1Sizer->Add(Match3Table1Ctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL,
2611 0);
2612 wxStaticBox *match3tbl2Box = new wxStaticBox(this, wxID_STATIC,
2613 wxT("Table #2 column"),
2614 wxDefaultPosition,
2615 wxDefaultSize);
2616 wxBoxSizer *match3tbl2Sizer = new wxStaticBoxSizer(match3tbl2Box, wxVERTICAL);
2617 match3Sizer->Add(match3tbl2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
2618 Match3Table2Ctrl =
2619 new wxComboBox(this, ID_QVC_MATCH_3_T2, wxT(""), wxDefaultPosition,
2620 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
2621 Match3Table2Ctrl->Enable(false);
2622 match3tbl2Sizer->Add(Match3Table2Ctrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL,
2623 0);
2624
2625 // adding the event handlers
2626 Connect(ID_QVC_TABLE_2, wxEVT_COMMAND_CHECKBOX_CLICKED,
2627 (wxObjectEventFunction) & ComposerMainPage::OnTable2Enabled);
2628 Connect(ID_QVC_TABLE_NAME_1, wxEVT_COMMAND_COMBOBOX_SELECTED,
2629 (wxObjectEventFunction) & ComposerMainPage::OnTable1Selected);
2630 Connect(ID_QVC_TABLE_NAME_2, wxEVT_COMMAND_COMBOBOX_SELECTED,
2631 (wxObjectEventFunction) & ComposerMainPage::OnTable2Selected);
2632 Connect(ID_QVC_TABLE_ALIAS_1, wxEVT_COMMAND_TEXT_UPDATED,
2633 (wxObjectEventFunction) & ComposerMainPage::OnTable1AliasChanged);
2634 Connect(ID_QVC_TABLE_ALIAS_2, wxEVT_COMMAND_TEXT_UPDATED,
2635 (wxObjectEventFunction) & ComposerMainPage::OnTable2AliasChanged);
2636 Connect(ID_QVC_COLUMNS_1, wxEVT_COMMAND_LISTBOX_SELECTED,
2637 (wxObjectEventFunction) & ComposerMainPage::OnColumns1Selected);
2638 Connect(ID_QVC_COLUMNS_2, wxEVT_COMMAND_LISTBOX_SELECTED,
2639 (wxObjectEventFunction) & ComposerMainPage::OnColumns2Selected);
2640 Connect(ID_QVC_JOIN_MODE, wxEVT_COMMAND_RADIOBOX_SELECTED,
2641 (wxObjectEventFunction) & ComposerMainPage::OnJoinModeChanged);
2642 Connect(ID_QVC_MATCH_2_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
2643 (wxObjectEventFunction) & ComposerMainPage::OnMatch2Enabled);
2644 Connect(ID_QVC_MATCH_3_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
2645 (wxObjectEventFunction) & ComposerMainPage::OnMatch3Enabled);
2646 Connect(ID_QVC_MATCH_1_T1, wxEVT_COMMAND_COMBOBOX_SELECTED,
2647 (wxObjectEventFunction) & ComposerMainPage::OnMatch1Table1Selected);
2648 Connect(ID_QVC_MATCH_1_T2, wxEVT_COMMAND_COMBOBOX_SELECTED,
2649 (wxObjectEventFunction) & ComposerMainPage::OnMatch1Table2Selected);
2650 Connect(ID_QVC_MATCH_2_T1, wxEVT_COMMAND_COMBOBOX_SELECTED,
2651 (wxObjectEventFunction) & ComposerMainPage::OnMatch2Table1Selected);
2652 Connect(ID_QVC_MATCH_2_T2, wxEVT_COMMAND_COMBOBOX_SELECTED,
2653 (wxObjectEventFunction) & ComposerMainPage::OnMatch2Table2Selected);
2654 Connect(ID_QVC_MATCH_3_T1, wxEVT_COMMAND_COMBOBOX_SELECTED,
2655 (wxObjectEventFunction) & ComposerMainPage::OnMatch3Table1Selected);
2656 Connect(ID_QVC_MATCH_3_T2, wxEVT_COMMAND_COMBOBOX_SELECTED,
2657 (wxObjectEventFunction) & ComposerMainPage::OnMatch3Table2Selected);
2658 }
2659
SelectGeometryColumn(wxString & column,bool table2)2660 void ComposerMainPage::SelectGeometryColumn(wxString & column, bool table2)
2661 {
2662 // selecting the geometry column
2663 wxListBox *lb = Table1ColumnsCtrl;
2664 if (table2 == true)
2665 lb = Table2ColumnsCtrl;
2666 int sel = lb->FindString(column);
2667 if (sel != wxNOT_FOUND)
2668 lb->Select(sel);
2669 }
2670
InitializeComboColumns(wxComboBox * ctrl,bool table2)2671 void ComposerMainPage::InitializeComboColumns(wxComboBox * ctrl, bool table2)
2672 {
2673 //
2674 // initializing a column list ComboBox
2675 //
2676 ctrl->Clear();
2677 AuxColumn *pColumn;
2678 if (table2 == false)
2679 pColumn = Parent->GetColumn1List()->GetFirst();
2680 else
2681 pColumn = Parent->GetColumn2List()->GetFirst();
2682 while (pColumn)
2683 {
2684 wxString col = pColumn->GetName();
2685 ctrl->Append(col);
2686 pColumn = pColumn->GetNext();
2687 }
2688 }
2689
InitializeListColumns(wxListBox * ctrl,bool table2)2690 void ComposerMainPage::InitializeListColumns(wxListBox * ctrl, bool table2)
2691 {
2692 //
2693 // initializing a column list ListBox
2694 //
2695 ctrl->Clear();
2696 AuxColumn *pColumn;
2697 if (table2 == false)
2698 pColumn = Parent->GetColumn1List()->GetFirst();
2699 else
2700 pColumn = Parent->GetColumn2List()->GetFirst();
2701 while (pColumn)
2702 {
2703 wxString col = pColumn->GetName();
2704 ctrl->Append(col);
2705 pColumn = pColumn->GetNext();
2706 }
2707 }
2708
OnTable2Enabled(wxCommandEvent & WXUNUSED (event))2709 void ComposerMainPage::OnTable2Enabled(wxCommandEvent & WXUNUSED(event))
2710 {
2711 //
2712 // Table#2 enabled/disabled
2713 //
2714 Parent->SetTable2Enabled(Table2Ctrl->GetValue());
2715 if (Parent->IsTable2Enabled() == true)
2716 {
2717 Table2NameCtrl->Enable(true);
2718 Table2AliasCtrl->Enable(true);
2719 Table2ColumnsCtrl->Enable(true);
2720 JoinModeCtrl->Enable(true);
2721 if (Parent->IsLeftJoin() == false)
2722 JoinModeCtrl->SetSelection(0);
2723 else
2724 JoinModeCtrl->SetSelection(1);
2725 Match2Ctrl->Enable(true);
2726 Match3Ctrl->Enable(true);
2727 InitializeComboColumns(Match1Table1Ctrl, false);
2728 Match1Table1Ctrl->Enable(true);
2729 Match1Table2Ctrl->Enable(true);
2730 if (Parent->IsMatch2Enabled() == true)
2731 {
2732 Match2Table1Ctrl->Enable(true);
2733 Match2Table2Ctrl->Enable(true);
2734 InitializeComboColumns(Match2Table1Ctrl, false);
2735 } else
2736 {
2737 Match2Table1Ctrl->Enable(false);
2738 Match2Table2Ctrl->Enable(false);
2739 }
2740 if (Parent->IsMatch3Enabled() == true)
2741 {
2742 Match3Table1Ctrl->Enable(true);
2743 Match3Table2Ctrl->Enable(true);
2744 InitializeComboColumns(Match3Table1Ctrl, false);
2745 } else
2746 {
2747 Match3Table1Ctrl->Enable(false);
2748 Match3Table2Ctrl->Enable(false);
2749 }
2750 } else
2751 {
2752 Table2NameCtrl->Enable(false);
2753 Parent->SetTableName2(wxT(""));
2754 Table2NameCtrl->SetSelection(wxNOT_FOUND);
2755 Table2AliasCtrl->Enable(false);
2756 Table2ColumnsCtrl->Enable(false);
2757 Parent->GetColumn2List()->Flush();
2758 Table2ColumnsCtrl->Clear();
2759 Parent->SetMatch2Enabled(false);
2760 Parent->SetMatch3Enabled(false);
2761 Match2Ctrl->SetValue(Parent->IsMatch2Enabled());
2762 Match3Ctrl->SetValue(Parent->IsMatch3Enabled());
2763 Match2Ctrl->Enable(false);
2764 Match3Ctrl->Enable(false);
2765 JoinModeCtrl->Enable(false);
2766 Match1Table1Ctrl->Enable(false);
2767 Match1Table2Ctrl->Enable(false);
2768 Match2Table1Ctrl->Enable(false);
2769 Match2Table2Ctrl->Enable(false);
2770 Match3Table1Ctrl->Enable(false);
2771 Match3Table2Ctrl->Enable(false);
2772 Match1Table1Ctrl->Clear();
2773 Match1Table2Ctrl->Clear();
2774 Match2Table1Ctrl->Clear();
2775 Match2Table2Ctrl->Clear();
2776 Match3Table1Ctrl->Clear();
2777 Match3Table2Ctrl->Clear();
2778 Parent->SetMatch1Table1(wxT(""));
2779 Parent->SetMatch2Table1(wxT(""));
2780 Parent->SetMatch3Table1(wxT(""));
2781 Parent->SetMatch1Table2(wxT(""));
2782 Parent->SetMatch2Table2(wxT(""));
2783 Parent->SetMatch3Table2(wxT(""));
2784 Parent->Table2Status(false);
2785 }
2786 Parent->UpdateSqlSample();
2787 }
2788
OnMatch2Enabled(wxCommandEvent & WXUNUSED (event))2789 void ComposerMainPage::OnMatch2Enabled(wxCommandEvent & WXUNUSED(event))
2790 {
2791 //
2792 // Match#2 enabled/disabled
2793 //
2794 Parent->SetMatch2Enabled(Match2Ctrl->GetValue());
2795 if (Parent->IsMatch2Enabled() == true)
2796 {
2797 Match2Table1Ctrl->Enable(true);
2798 Match2Table2Ctrl->Enable(true);
2799 InitializeComboColumns(Match2Table1Ctrl, false);
2800 InitializeComboColumns(Match2Table2Ctrl, true);
2801 } else
2802 {
2803 Match2Table1Ctrl->Enable(false);
2804 Match2Table2Ctrl->Enable(false);
2805 Parent->SetMatch2Table1(wxT(""));
2806 Parent->SetMatch2Table2(wxT(""));
2807 Match2Table1Ctrl->Clear();
2808 Match2Table2Ctrl->Clear();
2809 }
2810 Parent->UpdateSqlSample();
2811 }
2812
OnMatch3Enabled(wxCommandEvent & WXUNUSED (event))2813 void ComposerMainPage::OnMatch3Enabled(wxCommandEvent & WXUNUSED(event))
2814 {
2815 //
2816 // Match#3 enabled/disabled
2817 //
2818 Parent->SetMatch3Enabled(Match3Ctrl->GetValue());
2819 if (Parent->IsMatch3Enabled() == true)
2820 {
2821 Match3Table1Ctrl->Enable(true);
2822 Match3Table2Ctrl->Enable(true);
2823 InitializeComboColumns(Match3Table1Ctrl, false);
2824 InitializeComboColumns(Match3Table2Ctrl, true);
2825 } else
2826 {
2827 Match3Table1Ctrl->Enable(false);
2828 Match3Table2Ctrl->Enable(false);
2829 Parent->SetMatch3Table1(wxT(""));
2830 Parent->SetMatch3Table2(wxT(""));
2831 Match3Table1Ctrl->Clear();
2832 Match3Table2Ctrl->Clear();
2833 }
2834 Parent->UpdateSqlSample();
2835 }
2836
OnTable1AliasChanged(wxCommandEvent & WXUNUSED (event))2837 void ComposerMainPage::OnTable1AliasChanged(wxCommandEvent & WXUNUSED(event))
2838 {
2839 //
2840 // Table#1 alias-name changed
2841 //
2842 Parent->SetTableAlias1(Table1AliasCtrl->GetValue());
2843 Parent->UpdateSqlSample();
2844 }
2845
OnTable2AliasChanged(wxCommandEvent & WXUNUSED (event))2846 void ComposerMainPage::OnTable2AliasChanged(wxCommandEvent & WXUNUSED(event))
2847 {
2848 //
2849 // Table#2 alias-name changed
2850 //
2851 Parent->SetTableAlias2(Table2AliasCtrl->GetValue());
2852 Parent->UpdateSqlSample();
2853 }
2854
OnJoinModeChanged(wxCommandEvent & WXUNUSED (event))2855 void ComposerMainPage::OnJoinModeChanged(wxCommandEvent & WXUNUSED(event))
2856 {
2857 //
2858 // Join mode changed
2859 //
2860 if (JoinModeCtrl->GetSelection() == 1)
2861 Parent->SetLeftJoin(true);
2862 else
2863 Parent->SetLeftJoin(false);
2864 Parent->UpdateSqlSample();
2865 }
2866
OnTable1Selected(wxCommandEvent & WXUNUSED (event))2867 void ComposerMainPage::OnTable1Selected(wxCommandEvent & WXUNUSED(event))
2868 {
2869 //
2870 // Table#1 selection changed
2871 //
2872 bool changed = true;
2873 if (Table1NameCtrl->GetValue() == Parent->GetTableName1())
2874 changed = false;
2875 Parent->SetTableName1(Table1NameCtrl->GetValue());
2876 Parent->PopulateColumnList1();
2877 InitializeListColumns(Table1ColumnsCtrl, false);
2878 InitializeComboColumns(Match1Table1Ctrl, false);
2879 InitializeComboColumns(Match2Table1Ctrl, false);
2880 InitializeComboColumns(Match3Table1Ctrl, false);
2881 Parent->SetMatch1Table1(wxT(""));
2882 Parent->SetMatch2Table1(wxT(""));
2883 Parent->SetMatch3Table1(wxT(""));
2884 if (Parent->GetTableName1().Len() == 0)
2885 Parent->Table1Status(false);
2886 else
2887 {
2888 if (changed == true)
2889 Parent->Table1Status(false);
2890 Parent->Table1Status(true);
2891 }
2892 Parent->UpdateSqlSample();
2893 }
2894
OnTable2Selected(wxCommandEvent & WXUNUSED (event))2895 void ComposerMainPage::OnTable2Selected(wxCommandEvent & WXUNUSED(event))
2896 {
2897 //
2898 // Table#2 selection changed
2899 //
2900 bool changed = true;
2901 if (Table2NameCtrl->GetValue() == Parent->GetTableName2())
2902 changed = false;
2903 Parent->SetTableName2(Table2NameCtrl->GetValue());
2904 Parent->PopulateColumnList2();
2905 Table2ColumnsCtrl->Clear();
2906 InitializeListColumns(Table2ColumnsCtrl, true);
2907 InitializeComboColumns(Match1Table2Ctrl, true);
2908 InitializeComboColumns(Match2Table2Ctrl, true);
2909 InitializeComboColumns(Match3Table2Ctrl, true);
2910 Parent->SetMatch1Table2(wxT(""));
2911 Parent->SetMatch2Table2(wxT(""));
2912 Parent->SetMatch3Table2(wxT(""));
2913 if (Parent->GetTableName2().Len() == 0)
2914 Parent->Table2Status(false);
2915 else
2916 {
2917 if (changed == true)
2918 Parent->Table2Status(false);
2919 Parent->Table2Status(true);
2920 }
2921 Parent->UpdateSqlSample();
2922 }
2923
OnColumns1Selected(wxCommandEvent & WXUNUSED (event))2924 void ComposerMainPage::OnColumns1Selected(wxCommandEvent & WXUNUSED(event))
2925 {
2926 //
2927 // Table#1 columns selection changed
2928 //
2929 int i;
2930 int count = Table1ColumnsCtrl->GetCount();
2931 for (i = 0; i < count; i++)
2932 {
2933 // marking the selected columns
2934 if (Table1ColumnsCtrl->IsSelected(i) == true)
2935 Parent->GetColumn1List()->SetState(i, true);
2936 else
2937 Parent->GetColumn1List()->SetState(i, false);
2938 }
2939 Parent->SelectGeometryColumn();
2940 Parent->UpdateSqlSample();
2941 }
2942
OnColumns2Selected(wxCommandEvent & WXUNUSED (event))2943 void ComposerMainPage::OnColumns2Selected(wxCommandEvent & WXUNUSED(event))
2944 {
2945 //
2946 // Table#2 columns selection changed
2947 //
2948 int i;
2949 int count = Table2ColumnsCtrl->GetCount();
2950 for (i = 0; i < count; i++)
2951 {
2952 // marking the selected columns
2953 if (Table2ColumnsCtrl->IsSelected(i) == true)
2954 Parent->GetColumn2List()->SetState(i, true);
2955 else
2956 Parent->GetColumn2List()->SetState(i, false);
2957 }
2958 Parent->SelectGeometryColumn();
2959 Parent->UpdateSqlSample();
2960 }
2961
OnMatch1Table1Selected(wxCommandEvent & WXUNUSED (event))2962 void ComposerMainPage::OnMatch1Table1Selected(wxCommandEvent & WXUNUSED(event))
2963 {
2964 //
2965 // Match #1 table #1 selection changed
2966 //
2967 Parent->SetMatch1Table1(Match1Table1Ctrl->GetValue());
2968 Parent->UpdateSqlSample();
2969 }
2970
OnMatch1Table2Selected(wxCommandEvent & WXUNUSED (event))2971 void ComposerMainPage::OnMatch1Table2Selected(wxCommandEvent & WXUNUSED(event))
2972 {
2973 //
2974 // Match #1 table #2 selection changed
2975 //
2976 Parent->SetMatch1Table2(Match1Table2Ctrl->GetValue());
2977 Parent->UpdateSqlSample();
2978 }
2979
OnMatch2Table1Selected(wxCommandEvent & WXUNUSED (event))2980 void ComposerMainPage::OnMatch2Table1Selected(wxCommandEvent & WXUNUSED(event))
2981 {
2982 //
2983 // Match #2 table #1 selection changed
2984 //
2985 Parent->SetMatch2Table1(Match2Table1Ctrl->GetValue());
2986 Parent->UpdateSqlSample();
2987 }
2988
OnMatch2Table2Selected(wxCommandEvent & WXUNUSED (event))2989 void ComposerMainPage::OnMatch2Table2Selected(wxCommandEvent & WXUNUSED(event))
2990 {
2991 //
2992 // Match #2 table #2 selection changed
2993 //
2994 Parent->SetMatch2Table2(Match2Table2Ctrl->GetValue());
2995 Parent->UpdateSqlSample();
2996 }
2997
OnMatch3Table1Selected(wxCommandEvent & WXUNUSED (event))2998 void ComposerMainPage::OnMatch3Table1Selected(wxCommandEvent & WXUNUSED(event))
2999 {
3000 //
3001 // Match #3 table #1 selection changed
3002 //
3003 Parent->SetMatch3Table1(Match3Table1Ctrl->GetValue());
3004 Parent->UpdateSqlSample();
3005 }
3006
OnMatch3Table2Selected(wxCommandEvent & WXUNUSED (event))3007 void ComposerMainPage::OnMatch3Table2Selected(wxCommandEvent & WXUNUSED(event))
3008 {
3009 //
3010 // Match #3 table #2 selection changed
3011 //
3012 Parent->SetMatch3Table2(Match3Table2Ctrl->GetValue());
3013 Parent->UpdateSqlSample();
3014 }
3015
Create(ComposerDialog * parent)3016 bool ComposerFilterPage::Create(ComposerDialog * parent)
3017 {
3018 //
3019 // creating the dialog
3020 //
3021 Parent = parent;
3022 if (wxPanel::Create(Parent->GetTabCtrl()) == false)
3023 return false;
3024 // populates individual controls
3025 CreateControls();
3026 // sets dialog sizer
3027 GetSizer()->Fit(this);
3028 GetSizer()->SetSizeHints(this);
3029 // centers the dialog window
3030 Centre();
3031 return true;
3032 }
3033
CreateControls()3034 void ComposerFilterPage::CreateControls()
3035 {
3036 //
3037 // creating individual control and setting initial values
3038 //
3039 wxSize size;
3040 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
3041 this->SetSizer(topSizer);
3042 wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
3043 topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
3044
3045 // the WHERE clauses row
3046 wxBoxSizer *whereSizer = new wxBoxSizer(wxHORIZONTAL);
3047 boxSizer->Add(whereSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
3048
3049 // the WHERE clause #1 pane
3050 wxBoxSizer *where1BoxSizer = new wxBoxSizer(wxVERTICAL);
3051 whereSizer->Add(where1BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3052 wxStaticBox *where1Box = new wxStaticBox(this, wxID_STATIC,
3053 wxT("Filter #1"),
3054 wxDefaultPosition,
3055 wxDefaultSize);
3056 wxBoxSizer *where1Sizer = new wxStaticBoxSizer(where1Box, wxVERTICAL);
3057 where1BoxSizer->Add(where1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3058 Where1EnabledCtrl =
3059 new wxCheckBox(this, ID_QVC_WHERE_1_ENABLE, wxT("Enable"));
3060 Where1EnabledCtrl->SetValue(false);
3061 if (Parent->GetTableName1().Len() == 0 && Parent->GetTableName2().Len() == 0)
3062 Where1EnabledCtrl->Enable(false);
3063 where1Sizer->Add(Where1EnabledCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3064 wxString where1Tables[2];
3065 where1Tables[0] = wxT("&Main table columns");
3066 where1Tables[1] = wxT("&Table #2 columns");
3067 Where1TableCtrl = new wxRadioBox(this, ID_QVC_WHERE_1_TABLE,
3068 wxT(""),
3069 wxDefaultPosition, wxDefaultSize, 2,
3070 where1Tables, 1, wxRA_SPECIFY_COLS);
3071 Where1TableCtrl->SetSelection(0);
3072 Where1TableCtrl->Enable(false);
3073 where1Sizer->Add(Where1TableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3074 wxStaticBox *cols1Box = new wxStaticBox(this, wxID_STATIC,
3075 wxT("Column to be filtered"),
3076 wxDefaultPosition,
3077 wxDefaultSize);
3078 wxBoxSizer *cols1Sizer = new wxStaticBoxSizer(cols1Box, wxVERTICAL);
3079 where1Sizer->Add(cols1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3080 Where1ColumnCtrl =
3081 new wxComboBox(this, ID_QVC_WHERE_1_COLUMN, wxT(""), wxDefaultPosition,
3082 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
3083 Where1ColumnCtrl->Enable(false);
3084 cols1Sizer->Add(Where1ColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3085 wxStaticBox *oper1Box = new wxStaticBox(this, wxID_STATIC,
3086 wxT("Comparison operator"),
3087 wxDefaultPosition,
3088 wxDefaultSize);
3089 wxBoxSizer *oper1Sizer = new wxStaticBoxSizer(oper1Box, wxVERTICAL);
3090 where1Sizer->Add(oper1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3091 Where1OperatorCtrl =
3092 new wxComboBox(this, ID_QVC_WHERE_1_OPERATOR, wxT(""), wxDefaultPosition,
3093 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
3094 Where1OperatorCtrl->Enable(false);
3095 oper1Sizer->Add(Where1OperatorCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3096 size = Where1OperatorCtrl->GetSize();
3097 wxStaticBox *value1Box = new wxStaticBox(this, wxID_STATIC,
3098 wxT("Value"),
3099 wxDefaultPosition,
3100 wxDefaultSize);
3101 wxBoxSizer *value1Sizer = new wxStaticBoxSizer(value1Box, wxVERTICAL);
3102 where1Sizer->Add(value1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3103 Where1ValueCtrl =
3104 new wxTextCtrl(this, ID_QVC_WHERE_1_VALUE, wxT(""), wxDefaultPosition,
3105 size);
3106 Where1ValueCtrl->Enable(false);
3107 value1Sizer->Add(Where1ValueCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3108
3109 // the CONNECTOR 1-2 pane
3110 wxString bool12[2];
3111 bool12[0] = wxT("&AND");
3112 bool12[1] = wxT("&OR");
3113 Connector12Ctrl = new wxRadioBox(this, ID_QVC_CONNECTOR_12,
3114 wxT(""),
3115 wxDefaultPosition, wxDefaultSize, 2,
3116 bool12, 1, wxRA_SPECIFY_COLS);
3117 Connector12Ctrl->SetSelection(0);
3118 Connector12Ctrl->Enable(false);
3119 whereSizer->Add(Connector12Ctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3120
3121 // the WHERE clause #2 pane
3122 wxBoxSizer *where2BoxSizer = new wxBoxSizer(wxVERTICAL);
3123 whereSizer->Add(where2BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3124 wxStaticBox *where2Box = new wxStaticBox(this, wxID_STATIC,
3125 wxT("Filter #2"),
3126 wxDefaultPosition,
3127 wxDefaultSize);
3128 wxBoxSizer *where2Sizer = new wxStaticBoxSizer(where2Box, wxVERTICAL);
3129 where2BoxSizer->Add(where2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3130 Where2EnabledCtrl =
3131 new wxCheckBox(this, ID_QVC_WHERE_2_ENABLE, wxT("Enable"));
3132 Where2EnabledCtrl->SetValue(false);
3133 if (Parent->GetTableName1().Len() == 0 && Parent->GetTableName2().Len() == 0)
3134 Where2EnabledCtrl->Enable(false);
3135 where2Sizer->Add(Where2EnabledCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3136 wxString where2Tables[2];
3137 where2Tables[0] = wxT("&Main table columns");
3138 where2Tables[1] = wxT("&Table #2 columns");
3139 Where2TableCtrl = new wxRadioBox(this, ID_QVC_WHERE_2_TABLE,
3140 wxT(""),
3141 wxDefaultPosition, wxDefaultSize, 2,
3142 where2Tables, 1, wxRA_SPECIFY_COLS);
3143 Where2TableCtrl->SetSelection(0);
3144 Where2TableCtrl->Enable(false);
3145 where2Sizer->Add(Where2TableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3146 wxStaticBox *cols2Box = new wxStaticBox(this, wxID_STATIC,
3147 wxT("Column to be filtered"),
3148 wxDefaultPosition,
3149 wxDefaultSize);
3150 wxBoxSizer *cols2Sizer = new wxStaticBoxSizer(cols2Box, wxVERTICAL);
3151 where2Sizer->Add(cols2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3152 Where2ColumnCtrl =
3153 new wxComboBox(this, ID_QVC_WHERE_2_COLUMN, wxT(""), wxDefaultPosition,
3154 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
3155 Where2ColumnCtrl->Enable(false);
3156 cols2Sizer->Add(Where2ColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3157 wxStaticBox *oper2Box = new wxStaticBox(this, wxID_STATIC,
3158 wxT("Comparison operator"),
3159 wxDefaultPosition,
3160 wxDefaultSize);
3161 wxBoxSizer *oper2Sizer = new wxStaticBoxSizer(oper2Box, wxVERTICAL);
3162 where2Sizer->Add(oper2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3163 Where2OperatorCtrl =
3164 new wxComboBox(this, ID_QVC_WHERE_2_OPERATOR, wxT(""), wxDefaultPosition,
3165 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
3166 Where2OperatorCtrl->Enable(false);
3167 oper2Sizer->Add(Where2OperatorCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3168 size = Where2OperatorCtrl->GetSize();
3169 wxStaticBox *value2Box = new wxStaticBox(this, wxID_STATIC,
3170 wxT("Value"),
3171 wxDefaultPosition,
3172 wxDefaultSize);
3173 wxBoxSizer *value2Sizer = new wxStaticBoxSizer(value2Box, wxVERTICAL);
3174 where2Sizer->Add(value2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3175 Where2ValueCtrl =
3176 new wxTextCtrl(this, ID_QVC_WHERE_2_VALUE, wxT(""), wxDefaultPosition,
3177 size);
3178 Where2ValueCtrl->Enable(false);
3179 value2Sizer->Add(Where2ValueCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3180
3181 // the CONNECTOR 2-3 pane
3182 wxString bool23[2];
3183 bool23[0] = wxT("&AND");
3184 bool23[1] = wxT("&OR");
3185 Connector23Ctrl = new wxRadioBox(this, ID_QVC_CONNECTOR_23,
3186 wxT(""),
3187 wxDefaultPosition, wxDefaultSize, 2,
3188 bool12, 1, wxRA_SPECIFY_COLS);
3189 Connector23Ctrl->SetSelection(0);
3190 Connector23Ctrl->Enable(false);
3191 whereSizer->Add(Connector23Ctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3192
3193 // the WHERE clause #3 pane
3194 wxBoxSizer *where3BoxSizer = new wxBoxSizer(wxVERTICAL);
3195 whereSizer->Add(where3BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3196 wxStaticBox *where3Box = new wxStaticBox(this, wxID_STATIC,
3197 wxT("Filter #3"),
3198 wxDefaultPosition,
3199 wxDefaultSize);
3200 wxBoxSizer *where3Sizer = new wxStaticBoxSizer(where3Box, wxVERTICAL);
3201 where3BoxSizer->Add(where3Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3202 Where3EnabledCtrl =
3203 new wxCheckBox(this, ID_QVC_WHERE_3_ENABLE, wxT("Enable"));
3204 Where3EnabledCtrl->SetValue(false);
3205 if (Parent->GetTableName1().Len() == 0 && Parent->GetTableName2().Len() == 0)
3206 Where3EnabledCtrl->Enable(false);
3207 where3Sizer->Add(Where3EnabledCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
3208 wxString where3Tables[2];
3209 where3Tables[0] = wxT("&Main table columns");
3210 where3Tables[1] = wxT("&Table #2 columns");
3211 Where3TableCtrl = new wxRadioBox(this, ID_QVC_WHERE_3_TABLE,
3212 wxT(""),
3213 wxDefaultPosition, wxDefaultSize, 2,
3214 where2Tables, 1, wxRA_SPECIFY_COLS);
3215 Where3TableCtrl->SetSelection(0);
3216 Where3TableCtrl->Enable(false);
3217 where3Sizer->Add(Where3TableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3218 wxStaticBox *cols3Box = new wxStaticBox(this, wxID_STATIC,
3219 wxT("Column to be filtered"),
3220 wxDefaultPosition,
3221 wxDefaultSize);
3222 wxBoxSizer *cols3Sizer = new wxStaticBoxSizer(cols3Box, wxVERTICAL);
3223 where3Sizer->Add(cols3Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3224 Where3ColumnCtrl =
3225 new wxComboBox(this, ID_QVC_WHERE_3_COLUMN, wxT(""), wxDefaultPosition,
3226 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
3227 Where3ColumnCtrl->Enable(false);
3228 cols3Sizer->Add(Where3ColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3229 wxStaticBox *oper3Box = new wxStaticBox(this, wxID_STATIC,
3230 wxT("Comparison operator"),
3231 wxDefaultPosition,
3232 wxDefaultSize);
3233 wxBoxSizer *oper3Sizer = new wxStaticBoxSizer(oper3Box, wxVERTICAL);
3234 where3Sizer->Add(oper3Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3235 Where3OperatorCtrl =
3236 new wxComboBox(this, ID_QVC_WHERE_3_OPERATOR, wxT(""), wxDefaultPosition,
3237 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
3238 Where3OperatorCtrl->Enable(false);
3239 oper3Sizer->Add(Where3OperatorCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3240 size = Where3OperatorCtrl->GetSize();
3241 wxStaticBox *value3Box = new wxStaticBox(this, wxID_STATIC,
3242 wxT("Value"),
3243 wxDefaultPosition,
3244 wxDefaultSize);
3245 wxBoxSizer *value3Sizer = new wxStaticBoxSizer(value3Box, wxVERTICAL);
3246 where3Sizer->Add(value3Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
3247 Where3ValueCtrl =
3248 new wxTextCtrl(this, ID_QVC_WHERE_3_VALUE, wxT(""), wxDefaultPosition,
3249 size);
3250 Where3ValueCtrl->Enable(false);
3251 value3Sizer->Add(Where3ValueCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
3252
3253 // adding the event handlers
3254 Connect(ID_QVC_WHERE_1_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
3255 (wxObjectEventFunction) & ComposerFilterPage::OnWhere1Enabled);
3256 Connect(ID_QVC_WHERE_2_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
3257 (wxObjectEventFunction) & ComposerFilterPage::OnWhere2Enabled);
3258 Connect(ID_QVC_WHERE_3_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
3259 (wxObjectEventFunction) & ComposerFilterPage::OnWhere3Enabled);
3260 Connect(ID_QVC_WHERE_1_TABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
3261 (wxObjectEventFunction) & ComposerFilterPage::OnWhere1TableChanged);
3262 Connect(ID_QVC_WHERE_2_TABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
3263 (wxObjectEventFunction) & ComposerFilterPage::OnWhere2TableChanged);
3264 Connect(ID_QVC_WHERE_3_TABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
3265 (wxObjectEventFunction) & ComposerFilterPage::OnWhere3TableChanged);
3266 Connect(ID_QVC_CONNECTOR_12, wxEVT_COMMAND_RADIOBOX_SELECTED,
3267 (wxObjectEventFunction) & ComposerFilterPage::OnConnector12Changed);
3268 Connect(ID_QVC_CONNECTOR_23, wxEVT_COMMAND_RADIOBOX_SELECTED,
3269 (wxObjectEventFunction) & ComposerFilterPage::OnConnector23Changed);
3270 Connect(ID_QVC_WHERE_1_COLUMN, wxEVT_COMMAND_COMBOBOX_SELECTED,
3271 (wxObjectEventFunction) & ComposerFilterPage::OnWhere1ColumnSelected);
3272 Connect(ID_QVC_WHERE_2_COLUMN, wxEVT_COMMAND_COMBOBOX_SELECTED,
3273 (wxObjectEventFunction) & ComposerFilterPage::OnWhere2ColumnSelected);
3274 Connect(ID_QVC_WHERE_3_COLUMN, wxEVT_COMMAND_COMBOBOX_SELECTED,
3275 (wxObjectEventFunction) & ComposerFilterPage::OnWhere3ColumnSelected);
3276 Connect(ID_QVC_WHERE_1_OPERATOR, wxEVT_COMMAND_COMBOBOX_SELECTED,
3277 (wxObjectEventFunction) &
3278 ComposerFilterPage::OnWhere1OperatorSelected);
3279 Connect(ID_QVC_WHERE_2_OPERATOR, wxEVT_COMMAND_COMBOBOX_SELECTED,
3280 (wxObjectEventFunction) &
3281 ComposerFilterPage::OnWhere2OperatorSelected);
3282 Connect(ID_QVC_WHERE_3_OPERATOR, wxEVT_COMMAND_COMBOBOX_SELECTED,
3283 (wxObjectEventFunction) &
3284 ComposerFilterPage::OnWhere3OperatorSelected);
3285 Connect(ID_QVC_WHERE_1_VALUE, wxEVT_COMMAND_TEXT_UPDATED,
3286 (wxObjectEventFunction) & ComposerFilterPage::OnWhere1ValueChanged);
3287 Connect(ID_QVC_WHERE_2_VALUE, wxEVT_COMMAND_TEXT_UPDATED,
3288 (wxObjectEventFunction) & ComposerFilterPage::OnWhere2ValueChanged);
3289 Connect(ID_QVC_WHERE_3_VALUE, wxEVT_COMMAND_TEXT_UPDATED,
3290 (wxObjectEventFunction) & ComposerFilterPage::OnWhere3ValueChanged);
3291 }
3292
Table1Status(bool ok)3293 void ComposerFilterPage::Table1Status(bool ok)
3294 {
3295 //
3296 // enabling/disabling Table#1 dependent fields
3297 //
3298 if (ok == false)
3299 {
3300 if (Parent->GetTableName2().Len() == 0)
3301 {
3302 Where1EnabledCtrl->SetValue(false);
3303 Parent->SetWhere1Enabled(false);
3304 Where1EnabledCtrl->Enable(false);
3305 Where2EnabledCtrl->SetValue(false);
3306 Parent->SetWhere2Enabled(false);
3307 Where2EnabledCtrl->Enable(false);
3308 Where3EnabledCtrl->SetValue(false);
3309 Parent->SetWhere3Enabled(false);
3310 Where3EnabledCtrl->Enable(false);
3311 Where1TableCtrl->SetSelection(0);
3312 Parent->SetWhere1Table2(false);
3313 Where1TableCtrl->Enable(false);
3314 Parent->SetWhere1Column(wxT(""));
3315 Where1ColumnCtrl->Clear();
3316 Where1ColumnCtrl->Enable(false);
3317 Parent->SetWhere1Operator(wxT(""));
3318 Where1OperatorCtrl->Clear();
3319 Where1OperatorCtrl->Enable(false);
3320 Parent->SetWhere1Operator(wxT(""));
3321 Where1ValueCtrl->SetValue(wxT(""));
3322 Where1ValueCtrl->Enable(false);
3323 Where2TableCtrl->SetSelection(0);
3324 Parent->SetWhere2Table2(false);
3325 Where2TableCtrl->Enable(false);
3326 Parent->SetWhere2Column(wxT(""));
3327 Where2ColumnCtrl->Clear();
3328 Where2ColumnCtrl->Enable(false);
3329 Parent->SetWhere2Operator(wxT(""));
3330 Where2OperatorCtrl->Clear();
3331 Where2OperatorCtrl->Enable(false);
3332 Parent->SetWhere2Operator(wxT(""));
3333 Where2ValueCtrl->SetValue(wxT(""));
3334 Where2ValueCtrl->Enable(false);
3335 Where3TableCtrl->SetSelection(0);
3336 Parent->SetWhere3Table2(false);
3337 Where3TableCtrl->Enable(false);
3338 Parent->SetWhere3Column(wxT(""));
3339 Where3ColumnCtrl->Clear();
3340 Where3ColumnCtrl->Enable(false);
3341 Parent->SetWhere3Operator(wxT(""));
3342 Where3OperatorCtrl->Clear();
3343 Where3OperatorCtrl->Enable(false);
3344 Parent->SetWhere3Operator(wxT(""));
3345 Where3ValueCtrl->SetValue(wxT(""));
3346 Where3ValueCtrl->Enable(false);
3347 Parent->SetAndOr12(true);
3348 Connector12Ctrl->SetSelection(0);
3349 Connector12Ctrl->Enable(false);
3350 Parent->SetAndOr23(true);
3351 Connector23Ctrl->SetSelection(0);
3352 Connector23Ctrl->Enable(false);
3353 } else
3354 {
3355 if (Parent->IsWhere1Table2() == false)
3356 {
3357 Where1EnabledCtrl->SetValue(false);
3358 Parent->SetWhere1Enabled(false);
3359 Where1TableCtrl->SetSelection(0);
3360 Parent->SetWhere1Table2(false);
3361 Where1TableCtrl->Enable(false);
3362 Parent->SetWhere1Column(wxT(""));
3363 Where1ColumnCtrl->Clear();
3364 Where1ColumnCtrl->Enable(false);
3365 Parent->SetWhere1Operator(wxT(""));
3366 Where1OperatorCtrl->Clear();
3367 Where1OperatorCtrl->Enable(false);
3368 Parent->SetWhere1Operator(wxT(""));
3369 Where1ValueCtrl->SetValue(wxT(""));
3370 Where1ValueCtrl->Enable(false);
3371 Parent->SetAndOr12(true);
3372 Connector12Ctrl->SetSelection(0);
3373 Connector12Ctrl->Enable(false);
3374 }
3375 if (Parent->IsWhere3Table2() == false)
3376 {
3377 Where3EnabledCtrl->SetValue(false);
3378 Parent->SetWhere3Enabled(false);
3379 Where3TableCtrl->SetSelection(0);
3380 Parent->SetWhere3Table2(false);
3381 Where3TableCtrl->Enable(false);
3382 Parent->SetWhere3Column(wxT(""));
3383 Where3ColumnCtrl->Clear();
3384 Where3ColumnCtrl->Enable(false);
3385 Parent->SetWhere3Operator(wxT(""));
3386 Where3OperatorCtrl->Clear();
3387 Where3OperatorCtrl->Enable(false);
3388 Where3ValueCtrl->SetValue(wxT(""));
3389 Where3ValueCtrl->Enable(false);
3390 Parent->SetAndOr23(true);
3391 Connector23Ctrl->SetSelection(0);
3392 Connector23Ctrl->Enable(false);
3393 }
3394 if (Parent->IsWhere2Table2() == false)
3395 {
3396 Where2EnabledCtrl->SetValue(false);
3397 Parent->SetWhere2Enabled(false);
3398 Where2TableCtrl->SetSelection(0);
3399 Parent->SetWhere2Table2(false);
3400 Where2TableCtrl->Enable(false);
3401 Parent->SetWhere2Column(wxT(""));
3402 Where2ColumnCtrl->Clear();
3403 Where2ColumnCtrl->Enable(false);
3404 Parent->SetWhere2Operator(wxT(""));
3405 Where2OperatorCtrl->Clear();
3406 Where2OperatorCtrl->Enable(false);
3407 Parent->SetWhere2Operator(wxT(""));
3408 Where2ValueCtrl->SetValue(wxT(""));
3409 Where2ValueCtrl->Enable(false);
3410 Parent->SetAndOr12(true);
3411 Connector12Ctrl->SetSelection(0);
3412 Connector12Ctrl->Enable(false);
3413 if (Parent->IsWhere3Enabled() == true
3414 && Parent->IsWhere1Enabled() == true)
3415 ;
3416 else
3417 {
3418 Parent->SetAndOr23(true);
3419 Connector23Ctrl->SetSelection(0);
3420 Connector23Ctrl->Enable(false);
3421 }
3422 }
3423 }
3424 } else
3425 {
3426 Where1EnabledCtrl->Enable(true);
3427 Where2EnabledCtrl->Enable(true);
3428 Where3EnabledCtrl->Enable(true);
3429 }
3430 }
3431
Table2Status(bool ok)3432 void ComposerFilterPage::Table2Status(bool ok)
3433 {
3434 //
3435 // enabling/disabling Table#2 dependent fields
3436 //
3437 if (ok == false)
3438 {
3439 if (Parent->GetTableName1().Len() == 0)
3440 {
3441 Where1EnabledCtrl->SetValue(false);
3442 Parent->SetWhere1Enabled(false);
3443 Where1EnabledCtrl->Enable(false);
3444 Where2EnabledCtrl->SetValue(false);
3445 Parent->SetWhere2Enabled(false);
3446 Where2EnabledCtrl->Enable(false);
3447 Where3EnabledCtrl->SetValue(false);
3448 Parent->SetWhere3Enabled(false);
3449 Where3EnabledCtrl->Enable(false);
3450 Where1TableCtrl->SetSelection(0);
3451 Parent->SetWhere1Table2(false);
3452 Where1TableCtrl->Enable(false);
3453 Parent->SetWhere1Column(wxT(""));
3454 Where1ColumnCtrl->Clear();
3455 Where1ColumnCtrl->Enable(false);
3456 Parent->SetWhere1Operator(wxT(""));
3457 Where1OperatorCtrl->Clear();
3458 Where1OperatorCtrl->Enable(false);
3459 Parent->SetWhere1Operator(wxT(""));
3460 Where1ValueCtrl->SetValue(wxT(""));
3461 Where1ValueCtrl->Enable(false);
3462 Where2TableCtrl->SetSelection(0);
3463 Parent->SetWhere2Table2(false);
3464 Where2TableCtrl->Enable(false);
3465 Parent->SetWhere2Column(wxT(""));
3466 Where2ColumnCtrl->Clear();
3467 Where2ColumnCtrl->Enable(false);
3468 Parent->SetWhere2Operator(wxT(""));
3469 Where2OperatorCtrl->Clear();
3470 Where2OperatorCtrl->Enable(false);
3471 Parent->SetWhere2Operator(wxT(""));
3472 Where2ValueCtrl->SetValue(wxT(""));
3473 Where2ValueCtrl->Enable(false);
3474 Where3TableCtrl->SetSelection(0);
3475 Parent->SetWhere3Table2(false);
3476 Where3TableCtrl->Enable(false);
3477 Parent->SetWhere3Column(wxT(""));
3478 Where3ColumnCtrl->Clear();
3479 Where3ColumnCtrl->Enable(false);
3480 Parent->SetWhere3Operator(wxT(""));
3481 Where3OperatorCtrl->Clear();
3482 Where3OperatorCtrl->Enable(false);
3483 Parent->SetWhere3Operator(wxT(""));
3484 Where3ValueCtrl->SetValue(wxT(""));
3485 Where3ValueCtrl->Enable(false);
3486 Parent->SetAndOr12(true);
3487 Connector12Ctrl->SetSelection(0);
3488 Connector12Ctrl->Enable(false);
3489 Parent->SetAndOr23(true);
3490 Connector23Ctrl->SetSelection(0);
3491 Connector23Ctrl->Enable(false);
3492 } else
3493 {
3494 if (Parent->IsWhere1Table2() == true)
3495 {
3496 Where1EnabledCtrl->SetValue(false);
3497 Parent->SetWhere1Enabled(false);
3498 Where1TableCtrl->SetSelection(0);
3499 Parent->SetWhere1Table2(false);
3500 Where1TableCtrl->Enable(false);
3501 Parent->SetWhere1Column(wxT(""));
3502 Where1ColumnCtrl->Clear();
3503 Where1ColumnCtrl->Enable(false);
3504 Parent->SetWhere1Operator(wxT(""));
3505 Where1OperatorCtrl->Clear();
3506 Where1OperatorCtrl->Enable(false);
3507 Parent->SetWhere1Operator(wxT(""));
3508 Where1ValueCtrl->SetValue(wxT(""));
3509 Where1ValueCtrl->Enable(false);
3510 Parent->SetAndOr12(true);
3511 Connector12Ctrl->SetSelection(0);
3512 Connector12Ctrl->Enable(false);
3513 }
3514 if (Parent->IsWhere3Table2() == true)
3515 {
3516 Where3EnabledCtrl->SetValue(false);
3517 Parent->SetWhere3Enabled(false);
3518 Where3TableCtrl->SetSelection(0);
3519 Parent->SetWhere3Table2(false);
3520 Where3TableCtrl->Enable(false);
3521 Parent->SetWhere3Column(wxT(""));
3522 Where3ColumnCtrl->Clear();
3523 Where3ColumnCtrl->Enable(false);
3524 Parent->SetWhere3Operator(wxT(""));
3525 Where3OperatorCtrl->Clear();
3526 Where3OperatorCtrl->Enable(false);
3527 Where3ValueCtrl->SetValue(wxT(""));
3528 Where3ValueCtrl->Enable(false);
3529 Parent->SetAndOr23(true);
3530 Connector23Ctrl->SetSelection(0);
3531 Connector23Ctrl->Enable(false);
3532 }
3533 if (Parent->IsWhere2Table2() == true)
3534 {
3535 Where2EnabledCtrl->SetValue(false);
3536 Parent->SetWhere2Enabled(false);
3537 Where2TableCtrl->SetSelection(0);
3538 Parent->SetWhere2Table2(false);
3539 Where2TableCtrl->Enable(false);
3540 Parent->SetWhere2Column(wxT(""));
3541 Where2ColumnCtrl->Clear();
3542 Where2ColumnCtrl->Enable(false);
3543 Parent->SetWhere2Operator(wxT(""));
3544 Where2OperatorCtrl->Clear();
3545 Where2OperatorCtrl->Enable(false);
3546 Parent->SetWhere2Operator(wxT(""));
3547 Where2ValueCtrl->SetValue(wxT(""));
3548 Where2ValueCtrl->Enable(false);
3549 Parent->SetAndOr12(true);
3550 Connector12Ctrl->SetSelection(0);
3551 Connector12Ctrl->Enable(false);
3552 if (Parent->IsWhere3Enabled() == true
3553 && Parent->IsWhere1Enabled() == true)
3554 ;
3555 else
3556 {
3557 Parent->SetAndOr23(true);
3558 Connector23Ctrl->SetSelection(0);
3559 Connector23Ctrl->Enable(false);
3560 }
3561 }
3562 }
3563 } else
3564 {
3565 Where1EnabledCtrl->Enable(true);
3566 Where2EnabledCtrl->Enable(true);
3567 Where3EnabledCtrl->Enable(true);
3568 }
3569 }
3570
InitializeOperators(wxComboBox * ctrl)3571 void ComposerFilterPage::InitializeOperators(wxComboBox * ctrl)
3572 {
3573 // initializing a list of boolean operators ComboBox
3574 ctrl->Clear();
3575 ctrl->Append(wxT("= {equal to}"));
3576 ctrl->Append(wxT("<> {not equal}"));
3577 ctrl->Append(wxT("< {lesser than}"));
3578 ctrl->Append(wxT("<= {lesser / equal}"));
3579 ctrl->Append(wxT("> {greather than}"));
3580 ctrl->Append(wxT(">= {greather / equal}"));
3581 ctrl->Append(wxT("LIKE {text search}"));
3582 ctrl->Append(wxT("IN {val1, val2, ...}"));
3583 ctrl->Append(wxT("IS NULL"));
3584 ctrl->Append(wxT("IS NOT NULL"));
3585 }
3586
InitializeColumns(wxComboBox * ctrl,bool table2)3587 void ComposerFilterPage::InitializeColumns(wxComboBox * ctrl, bool table2)
3588 {
3589 // initializing a columns list ComboBox
3590 ctrl->Clear();
3591 AuxColumn *pColumn;
3592 if (table2 == false)
3593 pColumn = Parent->GetColumn1List()->GetFirst();
3594 else
3595 pColumn = Parent->GetColumn2List()->GetFirst();
3596 while (pColumn)
3597 {
3598 wxString col = pColumn->GetName();
3599 ctrl->Append(col);
3600 pColumn = pColumn->GetNext();
3601 }
3602 }
3603
OnWhere1Enabled(wxCommandEvent & WXUNUSED (event))3604 void ComposerFilterPage::OnWhere1Enabled(wxCommandEvent & WXUNUSED(event))
3605 {
3606 //
3607 // Where #1 clause enabled/disabled
3608 //
3609 Parent->SetWhere1Enabled(Where1EnabledCtrl->GetValue());
3610 if (Parent->IsWhere1Enabled() == true)
3611 {
3612 if (Parent->IsTable2Enabled() == true)
3613 {
3614 if (Parent->IsWhere1Table2() == false)
3615 Where1TableCtrl->SetSelection(0);
3616 else
3617 Where1TableCtrl->SetSelection(1);
3618 Where1TableCtrl->Enable(true);
3619 } else
3620 {
3621 Parent->SetWhere1Table2(false);
3622 Where1TableCtrl->SetSelection(0);
3623 Where1TableCtrl->Enable(false);
3624 Parent->SetWhere1Column(wxT(""));
3625 Where1ColumnCtrl->Clear();
3626 }
3627 Parent->SetWhere1Column(wxT(""));
3628 InitializeColumns(Where1ColumnCtrl, Parent->IsWhere1Table2());
3629 Where1ColumnCtrl->Enable(true);
3630 Parent->SetWhere1Operator(wxT(""));
3631 InitializeOperators(Where1OperatorCtrl);
3632 Where1OperatorCtrl->Enable(true);
3633 Where1ValueCtrl->SetValue(wxT(""));
3634 Where1ValueCtrl->Enable(true);
3635 if (Parent->IsWhere2Enabled() == true)
3636 {
3637 Parent->SetAndOr12(true);
3638 Connector12Ctrl->SetSelection(0);
3639 Connector12Ctrl->Enable(true);
3640 } else if (Parent->IsWhere3Enabled() == true)
3641 {
3642 Parent->SetAndOr23(true);
3643 Connector23Ctrl->SetSelection(0);
3644 Connector23Ctrl->Enable(true);
3645 }
3646 } else
3647 {
3648 Where1TableCtrl->SetSelection(0);
3649 Parent->SetWhere1Table2(false);
3650 Where1TableCtrl->Enable(false);
3651 Parent->SetWhere1Column(wxT(""));
3652 Where1ColumnCtrl->Clear();
3653 Where1ColumnCtrl->Enable(false);
3654 Parent->SetWhere1Operator(wxT(""));
3655 Where1OperatorCtrl->Clear();
3656 Where1OperatorCtrl->Enable(false);
3657 Parent->SetWhere1Operator(wxT(""));
3658 Where1ValueCtrl->SetValue(wxT(""));
3659 Where1ValueCtrl->Enable(false);
3660 Parent->SetAndOr12(true);
3661 Connector12Ctrl->SetSelection(0);
3662 Connector12Ctrl->Enable(false);
3663 }
3664 Parent->UpdateSqlSample();
3665 }
3666
OnWhere2Enabled(wxCommandEvent & WXUNUSED (event))3667 void ComposerFilterPage::OnWhere2Enabled(wxCommandEvent & WXUNUSED(event))
3668 {
3669 //
3670 // Where #2 clause enabled/disabled
3671 //
3672 Parent->SetWhere2Enabled(Where2EnabledCtrl->GetValue());
3673 if (Parent->IsWhere2Enabled() == true)
3674 {
3675 if (Parent->IsTable2Enabled() == true)
3676 {
3677 if (Parent->IsWhere2Table2() == false)
3678 Where2TableCtrl->SetSelection(0);
3679 else
3680 Where2TableCtrl->SetSelection(1);
3681 Where2TableCtrl->Enable(true);
3682 } else
3683 {
3684 Parent->SetWhere2Table2(false);
3685 Where2TableCtrl->SetSelection(0);
3686 Where2TableCtrl->Enable(false);
3687 Parent->SetWhere2Column(wxT(""));
3688 Where2ColumnCtrl->Clear();
3689 }
3690 Parent->SetWhere2Column(wxT(""));
3691 InitializeColumns(Where2ColumnCtrl, Parent->IsWhere2Table2());
3692 Where2ColumnCtrl->Enable(true);
3693 Parent->SetWhere2Operator(wxT(""));
3694 InitializeOperators(Where2OperatorCtrl);
3695 Where2OperatorCtrl->Enable(true);
3696 Where2ValueCtrl->SetValue(wxT(""));
3697 Where2ValueCtrl->Enable(true);
3698 if (Parent->IsWhere1Enabled() == true)
3699 {
3700 Parent->SetAndOr12(true);
3701 Connector12Ctrl->SetSelection(0);
3702 Connector12Ctrl->Enable(true);
3703 }
3704 if (Parent->IsWhere3Enabled() == true)
3705 {
3706 Parent->SetAndOr23(true);
3707 Connector23Ctrl->SetSelection(0);
3708 Connector23Ctrl->Enable(true);
3709 }
3710 } else
3711 {
3712 Where2TableCtrl->SetSelection(0);
3713 Parent->SetWhere2Table2(false);
3714 Where2TableCtrl->Enable(false);
3715 Parent->SetWhere2Column(wxT(""));
3716 Where2ColumnCtrl->Clear();
3717 Where2ColumnCtrl->Enable(false);
3718 Parent->SetWhere2Operator(wxT(""));
3719 Where2OperatorCtrl->Clear();
3720 Where2OperatorCtrl->Enable(false);
3721 Parent->SetWhere2Operator(wxT(""));
3722 Where2ValueCtrl->SetValue(wxT(""));
3723 Where2ValueCtrl->Enable(false);
3724 Parent->SetAndOr12(true);
3725 Connector12Ctrl->SetSelection(0);
3726 Connector12Ctrl->Enable(false);
3727 if (Parent->IsWhere3Enabled() == true
3728 && Parent->IsWhere1Enabled() == true)
3729 ;
3730 else
3731 {
3732 Parent->SetAndOr23(true);
3733 Connector23Ctrl->SetSelection(0);
3734 Connector23Ctrl->Enable(false);
3735 }
3736 }
3737 Parent->UpdateSqlSample();
3738 }
3739
OnWhere3Enabled(wxCommandEvent & WXUNUSED (event))3740 void ComposerFilterPage::OnWhere3Enabled(wxCommandEvent & WXUNUSED(event))
3741 {
3742 //
3743 // Where #3 clause enabled/disabled
3744 //
3745 Parent->SetWhere3Enabled(Where3EnabledCtrl->GetValue());
3746 if (Parent->IsWhere3Enabled() == true)
3747 {
3748 if (Parent->IsTable2Enabled() == true)
3749 {
3750 if (Parent->IsWhere3Table2() == false)
3751 Where3TableCtrl->SetSelection(0);
3752 else
3753 Where3TableCtrl->SetSelection(1);
3754 Where3TableCtrl->Enable(true);
3755 } else
3756 {
3757 Parent->SetWhere3Table2(false);
3758 Where3TableCtrl->SetSelection(0);
3759 Where3TableCtrl->Enable(false);
3760 Parent->SetWhere3Column(wxT(""));
3761 Where3ColumnCtrl->Clear();
3762 }
3763 Parent->SetWhere3Column(wxT(""));
3764 InitializeColumns(Where3ColumnCtrl, Parent->IsWhere3Table2());
3765 Where3ColumnCtrl->Enable(true);
3766 Parent->SetWhere3Operator(wxT(""));
3767 InitializeOperators(Where3OperatorCtrl);
3768 Where3OperatorCtrl->Enable(true);
3769 Where3ValueCtrl->SetValue(wxT(""));
3770 Where3ValueCtrl->Enable(true);
3771 if (Parent->IsWhere2Enabled() == true
3772 || Parent->IsWhere1Enabled() == true)
3773 {
3774 Parent->SetAndOr23(true);
3775 Connector23Ctrl->SetSelection(0);
3776 Connector23Ctrl->Enable(true);
3777 }
3778 } else
3779 {
3780 Where3TableCtrl->SetSelection(0);
3781 Parent->SetWhere3Table2(false);
3782 Where3TableCtrl->Enable(false);
3783 Parent->SetWhere3Column(wxT(""));
3784 Where3ColumnCtrl->Clear();
3785 Where3ColumnCtrl->Enable(false);
3786 Parent->SetWhere3Operator(wxT(""));
3787 Where3OperatorCtrl->Clear();
3788 Where3OperatorCtrl->Enable(false);
3789 Where3ValueCtrl->SetValue(wxT(""));
3790 Where3ValueCtrl->Enable(false);
3791 Parent->SetAndOr23(true);
3792 Connector23Ctrl->SetSelection(0);
3793 Connector23Ctrl->Enable(false);
3794 }
3795 Parent->UpdateSqlSample();
3796 }
3797
OnWhere1TableChanged(wxCommandEvent & WXUNUSED (event))3798 void ComposerFilterPage::OnWhere1TableChanged(wxCommandEvent & WXUNUSED(event))
3799 {
3800 //
3801 // Where #1 table changed
3802 //
3803 if (Where1TableCtrl->GetSelection() == 1)
3804 Parent->SetWhere1Table2(true);
3805 else
3806 Parent->SetWhere1Table2(false);
3807 InitializeColumns(Where1ColumnCtrl, Parent->IsWhere1Table2());
3808 }
3809
OnWhere2TableChanged(wxCommandEvent & WXUNUSED (event))3810 void ComposerFilterPage::OnWhere2TableChanged(wxCommandEvent & WXUNUSED(event))
3811 {
3812 //
3813 // Where #2 table changed
3814 //
3815 if (Where2TableCtrl->GetSelection() == 1)
3816 Parent->SetWhere2Table2(true);
3817 else
3818 Parent->SetWhere2Table2(false);
3819 InitializeColumns(Where2ColumnCtrl, Parent->IsWhere2Table2());
3820 }
3821
OnWhere3TableChanged(wxCommandEvent & WXUNUSED (event))3822 void ComposerFilterPage::OnWhere3TableChanged(wxCommandEvent & WXUNUSED(event))
3823 {
3824 //
3825 // Where #3 table changed
3826 //
3827 if (Where3TableCtrl->GetSelection() == 1)
3828 Parent->SetWhere3Table2(true);
3829 else
3830 Parent->SetWhere3Table2(false);
3831 InitializeColumns(Where3ColumnCtrl, Parent->IsWhere3Table2());
3832 }
3833
OnConnector12Changed(wxCommandEvent & WXUNUSED (event))3834 void ComposerFilterPage::OnConnector12Changed(wxCommandEvent & WXUNUSED(event))
3835 {
3836 //
3837 // Connector 1-2 changed
3838 //
3839 if (Connector12Ctrl->GetSelection() == 0)
3840 Parent->SetAndOr12(true);
3841 else
3842 Parent->SetAndOr12(false);
3843 Parent->UpdateSqlSample();
3844 }
3845
OnConnector23Changed(wxCommandEvent & WXUNUSED (event))3846 void ComposerFilterPage::OnConnector23Changed(wxCommandEvent & WXUNUSED(event))
3847 {
3848 //
3849 // Connector 2-3 changed
3850 //
3851 if (Connector23Ctrl->GetSelection() == 0)
3852 Parent->SetAndOr23(true);
3853 else
3854 Parent->SetAndOr23(false);
3855 Parent->UpdateSqlSample();
3856 }
3857
3858 void ComposerFilterPage::
OnWhere1ColumnSelected(wxCommandEvent & WXUNUSED (event))3859 OnWhere1ColumnSelected(wxCommandEvent & WXUNUSED(event))
3860 {
3861 //
3862 // Where #1 column changed
3863 //
3864 Parent->SetWhere1Column(Where1ColumnCtrl->GetValue());
3865 Parent->UpdateSqlSample();
3866 }
3867
3868 void ComposerFilterPage::
OnWhere2ColumnSelected(wxCommandEvent & WXUNUSED (event))3869 OnWhere2ColumnSelected(wxCommandEvent & WXUNUSED(event))
3870 {
3871 //
3872 // Where #2 column changed
3873 //
3874 Parent->SetWhere2Column(Where2ColumnCtrl->GetValue());
3875 Parent->UpdateSqlSample();
3876 }
3877
3878 void ComposerFilterPage::
OnWhere3ColumnSelected(wxCommandEvent & WXUNUSED (event))3879 OnWhere3ColumnSelected(wxCommandEvent & WXUNUSED(event))
3880 {
3881 //
3882 // Where #3 column changed
3883 //
3884 Parent->SetWhere3Column(Where3ColumnCtrl->GetValue());
3885 Parent->UpdateSqlSample();
3886 }
3887
3888 void ComposerFilterPage::
OnWhere1OperatorSelected(wxCommandEvent & WXUNUSED (event))3889 OnWhere1OperatorSelected(wxCommandEvent & WXUNUSED(event))
3890 {
3891 //
3892 // Where #1 operator changed
3893 //
3894 wxString str = Where1OperatorCtrl->GetValue();
3895 wxString clean = wxT("");
3896 if (str == wxT("= {equal to}"))
3897 clean = wxT("=");
3898 if (str == wxT("<> {not equal}"))
3899 clean = wxT("<>");
3900 if (str == wxT("< {lesser than}"))
3901 clean = wxT("<");
3902 if (str == wxT("<= {lesser / equal}"))
3903 clean = wxT("<=");
3904 if (str == wxT("> {greather than}"))
3905 clean = wxT(">");
3906 if (str == wxT(">= {greather / equal}"))
3907 clean = wxT(">=");
3908 if (str == wxT("LIKE {text search}"))
3909 clean = wxT("LIKE");
3910 if (str == wxT("IN {val1, val2, ...}"))
3911 clean = wxT("IN");
3912 if (str == wxT("IS NULL"))
3913 clean = wxT("IS NULL");
3914 if (str == wxT("IS NOT NULL"))
3915 clean = wxT("IS NOT NULL");
3916 Parent->SetWhere1Operator(clean);
3917 if (Parent->GetWhere1Operator() == wxT("IS NULL")
3918 || Parent->GetWhere1Operator() == wxT("IS NOT NULL"))
3919 {
3920 Where1ValueCtrl->SetValue(wxT(""));
3921 Parent->SetWhere1Value(wxT(""));
3922 Where1ValueCtrl->Enable(false);
3923 } else
3924 {
3925 Where1ValueCtrl->SetValue(Parent->GetWhere1Value());
3926 Where1ValueCtrl->Enable(true);
3927 }
3928 Parent->UpdateSqlSample();
3929 }
3930
3931 void ComposerFilterPage::
OnWhere2OperatorSelected(wxCommandEvent & WXUNUSED (event))3932 OnWhere2OperatorSelected(wxCommandEvent & WXUNUSED(event))
3933 {
3934 //
3935 // Where #2 operator changed
3936 //
3937 wxString str = Where2OperatorCtrl->GetValue();
3938 wxString clean = wxT("");
3939 if (str == wxT("= {equal to}"))
3940 clean = wxT("=");
3941 if (str == wxT("<> {not equal}"))
3942 clean = wxT("<>");
3943 if (str == wxT("< {lesser than}"))
3944 clean = wxT("<");
3945 if (str == wxT("<= {lesser / equal}"))
3946 clean = wxT("<=");
3947 if (str == wxT("> {greather than}"))
3948 clean = wxT(">");
3949 if (str == wxT(">= {greather / equal}"))
3950 clean = wxT(">=");
3951 if (str == wxT("LIKE {text search}"))
3952 clean = wxT("LIKE");
3953 if (str == wxT("IN {val1, val2, ...}"))
3954 clean = wxT("IN");
3955 if (str == wxT("IS NULL"))
3956 clean = wxT("IS NULL");
3957 if (str == wxT("IS NOT NULL"))
3958 clean = wxT("IS NOT NULL");
3959 Parent->SetWhere2Operator(clean);
3960 if (Parent->GetWhere2Operator() == wxT("IS NULL")
3961 || Parent->GetWhere2Operator() == wxT("IS NOT NULL"))
3962 {
3963 Where2ValueCtrl->SetValue(wxT(""));
3964 Parent->SetWhere2Value(wxT(""));
3965 Where2ValueCtrl->Enable(false);
3966 } else
3967 {
3968 Where2ValueCtrl->SetValue(Parent->GetWhere2Value());
3969 Where2ValueCtrl->Enable(true);
3970 }
3971 Parent->UpdateSqlSample();
3972 }
3973
3974 void ComposerFilterPage::
OnWhere3OperatorSelected(wxCommandEvent & WXUNUSED (event))3975 OnWhere3OperatorSelected(wxCommandEvent & WXUNUSED(event))
3976 {
3977 //
3978 // Where #3 operator changed
3979 //
3980 wxString str = Where3OperatorCtrl->GetValue();
3981 wxString clean = wxT("");
3982 if (str == wxT("= {equal to}"))
3983 clean = wxT("=");
3984 if (str == wxT("<> {not equal}"))
3985 clean = wxT("<>");
3986 if (str == wxT("< {lesser than}"))
3987 clean = wxT("<");
3988 if (str == wxT("<= {lesser / equal}"))
3989 clean = wxT("<=");
3990 if (str == wxT("> {greather than}"))
3991 clean = wxT(">");
3992 if (str == wxT(">= {greather / equal}"))
3993 clean = wxT(">=");
3994 if (str == wxT("LIKE {text search}"))
3995 clean = wxT("LIKE");
3996 if (str == wxT("IN {val1, val2, ...}"))
3997 clean = wxT("IN");
3998 if (str == wxT("IS NULL"))
3999 clean = wxT("IS NULL");
4000 if (str == wxT("IS NOT NULL"))
4001 clean = wxT("IS NOT NULL");
4002 Parent->SetWhere3Operator(clean);
4003 if (Parent->GetWhere3Operator() == wxT("IS NULL")
4004 || Parent->GetWhere3Operator() == wxT("IS NOT NULL"))
4005 {
4006 Where3ValueCtrl->SetValue(wxT(""));
4007 Parent->SetWhere3Value(wxT(""));
4008 Where3ValueCtrl->Enable(false);
4009 } else
4010 {
4011 Where3ValueCtrl->SetValue(Parent->GetWhere3Value());
4012 Where3ValueCtrl->Enable(true);
4013 }
4014 Parent->UpdateSqlSample();
4015 }
4016
OnWhere1ValueChanged(wxCommandEvent & WXUNUSED (event))4017 void ComposerFilterPage::OnWhere1ValueChanged(wxCommandEvent & WXUNUSED(event))
4018 {
4019 //
4020 // Where #1 value changed
4021 //
4022 Parent->SetWhere1Value(Where1ValueCtrl->GetValue());
4023 Parent->UpdateSqlSample();
4024 }
4025
OnWhere2ValueChanged(wxCommandEvent & WXUNUSED (event))4026 void ComposerFilterPage::OnWhere2ValueChanged(wxCommandEvent & WXUNUSED(event))
4027 {
4028 //
4029 // Where #2 value changed
4030 //
4031 Parent->SetWhere2Value(Where2ValueCtrl->GetValue());
4032 Parent->UpdateSqlSample();
4033 }
4034
OnWhere3ValueChanged(wxCommandEvent & WXUNUSED (event))4035 void ComposerFilterPage::OnWhere3ValueChanged(wxCommandEvent & WXUNUSED(event))
4036 {
4037 //
4038 // Where #3 value changed
4039 //
4040 Parent->SetWhere3Value(Where3ValueCtrl->GetValue());
4041 Parent->UpdateSqlSample();
4042 }
4043
Create(ComposerDialog * parent)4044 bool ComposerOrderPage::Create(ComposerDialog * parent)
4045 {
4046 //
4047 // creating the dialog
4048 //
4049 Parent = parent;
4050 if (wxPanel::Create(Parent->GetTabCtrl()) == false)
4051 return false;
4052 // populates individual controls
4053 CreateControls();
4054 // sets dialog sizer
4055 GetSizer()->Fit(this);
4056 GetSizer()->SetSizeHints(this);
4057 // centers the dialog window
4058 Centre();
4059 return true;
4060 }
4061
CreateControls()4062 void ComposerOrderPage::CreateControls()
4063 {
4064 //
4065 // creating individual control and setting initial values
4066 //
4067 wxSize size;
4068 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
4069 this->SetSizer(topSizer);
4070 wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
4071 topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4072
4073 // the ORDER BY clauses row
4074 wxBoxSizer *OrderSizer = new wxBoxSizer(wxHORIZONTAL);
4075 boxSizer->Add(OrderSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4076
4077 // the Order clause #1 pane
4078 wxBoxSizer *Order1BoxSizer = new wxBoxSizer(wxVERTICAL);
4079 OrderSizer->Add(Order1BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4080 wxStaticBox *Order1Box = new wxStaticBox(this, wxID_STATIC,
4081 wxT("Order by #1"),
4082 wxDefaultPosition,
4083 wxDefaultSize);
4084 wxBoxSizer *Order1Sizer = new wxStaticBoxSizer(Order1Box, wxVERTICAL);
4085 Order1BoxSizer->Add(Order1Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4086 Order1EnabledCtrl =
4087 new wxCheckBox(this, ID_QVC_ORDER_1_ENABLE, wxT("Enable"));
4088 Order1EnabledCtrl->SetValue(false);
4089 if (Parent->GetTableName1().Len() == 0 && Parent->GetTableName2().Len() == 0)
4090 Order1EnabledCtrl->Enable(false);
4091 Order1Sizer->Add(Order1EnabledCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
4092 wxString Order1Tables[2];
4093 Order1Tables[0] = wxT("&Main table columns");
4094 Order1Tables[1] = wxT("&Table #2 columns");
4095 Order1TableCtrl = new wxRadioBox(this, ID_QVC_ORDER_1_TABLE,
4096 wxT(""),
4097 wxDefaultPosition, wxDefaultSize, 2,
4098 Order1Tables, 1, wxRA_SPECIFY_COLS);
4099 Order1TableCtrl->SetSelection(0);
4100 Order1TableCtrl->Enable(false);
4101 Order1Sizer->Add(Order1TableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4102 Order1ColumnCtrl =
4103 new wxComboBox(this, ID_QVC_ORDER_1_COLUMN, wxT(""), wxDefaultPosition,
4104 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
4105 Order1ColumnCtrl->Enable(false);
4106 Order1Sizer->Add(Order1ColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4107 wxString desc1[2];
4108 desc1[0] = wxT("&Descending [Z-A]");
4109 desc1[1] = wxT("&Ascending [A-Z]");
4110 Order1DescCtrl = new wxRadioBox(this, ID_QVC_ORDER_1_DESC,
4111 wxT("Direction"),
4112 wxDefaultPosition, wxDefaultSize, 2,
4113 desc1, 1, wxRA_SPECIFY_COLS);
4114 Order1DescCtrl->SetSelection(1);
4115 Order1DescCtrl->Enable(false);
4116 Order1Sizer->Add(Order1DescCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4117
4118 // the Order clause #2 pane
4119 wxBoxSizer *Order2BoxSizer = new wxBoxSizer(wxVERTICAL);
4120 OrderSizer->Add(Order2BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4121 wxStaticBox *Order2Box = new wxStaticBox(this, wxID_STATIC,
4122 wxT("Order by #2"),
4123 wxDefaultPosition,
4124 wxDefaultSize);
4125 wxBoxSizer *Order2Sizer = new wxStaticBoxSizer(Order2Box, wxVERTICAL);
4126 Order2BoxSizer->Add(Order2Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4127 Order2EnabledCtrl =
4128 new wxCheckBox(this, ID_QVC_ORDER_2_ENABLE, wxT("Enable"));
4129 Order2EnabledCtrl->SetValue(false);
4130 if (Parent->GetTableName1().Len() == 0 && Parent->GetTableName2().Len() == 0)
4131 Order2EnabledCtrl->Enable(false);
4132 Order2Sizer->Add(Order2EnabledCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
4133 wxString Order2Tables[2];
4134 Order2Tables[0] = wxT("&Main table columns");
4135 Order2Tables[1] = wxT("&Table #2 columns");
4136 Order2TableCtrl = new wxRadioBox(this, ID_QVC_ORDER_2_TABLE,
4137 wxT(""),
4138 wxDefaultPosition, wxDefaultSize, 2,
4139 Order2Tables, 1, wxRA_SPECIFY_COLS);
4140 Order2TableCtrl->SetSelection(0);
4141 Order2TableCtrl->Enable(false);
4142 Order2Sizer->Add(Order2TableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4143 Order2ColumnCtrl =
4144 new wxComboBox(this, ID_QVC_ORDER_2_COLUMN, wxT(""), wxDefaultPosition,
4145 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
4146 Order2ColumnCtrl->Enable(false);
4147 Order2Sizer->Add(Order2ColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4148 wxString desc2[2];
4149 desc2[0] = wxT("&Descending [Z-A]");
4150 desc2[1] = wxT("&Ascending [A-Z]");
4151 Order2DescCtrl = new wxRadioBox(this, ID_QVC_ORDER_2_DESC,
4152 wxT("Direction"),
4153 wxDefaultPosition, wxDefaultSize, 2,
4154 desc2, 1, wxRA_SPECIFY_COLS);
4155 Order2DescCtrl->SetSelection(1);
4156 Order2DescCtrl->Enable(false);
4157 Order2Sizer->Add(Order2DescCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4158
4159 // the Order clause #3 pane
4160 wxBoxSizer *Order3BoxSizer = new wxBoxSizer(wxVERTICAL);
4161 OrderSizer->Add(Order3BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4162 wxStaticBox *Order3Box = new wxStaticBox(this, wxID_STATIC,
4163 wxT("Order by #3"),
4164 wxDefaultPosition,
4165 wxDefaultSize);
4166 wxBoxSizer *Order3Sizer = new wxStaticBoxSizer(Order3Box, wxVERTICAL);
4167 Order3BoxSizer->Add(Order3Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4168 Order3EnabledCtrl =
4169 new wxCheckBox(this, ID_QVC_ORDER_3_ENABLE, wxT("Enable"));
4170 Order3EnabledCtrl->SetValue(false);
4171 if (Parent->GetTableName1().Len() == 0 && Parent->GetTableName2().Len() == 0)
4172 Order3EnabledCtrl->Enable(false);
4173 Order3Sizer->Add(Order3EnabledCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
4174 wxString Order3Tables[2];
4175 Order3Tables[0] = wxT("&Main table columns");
4176 Order3Tables[1] = wxT("&Table #2 columns");
4177 Order3TableCtrl = new wxRadioBox(this, ID_QVC_ORDER_3_TABLE,
4178 wxT(""),
4179 wxDefaultPosition, wxDefaultSize, 2,
4180 Order2Tables, 1, wxRA_SPECIFY_COLS);
4181 Order3TableCtrl->SetSelection(0);
4182 Order3TableCtrl->Enable(false);
4183 Order3Sizer->Add(Order3TableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4184 Order3ColumnCtrl =
4185 new wxComboBox(this, ID_QVC_ORDER_3_COLUMN, wxT(""), wxDefaultPosition,
4186 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
4187 Order3ColumnCtrl->Enable(false);
4188 Order3Sizer->Add(Order3ColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4189 wxString desc3[2];
4190 desc3[0] = wxT("&Descending [Z-A]");
4191 desc3[1] = wxT("&Ascending [A-Z]");
4192 Order3DescCtrl = new wxRadioBox(this, ID_QVC_ORDER_3_DESC,
4193 wxT("Direction"),
4194 wxDefaultPosition, wxDefaultSize, 2,
4195 desc3, 1, wxRA_SPECIFY_COLS);
4196 Order3DescCtrl->SetSelection(1);
4197 Order3DescCtrl->Enable(false);
4198 Order3Sizer->Add(Order3DescCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4199
4200 // the Order clause #4 pane
4201 wxBoxSizer *Order4BoxSizer = new wxBoxSizer(wxVERTICAL);
4202 OrderSizer->Add(Order4BoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 0);
4203 wxStaticBox *Order4Box = new wxStaticBox(this, wxID_STATIC,
4204 wxT("Order by #4"),
4205 wxDefaultPosition,
4206 wxDefaultSize);
4207 wxBoxSizer *Order4Sizer = new wxStaticBoxSizer(Order4Box, wxVERTICAL);
4208 Order4BoxSizer->Add(Order4Sizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4209 Order4EnabledCtrl =
4210 new wxCheckBox(this, ID_QVC_ORDER_4_ENABLE, wxT("Enable"));
4211 Order4EnabledCtrl->SetValue(false);
4212 if (Parent->GetTableName1().Len() == 0 && Parent->GetTableName2().Len() == 0)
4213 Order4EnabledCtrl->Enable(false);
4214 Order4Sizer->Add(Order4EnabledCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 1);
4215 wxString Order4Tables[2];
4216 Order4Tables[0] = wxT("&Main table columns");
4217 Order4Tables[1] = wxT("&Table #2 columns");
4218 Order4TableCtrl = new wxRadioBox(this, ID_QVC_ORDER_4_TABLE,
4219 wxT(""),
4220 wxDefaultPosition, wxDefaultSize, 2,
4221 Order2Tables, 1, wxRA_SPECIFY_COLS);
4222 Order4TableCtrl->SetSelection(0);
4223 Order4TableCtrl->Enable(false);
4224 Order4Sizer->Add(Order4TableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4225 Order4ColumnCtrl =
4226 new wxComboBox(this, ID_QVC_ORDER_4_COLUMN, wxT(""), wxDefaultPosition,
4227 wxSize(130, 21), 0, NULL, wxCB_DROPDOWN | wxCB_READONLY);
4228 Order4ColumnCtrl->Enable(false);
4229 Order4Sizer->Add(Order4ColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4230 wxString desc4[2];
4231 desc4[0] = wxT("&Descending [Z-A]");
4232 desc4[1] = wxT("&Ascending [A-Z]");
4233 Order4DescCtrl = new wxRadioBox(this, ID_QVC_ORDER_4_DESC,
4234 wxT("Direction"),
4235 wxDefaultPosition, wxDefaultSize, 2,
4236 desc4, 1, wxRA_SPECIFY_COLS);
4237 Order4DescCtrl->SetSelection(1);
4238 Order4DescCtrl->Enable(false);
4239 Order4Sizer->Add(Order4DescCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4240
4241 // adding the event handlers
4242 Connect(ID_QVC_ORDER_1_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
4243 (wxObjectEventFunction) & ComposerOrderPage::OnOrder1Enabled);
4244 Connect(ID_QVC_ORDER_2_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
4245 (wxObjectEventFunction) & ComposerOrderPage::OnOrder2Enabled);
4246 Connect(ID_QVC_ORDER_3_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
4247 (wxObjectEventFunction) & ComposerOrderPage::OnOrder3Enabled);
4248 Connect(ID_QVC_ORDER_4_ENABLE, wxEVT_COMMAND_CHECKBOX_CLICKED,
4249 (wxObjectEventFunction) & ComposerOrderPage::OnOrder4Enabled);
4250 Connect(ID_QVC_ORDER_1_TABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
4251 (wxObjectEventFunction) & ComposerOrderPage::OnOrder1TableChanged);
4252 Connect(ID_QVC_ORDER_2_TABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
4253 (wxObjectEventFunction) & ComposerOrderPage::OnOrder2TableChanged);
4254 Connect(ID_QVC_ORDER_3_TABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
4255 (wxObjectEventFunction) & ComposerOrderPage::OnOrder3TableChanged);
4256 Connect(ID_QVC_ORDER_4_TABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
4257 (wxObjectEventFunction) & ComposerOrderPage::OnOrder4TableChanged);
4258 Connect(ID_QVC_ORDER_1_COLUMN, wxEVT_COMMAND_COMBOBOX_SELECTED,
4259 (wxObjectEventFunction) & ComposerOrderPage::OnOrder1ColumnSelected);
4260 Connect(ID_QVC_ORDER_2_COLUMN, wxEVT_COMMAND_COMBOBOX_SELECTED,
4261 (wxObjectEventFunction) & ComposerOrderPage::OnOrder2ColumnSelected);
4262 Connect(ID_QVC_ORDER_3_COLUMN, wxEVT_COMMAND_COMBOBOX_SELECTED,
4263 (wxObjectEventFunction) & ComposerOrderPage::OnOrder3ColumnSelected);
4264 Connect(ID_QVC_ORDER_4_COLUMN, wxEVT_COMMAND_COMBOBOX_SELECTED,
4265 (wxObjectEventFunction) & ComposerOrderPage::OnOrder4ColumnSelected);
4266 Connect(ID_QVC_ORDER_1_DESC, wxEVT_COMMAND_RADIOBOX_SELECTED,
4267 (wxObjectEventFunction) & ComposerOrderPage::OnOrder1DescChanged);
4268 Connect(ID_QVC_ORDER_2_DESC, wxEVT_COMMAND_RADIOBOX_SELECTED,
4269 (wxObjectEventFunction) & ComposerOrderPage::OnOrder2DescChanged);
4270 Connect(ID_QVC_ORDER_3_DESC, wxEVT_COMMAND_RADIOBOX_SELECTED,
4271 (wxObjectEventFunction) & ComposerOrderPage::OnOrder3DescChanged);
4272 Connect(ID_QVC_ORDER_4_DESC, wxEVT_COMMAND_RADIOBOX_SELECTED,
4273 (wxObjectEventFunction) & ComposerOrderPage::OnOrder4DescChanged);
4274 }
4275
Table1Status(bool ok)4276 void ComposerOrderPage::Table1Status(bool ok)
4277 {
4278 //
4279 // enabling/disabling Table#1 dependent fields
4280 //
4281 if (ok == false)
4282 {
4283 if (Parent->GetTableName2().Len() == 0)
4284 {
4285 Order1EnabledCtrl->SetValue(false);
4286 Parent->SetOrder1Enabled(false);
4287 Order1EnabledCtrl->Enable(false);
4288 Order2EnabledCtrl->SetValue(false);
4289 Parent->SetOrder2Enabled(false);
4290 Order2EnabledCtrl->Enable(false);
4291 Order3EnabledCtrl->SetValue(false);
4292 Parent->SetOrder3Enabled(false);
4293 Order3EnabledCtrl->Enable(false);
4294 Order4EnabledCtrl->SetValue(false);
4295 Parent->SetOrder4Enabled(false);
4296 Order4EnabledCtrl->Enable(false);
4297 Order1TableCtrl->SetSelection(0);
4298 Parent->SetOrder1Table2(false);
4299 Order1TableCtrl->Enable(false);
4300 Parent->SetOrder1Column(wxT(""));
4301 Order1ColumnCtrl->Clear();
4302 Order1ColumnCtrl->Enable(false);
4303 Order1DescCtrl->SetSelection(1);
4304 Parent->SetOrder1Desc(false);
4305 Order1DescCtrl->Enable(false);
4306 Order2TableCtrl->SetSelection(0);
4307 Parent->SetOrder2Table2(false);
4308 Order2TableCtrl->Enable(false);
4309 Parent->SetOrder2Column(wxT(""));
4310 Order2ColumnCtrl->Clear();
4311 Order2ColumnCtrl->Enable(false);
4312 Order2DescCtrl->SetSelection(1);
4313 Parent->SetOrder2Desc(false);
4314 Order2DescCtrl->Enable(false);
4315 Order3TableCtrl->SetSelection(0);
4316 Parent->SetOrder3Table2(false);
4317 Order3TableCtrl->Enable(false);
4318 Parent->SetOrder3Column(wxT(""));
4319 Order3ColumnCtrl->Clear();
4320 Order3ColumnCtrl->Enable(false);
4321 Order3DescCtrl->SetSelection(1);
4322 Parent->SetOrder3Desc(false);
4323 Order3DescCtrl->Enable(false);
4324 Order4TableCtrl->SetSelection(0);
4325 Parent->SetOrder4Table2(false);
4326 Order4TableCtrl->Enable(false);
4327 Parent->SetOrder4Column(wxT(""));
4328 Order4ColumnCtrl->Clear();
4329 Order4ColumnCtrl->Enable(false);
4330 Order4DescCtrl->SetSelection(1);
4331 Parent->SetOrder4Desc(false);
4332 Order4DescCtrl->Enable(false);
4333 } else
4334 {
4335 if (Parent->IsOrder1Table2() == false)
4336 {
4337 Order1EnabledCtrl->SetValue(false);
4338 Parent->SetOrder1Enabled(false);
4339 Order1TableCtrl->SetSelection(0);
4340 Parent->SetOrder1Table2(false);
4341 Order1TableCtrl->Enable(false);
4342 Parent->SetOrder1Column(wxT(""));
4343 Order1ColumnCtrl->Clear();
4344 Order1ColumnCtrl->Enable(false);
4345 Order1DescCtrl->SetSelection(1);
4346 Parent->SetOrder1Desc(false);
4347 Order1DescCtrl->Enable(false);
4348 }
4349 if (Parent->IsOrder2Table2() == false)
4350 {
4351 Order2EnabledCtrl->SetValue(false);
4352 Parent->SetOrder2Enabled(false);
4353 Order2TableCtrl->SetSelection(0);
4354 Parent->SetOrder2Table2(false);
4355 Order2TableCtrl->Enable(false);
4356 Parent->SetOrder2Column(wxT(""));
4357 Order2ColumnCtrl->Clear();
4358 Order2ColumnCtrl->Enable(false);
4359 Order2DescCtrl->SetSelection(1);
4360 Parent->SetOrder2Desc(false);
4361 Order2DescCtrl->Enable(false);
4362 }
4363 if (Parent->IsOrder3Table2() == false)
4364 {
4365 Order3EnabledCtrl->SetValue(false);
4366 Parent->SetOrder3Enabled(false);
4367 Order3TableCtrl->SetSelection(0);
4368 Parent->SetOrder3Table2(false);
4369 Order3TableCtrl->Enable(false);
4370 Parent->SetOrder3Column(wxT(""));
4371 Order3ColumnCtrl->Clear();
4372 Order3ColumnCtrl->Enable(false);
4373 Order3DescCtrl->SetSelection(1);
4374 Parent->SetOrder3Desc(false);
4375 Order3DescCtrl->Enable(false);
4376 }
4377 if (Parent->IsOrder4Table2() == false)
4378 {
4379 Order4EnabledCtrl->SetValue(false);
4380 Parent->SetOrder4Enabled(false);
4381 Order4TableCtrl->SetSelection(0);
4382 Parent->SetOrder4Table2(false);
4383 Order4TableCtrl->Enable(false);
4384 Parent->SetOrder4Column(wxT(""));
4385 Order4ColumnCtrl->Clear();
4386 Order4ColumnCtrl->Enable(false);
4387 Order4DescCtrl->SetSelection(1);
4388 Parent->SetOrder4Desc(false);
4389 Order4DescCtrl->Enable(false);
4390 }
4391 }
4392 } else
4393 {
4394 Order1EnabledCtrl->Enable(true);
4395 Order2EnabledCtrl->Enable(true);
4396 Order3EnabledCtrl->Enable(true);
4397 Order4EnabledCtrl->Enable(true);
4398 }
4399 }
4400
Table2Status(bool ok)4401 void ComposerOrderPage::Table2Status(bool ok)
4402 {
4403 //
4404 // enabling/disabling Table#2 dependent fields
4405 //
4406 if (ok == false)
4407 {
4408 if (Parent->GetTableName1().Len() == 0)
4409 {
4410 Order1EnabledCtrl->SetValue(false);
4411 Parent->SetOrder1Enabled(false);
4412 Order1EnabledCtrl->Enable(false);
4413 Order2EnabledCtrl->SetValue(false);
4414 Parent->SetOrder2Enabled(false);
4415 Order2EnabledCtrl->Enable(false);
4416 Order3EnabledCtrl->SetValue(false);
4417 Parent->SetOrder3Enabled(false);
4418 Order3EnabledCtrl->Enable(false);
4419 Order4EnabledCtrl->SetValue(false);
4420 Parent->SetOrder4Enabled(false);
4421 Order4EnabledCtrl->Enable(false);
4422 Order1TableCtrl->SetSelection(0);
4423 Parent->SetOrder1Table2(false);
4424 Order1TableCtrl->Enable(false);
4425 Parent->SetOrder1Column(wxT(""));
4426 Order1ColumnCtrl->Clear();
4427 Order1ColumnCtrl->Enable(false);
4428 Order1DescCtrl->SetSelection(1);
4429 Parent->SetOrder1Desc(false);
4430 Order1DescCtrl->Enable(false);
4431 Parent->SetOrder2Table2(false);
4432 Order2TableCtrl->Enable(false);
4433 Parent->SetOrder2Column(wxT(""));
4434 Order2ColumnCtrl->Clear();
4435 Order2ColumnCtrl->Enable(false);
4436 Order2DescCtrl->SetSelection(1);
4437 Parent->SetOrder2Desc(false);
4438 Order2DescCtrl->Enable(false);
4439 Order3TableCtrl->SetSelection(0);
4440 Parent->SetOrder3Table2(false);
4441 Order3TableCtrl->Enable(false);
4442 Parent->SetOrder3Column(wxT(""));
4443 Order3ColumnCtrl->Clear();
4444 Order3ColumnCtrl->Enable(false);
4445 Order3DescCtrl->SetSelection(1);
4446 Parent->SetOrder3Desc(false);
4447 Order3DescCtrl->Enable(false);
4448 Order4TableCtrl->SetSelection(0);
4449 Parent->SetOrder4Table2(false);
4450 Order4TableCtrl->Enable(false);
4451 Parent->SetOrder4Column(wxT(""));
4452 Order4ColumnCtrl->Clear();
4453 Order4ColumnCtrl->Enable(false);
4454 Order4DescCtrl->SetSelection(1);
4455 Parent->SetOrder4Desc(false);
4456 Order4DescCtrl->Enable(false);
4457 } else
4458 {
4459 if (Parent->IsOrder1Table2() == true)
4460 {
4461 Order1EnabledCtrl->SetValue(false);
4462 Parent->SetOrder1Enabled(false);
4463 Order1TableCtrl->SetSelection(0);
4464 Parent->SetOrder1Table2(false);
4465 Order1TableCtrl->Enable(false);
4466 Parent->SetOrder1Column(wxT(""));
4467 Order1ColumnCtrl->Clear();
4468 Order1ColumnCtrl->Enable(false);
4469 Order1DescCtrl->SetSelection(1);
4470 Parent->SetOrder1Desc(false);
4471 Order1DescCtrl->Enable(false);
4472 }
4473 if (Parent->IsOrder2Table2() == true)
4474 {
4475 Order2EnabledCtrl->SetValue(false);
4476 Parent->SetOrder2Enabled(false);
4477 Order2TableCtrl->SetSelection(0);
4478 Parent->SetOrder2Table2(false);
4479 Order2TableCtrl->Enable(false);
4480 Parent->SetOrder2Column(wxT(""));
4481 Order2ColumnCtrl->Clear();
4482 Order2ColumnCtrl->Enable(false);
4483 Order2DescCtrl->SetSelection(1);
4484 Parent->SetOrder2Desc(false);
4485 Order2DescCtrl->Enable(false);
4486 }
4487 if (Parent->IsOrder3Table2() == true)
4488 {
4489 Order3EnabledCtrl->SetValue(false);
4490 Parent->SetOrder3Enabled(false);
4491 Order3TableCtrl->SetSelection(0);
4492 Parent->SetOrder3Table2(false);
4493 Order3TableCtrl->Enable(false);
4494 Parent->SetOrder3Column(wxT(""));
4495 Order3ColumnCtrl->Clear();
4496 Order3ColumnCtrl->Enable(false);
4497 Order3DescCtrl->SetSelection(1);
4498 Parent->SetOrder3Desc(false);
4499 Order3DescCtrl->Enable(false);
4500 }
4501 if (Parent->IsOrder4Table2() == true)
4502 {
4503 Order4EnabledCtrl->SetValue(false);
4504 Parent->SetOrder4Enabled(false);
4505 Order4TableCtrl->SetSelection(0);
4506 Parent->SetOrder4Table2(false);
4507 Order4TableCtrl->Enable(false);
4508 Parent->SetOrder4Column(wxT(""));
4509 Order4ColumnCtrl->Clear();
4510 Order4ColumnCtrl->Enable(false);
4511 Order4DescCtrl->SetSelection(1);
4512 Parent->SetOrder4Desc(false);
4513 Order4DescCtrl->Enable(false);
4514 }
4515 }
4516 } else
4517 {
4518 Order1EnabledCtrl->Enable(true);
4519 Order2EnabledCtrl->Enable(true);
4520 Order3EnabledCtrl->Enable(true);
4521 Order4EnabledCtrl->Enable(true);
4522 }
4523 }
4524
OnOrder1Enabled(wxCommandEvent & WXUNUSED (event))4525 void ComposerOrderPage::OnOrder1Enabled(wxCommandEvent & WXUNUSED(event))
4526 {
4527 //
4528 // Order #1 clause enabled/disabled
4529 //
4530 Parent->SetOrder1Enabled(Order1EnabledCtrl->GetValue());
4531 if (Parent->IsOrder1Enabled() == true)
4532 {
4533 if (Parent->IsTable2Enabled() == true)
4534 {
4535 if (Parent->IsOrder1Table2() == false)
4536 Order1TableCtrl->SetSelection(0);
4537 else
4538 Order1TableCtrl->SetSelection(1);
4539 Order1TableCtrl->Enable(true);
4540 } else
4541 {
4542 Parent->SetOrder1Table2(false);
4543 Order1TableCtrl->SetSelection(0);
4544 Order1TableCtrl->Enable(false);
4545 Parent->SetOrder1Column(wxT(""));
4546 Order1ColumnCtrl->Clear();
4547 }
4548 Parent->SetOrder1Column(wxT(""));
4549 InitializeColumns(Order1ColumnCtrl, Parent->IsOrder1Table2());
4550 Order1ColumnCtrl->Enable(true);
4551 if (Parent->IsOrder1Desc() == true)
4552 Order1DescCtrl->SetSelection(0);
4553 else
4554 Order1DescCtrl->SetSelection(1);
4555 Order1DescCtrl->Enable(true);
4556 } else
4557 {
4558 Order1TableCtrl->SetSelection(0);
4559 Parent->SetOrder1Table2(false);
4560 Order1TableCtrl->Enable(false);
4561 Parent->SetOrder1Column(wxT(""));
4562 Order1ColumnCtrl->Clear();
4563 Order1ColumnCtrl->Enable(false);
4564 Parent->SetOrder1Desc(false);
4565 Order1DescCtrl->SetSelection(1);
4566 Order1DescCtrl->Enable(false);
4567 }
4568 Parent->UpdateSqlSample();
4569 }
4570
OnOrder2Enabled(wxCommandEvent & WXUNUSED (event))4571 void ComposerOrderPage::OnOrder2Enabled(wxCommandEvent & WXUNUSED(event))
4572 {
4573 //
4574 // Order #2 clause enabled/disabled
4575 //
4576 Parent->SetOrder2Enabled(Order2EnabledCtrl->GetValue());
4577 if (Parent->IsOrder2Enabled() == true)
4578 {
4579 if (Parent->IsTable2Enabled() == true)
4580 {
4581 if (Parent->IsOrder2Table2() == false)
4582 Order2TableCtrl->SetSelection(0);
4583 else
4584 Order2TableCtrl->SetSelection(1);
4585 Order2TableCtrl->Enable(true);
4586 } else
4587 {
4588 Parent->SetOrder2Table2(false);
4589 Order2TableCtrl->SetSelection(0);
4590 Order2TableCtrl->Enable(false);
4591 Parent->SetOrder2Column(wxT(""));
4592 Order2ColumnCtrl->Clear();
4593 }
4594 Parent->SetOrder2Column(wxT(""));
4595 InitializeColumns(Order2ColumnCtrl, Parent->IsOrder2Table2());
4596 Order2ColumnCtrl->Enable(true);
4597 if (Parent->IsOrder2Desc() == true)
4598 Order2DescCtrl->SetSelection(0);
4599 else
4600 Order2DescCtrl->SetSelection(1);
4601 Order2DescCtrl->Enable(true);
4602 } else
4603 {
4604 Order2TableCtrl->SetSelection(0);
4605 Parent->SetOrder2Table2(false);
4606 Order2TableCtrl->Enable(false);
4607 Parent->SetOrder2Column(wxT(""));
4608 Order2ColumnCtrl->Clear();
4609 Order2ColumnCtrl->Enable(false);
4610 Parent->SetOrder2Desc(false);
4611 Order2DescCtrl->SetSelection(1);
4612 Order2DescCtrl->Enable(false);
4613 }
4614 Parent->UpdateSqlSample();
4615 }
4616
OnOrder3Enabled(wxCommandEvent & WXUNUSED (event))4617 void ComposerOrderPage::OnOrder3Enabled(wxCommandEvent & WXUNUSED(event))
4618 {
4619 //
4620 // Order #3 clause enabled/disabled
4621 //
4622 Parent->SetOrder3Enabled(Order3EnabledCtrl->GetValue());
4623 if (Parent->IsOrder3Enabled() == true)
4624 {
4625 if (Parent->IsTable2Enabled() == true)
4626 {
4627 if (Parent->IsOrder3Table2() == false)
4628 Order3TableCtrl->SetSelection(0);
4629 else
4630 Order3TableCtrl->SetSelection(1);
4631 Order3TableCtrl->Enable(true);
4632 } else
4633 {
4634 Parent->SetOrder3Table2(false);
4635 Order3TableCtrl->SetSelection(0);
4636 Order3TableCtrl->Enable(false);
4637 Parent->SetOrder3Column(wxT(""));
4638 Order3ColumnCtrl->Clear();
4639 }
4640 Parent->SetOrder3Column(wxT(""));
4641 InitializeColumns(Order3ColumnCtrl, Parent->IsOrder3Table2());
4642 Order3ColumnCtrl->Enable(true);
4643 if (Parent->IsOrder3Desc() == true)
4644 Order3DescCtrl->SetSelection(0);
4645 else
4646 Order3DescCtrl->SetSelection(1);
4647 Order3DescCtrl->Enable(true);
4648 } else
4649 {
4650 Order3TableCtrl->SetSelection(0);
4651 Parent->SetOrder3Table2(false);
4652 Order3TableCtrl->Enable(false);
4653 Parent->SetOrder3Column(wxT(""));
4654 Order3ColumnCtrl->Clear();
4655 Order3ColumnCtrl->Enable(false);
4656 Parent->SetOrder3Desc(false);
4657 Order3DescCtrl->SetSelection(1);
4658 Order3DescCtrl->Enable(false);
4659 }
4660 Parent->UpdateSqlSample();
4661 }
4662
OnOrder4Enabled(wxCommandEvent & WXUNUSED (event))4663 void ComposerOrderPage::OnOrder4Enabled(wxCommandEvent & WXUNUSED(event))
4664 {
4665 //
4666 // Order #4 clause enabled/disabled
4667 //
4668 Parent->SetOrder4Enabled(Order4EnabledCtrl->GetValue());
4669 if (Parent->IsOrder4Enabled() == true)
4670 {
4671 if (Parent->IsTable2Enabled() == true)
4672 {
4673 if (Parent->IsOrder4Table2() == false)
4674 Order4TableCtrl->SetSelection(0);
4675 else
4676 Order4TableCtrl->SetSelection(1);
4677 Order4TableCtrl->Enable(true);
4678 } else
4679 {
4680 Parent->SetOrder4Table2(false);
4681 Order4TableCtrl->SetSelection(0);
4682 Order4TableCtrl->Enable(false);
4683 Parent->SetOrder4Column(wxT(""));
4684 Order4ColumnCtrl->Clear();
4685 }
4686 Parent->SetOrder4Column(wxT(""));
4687 InitializeColumns(Order4ColumnCtrl, Parent->IsOrder4Table2());
4688 Order4ColumnCtrl->Enable(true);
4689 if (Parent->IsOrder4Desc() == true)
4690 Order4DescCtrl->SetSelection(0);
4691 else
4692 Order4DescCtrl->SetSelection(1);
4693 Order4DescCtrl->Enable(true);
4694 } else
4695 {
4696 Order4TableCtrl->SetSelection(0);
4697 Parent->SetOrder4Table2(false);
4698 Order4TableCtrl->Enable(false);
4699 Parent->SetOrder4Column(wxT(""));
4700 Order4ColumnCtrl->Clear();
4701 Order4ColumnCtrl->Enable(false);
4702 Parent->SetOrder4Desc(false);
4703 Order4DescCtrl->SetSelection(1);
4704 Order4DescCtrl->Enable(false);
4705 }
4706 Parent->UpdateSqlSample();
4707 }
4708
InitializeColumns(wxComboBox * ctrl,bool table2)4709 void ComposerOrderPage::InitializeColumns(wxComboBox * ctrl, bool table2)
4710 {
4711 // initializing a columns list ComboBox
4712 ctrl->Clear();
4713 AuxColumn *pColumn;
4714 if (table2 == false)
4715 pColumn = Parent->GetColumn1List()->GetFirst();
4716 else
4717 pColumn = Parent->GetColumn2List()->GetFirst();
4718 while (pColumn)
4719 {
4720 wxString col = pColumn->GetName();
4721 ctrl->Append(col);
4722 pColumn = pColumn->GetNext();
4723 }
4724 }
4725
OnOrder1TableChanged(wxCommandEvent & WXUNUSED (event))4726 void ComposerOrderPage::OnOrder1TableChanged(wxCommandEvent & WXUNUSED(event))
4727 {
4728 //
4729 // Order #1 table changed
4730 //
4731 if (Order1TableCtrl->GetSelection() == 1)
4732 Parent->SetOrder1Table2(true);
4733 else
4734 Parent->SetOrder1Table2(false);
4735 InitializeColumns(Order1ColumnCtrl, Parent->IsOrder1Table2());
4736 }
4737
OnOrder2TableChanged(wxCommandEvent & WXUNUSED (event))4738 void ComposerOrderPage::OnOrder2TableChanged(wxCommandEvent & WXUNUSED(event))
4739 {
4740 //
4741 // Order #2 table changed
4742 //
4743 if (Order2TableCtrl->GetSelection() == 1)
4744 Parent->SetOrder2Table2(true);
4745 else
4746 Parent->SetOrder2Table2(false);
4747 InitializeColumns(Order2ColumnCtrl, Parent->IsOrder2Table2());
4748 }
4749
OnOrder3TableChanged(wxCommandEvent & WXUNUSED (event))4750 void ComposerOrderPage::OnOrder3TableChanged(wxCommandEvent & WXUNUSED(event))
4751 {
4752 //
4753 // Order #3 table changed
4754 //
4755 if (Order3TableCtrl->GetSelection() == 1)
4756 Parent->SetOrder3Table2(true);
4757 else
4758 Parent->SetOrder3Table2(false);
4759 InitializeColumns(Order3ColumnCtrl, Parent->IsOrder3Table2());
4760 }
4761
OnOrder4TableChanged(wxCommandEvent & WXUNUSED (event))4762 void ComposerOrderPage::OnOrder4TableChanged(wxCommandEvent & WXUNUSED(event))
4763 {
4764 //
4765 // Order #4 table changed
4766 //
4767 if (Order4TableCtrl->GetSelection() == 1)
4768 Parent->SetOrder4Table2(true);
4769 else
4770 Parent->SetOrder4Table2(false);
4771 InitializeColumns(Order4ColumnCtrl, Parent->IsOrder4Table2());
4772 }
4773
OnOrder1ColumnSelected(wxCommandEvent & WXUNUSED (event))4774 void ComposerOrderPage::OnOrder1ColumnSelected(wxCommandEvent & WXUNUSED(event))
4775 {
4776 //
4777 // Order #1 column changed
4778 //
4779 Parent->SetOrder1Column(Order1ColumnCtrl->GetValue());
4780 Parent->UpdateSqlSample();
4781 }
4782
OnOrder2ColumnSelected(wxCommandEvent & WXUNUSED (event))4783 void ComposerOrderPage::OnOrder2ColumnSelected(wxCommandEvent & WXUNUSED(event))
4784 {
4785 //
4786 // Order #2 column changed
4787 //
4788 Parent->SetOrder2Column(Order2ColumnCtrl->GetValue());
4789 Parent->UpdateSqlSample();
4790 }
4791
OnOrder3ColumnSelected(wxCommandEvent & WXUNUSED (event))4792 void ComposerOrderPage::OnOrder3ColumnSelected(wxCommandEvent & WXUNUSED(event))
4793 {
4794 //
4795 // Order #3 column changed
4796 //
4797 Parent->SetOrder3Column(Order3ColumnCtrl->GetValue());
4798 Parent->UpdateSqlSample();
4799 }
4800
OnOrder4ColumnSelected(wxCommandEvent & WXUNUSED (event))4801 void ComposerOrderPage::OnOrder4ColumnSelected(wxCommandEvent & WXUNUSED(event))
4802 {
4803 //
4804 // Order #4 column changed
4805 //
4806 Parent->SetOrder4Column(Order4ColumnCtrl->GetValue());
4807 Parent->UpdateSqlSample();
4808 }
4809
OnOrder1DescChanged(wxCommandEvent & WXUNUSED (event))4810 void ComposerOrderPage::OnOrder1DescChanged(wxCommandEvent & WXUNUSED(event))
4811 {
4812 //
4813 // Order #1 Asc/Desc changed
4814 //
4815 if (Order1DescCtrl->GetSelection() == 0)
4816 Parent->SetOrder1Desc(true);
4817 else
4818 Parent->SetOrder1Desc(false);
4819 Parent->UpdateSqlSample();
4820 }
4821
OnOrder2DescChanged(wxCommandEvent & WXUNUSED (event))4822 void ComposerOrderPage::OnOrder2DescChanged(wxCommandEvent & WXUNUSED(event))
4823 {
4824 //
4825 // Order #2 Asc/Desc changed
4826 //
4827 if (Order2DescCtrl->GetSelection() == 0)
4828 Parent->SetOrder2Desc(true);
4829 else
4830 Parent->SetOrder2Desc(false);
4831 Parent->UpdateSqlSample();
4832 }
4833
OnOrder3DescChanged(wxCommandEvent & WXUNUSED (event))4834 void ComposerOrderPage::OnOrder3DescChanged(wxCommandEvent & WXUNUSED(event))
4835 {
4836 //
4837 // Order #3 Asc/Desc changed
4838 //
4839 if (Order3DescCtrl->GetSelection() == 0)
4840 Parent->SetOrder3Desc(true);
4841 else
4842 Parent->SetOrder3Desc(false);
4843 Parent->UpdateSqlSample();
4844 }
4845
OnOrder4DescChanged(wxCommandEvent & WXUNUSED (event))4846 void ComposerOrderPage::OnOrder4DescChanged(wxCommandEvent & WXUNUSED(event))
4847 {
4848 //
4849 // Order #4 Asc/Desc changed
4850 //
4851 if (Order4DescCtrl->GetSelection() == 0)
4852 Parent->SetOrder4Desc(true);
4853 else
4854 Parent->SetOrder4Desc(false);
4855 Parent->UpdateSqlSample();
4856 }
4857
Create(ComposerDialog * parent)4858 bool ComposerViewPage::Create(ComposerDialog * parent)
4859 {
4860 //
4861 // creating the dialog
4862 //
4863 Parent = parent;
4864 if (wxPanel::Create(Parent->GetTabCtrl()) == false)
4865 return false;
4866 // populates individual controls
4867 CreateControls();
4868 // sets dialog sizer
4869 GetSizer()->Fit(this);
4870 GetSizer()->SetSizeHints(this);
4871 // centers the dialog window
4872 Centre();
4873 return true;
4874 }
4875
CreateControls()4876 void ComposerViewPage::CreateControls()
4877 {
4878 //
4879 // creating individual control and setting initial values
4880 //
4881 wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL);
4882 this->SetSizer(topSizer);
4883 wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
4884 topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4885
4886 // the VIEw row
4887 wxBoxSizer *viewMainSizer = new wxBoxSizer(wxHORIZONTAL);
4888 boxSizer->Add(viewMainSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4889 // the VIEW pane
4890 wxBoxSizer *viewBoxSizer = new wxBoxSizer(wxHORIZONTAL);
4891 viewMainSizer->Add(viewBoxSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4892 wxStaticBox *viewBox = new wxStaticBox(this, wxID_STATIC,
4893 wxT("Create View options"),
4894 wxDefaultPosition,
4895 wxDefaultSize);
4896 wxBoxSizer *viewSizer = new wxStaticBoxSizer(viewBox, wxVERTICAL);
4897 viewBoxSizer->Add(viewSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4898 wxString viewModes[3];
4899 viewModes[0] = wxT("&No View [execute SELECT query]");
4900 viewModes[1] = wxT("&Create View [ordinary SQL view]");
4901 viewModes[2] = wxT("&Create Spatial View [could be used as a GIS Layer]");
4902 ViewTypeCtrl = new wxRadioBox(this, ID_QVC_VIEW_TYPE,
4903 wxT("View type"),
4904 wxDefaultPosition, wxDefaultSize, 3,
4905 viewModes, 1, wxRA_SPECIFY_COLS);
4906 ViewTypeCtrl->SetSelection(0);
4907 viewSizer->Add(ViewTypeCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4908 wxSize size = ViewTypeCtrl->GetSize();
4909 wxStaticBox *viewNmBox = new wxStaticBox(this, wxID_STATIC,
4910 wxT("View name"),
4911 wxDefaultPosition,
4912 wxDefaultSize);
4913 wxBoxSizer *viewNmSizer = new wxStaticBoxSizer(viewNmBox, wxVERTICAL);
4914 viewSizer->Add(viewNmSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4915 ViewNameCtrl =
4916 new wxTextCtrl(this, ID_QVC_VIEW_NAME, Parent->GetViewName(),
4917 wxDefaultPosition, wxSize(size.GetWidth() - 10, 21));
4918 ViewNameCtrl->Enable(false);
4919 viewNmSizer->Add(ViewNameCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4920
4921 // the GEOMETRY pane
4922 wxStaticBox *geomBox = new wxStaticBox(this, wxID_STATIC,
4923 wxT("Geometry Column"),
4924 wxDefaultPosition,
4925 wxDefaultSize);
4926 wxBoxSizer *geomSizer = new wxStaticBoxSizer(geomBox, wxVERTICAL);
4927 viewBoxSizer->Add(geomSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 2);
4928 wxString geomTables[2];
4929 geomTables[0] = wxT("&Main table geometries");
4930 geomTables[1] = wxT("&Table #2 geometries");
4931 GeomTableCtrl = new wxRadioBox(this, ID_QVC_VIEW_GEOTABLE,
4932 wxT(""),
4933 wxDefaultPosition, wxDefaultSize, 2,
4934 geomTables, 1, wxRA_SPECIFY_COLS);
4935 GeomTableCtrl->SetSelection(0);
4936 GeomTableCtrl->Enable(false);
4937 geomSizer->Add(GeomTableCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 1);
4938 size = GeomTableCtrl->GetSize();
4939 GeometryColumnCtrl =
4940 new wxComboBox(this, ID_QVC_VIEW_GEOMETRY, wxT(""), wxDefaultPosition,
4941 wxSize(size.GetWidth() - 5, 21), 0, NULL,
4942 wxCB_DROPDOWN | wxCB_READONLY);
4943 GeometryColumnCtrl->Enable(false);
4944 geomSizer->Add(GeometryColumnCtrl, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
4945
4946 // Writable View
4947 wxStaticBox *writeBox = new wxStaticBox(this, wxID_STATIC,
4948 wxT("Read/Write View"),
4949 wxDefaultPosition,
4950 wxDefaultSize);
4951 wxBoxSizer *writeSizer = new wxStaticBoxSizer(writeBox, wxHORIZONTAL);
4952 boxSizer->Add(writeSizer, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 2);
4953 Writable1Ctrl =
4954 new wxCheckBox(this, ID_QVC_WRITABLE_1, wxT("RW Enabled Main Table"));
4955 Writable1Ctrl->SetValue(false);
4956 Writable1Ctrl->Enable(false);
4957 writeSizer->Add(Writable1Ctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3);
4958 Writable2Ctrl =
4959 new wxCheckBox(this, ID_QVC_WRITABLE_2, wxT("RW Enabled Table #2"));
4960 Writable2Ctrl->SetValue(false);
4961 Writable2Ctrl->Enable(false);
4962 writeSizer->Add(Writable2Ctrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 3);
4963
4964 // adding the event handlers
4965 Connect(ID_QVC_VIEW_TYPE, wxEVT_COMMAND_RADIOBOX_SELECTED,
4966 (wxObjectEventFunction) & ComposerViewPage::OnViewTypeChanged);
4967 Connect(ID_QVC_VIEW_NAME, wxEVT_COMMAND_TEXT_UPDATED,
4968 (wxObjectEventFunction) & ComposerViewPage::OnViewNameChanged);
4969 Connect(ID_QVC_VIEW_GEOTABLE, wxEVT_COMMAND_RADIOBOX_SELECTED,
4970 (wxObjectEventFunction) & ComposerViewPage::OnGeomTableChanged);
4971 Connect(ID_QVC_VIEW_GEOMETRY, wxEVT_COMMAND_COMBOBOX_SELECTED,
4972 (wxObjectEventFunction) & ComposerViewPage::OnGeometryColumnSelected);
4973 Connect(ID_QVC_WRITABLE_1, wxEVT_COMMAND_CHECKBOX_CLICKED,
4974 (wxObjectEventFunction) & ComposerViewPage::OnWritable1Changed);
4975 Connect(ID_QVC_WRITABLE_2, wxEVT_COMMAND_CHECKBOX_CLICKED,
4976 (wxObjectEventFunction) & ComposerViewPage::OnWritable2Changed);
4977 }
4978
Table1Status(bool ok)4979 void ComposerViewPage::Table1Status(bool ok)
4980 {
4981 //
4982 // enabling/disabling Table#1 dependent fields
4983 //
4984 if (ok == false)
4985 {
4986 if (Parent->GetTableName2().Len() == 0)
4987 {
4988 GeomTableCtrl->SetSelection(0);
4989 Parent->SetViewGeomTable2(false);
4990 GeometryColumnCtrl->Clear();
4991 Parent->SetGeometryColumn(wxT(""));
4992 } else
4993 {
4994 if (Parent->IsViewGeomTable2() == false)
4995 {
4996 GeomTableCtrl->SetSelection(0);
4997 Parent->SetViewGeomTable2(false);
4998 GeometryColumnCtrl->Clear();
4999 Parent->SetGeometryColumn(wxT(""));
5000 }
5001 }
5002 } else
5003 {
5004 if (Parent->IsTable2Enabled() == false)
5005 {
5006 GeomTableCtrl->SetSelection(0);
5007 Parent->SetViewGeomTable2(false);
5008 GeomTableCtrl->Enable(false);
5009 } else
5010 {
5011 if (Parent->IsSpatialView() == true)
5012 {
5013 if (Parent->IsViewGeomTable2() == true)
5014 GeomTableCtrl->SetSelection(1);
5015 else
5016 GeomTableCtrl->SetSelection(0);
5017 GeomTableCtrl->Enable(true);
5018 GeometryColumnCtrl->Enable(true);
5019 InitializeGeometries(Parent->IsViewGeomTable2());
5020 } else
5021 {
5022 GeomTableCtrl->SetSelection(0);
5023 Parent->SetViewGeomTable2(false);
5024 GeomTableCtrl->Enable(false);
5025 }
5026 }
5027 }
5028 }
5029
Table2Status(bool ok)5030 void ComposerViewPage::Table2Status(bool ok)
5031 {
5032 //
5033 // enabling/disabling Table#2 dependent fields
5034 //
5035 if (ok == false)
5036 {
5037 if (Parent->GetTableName1().Len() == 0)
5038 {
5039 GeomTableCtrl->SetSelection(0);
5040 Parent->SetViewGeomTable2(false);
5041 GeometryColumnCtrl->Clear();
5042 Parent->SetGeometryColumn(wxT(""));
5043 } else
5044 {
5045 if (Parent->IsOrder1Table2() == true)
5046 {
5047 GeomTableCtrl->SetSelection(0);
5048 Parent->SetViewGeomTable2(false);
5049 GeometryColumnCtrl->Clear();
5050 Parent->SetGeometryColumn(wxT(""));
5051 }
5052 }
5053 } else
5054 {
5055 if (Parent->IsSpatialView() == true)
5056 {
5057 if (Parent->IsViewGeomTable2() == true)
5058 GeomTableCtrl->SetSelection(1);
5059 else
5060 GeomTableCtrl->SetSelection(0);
5061 GeomTableCtrl->Enable(true);
5062 GeometryColumnCtrl->Enable(true);
5063 InitializeGeometries(Parent->IsViewGeomTable2());
5064 } else
5065 {
5066 GeomTableCtrl->SetSelection(0);
5067 Parent->SetViewGeomTable2(false);
5068 GeomTableCtrl->Enable(false);
5069 }
5070 }
5071 }
5072
InitializeGeometries(bool table2)5073 void ComposerViewPage::InitializeGeometries(bool table2)
5074 {
5075 // initializing the Geometry columns list ComboBox
5076 GeometryColumnCtrl->Clear();
5077 AuxTable *pTbl = NULL;
5078 AuxTable *pTable;
5079 wxString tbl = Parent->GetTableName1();
5080 if (table2 == true)
5081 tbl = Parent->GetTableName2();
5082 pTable = Parent->GetTableList()->GetFirst();
5083 while (pTable)
5084 {
5085 if (pTable->GetTableName() == tbl)
5086 {
5087 pTbl = pTable;
5088 break;
5089 }
5090 pTable = pTable->GetNext();
5091 }
5092 if (pTbl)
5093 {
5094 // initializing Geometry columns
5095 int i;
5096 for (i = 0; i < pTable->GetGeometriesCount(); i++)
5097 GeometryColumnCtrl->Append(pTable->GetGeometryColumn(i));
5098 }
5099 }
5100
OnViewTypeChanged(wxCommandEvent & WXUNUSED (event))5101 void ComposerViewPage::OnViewTypeChanged(wxCommandEvent & WXUNUSED(event))
5102 {
5103 //
5104 // View type changed
5105 //
5106 Parent->SetPlainView(false);
5107 Parent->SetSpatialView(false);
5108 if (ViewTypeCtrl->GetSelection() == 1)
5109 Parent->SetPlainView(true);
5110 if (ViewTypeCtrl->GetSelection() == 2)
5111 Parent->SetSpatialView(true);
5112 if (Parent->IsPlainView() == true || Parent->IsSpatialView() == true)
5113 {
5114 ViewNameCtrl->Enable(true);
5115 } else
5116 {
5117 ViewNameCtrl->Enable(false);
5118 ViewNameCtrl->SetValue(wxT(""));
5119 Parent->SetViewName(wxT(""));
5120 }
5121 if (Parent->IsSpatialView() == true)
5122 {
5123 InitializeGeometries(Parent->IsViewGeomTable2());
5124 if (Parent->IsTable2Enabled() == true)
5125 GeomTableCtrl->Enable(true);
5126 GeometryColumnCtrl->Enable(true);
5127 Writable1Ctrl->Enable(true);
5128 if (Parent->IsTable2Enabled() == true)
5129 {
5130 Writable2Ctrl->Enable(true);
5131 Writable2Ctrl->SetValue(false);
5132 Parent->SetWritable2(false);
5133 }
5134 } else
5135 {
5136 GeomTableCtrl->Enable(false);
5137 GeomTableCtrl->SetSelection(0);
5138 Parent->SetViewGeomTable2(false);
5139 GeometryColumnCtrl->Enable(false);
5140 GeometryColumnCtrl->Clear();
5141 Parent->SetGeometryColumn(wxT(""));
5142 Writable1Ctrl->Enable(false);
5143 Writable2Ctrl->Enable(false);
5144 Writable1Ctrl->SetValue(false);
5145 Writable2Ctrl->SetValue(false);
5146 Parent->SetWritable1(false);
5147 Parent->SetWritable2(false);
5148 }
5149 Parent->UpdateSqlSample();
5150 }
5151
OnViewNameChanged(wxCommandEvent & WXUNUSED (event))5152 void ComposerViewPage::OnViewNameChanged(wxCommandEvent & WXUNUSED(event))
5153 {
5154 //
5155 // View name changed
5156 //
5157 Parent->SetViewName(ViewNameCtrl->GetValue());
5158 Parent->UpdateSqlSample();
5159 }
5160
OnGeomTableChanged(wxCommandEvent & WXUNUSED (event))5161 void ComposerViewPage::OnGeomTableChanged(wxCommandEvent & WXUNUSED(event))
5162 {
5163 //
5164 // View Geom table changed
5165 //
5166 if (GeomTableCtrl->GetSelection() == 1)
5167 Parent->SetViewGeomTable2(true);
5168 else
5169 Parent->SetViewGeomTable2(false);
5170 InitializeGeometries(Parent->IsViewGeomTable2());
5171 }
5172
5173 void ComposerViewPage::
OnGeometryColumnSelected(wxCommandEvent & WXUNUSED (event))5174 OnGeometryColumnSelected(wxCommandEvent & WXUNUSED(event))
5175 {
5176 //
5177 // Geometry column selection changed
5178 //
5179 Parent->SetGeometryColumn(GeometryColumnCtrl->GetValue());
5180 Parent->SelectGeometryColumn();
5181 Parent->UpdateSqlSample();
5182 }
5183
OnWritable1Changed(wxCommandEvent & WXUNUSED (event))5184 void ComposerViewPage::OnWritable1Changed(wxCommandEvent & WXUNUSED(event))
5185 {
5186 //
5187 // Main Table Read/Write enabled/disabled
5188 //
5189 Parent->SetWritable1(Writable1Ctrl->GetValue());
5190 if (Parent->IsWritable1() == false)
5191 {
5192 Parent->SetWritable2(false);
5193 Writable2Ctrl->SetValue(false);
5194 }
5195 }
5196
OnWritable2Changed(wxCommandEvent & WXUNUSED (event))5197 void ComposerViewPage::OnWritable2Changed(wxCommandEvent & WXUNUSED(event))
5198 {
5199 //
5200 // Table#2 Read/Write enabled/disabled
5201 //
5202 Parent->SetWritable2(Writable2Ctrl->GetValue());
5203 if (Parent->IsWritable2() == true)
5204 {
5205 Parent->SetWritable1(true);
5206 Writable1Ctrl->SetValue(true);
5207 }
5208 }
5209
AuxTable(wxString & table)5210 AuxTable::AuxTable(wxString & table)
5211 {
5212 // constructor - table item
5213 TableName = table;
5214 MaxGeometryIndex = 0;
5215 Next = NULL;
5216 }
5217
AddGeometryColumn(wxString & geom)5218 void AuxTable::AddGeometryColumn(wxString & geom)
5219 {
5220 // adding a Geometry column
5221 if (MaxGeometryIndex < 128)
5222 Geometries[MaxGeometryIndex++] = geom;
5223 }
5224
GetGeometryColumn(int ind)5225 wxString & AuxTable::GetGeometryColumn(int ind)
5226 {
5227 // returns a Geometry column
5228 return Geometries[ind];
5229 }
5230
AuxTableList()5231 AuxTableList::AuxTableList()
5232 {
5233 // constructor - table list
5234 First = NULL;
5235 Last = NULL;
5236 Count = 0;
5237 }
5238
~AuxTableList()5239 AuxTableList::~AuxTableList()
5240 {
5241 // destructor - table list
5242 Flush();
5243 }
5244
Flush()5245 void AuxTableList::Flush()
5246 {
5247 // cleanup
5248 AuxTable *pT;
5249 AuxTable *pTn;
5250 pT = First;
5251 while (pT)
5252 {
5253 pTn = pT->GetNext();
5254 delete pT;
5255 pT = pTn;
5256 }
5257 First = NULL;
5258 Last = NULL;
5259 Count = 0;
5260 }
5261
Populate(sqlite3 * handle)5262 void AuxTableList::Populate(sqlite3 * handle)
5263 {
5264 // populating a table list
5265 int i;
5266 char **results;
5267 int rows;
5268 int columns;
5269 char *errMsg = NULL;
5270 char *name;
5271 char *geom;
5272 wxString tblName;
5273 wxString geomCol;
5274 wxString sql;
5275 AuxTable *pTable;
5276 // retrieving the Table Names
5277 sql =
5278 wxT
5279 ("SELECT name FROM sqlite_master WHERE (type = 'table' OR type = 'view') ORDER BY name");
5280 int ret = sqlite3_get_table(handle, sql.ToUTF8(), &results,
5281 &rows, &columns, &errMsg);
5282 if (ret != SQLITE_OK)
5283 return;
5284 if (rows < 1)
5285 ;
5286 else
5287 {
5288 for (i = 1; i <= rows; i++)
5289 {
5290 name = results[(i * columns) + 0];
5291 tblName = wxString::FromUTF8(name);
5292 pTable = new AuxTable(tblName);
5293 if (!First)
5294 First = pTable;
5295 if (Last)
5296 Last->SetNext(pTable);
5297 Last = pTable;
5298 Count++;
5299 }
5300 }
5301 sqlite3_free_table(results);
5302
5303 // retrieving the Geometry Columns
5304 sql = wxT("SELECT f_table_name, f_geometry_column FROM geometry_columns");
5305 ret = sqlite3_get_table(handle, sql.ToUTF8(), &results,
5306 &rows, &columns, &errMsg);
5307 if (ret != SQLITE_OK)
5308 return;
5309 if (rows < 1)
5310 ;
5311 else
5312 {
5313 for (i = 1; i <= rows; i++)
5314 {
5315 name = results[(i * columns) + 0];
5316 geom = results[(i * columns) + 1];
5317 tblName = wxString::FromUTF8(name);
5318 geomCol = wxString::FromUTF8(geom);
5319 pTable = First;
5320 while (pTable)
5321 {
5322 char tbl[1024];
5323 strcpy(tbl, pTable->GetTableName().ToUTF8());
5324 if (strcasecmp(tbl, name) == 0)
5325 {
5326 pTable->AddGeometryColumn(geomCol);
5327 break;
5328 }
5329 pTable = pTable->GetNext();
5330 }
5331 }
5332 }
5333 sqlite3_free_table(results);
5334 }
5335
AuxColumn(wxString & name)5336 AuxColumn::AuxColumn(wxString & name)
5337 {
5338 // constructor - column item
5339 Name = name;
5340 Selected = false;
5341 Next = NULL;
5342 }
5343
AuxColumnList()5344 AuxColumnList::AuxColumnList()
5345 {
5346 // constructor - column list
5347 First = NULL;
5348 Last = NULL;
5349 Count = 0;
5350 }
5351
~AuxColumnList()5352 AuxColumnList::~AuxColumnList()
5353 {
5354 // destructor - column list
5355 Flush();
5356 }
5357
Flush()5358 void AuxColumnList::Flush()
5359 {
5360 // cleanup
5361 AuxColumn *pC;
5362 AuxColumn *pCn;
5363 pC = First;
5364 while (pC)
5365 {
5366 pCn = pC->GetNext();
5367 delete pC;
5368 pC = pCn;
5369 }
5370 First = NULL;
5371 Last = NULL;
5372 Count = 0;
5373 }
5374
SetState(int ind,bool mode)5375 void AuxColumnList::SetState(int ind, bool mode)
5376 {
5377 // setting the selection state for some column identified by its position
5378 AuxColumn *pC;
5379 int cnt = 0;
5380 pC = First;
5381 while (pC)
5382 {
5383 if (cnt == ind)
5384 {
5385 pC->SetState(mode);
5386 return;
5387 }
5388 cnt++;
5389 pC = pC->GetNext();
5390 }
5391 }
5392
SetState(wxString & column)5393 void AuxColumnList::SetState(wxString & column)
5394 {
5395 // forcing the selection state for some column identified by its name
5396 AuxColumn *pC;
5397 pC = First;
5398 while (pC)
5399 {
5400 if (pC->GetName() == column)
5401 {
5402 pC->SetState(true);
5403 return;
5404 }
5405 pC = pC->GetNext();
5406 }
5407 }
5408
HasSelectedColumns()5409 bool AuxColumnList::HasSelectedColumns()
5410 {
5411 // setting the selection state for some column identified by its position
5412 AuxColumn *pC;
5413 int cnt = 0;
5414 pC = First;
5415 while (pC)
5416 {
5417 cnt++;
5418 pC = pC->GetNext();
5419 }
5420 if (cnt)
5421 return true;
5422 return false;
5423 }
5424
Populate(sqlite3 * handle,wxString & table)5425 void AuxColumnList::Populate(sqlite3 * handle, wxString & table)
5426 {
5427 // populating a column list
5428 int i;
5429 char **results;
5430 int rows;
5431 int columns;
5432 char *errMsg = NULL;
5433 char *name;
5434 wxString colName;
5435 wxString sql;
5436 AuxColumn *pCol;
5437 char xname[1024];
5438 Flush();
5439 sql = wxT("PRAGMA table_info(");
5440 strcpy(xname, table.ToUTF8());
5441 MyFrame::DoubleQuotedSql(xname);
5442 sql += wxString::FromUTF8(xname);
5443 sql += wxT(")");
5444 int ret = sqlite3_get_table(handle, sql.ToUTF8(), &results,
5445 &rows, &columns, &errMsg);
5446 if (ret != SQLITE_OK)
5447 return;
5448 if (rows < 1)
5449 ;
5450 else
5451 {
5452 // inserting the ROWID
5453 colName = wxT("ROWID");
5454 pCol = new AuxColumn(colName);
5455 if (!First)
5456 First = pCol;
5457 if (Last)
5458 Last->SetNext(pCol);
5459 Last = pCol;
5460 Count++;
5461 for (i = 1; i <= rows; i++)
5462 {
5463 name = results[(i * columns) + 1];
5464 if (strcasecmp(name, "ROWID") == 0)
5465 continue;
5466 colName = wxString::FromUTF8(name);
5467 pCol = new AuxColumn(colName);
5468 if (!First)
5469 First = pCol;
5470 if (Last)
5471 Last->SetNext(pCol);
5472 Last = pCol;
5473 Count++;
5474 }
5475 }
5476 sqlite3_free_table(results);
5477 }
5478