1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets database demo app
4 // Author: George Tasker
8 // Copyright: (c) 1998 Remstar International, Inc.
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
15 This sample program demonstrates the cross-platform ODBC database classes
16 donated by the development team at Remstar International.
18 The table this sample is based on is developer contact table, and shows
19 some of the simple uses of the database classes wxDb and wxDbTable.
25 #pragma implementation "dbtest.h"
28 #include "wx/wxprec.h"
38 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMAC__)
42 #include <stdio.h> /* Included strictly for reading the text file with the database parameters */
44 //#include "wx/db.h" /* Required in the file which will get the data source connection */
45 //#include "wx/dbtable.h" /* Has the wxDbTable object from which all data objects will inherit their data table functionality */
47 //extern wxDbList WXDLLEXPORT *PtrBegDbList; /* from db.cpp, used in getting back error results from db connections */
51 #include "wx/generic/gridctrl.h"
52 #include "wx/dbgrid.h"
57 #include "dbtest.h" /* Header file for this demonstration program */
58 #include "listdb.h" /* Code to support the "Lookup" button on the editor dialog */
60 IMPLEMENT_APP(DatabaseDemoApp
)
62 extern wxChar ListDB_Selection
[]; /* Used to return the first column value for the selected line from the listDB routines */
63 extern wxChar ListDB_Selection2
[]; /* Used to return the second column value for the selected line from the listDB routines */
65 #ifdef wxODBC_BLOB_SUPPORT
67 #include "wx/mstream.h"
69 #include "wx/bitmap.h"
70 #include "wx/statbmp.h"
74 #error Sample cannot be compiled unless setup.h has wxUSE_ODBC set to 1
78 bool DataTypeSupported(wxDb
*pDb
, SWORD datatype
, wxString
*nativeDataTypeName
)
80 wxDbSqlTypeInfo sqlTypeInfo
;
82 bool breakpoint
= false;
84 *nativeDataTypeName
= wxEmptyString
;
85 if (pDb
->GetDataTypeInfo(datatype
, sqlTypeInfo
))
87 *nativeDataTypeName
= sqlTypeInfo
.TypeName
;
93 } // GetDataTypesSupported();
97 void CheckSupportForAllDataTypes(wxDb
*pDb
)
99 wxString nativeDataTypeName
;
101 wxLogMessage(wxT("\nThe following datatypes are supported by the\ndatabase you are currently connected to:"));
103 if (DataTypeSupported(pDb
,SQL_C_BINARY
, &nativeDataTypeName
))
105 nativeDataTypeName
= wxT("SQL_C_BINARY (") + nativeDataTypeName
;
106 nativeDataTypeName
+= wxT(")\n");
107 wxLogMessage(nativeDataTypeName
);
111 if (DataTypeSupported(pDb
,SQL_C_BIT
, &nativeDataTypeName
))
113 nativeDataTypeName
= wxT("SQL_C_BIT (") + nativeDataTypeName
;
114 nativeDataTypeName
+= wxT(")\n");
115 wxLogMessage(nativeDataTypeName
);
118 #ifdef SQL_C_BOOKMARK
119 if (DataTypeSupported(pDb
,SQL_C_BOOKMARK
, &nativeDataTypeName
))
121 nativeDataTypeName
= wxT("SQL_C_BOOKMARK (") + nativeDataTypeName
;
122 nativeDataTypeName
+= wxT(")\n");
123 wxLogMessage(nativeDataTypeName
);
127 if (DataTypeSupported(pDb
,SQL_C_CHAR
, &nativeDataTypeName
))
129 nativeDataTypeName
= wxT("SQL_C_CHAR (") + nativeDataTypeName
;
130 nativeDataTypeName
+= wxT(")\n");
131 wxLogMessage(nativeDataTypeName
);
135 if (DataTypeSupported(pDb
,SQL_C_DATE
, &nativeDataTypeName
))
137 nativeDataTypeName
= wxT("SQL_C_DATE (") + nativeDataTypeName
;
138 nativeDataTypeName
+= wxT(")\n");
139 wxLogMessage(nativeDataTypeName
);
143 if (DataTypeSupported(pDb
,SQL_C_DEFAULT
, &nativeDataTypeName
))
145 nativeDataTypeName
= wxT("SQL_C_DEFAULT (") + nativeDataTypeName
;
146 nativeDataTypeName
+= wxT(")\n");
147 wxLogMessage(nativeDataTypeName
);
151 if (DataTypeSupported(pDb
,SQL_C_DOUBLE
, &nativeDataTypeName
))
153 nativeDataTypeName
= wxT("SQL_C_DOUBLE (") + nativeDataTypeName
;
154 nativeDataTypeName
+= wxT(")\n");
155 wxLogMessage(nativeDataTypeName
);
159 if (DataTypeSupported(pDb
,SQL_C_FLOAT
, &nativeDataTypeName
))
161 nativeDataTypeName
= wxT("SQL_C_FLOAT (") + nativeDataTypeName
;
162 nativeDataTypeName
+= wxT(")\n");
163 wxLogMessage(nativeDataTypeName
);
167 if (DataTypeSupported(pDb
,SQL_C_GUID
, &nativeDataTypeName
))
169 nativeDataTypeName
= wxT("SQL_C_GUID (") + nativeDataTypeName
;
170 nativeDataTypeName
+= wxT(")\n");
171 wxLogMessage(nativeDataTypeName
);
174 #ifdef SQL_C_INTERVAL_DAY
175 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_DAY
, &nativeDataTypeName
))
177 nativeDataTypeName
= wxT("SQL_C_INTERVAL_DAY (") + nativeDataTypeName
;
178 nativeDataTypeName
+= wxT(")\n");
179 wxLogMessage(nativeDataTypeName
);
182 #ifdef SQL_C_INTERVAL_DAY_TO_HOUR
183 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_DAY_TO_HOUR
, &nativeDataTypeName
))
185 nativeDataTypeName
= wxT("SQL_C_INTERVAL_DAY_TO_HOUR (") + nativeDataTypeName
;
186 nativeDataTypeName
+= wxT(")\n");
187 wxLogMessage(nativeDataTypeName
);
190 #ifdef SQL_C_INTERVAL_DAY_TO_MINUTE
191 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_DAY_TO_MINUTE
, &nativeDataTypeName
))
193 nativeDataTypeName
= wxT("SQL_C_INTERVAL_DAY_TO_MINUTE (") + nativeDataTypeName
;
194 nativeDataTypeName
+= wxT(")\n");
195 wxLogMessage(nativeDataTypeName
);
198 #ifdef SQL_C_INTERVAL_DAY_TO_SECOND
199 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_DAY_TO_SECOND
, &nativeDataTypeName
))
201 nativeDataTypeName
= wxT("SQL_C_INTERVAL_DAY_TO_SECOND (") + nativeDataTypeName
;
202 nativeDataTypeName
+= wxT(")\n");
203 wxLogMessage(nativeDataTypeName
);
206 #ifdef SQL_C_INTERVAL_HOUR
207 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_HOUR
, &nativeDataTypeName
))
209 nativeDataTypeName
= wxT("SQL_C_INTERVAL_HOUR (") + nativeDataTypeName
;
210 nativeDataTypeName
+= wxT(")\n");
211 wxLogMessage(nativeDataTypeName
);
214 #ifdef SQL_C_INTERVAL_HOUR_TO_MINUTE
215 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_HOUR_TO_MINUTE
, &nativeDataTypeName
))
217 nativeDataTypeName
= wxT("SQL_C_INTERVAL_HOUR_TO_MINUTE (") + nativeDataTypeName
;
218 nativeDataTypeName
+= wxT(")\n");
219 wxLogMessage(nativeDataTypeName
);
222 #ifdef SQL_C_INTERVAL_HOUR_TO_SECOND
223 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_HOUR_TO_SECOND
, &nativeDataTypeName
))
225 nativeDataTypeName
= wxT("SQL_C_INTERVAL_HOUR_TO_SECOND (") + nativeDataTypeName
;
226 nativeDataTypeName
+= wxT(")\n");
227 wxLogMessage(nativeDataTypeName
);
230 #ifdef SQL_C_INTERVAL_MINUTE
231 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_MINUTE
, &nativeDataTypeName
))
233 nativeDataTypeName
= wxT("SQL_C_INTERVAL_MINUTE (") + nativeDataTypeName
;
234 nativeDataTypeName
+= wxT(")\n");
235 wxLogMessage(nativeDataTypeName
);
238 #ifdef SQL_C_INTERVAL_MINUTE_TO_SECOND
239 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_MINUTE_TO_SECOND
, &nativeDataTypeName
))
241 nativeDataTypeName
= wxT("SQL_C_INTERVAL_MINUTE_TO_SECOND (") + nativeDataTypeName
;
242 nativeDataTypeName
+= wxT(")\n");
243 wxLogMessage(nativeDataTypeName
);
246 #ifdef SQL_C_INTERVAL_MONTH
247 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_MONTH
, &nativeDataTypeName
))
249 nativeDataTypeName
= wxT("SQL_C_INTERVAL_MONTH (") + nativeDataTypeName
;
250 nativeDataTypeName
+= wxT(")\n");
251 wxLogMessage(nativeDataTypeName
);
254 #ifdef SQL_C_INTERVAL_SECOND
255 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_SECOND
, &nativeDataTypeName
))
257 nativeDataTypeName
= wxT("SQL_C_INTERVAL_SECOND (") + nativeDataTypeName
;
258 nativeDataTypeName
+= wxT(")\n");
259 wxLogMessage(nativeDataTypeName
);
262 #ifdef SQL_C_INTERVAL_YEAR
263 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_YEAR
, &nativeDataTypeName
))
265 nativeDataTypeName
= wxT("SQL_C_INTERVAL_YEAR (") + nativeDataTypeName
;
266 nativeDataTypeName
+= wxT(")\n");
267 wxLogMessage(nativeDataTypeName
);
270 #ifdef SQL_C_INTERVAL_YEAR_TO_MONTH
271 if (DataTypeSupported(pDb
,SQL_C_INTERVAL_YEAR_TO_MONTH
, &nativeDataTypeName
))
273 nativeDataTypeName
= wxT("SQL_C_INTERVAL_YEAR_TO_MONTH (") + nativeDataTypeName
;
274 nativeDataTypeName
+= wxT(")\n");
275 wxLogMessage(nativeDataTypeName
);
279 if (DataTypeSupported(pDb
,SQL_C_LONG
, &nativeDataTypeName
))
281 nativeDataTypeName
= wxT("SQL_C_LONG (") + nativeDataTypeName
;
282 nativeDataTypeName
+= wxT(")\n");
283 wxLogMessage(nativeDataTypeName
);
287 if (DataTypeSupported(pDb
,SQL_C_NUMERIC
, &nativeDataTypeName
))
289 nativeDataTypeName
= wxT("SQL_C_NUMERIC (") + nativeDataTypeName
;
290 nativeDataTypeName
+= wxT(")\n");
291 wxLogMessage(nativeDataTypeName
);
295 if (DataTypeSupported(pDb
,SQL_C_SBIGINT
, &nativeDataTypeName
))
297 nativeDataTypeName
= wxT("SQL_C_SBIGINT (") + nativeDataTypeName
;
298 nativeDataTypeName
+= wxT(")\n");
299 wxLogMessage(nativeDataTypeName
);
303 if (DataTypeSupported(pDb
,SQL_C_SHORT
, &nativeDataTypeName
))
305 nativeDataTypeName
= wxT("SQL_C_SHORT (") + nativeDataTypeName
;
306 nativeDataTypeName
+= wxT(")\n");
307 wxLogMessage(nativeDataTypeName
);
311 if (DataTypeSupported(pDb
,SQL_C_SLONG
, &nativeDataTypeName
))
313 nativeDataTypeName
= wxT("SQL_C_SLONG (") + nativeDataTypeName
;
314 nativeDataTypeName
+= wxT(")\n");
315 wxLogMessage(nativeDataTypeName
);
319 if (DataTypeSupported(pDb
,SQL_C_SSHORT
, &nativeDataTypeName
))
321 nativeDataTypeName
= wxT("SQL_C_SSHORT (") + nativeDataTypeName
;
322 nativeDataTypeName
+= wxT(")\n");
323 wxLogMessage(nativeDataTypeName
);
326 #ifdef SQL_C_STINYINT
327 if (DataTypeSupported(pDb
,SQL_C_STINYINT
, &nativeDataTypeName
))
329 nativeDataTypeName
= wxT("SQL_C_STINYINT (") + nativeDataTypeName
;
330 nativeDataTypeName
+= wxT(")\n");
331 wxLogMessage(nativeDataTypeName
);
335 if (DataTypeSupported(pDb
,SQL_C_TIME
, &nativeDataTypeName
))
337 nativeDataTypeName
= wxT("SQL_C_TIME (") + nativeDataTypeName
;
338 nativeDataTypeName
+= wxT(")\n");
339 wxLogMessage(nativeDataTypeName
);
342 #ifdef SQL_C_TIMESTAMP
343 if (DataTypeSupported(pDb
,SQL_C_TIMESTAMP
, &nativeDataTypeName
))
345 nativeDataTypeName
= wxT("SQL_C_TIMESTAMP (") + nativeDataTypeName
;
346 nativeDataTypeName
+= wxT(")\n");
347 wxLogMessage(nativeDataTypeName
);
351 if (DataTypeSupported(pDb
,SQL_C_TINYINT
, &nativeDataTypeName
))
353 nativeDataTypeName
= wxT("SQL_C_TINYINT (") + nativeDataTypeName
;
354 nativeDataTypeName
+= wxT(")\n");
355 wxLogMessage(nativeDataTypeName
);
358 #ifdef SQL_C_TYPE_DATE
359 if (DataTypeSupported(pDb
,SQL_C_TYPE_DATE
, &nativeDataTypeName
))
361 nativeDataTypeName
= wxT("SQL_C_TYPE_DATE (") + nativeDataTypeName
;
362 nativeDataTypeName
+= wxT(")\n");
363 wxLogMessage(nativeDataTypeName
);
366 #ifdef SQL_C_TYPE_TIME
367 if (DataTypeSupported(pDb
,SQL_C_TYPE_TIME
, &nativeDataTypeName
))
369 nativeDataTypeName
= wxT("SQL_C_TYPE_TIME (") + nativeDataTypeName
;
370 nativeDataTypeName
+= wxT(")\n");
371 wxLogMessage(nativeDataTypeName
);
374 #ifdef SQL_C_TYPE_TIMESTAMP
375 if (DataTypeSupported(pDb
,SQL_C_TYPE_TIMESTAMP
, &nativeDataTypeName
))
377 nativeDataTypeName
= wxT("SQL_C_TYPE_TIMESTAMP (") + nativeDataTypeName
;
378 nativeDataTypeName
+= wxT(")\n");
379 wxLogMessage(nativeDataTypeName
);
383 if (DataTypeSupported(pDb
,SQL_C_UBIGINT
, &nativeDataTypeName
))
385 nativeDataTypeName
= wxT("SQL_C_UBIGINT (") + nativeDataTypeName
;
386 nativeDataTypeName
+= wxT(")\n");
387 wxLogMessage(nativeDataTypeName
);
391 if (DataTypeSupported(pDb
,SQL_C_ULONG
, &nativeDataTypeName
))
393 nativeDataTypeName
= wxT("SQL_C_ULONG (") + nativeDataTypeName
;
394 nativeDataTypeName
+= wxT(")\n");
395 wxLogMessage(nativeDataTypeName
);
399 if (DataTypeSupported(pDb
,SQL_C_USHORT
, &nativeDataTypeName
))
401 nativeDataTypeName
= wxT("SQL_C_USHORT (") + nativeDataTypeName
;
402 nativeDataTypeName
+= wxT(")\n");
403 wxLogMessage(nativeDataTypeName
);
406 #ifdef SQL_C_UTINYINT
407 if (DataTypeSupported(pDb
,SQL_C_UTINYINT
, &nativeDataTypeName
))
409 nativeDataTypeName
= wxT("SQL_C_UTINYINT (") + nativeDataTypeName
;
410 nativeDataTypeName
+= wxT(")\n");
411 wxLogMessage(nativeDataTypeName
);
414 #ifdef SQL_C_VARBOOKMARK
415 if (DataTypeSupported(pDb
,SQL_C_VARBOOKMARK
, &nativeDataTypeName
))
417 nativeDataTypeName
= wxT("SQL_C_VARBOOKMARK (") + nativeDataTypeName
;
418 nativeDataTypeName
+= wxT(")\n");
419 wxLogMessage(nativeDataTypeName
);
423 if (DataTypeSupported(pDb
,SQL_C_WXCHAR
, &nativeDataTypeName
))
425 nativeDataTypeName
= wxT("SQL_C_WXCHAR (") + nativeDataTypeName
;
426 nativeDataTypeName
+= wxT(")\n");
427 wxLogMessage(nativeDataTypeName
);
431 // Extended SQL types
433 if (DataTypeSupported(pDb
,SQL_DATE
, &nativeDataTypeName
))
435 nativeDataTypeName
= wxT("SQL_DATE (") + nativeDataTypeName
;
436 nativeDataTypeName
+= wxT(")\n");
437 wxLogMessage(nativeDataTypeName
);
441 if (DataTypeSupported(pDb
,SQL_INTERVAL
, &nativeDataTypeName
))
443 nativeDataTypeName
= wxT("SQL_INTERVAL (") + nativeDataTypeName
;
444 nativeDataTypeName
+= wxT(")\n");
445 wxLogMessage(nativeDataTypeName
);
449 if (DataTypeSupported(pDb
,SQL_TIME
, &nativeDataTypeName
))
451 nativeDataTypeName
= wxT("SQL_TIME (") + nativeDataTypeName
;
452 nativeDataTypeName
+= wxT(")\n");
453 wxLogMessage(nativeDataTypeName
);
457 if (DataTypeSupported(pDb
,SQL_TIMESTAMP
, &nativeDataTypeName
))
459 nativeDataTypeName
= wxT("SQL_TIMESTAMP (") + nativeDataTypeName
;
460 nativeDataTypeName
+= wxT(")\n");
461 wxLogMessage(nativeDataTypeName
);
464 #ifdef SQL_LONGVARCHAR
465 if (DataTypeSupported(pDb
,SQL_LONGVARCHAR
, &nativeDataTypeName
))
467 nativeDataTypeName
= wxT("SQL_LONGVARCHAR (") + nativeDataTypeName
;
468 nativeDataTypeName
+= wxT(")\n");
469 wxLogMessage(nativeDataTypeName
);
473 if (DataTypeSupported(pDb
,SQL_BINARY
, &nativeDataTypeName
))
475 nativeDataTypeName
= wxT("SQL_BINARY (") + nativeDataTypeName
;
476 nativeDataTypeName
+= wxT(")\n");
477 wxLogMessage(nativeDataTypeName
);
481 if (DataTypeSupported(pDb
,SQL_VARBINARY
, &nativeDataTypeName
))
483 nativeDataTypeName
= wxT("SQL_VARBINARY (") + nativeDataTypeName
;
484 nativeDataTypeName
+= wxT(")\n");
485 wxLogMessage(nativeDataTypeName
);
488 #ifdef SQL_LONGVARBINARY
489 if (DataTypeSupported(pDb
,SQL_LONGVARBINARY
, &nativeDataTypeName
))
491 nativeDataTypeName
= wxT("SQL_LOGVARBINARY (") + nativeDataTypeName
;
492 nativeDataTypeName
+= wxT(")\n");
493 wxLogMessage(nativeDataTypeName
);
497 if (DataTypeSupported(pDb
,SQL_BIGINT
, &nativeDataTypeName
))
499 nativeDataTypeName
= wxT("SQL_BIGINT (") + nativeDataTypeName
;
500 nativeDataTypeName
+= wxT(")\n");
501 wxLogMessage(nativeDataTypeName
);
505 if (DataTypeSupported(pDb
,SQL_TINYINT
, &nativeDataTypeName
))
507 nativeDataTypeName
= wxT("SQL_TINYINT (") + nativeDataTypeName
;
508 nativeDataTypeName
+= wxT(")\n");
509 wxLogMessage(nativeDataTypeName
);
513 if (DataTypeSupported(pDb
,SQL_BIT
, &nativeDataTypeName
))
515 nativeDataTypeName
= wxT("SQL_BIT (") + nativeDataTypeName
;
516 nativeDataTypeName
+= wxT(")\n");
517 wxLogMessage(nativeDataTypeName
);
521 if (DataTypeSupported(pDb
,SQL_GUID
, &nativeDataTypeName
))
523 nativeDataTypeName
= wxT("SQL_GUID (") + nativeDataTypeName
;
524 nativeDataTypeName
+= wxT(")\n");
525 wxLogMessage(nativeDataTypeName
);
530 if (DataTypeSupported(pDb
,SQL_CHAR
, &nativeDataTypeName
))
532 nativeDataTypeName
= wxT("SQL_CHAR (") + nativeDataTypeName
;
533 nativeDataTypeName
+= wxT(")\n");
534 wxLogMessage(nativeDataTypeName
);
538 if (DataTypeSupported(pDb
,SQL_INTEGER
, &nativeDataTypeName
))
540 nativeDataTypeName
= wxT("SQL_INTEGER (") + nativeDataTypeName
;
541 nativeDataTypeName
+= wxT(")\n");
542 wxLogMessage(nativeDataTypeName
);
546 if (DataTypeSupported(pDb
,SQL_SMALLINT
, &nativeDataTypeName
))
548 nativeDataTypeName
= wxT("SQL_SAMLLINT (") + nativeDataTypeName
;
549 nativeDataTypeName
+= wxT(")\n");
550 wxLogMessage(nativeDataTypeName
);
554 if (DataTypeSupported(pDb
,SQL_REAL
, &nativeDataTypeName
))
556 nativeDataTypeName
= wxT("SQL_REAL (") + nativeDataTypeName
;
557 nativeDataTypeName
+= wxT(")\n");
558 wxLogMessage(nativeDataTypeName
);
562 if (DataTypeSupported(pDb
,SQL_DOUBLE
, &nativeDataTypeName
))
564 nativeDataTypeName
= wxT("SQL_DOUBLE (") + nativeDataTypeName
;
565 nativeDataTypeName
+= wxT(")\n");
566 wxLogMessage(nativeDataTypeName
);
570 if (DataTypeSupported(pDb
,SQL_NUMERIC
, &nativeDataTypeName
))
572 nativeDataTypeName
= wxT("SQL_NUMERIC (") + nativeDataTypeName
;
573 nativeDataTypeName
+= wxT(")\n");
574 wxLogMessage(nativeDataTypeName
);
578 if (DataTypeSupported(pDb
,SQL_DATE
, &nativeDataTypeName
))
580 nativeDataTypeName
= wxT("SQL_DATE (") + nativeDataTypeName
;
581 nativeDataTypeName
+= wxT(")\n");
582 wxLogMessage(nativeDataTypeName
);
586 if (DataTypeSupported(pDb
,SQL_TIME
, &nativeDataTypeName
))
588 nativeDataTypeName
= wxT("SQL_TIME (") + nativeDataTypeName
;
589 nativeDataTypeName
+= wxT(")\n");
590 wxLogMessage(nativeDataTypeName
);
594 if (DataTypeSupported(pDb
,SQL_TIMESTAMP
, &nativeDataTypeName
))
596 nativeDataTypeName
= wxT("SQL_TIMESTAMP (") + nativeDataTypeName
;
597 nativeDataTypeName
+= wxT(")\n");
598 wxLogMessage(nativeDataTypeName
);
602 if (DataTypeSupported(pDb
,SQL_VARCHAR
, &nativeDataTypeName
))
604 nativeDataTypeName
= wxT("SQL_VARCHAR (") + nativeDataTypeName
;
605 nativeDataTypeName
+= wxT(")\n");
606 wxLogMessage(nativeDataTypeName
);
612 if (DataTypeSupported(pDb
,SQL_C_TCHAR
, &nativeDataTypeName
))
614 nativeDataTypeName
= wxT("SQL_C_TCHAR (") + nativeDataTypeName
;
615 nativeDataTypeName
+= wxT(")\n");
616 wxLogMessage(nativeDataTypeName
);
620 if (DataTypeSupported(pDb
,SQL_WVARCHAR
, &nativeDataTypeName
))
622 nativeDataTypeName
= wxT("SQL_WVARCHAR (") + nativeDataTypeName
;
623 nativeDataTypeName
+= wxT(")\n");
624 wxLogMessage(nativeDataTypeName
);
628 if (DataTypeSupported(pDb
,SQL_WCHAR
, &nativeDataTypeName
))
630 nativeDataTypeName
= wxT("SQL_WCHAR (") + nativeDataTypeName
;
631 nativeDataTypeName
+= wxT(")\n");
632 wxLogMessage(nativeDataTypeName
);
636 wxLogMessage(wxT("Done\n"));
637 } // CheckSupportForAllDataTypes()
640 bool DatabaseDemoApp::OnInit()
645 // Create the main frame window
646 DemoFrame
= new DatabaseDemoFrame(NULL
, wxT("wxWidgets Database Demo"), wxPoint(50, 50), wxSize(537, 530));
649 DemoFrame
->SetIcon(wxICON(db
));
652 wxMenu
*file_menu
= new wxMenu
;
653 file_menu
->Append(FILE_CREATE_ID
, wxT("&Create CONTACT table"));
654 file_menu
->Append(FILE_RECREATE_TABLE
, wxT("&Recreate CONTACT table"));
655 file_menu
->Append(FILE_RECREATE_INDEXES
, wxT("&Recreate CONTACT indexes"));
657 file_menu
->Append(FILE_DBGRID_TABLE
, wxT("&Open DB Grid example"));
659 file_menu
->Append(FILE_EXIT
, wxT("E&xit"));
661 wxMenu
*edit_menu
= new wxMenu
;
662 edit_menu
->Append(EDIT_PARAMETERS
, wxT("&Parameters..."));
664 wxMenu
*help_menu
= new wxMenu
;
665 help_menu
->Append(HELP_ABOUT
, wxT("&About"));
667 wxMenuBar
*menu_bar
= new wxMenuBar
;
668 menu_bar
->Append(file_menu
, wxT("&File"));
669 menu_bar
->Append(edit_menu
, wxT("&Edit"));
670 menu_bar
->Append(help_menu
, wxT("&Help"));
671 DemoFrame
->SetMenuBar(menu_bar
);
673 params
.ODBCSource
[0] = 0;
674 params
.UserName
[0] = 0;
675 params
.Password
[0] = 0;
676 params
.DirPath
[0] = 0;
678 #ifdef wxODBC_BLOB_SUPPORT
679 wxInitAllImageHandlers();
680 wxImage::InitStandardHandlers();
681 wxBitmap::InitStandardHandlers();
685 DemoFrame
->Show(true);
687 // Passing NULL for the SQL environment handle causes
688 // the wxDbConnectInf constructor to obtain a handle
691 // WARNING: Be certain that you do not free this handle
692 // directly with SQLFreeEnv(). Use either the
693 // method ::FreeHenv() or delete the DbConnectInf.
694 DbConnectInf
= new wxDbConnectInf(NULL
, params
.ODBCSource
, params
.UserName
,
695 params
.Password
, params
.DirPath
);
697 if (!DbConnectInf
|| !DbConnectInf
->GetHenv())
699 wxMessageBox(wxT("Unable to define data source connection info."), wxT("DB CONNECTION ERROR..."),wxOK
| wxICON_EXCLAMATION
);
700 wxDELETE(DbConnectInf
);
703 if (!ReadParamFile(params
))
704 DemoFrame
->BuildParameterDialog(NULL
);
706 if (!wxStrlen(params
.ODBCSource
))
708 wxDELETE(DbConnectInf
);
712 DbConnectInf
->SetDsn(params
.ODBCSource
);
713 DbConnectInf
->SetUserID(params
.UserName
);
714 DbConnectInf
->SetPassword(params
.Password
);
715 DbConnectInf
->SetDefaultDir(params
.DirPath
);
717 READONLY_DB
= wxDbGetConnection(DbConnectInf
);
718 if (READONLY_DB
== 0)
720 wxMessageBox(wxT("Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the CONTACT table prior to making a connection\n(using tools provided by the database manufacturer)"), wxT("DB CONNECTION ERROR..."),wxOK
| wxICON_EXCLAMATION
);
721 DemoFrame
->BuildParameterDialog(NULL
);
722 wxDELETE(DbConnectInf
);
723 wxMessageBox(wxT("Now exiting program.\n\nRestart program to try any new settings."),wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
727 DemoFrame
->BuildEditorDialog();
730 DemoFrame
->Refresh();
733 } // DatabaseDemoApp::OnInit()
737 * Remove CR or CR/LF from a character string.
739 wxChar
* wxRemoveLineTerminator(wxChar
* aString
)
741 int len
= wxStrlen(aString
);
742 while (len
> 0 && (aString
[len
-1] == wxT('\r') || aString
[len
-1] == wxT('\n'))) {
743 aString
[len
-1] = wxT('\0');
750 bool DatabaseDemoApp::ReadParamFile(Cparameters
¶ms
)
753 if ((paramFile
= wxFopen(PARAM_FILENAME
, wxT("r"))) == NULL
)
756 tStr
.Printf(wxT("Unable to open the parameter file '%s' for reading.\n\nYou must specify the data source, user name, and\npassword that will be used and save those settings."),PARAM_FILENAME
.c_str());
757 wxMessageBox(tStr
,wxT("File I/O Error..."),wxOK
| wxICON_EXCLAMATION
);
762 wxChar buffer
[1000+1];
763 wxFgets(buffer
, sizeof(params
.ODBCSource
), paramFile
);
764 wxRemoveLineTerminator(buffer
);
765 wxStrcpy(params
.ODBCSource
,buffer
);
767 wxFgets(buffer
, sizeof(params
.UserName
), paramFile
);
768 wxRemoveLineTerminator(buffer
);
769 wxStrcpy(params
.UserName
,buffer
);
771 wxFgets(buffer
, sizeof(params
.Password
), paramFile
);
772 wxRemoveLineTerminator(buffer
);
773 wxStrcpy(params
.Password
,buffer
);
775 wxFgets(buffer
, sizeof(params
.DirPath
), paramFile
);
776 wxRemoveLineTerminator(buffer
);
777 wxStrcpy(params
.DirPath
,buffer
);
782 } // DatabaseDemoApp::ReadParamFile()
785 bool DatabaseDemoApp::WriteParamFile(Cparameters
&WXUNUSED(params
))
788 if ((paramFile
= wxFopen(PARAM_FILENAME
, wxT("wt"))) == NULL
)
791 tStr
.Printf(wxT("Unable to write/overwrite '%s'."),PARAM_FILENAME
.c_str());
792 wxMessageBox(tStr
,wxT("File I/O Error..."),wxOK
| wxICON_EXCLAMATION
);
796 wxFputs(wxGetApp().params
.ODBCSource
, paramFile
);
797 wxFputc(wxT('\n'), paramFile
);
798 wxFputs(wxGetApp().params
.UserName
, paramFile
);
799 wxFputc(wxT('\n'), paramFile
);
800 wxFputs(wxGetApp().params
.Password
, paramFile
);
801 wxFputc(wxT('\n'), paramFile
);
802 wxFputs(wxGetApp().params
.DirPath
, paramFile
);
803 wxFputc(wxT('\n'), paramFile
);
807 } // DatabaseDemoApp::WriteParamFile()
810 void DatabaseDemoApp::CreateDataTable(bool recreate
)
814 Ok
= (wxMessageBox(wxT("Any data currently residing in the table will be erased.\n\nAre you sure?"),wxT("Confirm"),wxYES_NO
|wxICON_QUESTION
) == wxYES
);
823 Contact
->GetDb()->RollbackTrans(); // Make sure the current cursor is in a known/stable state
825 if (!Contact
->CreateTable(recreate
))
829 tStr
= wxT("Error creating CONTACTS table.\nTable was not created.\n\n");
830 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),Contact
->GetDb(),__TFILE__
,__LINE__
),
831 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
837 if (!Contact
->CreateIndexes(recreate
))
841 tStr
= wxT("Error creating CONTACTS indexes.\nIndexes will be unavailable.\n\n");
842 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),Contact
->GetDb(),__TFILE__
,__LINE__
),
843 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
852 wxMessageBox(wxT("Table and index(es) were successfully created."),wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
853 } // DatabaseDemoApp::CreateDataTable()
856 BEGIN_EVENT_TABLE(DatabaseDemoFrame
, wxFrame
)
857 EVT_MENU(FILE_CREATE_ID
, DatabaseDemoFrame::OnCreate
)
858 EVT_MENU(FILE_RECREATE_TABLE
, DatabaseDemoFrame::OnRecreateTable
)
859 EVT_MENU(FILE_RECREATE_INDEXES
, DatabaseDemoFrame::OnRecreateIndexes
)
861 EVT_MENU(FILE_DBGRID_TABLE
, DatabaseDemoFrame::OnDbGridTable
)
863 EVT_MENU(FILE_EXIT
, DatabaseDemoFrame::OnExit
)
864 EVT_MENU(EDIT_PARAMETERS
, DatabaseDemoFrame::OnEditParameters
)
865 EVT_MENU(HELP_ABOUT
, DatabaseDemoFrame::OnAbout
)
866 EVT_CLOSE(DatabaseDemoFrame::OnCloseWindow
)
870 // DatabaseDemoFrame constructor
871 DatabaseDemoFrame::DatabaseDemoFrame(wxFrame
*frame
, const wxString
& title
,
872 const wxPoint
& pos
, const wxSize
& size
):
873 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
875 // Put any code in necessary for initializing the main frame here
880 delete wxLog::SetActiveTarget(new wxLogStderr
);
883 } // DatabaseDemoFrame constructor
885 DatabaseDemoFrame::~DatabaseDemoFrame()
888 delete wxLog::SetActiveTarget(NULL
);
890 } // DatabaseDemoFrame destructor
893 void DatabaseDemoFrame::OnCreate(wxCommandEvent
& WXUNUSED(event
))
895 wxGetApp().CreateDataTable(false);
896 } // DatabaseDemoFrame::OnCreate()
899 void DatabaseDemoFrame::OnRecreateTable(wxCommandEvent
& WXUNUSED(event
))
901 wxGetApp().CreateDataTable(true);
902 } // DatabaseDemoFrame::OnRecreate()
905 void DatabaseDemoFrame::OnRecreateIndexes(wxCommandEvent
& WXUNUSED(event
))
907 wxGetApp().Contact
->GetDb()->RollbackTrans(); // Make sure the current cursor is in a known/stable state
909 if (!wxGetApp().Contact
->CreateIndexes(true))
914 tStr
= wxT("Error creating CONTACTS indexes.\nNew indexes will be unavailable.\n\n");
915 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
916 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
920 wxMessageBox(wxT("Index(es) were successfully recreated."),wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
922 } // DatabaseDemoFrame::OnRecreateIndexes()
926 void DatabaseDemoFrame::OnDbGridTable(wxCommandEvent
& WXUNUSED(event
))
928 DbGridFrame
*frame
= new DbGridFrame(this);
929 if (frame
->Initialize())
936 void DatabaseDemoFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
939 } // DatabaseDemoFrame::OnExit()
942 void DatabaseDemoFrame::OnEditParameters(wxCommandEvent
& WXUNUSED(event
))
944 if ((pEditorDlg
->mode
!= mCreate
) && (pEditorDlg
->mode
!= mEdit
))
945 BuildParameterDialog(this);
947 wxMessageBox(wxT("Cannot change database parameters while creating or editing a record"),wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
948 } // DatabaseDemoFrame::OnEditParameters()
951 void DatabaseDemoFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
953 wxMessageBox(wxT("wxWidgets sample program for database classes\n\nContributed on 27 July 1998"),wxT("About..."),wxOK
| wxICON_INFORMATION
);
954 } // DatabaseDemoFrame::OnAbout()
957 // Put any additional checking necessary to make certain it is alright
958 // to close the program here that is not done elsewhere
959 void DatabaseDemoFrame::OnCloseWindow(wxCloseEvent
& event
)
962 if (pEditorDlg
&& pEditorDlg
->Close())
973 wxDELETE(wxGetApp().Contact
);
975 // This function will close all the connections to the database that have been
976 // previously cached.
977 wxDbCloseConnections();
979 // Deletion of the wxDbConnectInf instance must be the LAST thing done that
980 // has anything to do with the database. Deleting this before disconnecting,
981 // freeing/closing connections, etc will result in a crash!
982 wxDELETE(wxGetApp().DbConnectInf
);
986 } // DatabaseDemoFrame::OnCloseWindow()
989 void DatabaseDemoFrame::BuildEditorDialog()
992 pEditorDlg
= new CeditorDlg(this);
995 pEditorDlg
->Initialize();
996 if (!pEditorDlg
->initialized
)
1000 wxMessageBox(wxT("Unable to initialize the editor dialog for some reason"),wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
1006 wxMessageBox(wxT("Unable to create the editor dialog for some reason"),wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
1009 } // DatabaseDemoFrame::BuildEditorDialog()
1012 void DatabaseDemoFrame::BuildParameterDialog(wxWindow
*parent
)
1014 pParamDlg
= new CparameterDlg(parent
);
1017 wxMessageBox(wxT("Unable to create the parameter dialog for some reason"),wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
1018 } // DatabaseDemoFrame::BuildParameterDialog()
1022 * Constructor note: If no wxDb object is passed in, a new connection to the database
1023 * is created for this instance of Ccontact. This can be a slow process depending
1024 * on the database engine being used, and some database engines have a limit on the
1025 * number of connections (either hard limits, or license restricted) so care should
1026 * be used to use as few connections as is necessary.
1028 * IMPORTANT: Objects which share a wxDb pointer are ALL acted upon whenever a member
1029 * function of pDb is called (i.e. CommitTrans() or RollbackTrans(), so if modifying
1030 * or creating a table objects which use the same pDb, know that all the objects
1031 * will be committed or rolled back when any of the objects has this function call made.
1033 Ccontact::Ccontact (wxDb
*pwxDb
) : wxDbTable(pwxDb
? pwxDb
: wxDbGetConnection(wxGetApp().DbConnectInf
),
1034 CONTACT_TABLE_NAME
, CONTACT_NO_COLS
, (const wxString
&)wxEmptyString
,
1035 !wxDB_QUERY_ONLY
, wxGetApp().DbConnectInf
->GetDefaultDir())
1037 // This is used to represent whether the database connection should be released
1038 // when this instance of the object is deleted. If using the same connection
1039 // for multiple instance of database objects, then the connection should only be
1040 // released when the last database instance using the connection is deleted
1041 freeDbConn
= !pwxDb
;
1044 GetDb()->SetSqlLogging(sqlLogON
);
1048 } // Ccontact Constructor
1051 void Ccontact::Initialize()
1060 JoinDate
.year
= 1980;
1064 JoinDate
.minute
= 0;
1065 JoinDate
.second
= 0;
1066 JoinDate
.fraction
= 0;
1067 NativeLanguage
= langENGLISH
;
1068 IsDeveloper
= false;
1072 memset(Picture
, 0, MAX_PICTURE_SIZE
);
1073 } // Ccontact::Initialize
1076 Ccontact::~Ccontact()
1080 if (!wxDbFreeConnection(GetDb()))
1083 tStr
= wxT("Unable to Free the Ccontact data table handle\n\n");
1085 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
1086 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
1089 } // Ccontract destructor
1093 * Handles setting up all the connections for the interface from the wxDbTable
1094 * functions to interface to the data structure used to store records in
1095 * memory, and for all the column definitions that define the table structure
1097 void Ccontact::SetupColumns()
1099 // NOTE: Columns now are 8 character names, as that is all dBase can support. Longer
1100 // names can be used for other database engines
1101 SetColDefs ( 0,wxT("NAME"), DB_DATA_TYPE_VARCHAR
, Name
, SQL_C_WXCHAR
, sizeof(Name
), true, true); // Primary index
1102 SetColDefs ( 1,wxT("ADDRESS1"), DB_DATA_TYPE_VARCHAR
, Addr1
, SQL_C_WXCHAR
, sizeof(Addr1
), false,true);
1103 SetColDefs ( 2,wxT("ADDRESS2"), DB_DATA_TYPE_VARCHAR
, Addr2
, SQL_C_WXCHAR
, sizeof(Addr2
), false,true);
1104 SetColDefs ( 3,wxT("CITY"), DB_DATA_TYPE_VARCHAR
, City
, SQL_C_WXCHAR
, sizeof(City
), false,true);
1105 SetColDefs ( 4,wxT("STATE"), DB_DATA_TYPE_VARCHAR
, State
, SQL_C_WXCHAR
, sizeof(State
), false,true);
1106 SetColDefs ( 5,wxT("POSTCODE"), DB_DATA_TYPE_VARCHAR
, PostalCode
, SQL_C_WXCHAR
, sizeof(PostalCode
), false,true);
1107 SetColDefs ( 6,wxT("COUNTRY"), DB_DATA_TYPE_VARCHAR
, Country
, SQL_C_WXCHAR
, sizeof(Country
), false,true);
1108 SetColDefs ( 7,wxT("JOINDATE"), DB_DATA_TYPE_DATE
, &JoinDate
, SQL_C_TIMESTAMP
, sizeof(JoinDate
), false,true);
1109 SetColDefs ( 8,wxT("IS_DEV"), DB_DATA_TYPE_INTEGER
, &IsDeveloper
, SQL_C_BOOLEAN(IsDeveloper
), sizeof(IsDeveloper
), false,true);
1110 SetColDefs ( 9,wxT("CONTRIBS"), DB_DATA_TYPE_INTEGER
, &Contributions
, SQL_C_UTINYINT
, sizeof(Contributions
), false,true);
1111 SetColDefs (10,wxT("LINE_CNT"), DB_DATA_TYPE_INTEGER
, &LinesOfCode
, SQL_C_ULONG
, sizeof(LinesOfCode
), false,true);
1112 SetColDefs (11,wxT("LANGUAGE"), DB_DATA_TYPE_INTEGER
, &NativeLanguage
, SQL_C_ENUM
, sizeof(NativeLanguage
), false,true);
1113 #ifdef wxODBC_BLOB_SUPPORT
1114 SetColDefs (12,wxT("PICSIZE"), DB_DATA_TYPE_INTEGER
, &BlobSize
, SQL_C_ULONG
, sizeof(BlobSize
), false,true);
1115 SetColDefs (13,wxT("PICTURE"), DB_DATA_TYPE_BLOB
, Picture
, SQL_C_BINARY
, sizeof(Picture
), false,true);
1117 } // Ccontact::SetupColumns
1120 bool Ccontact::CreateIndexes(bool recreate
)
1122 // This index could easily be accomplished with an "orderBy" clause,
1123 // but is done to show how to construct a non-primary index.
1125 wxDbIdxDef idxDef
[2];
1127 wxStrcpy(idxDef
[0].ColName
, wxT("IS_DEV"));
1128 idxDef
[0].Ascending
= true;
1130 wxStrcpy(idxDef
[1].ColName
, wxT("NAME"));
1131 idxDef
[1].Ascending
= true;
1133 indexName
= GetTableName();
1134 indexName
+= wxT("_IDX1");
1136 return CreateIndex(indexName
.c_str(), true, 2, idxDef
, recreate
);
1138 } // Ccontact::CreateIndexes()
1142 * Having a function to do a query on the primary key (and possibly others) is
1143 * very efficient and tighter coding so that it is available where ever the object
1144 * is. Great for use with multiple tables when not using views or outer joins
1146 bool Ccontact::FetchByName(const wxString
&name
)
1148 whereStr
.Printf(wxT("NAME = '%s'"),name
.c_str());
1149 SetWhereClause(whereStr
.c_str());
1150 SetOrderByClause(wxEmptyString
);
1158 } // Ccontact::FetchByName()
1163 * ************* DIALOGS ***************
1168 /* CeditorDlg constructor
1170 * Creates the dialog used for creating/editing/deleting/copying a Ccontact object.
1171 * This dialog actually is drawn in the main frame of the program
1173 * An instance of Ccontact is created - "Contact" - which is used to hold the Ccontact
1174 * object that is currently being worked with.
1177 BEGIN_EVENT_TABLE(CeditorDlg
, wxPanel
)
1178 EVT_BUTTON(wxID_ANY
, CeditorDlg::OnButton
)
1179 EVT_CLOSE(CeditorDlg::OnCloseWindow
)
1182 CeditorDlg::CeditorDlg(wxWindow
*parent
) : wxPanel (parent
, 0, 0, 537, 530)
1184 // Since the ::OnCommand() function is overridden, this prevents the widget
1185 // detection in ::OnCommand() until all widgets have been initialized to prevent
1186 // uninitialized pointers from crashing the program
1187 widgetPtrsSet
= false;
1189 initialized
= false;
1194 } // CeditorDlg constructor
1197 void CeditorDlg::OnCloseWindow(wxCloseEvent
& event
)
1200 if ((mode
!= mCreate
) && (mode
!= mEdit
))
1206 wxMessageBox(wxT("Must finish processing the current record being created/modified before exiting"),wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
1209 } // CeditorDlg::OnCloseWindow()
1212 void CeditorDlg::OnButton(wxCommandEvent
&event
)
1214 wxWindow
*win
= (wxWindow
*) event
.GetEventObject();
1215 OnCommand( *win
, event
);
1216 } // CeditorDlg::OnButton()
1219 void CeditorDlg::OnCommand(wxWindow
& win
, wxCommandEvent
& WXUNUSED(event
))
1221 wxString widgetName
;
1223 widgetName
= win
.GetName();
1228 if (widgetName
== pCreateBtn
->GetName())
1230 wxGetApp().Contact
->Initialize();
1233 pNameTxt
->SetValue(wxEmptyString
);
1234 pNameTxt
->SetFocus();
1238 if (widgetName
== pEditBtn
->GetName())
1240 saveName
= wxGetApp().Contact
->Name
;
1242 pNameTxt
->SetFocus();
1246 if (widgetName
== pCopyBtn
->GetName())
1249 pNameTxt
->SetValue(wxEmptyString
);
1250 pNameTxt
->SetFocus();
1254 if (widgetName
== pDeleteBtn
->GetName())
1256 bool Ok
= (wxMessageBox(wxT("Are you sure?"),wxT("Confirm"),wxYES_NO
|wxICON_QUESTION
) == wxYES
);
1261 if (Ok
&& wxGetApp().Contact
->Delete())
1263 // NOTE: Deletions are not finalized until a CommitTrans() is performed.
1264 // If the commit were not performed, the program will continue to
1265 // show the table contents as if they were deleted until this instance
1266 // of Ccontact is deleted. If the Commit wasn't performed, the
1267 // database will automatically Rollback the changes when the database
1268 // connection is terminated
1269 wxGetApp().Contact
->GetDb()->CommitTrans();
1271 // Try to get the row that followed the just deleted row in the orderBy sequence
1274 // There was now row (in sequence) after the just deleted row, so get the
1275 // row which preceded the just deleted row
1278 // There are now no rows remaining, so clear the dialog widgets
1279 wxGetApp().Contact
->Initialize();
1283 SetMode(mode
); // force reset of button enable/disable
1287 wxGetApp().Contact
->GetDb()->RollbackTrans();
1293 if (widgetName
== pSaveBtn
->GetName())
1299 if (widgetName
== pCancelBtn
->GetName())
1301 bool Ok
= (wxMessageBox(wxT("Are you sure?"),wxT("Confirm"),wxYES_NO
|wxICON_QUESTION
) == wxYES
);
1306 if (saveName
.empty())
1308 wxGetApp().Contact
->Initialize();
1315 // Requery previous record
1316 if (wxGetApp().Contact
->FetchByName(saveName
))
1324 // Previous record not available, retrieve first record in table
1325 if (wxGetApp().Contact
->GetDb()->Dbms() != dbmsPOSTGRES
&&
1326 wxGetApp().Contact
->GetDb()->Dbms() != dbmsMY_SQL
)
1328 wxGetApp().Contact
->whereStr
= wxT("NAME = (SELECT MIN(NAME) FROM ");
1329 wxGetApp().Contact
->whereStr
+= wxGetApp().Contact
->GetTableName();
1330 wxGetApp().Contact
->whereStr
+= wxT(")");
1331 wxGetApp().Contact
->SetWhereClause(wxGetApp().Contact
->whereStr
.c_str());
1334 wxGetApp().Contact
->SetWhereClause(wxEmptyString
);
1336 if (!wxGetApp().Contact
->Query())
1339 tStr
= wxT("ODBC error during Query()\n\n");
1340 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
1341 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
1346 if (wxGetApp().Contact
->GetNext()) // Successfully read first record
1352 // No contacts are available, clear dialog
1353 wxGetApp().Contact
->Initialize();
1359 if (widgetName
== pPrevBtn
->GetName())
1366 if (widgetName
== pNextBtn
->GetName())
1373 if (widgetName
== pQueryBtn
->GetName())
1375 // Display the query dialog box
1376 wxChar qryWhere
[DB_MAX_WHERE_CLAUSE_LEN
+1];
1377 wxStrcpy(qryWhere
, (const wxChar
*) wxGetApp().Contact
->qryWhereStr
);
1378 wxChar
*tblName
[] = {(wxChar
*)CONTACT_TABLE_NAME
.c_str(), 0};
1379 new CqueryDlg(GetParent(), wxGetApp().Contact
->GetDb(), tblName
, qryWhere
);
1381 // Query the first record in the new record set and
1382 // display it, if the query string has changed.
1383 if (wxStrcmp(qryWhere
, (const wxChar
*) wxGetApp().Contact
->qryWhereStr
))
1385 wxGetApp().Contact
->whereStr
.Empty();
1386 wxGetApp().Contact
->SetOrderByClause(wxT("NAME"));
1388 if (wxGetApp().Contact
->GetDb()->Dbms() != dbmsPOSTGRES
&&
1389 wxGetApp().Contact
->GetDb()->Dbms() != dbmsMY_SQL
)
1391 wxGetApp().Contact
->whereStr
= wxT("NAME = (SELECT MIN(NAME) FROM ");
1392 wxGetApp().Contact
->whereStr
+= CONTACT_TABLE_NAME
;
1395 // Append the query where string (if there is one)
1396 wxGetApp().Contact
->qryWhereStr
= qryWhere
;
1397 if (wxStrlen(qryWhere
))
1399 wxGetApp().Contact
->whereStr
+= wxT(" WHERE ");
1400 wxGetApp().Contact
->whereStr
+= wxGetApp().Contact
->qryWhereStr
;
1402 // Close the expression with a right paren
1403 wxGetApp().Contact
->whereStr
+= wxT(")");
1404 // Requery the table
1405 wxGetApp().Contact
->SetWhereClause(wxGetApp().Contact
->whereStr
.c_str());
1406 if (!wxGetApp().Contact
->Query())
1409 tStr
= wxT("ODBC error during Query()\n\n");
1410 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
1411 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
1415 // Display the first record from the query set
1416 if (!wxGetApp().Contact
->GetNext())
1417 wxGetApp().Contact
->Initialize();
1421 // Enable/Disable the reset button
1422 pResetBtn
->Enable(!wxGetApp().Contact
->qryWhereStr
.empty());
1428 if (widgetName
== pResetBtn
->GetName())
1430 // Clear the additional where criteria established by the query feature
1431 wxGetApp().Contact
->qryWhereStr
= wxEmptyString
;
1432 wxGetApp().Contact
->SetOrderByClause(wxT("NAME"));
1434 if (wxGetApp().Contact
->GetDb()->Dbms() != dbmsPOSTGRES
&&
1435 wxGetApp().Contact
->GetDb()->Dbms() != dbmsMY_SQL
)
1437 wxGetApp().Contact
->whereStr
= wxT("NAME = (SELECT MIN(NAME) FROM ");
1438 wxGetApp().Contact
->whereStr
+= CONTACT_TABLE_NAME
;
1439 wxGetApp().Contact
->whereStr
+= wxT(")");
1442 wxGetApp().Contact
->SetWhereClause(wxGetApp().Contact
->whereStr
.c_str());
1443 if (!wxGetApp().Contact
->Query())
1446 tStr
= wxT("ODBC error during Query()\n\n");
1447 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
1448 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
1451 if (!wxGetApp().Contact
->GetNext())
1452 wxGetApp().Contact
->Initialize();
1454 pResetBtn
->Enable(false);
1460 if (widgetName
== pNameListBtn
->GetName())
1462 new ClookUpDlg(/* wxWindow *parent */ this,
1463 /* const wxString &windowTitle */ wxT("Select contact name"),
1464 /* const wxString &tableName */ CONTACT_TABLE_NAME
,
1465 /* const wxString &dispCol1 */ wxT("NAME"),
1466 /* const wxString &dispCol2 */ wxT("JOINDATE"),
1467 /* const wxString &where */ wxT(""),
1468 /* const wxString &orderBy */ wxT("NAME"),
1469 /* wxDb *pDb */ wxGetApp().READONLY_DB
,
1470 /* const wxString &defDir */ wxGetApp().DbConnectInf
->GetDefaultDir(),
1471 /* bool distinctValues*/ true,
1474 if (ListDB_Selection
&& wxStrlen(ListDB_Selection
))
1476 wxString w
= wxT("NAME = '");
1477 w
+= ListDB_Selection
;
1485 if (widgetName
== pDataTypesBtn
->GetName())
1487 CheckSupportForAllDataTypes(wxGetApp().READONLY_DB
);
1488 wxMessageBox(wxT("Support datatypes was dumped to stdout."));
1490 } // Data types Button
1492 if (widgetName
== pDbDiagsBtn
->GetName())
1494 DisplayDbDiagnostics(wxGetApp().READONLY_DB
);
1495 wxMessageBox(wxT("Diagnostics info was dumped to stdout."));
1499 if (widgetName
== pCatalogBtn
->GetName())
1501 if (wxGetApp().Contact
->GetDb()->Catalog(wxEmptyString
, wxT("catalog.txt")))
1502 wxMessageBox(wxT("The file 'catalog.txt' was created."));
1504 wxMessageBox(wxT("Creation of the file 'catalog.txt' failed."));
1508 #ifdef wxODBC_BLOB_SUPPORT
1509 if (widgetName
== pChooseImageBtn
->GetName())
1514 if (widgetName
== pShowImageBtn
->GetName())
1520 } // CeditorDlg::OnCommand()
1523 bool CeditorDlg::Initialize()
1525 // Create the data structure and a new database connection.
1526 // (As there is not a pDb being passed in the constructor, a new database
1527 // connection is created)
1528 wxGetApp().Contact
= new Ccontact();
1530 if (!wxGetApp().Contact
)
1532 wxMessageBox(wxT("Unable to instantiate an instance of Ccontact"),wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
1536 // Check if the table exists or not. If it doesn't, ask the user if they want to
1537 // create the table. Continue trying to create the table until it exists, or user aborts
1538 while (!wxGetApp().Contact
->GetDb()->TableExists(CONTACT_TABLE_NAME
,
1539 wxGetApp().DbConnectInf
->GetUserID(),
1540 wxGetApp().DbConnectInf
->GetDefaultDir()))
1543 tStr
.Printf(wxT("Unable to open the table '%s'. The table may\nneed to be created.\n\nDo you wish to try to create/clear the table?\n\n"),CONTACT_TABLE_NAME
.c_str());
1544 bool createTable
= (wxMessageBox(tStr
.c_str(),wxT("Confirm"),wxYES_NO
|wxICON_QUESTION
) == wxYES
);
1552 wxGetApp().CreateDataTable(false);
1555 // Tables must be "opened" before anything other than creating/deleting table can be done
1556 if (!wxGetApp().Contact
->Open())
1558 // Table does exist, or there was some problem opening it. Currently this should
1559 // never fail, except in the case of the table not exisiting or the current
1560 // user has insufficent privileges to access the table
1562 // This code is experimenting with a new function that will hopefully be available
1563 // in the 2.4 release. This check will determine whether the open failing was due
1564 // to the table not existing, or the users privileges being insufficient to
1566 if (!wxGetApp().Contact
->GetDb()->TablePrivileges(CONTACT_TABLE_NAME
, wxT("SELECT"),
1567 wxGetApp().Contact
->GetDb()->GetUsername(),
1568 wxGetApp().Contact
->GetDb()->GetUsername(),
1569 wxGetApp().DbConnectInf
->GetDefaultDir()))
1572 tStr
.Printf(wxT("Unable to open the table '%s' (likely due to\ninsufficient privileges of the logged in user).\n\n"),CONTACT_TABLE_NAME
.c_str());
1574 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
1575 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
1579 if (!wxGetApp().Contact
->GetDb()->TableExists(CONTACT_TABLE_NAME
,
1580 wxGetApp().Contact
->GetDb()->GetUsername(),
1581 wxGetApp().DbConnectInf
->GetDefaultDir()))
1584 tStr
.Printf(wxT("Unable to open the table '%s' as the table\ndoes not appear to exist in the tablespace available\nto the currently logged in user.\n\n"),CONTACT_TABLE_NAME
.c_str());
1585 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
1586 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
1594 (void)new wxStaticBox(this, EDITOR_DIALOG_FN_GROUP
, wxEmptyString
, wxPoint(15, 1), wxSize(497, 69), 0, wxT("FunctionGrp"));
1595 (void)new wxStaticBox(this, EDITOR_DIALOG_SEARCH_GROUP
, wxEmptyString
, wxPoint(417, 1), wxSize(95, 242), 0, wxT("SearchGrp"));
1597 pCreateBtn
= new wxButton(this, EDITOR_DIALOG_CREATE
, wxT("&Create"), wxPoint( 25, 21), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("CreateBtn"));
1598 pEditBtn
= new wxButton(this, EDITOR_DIALOG_EDIT
, wxT("&Edit"), wxPoint(102, 21), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("EditBtn"));
1599 pDeleteBtn
= new wxButton(this, EDITOR_DIALOG_DELETE
, wxT("&Delete"), wxPoint(179, 21), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("DeleteBtn"));
1600 pCopyBtn
= new wxButton(this, EDITOR_DIALOG_COPY
, wxT("Cop&y"), wxPoint(256, 21), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("CopyBtn"));
1601 pSaveBtn
= new wxButton(this, EDITOR_DIALOG_SAVE
, wxT("&Save"), wxPoint(333, 21), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("SaveBtn"));
1602 pCancelBtn
= new wxButton(this, EDITOR_DIALOG_CANCEL
, wxT("C&ancel"), wxPoint(430, 21), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("CancelBtn"));
1603 pPrevBtn
= new wxButton(this, EDITOR_DIALOG_PREV
, wxT("<< &Prev"), wxPoint(430, 81), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("PrevBtn"));
1604 pNextBtn
= new wxButton(this, EDITOR_DIALOG_NEXT
, wxT("&Next >>"), wxPoint(430, 121), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("NextBtn"));
1605 pQueryBtn
= new wxButton(this, EDITOR_DIALOG_QUERY
, wxT("&Query"), wxPoint(430, 161), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("QueryBtn"));
1606 pResetBtn
= new wxButton(this, EDITOR_DIALOG_RESET
, wxT("&Reset"), wxPoint(430, 200), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("ResetBtn"));
1607 pNameMsg
= new wxStaticText(this, EDITOR_DIALOG_NAME_MSG
, wxT("Name:"), wxPoint( 17, 80), wxDefaultSize
, 0, wxT("NameMsg"));
1608 pNameTxt
= new wxTextCtrl(this, EDITOR_DIALOG_NAME_TEXT
, wxEmptyString
, wxPoint( 17, 97), wxSize(308, 25), 0, wxDefaultValidator
, wxT("NameTxt"));
1609 pNameListBtn
= new wxButton(this, EDITOR_DIALOG_LOOKUP
, wxT("&Lookup"), wxPoint(333, 97), wxSize( 70, 24), 0, wxDefaultValidator
, wxT("LookupBtn"));
1610 pAddress1Msg
= new wxStaticText(this, EDITOR_DIALOG_ADDRESS1_MSG
, wxT("Address:"), wxPoint( 17, 130), wxDefaultSize
, 0, wxT("Address1Msg"));
1611 pAddress1Txt
= new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT
, wxEmptyString
, wxPoint( 17, 147), wxSize(308, 25), 0, wxDefaultValidator
, wxT("Address1Txt"));
1612 pAddress2Msg
= new wxStaticText(this, EDITOR_DIALOG_ADDRESS2_MSG
, wxT("Address:"), wxPoint( 17, 180), wxDefaultSize
, 0, wxT("Address2Msg"));
1613 pAddress2Txt
= new wxTextCtrl(this, EDITOR_DIALOG_ADDRESS2_TEXT
, wxEmptyString
, wxPoint( 17, 197), wxSize(308, 25), 0, wxDefaultValidator
, wxT("Address2Txt"));
1614 pCityMsg
= new wxStaticText(this, EDITOR_DIALOG_CITY_MSG
, wxT("City:"), wxPoint( 17, 230), wxDefaultSize
, 0, wxT("CityMsg"));
1615 pCityTxt
= new wxTextCtrl(this, EDITOR_DIALOG_CITY_TEXT
, wxEmptyString
, wxPoint( 17, 247), wxSize(225, 25), 0, wxDefaultValidator
, wxT("CityTxt"));
1616 pStateMsg
= new wxStaticText(this, EDITOR_DIALOG_STATE_MSG
, wxT("State:"), wxPoint(250, 230), wxDefaultSize
, 0, wxT("StateMsg"));
1617 pStateTxt
= new wxTextCtrl(this, EDITOR_DIALOG_STATE_TEXT
, wxEmptyString
, wxPoint(250, 247), wxSize(153, 25), 0, wxDefaultValidator
, wxT("StateTxt"));
1618 pCountryMsg
= new wxStaticText(this, EDITOR_DIALOG_COUNTRY_MSG
, wxT("Country:"), wxPoint( 17, 280), wxDefaultSize
, 0, wxT("CountryMsg"));
1619 pCountryTxt
= new wxTextCtrl(this, EDITOR_DIALOG_COUNTRY_TEXT
, wxEmptyString
, wxPoint( 17, 297), wxSize(225, 25), 0, wxDefaultValidator
, wxT("CountryTxt"));
1620 pPostalCodeMsg
= new wxStaticText(this, EDITOR_DIALOG_POSTAL_MSG
, wxT("Postal Code:"),wxPoint(250, 280), wxDefaultSize
, 0, wxT("PostalCodeMsg"));
1621 pPostalCodeTxt
= new wxTextCtrl(this, EDITOR_DIALOG_POSTAL_TEXT
, wxEmptyString
, wxPoint(250, 297), wxSize(153, 25), 0, wxDefaultValidator
, wxT("PostalCodeTxt"));
1623 wxString choice_strings
[5];
1624 choice_strings
[0] = wxT("English");
1625 choice_strings
[1] = wxT("French");
1626 choice_strings
[2] = wxT("German");
1627 choice_strings
[3] = wxT("Spanish");
1628 choice_strings
[4] = wxT("Other");
1630 pNativeLangChoice
= new wxChoice(this, EDITOR_DIALOG_LANG_CHOICE
, wxPoint( 17, 346), wxSize(277, wxDefaultCoord
), 5, choice_strings
);
1631 pNativeLangMsg
= new wxStaticText(this, EDITOR_DIALOG_LANG_MSG
, wxT("Native language:"), wxPoint( 17, 330), wxDefaultSize
, 0, wxT("NativeLangMsg"));
1633 wxString radio_strings
[2];
1634 radio_strings
[0] = wxT("No");
1635 radio_strings
[1] = wxT("Yes");
1636 pDeveloperRadio
= new wxRadioBox(this,EDITOR_DIALOG_DEVELOPER
, wxT("Developer:"), wxPoint(303, 330), wxDefaultSize
, 2, radio_strings
, 2, wxHORIZONTAL
);
1637 pJoinDateMsg
= new wxStaticText(this, EDITOR_DIALOG_JOIN_MSG
, wxT("Date joined:"), wxPoint( 17, 380), wxDefaultSize
, 0, wxT("JoinDateMsg"));
1638 pJoinDateTxt
= new wxTextCtrl(this, EDITOR_DIALOG_JOIN_TEXT
, wxEmptyString
, wxPoint( 17, 397), wxSize(150, 25), 0, wxDefaultValidator
, wxT("JoinDateTxt"));
1639 pContribMsg
= new wxStaticText(this, EDITOR_DIALOG_CONTRIB_MSG
,wxT("Contributions:"), wxPoint(175, 380), wxDefaultSize
, 0, wxT("ContribMsg"));
1640 pContribTxt
= new wxTextCtrl(this, EDITOR_DIALOG_CONTRIB_TEXT
, wxEmptyString
, wxPoint(175, 397), wxSize(120, 25), 0, wxDefaultValidator
, wxT("ContribTxt"));
1641 pLinesMsg
= new wxStaticText(this, EDITOR_DIALOG_LINES_MSG
, wxT("Lines of code:"), wxPoint(303, 380), wxDefaultSize
, 0, wxT("LinesMsg"));
1642 pLinesTxt
= new wxTextCtrl(this, EDITOR_DIALOG_LINES_TEXT
, wxEmptyString
, wxPoint(303, 397), wxSize(100, 25), 0, wxDefaultValidator
, wxT("LinesTxt"));
1644 pCatalogBtn
= new wxButton(this, EDITOR_DIALOG_CATALOG
, wxT("Catalo&g"), wxPoint(430, 287), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("CatalogBtn"));
1645 pDataTypesBtn
= new wxButton(this, EDITOR_DIALOG_DATATYPES
, wxT("Data&types"), wxPoint(430, 337), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("DataTypesBtn"));
1646 pDbDiagsBtn
= new wxButton(this, EDITOR_DIALOG_DB_DIAGS
, wxT("DB Dia&gs"), wxPoint(430, 387), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("DbDiagsBtn"));
1648 #ifdef wxODBC_BLOB_SUPPORT
1649 pPictureMsg
= new wxStaticText(this, EDITOR_DIALOG_PIC_MSG
, wxT("Picture:"), wxPoint( 17,430), wxDefaultSize
, 0, wxT("PicMsg"));
1650 pPictSizeMsg
= new wxStaticText(this, EDITOR_DIALOG_PICSIZE_MSG
, wxT("Picture Bytes:"), wxPoint(175,430), wxDefaultSize
, 0, wxT("PicSizeMsg"));
1651 pChooseImageBtn
= new wxButton(this, EDITOR_DIALOG_PIC_BROWSE
, wxT("Select..."), wxPoint( 17,447), wxSize( 70, 24), 0, wxDefaultValidator
, wxT("PicBrowseBtn"));
1652 pShowImageBtn
= new wxButton(this, EDITOR_DIALOG_PIC_SHOW
, wxT("Show..."), wxPoint( 97,447), wxSize( 70, 24), 0, wxDefaultValidator
, wxT("PictShowBtn"));
1653 pPictSizeTxt
= new wxTextCtrl(this, EDITOR_DIALOG_PIC_SIZE_TEXT
, wxEmptyString
, wxPoint(175,447), wxSize(120, 25), 0, wxDefaultValidator
, wxT("PictSizeTxt"));
1656 // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
1657 // handle all widget processing
1658 widgetPtrsSet
= true;
1660 // Setup the orderBy and where clauses to return back a single record as the result set,
1661 // as there will only be one record being shown on the dialog at a time, this optimizes
1662 // network traffic by only returning a one row result
1664 wxGetApp().Contact
->SetOrderByClause(wxT("NAME")); // field name to sort by
1666 // The wxString "whereStr" is not a member of the wxDbTable object, it is a member variable
1667 // specifically in the Ccontact class. It is used here for simpler construction of a varying
1668 // length string, and then after the string is built, the wxDbTable member variable "where" is
1669 // assigned the pointer to the constructed string.
1671 // The constructed where clause below has a sub-query within it "SELECT MIN(NAME) FROM %s"
1672 // to achieve a single row (in this case the first name in alphabetical order).
1674 if (wxGetApp().Contact
->GetDb()->Dbms() != dbmsPOSTGRES
&&
1675 wxGetApp().Contact
->GetDb()->Dbms() != dbmsMY_SQL
)
1677 wxGetApp().Contact
->whereStr
.Printf(wxT("NAME = (SELECT MIN(NAME) FROM %s)"),
1678 wxGetApp().Contact
->GetTableName().c_str());
1679 // NOTE: (const wxChar*) returns a pointer which may not be valid later, so this is short term use only
1680 wxGetApp().Contact
->SetWhereClause(wxGetApp().Contact
->whereStr
);
1683 wxGetApp().Contact
->SetWhereClause(wxEmptyString
);
1685 // Perform the Query to get the result set.
1686 // NOTE: If there are no rows returned, that is a valid result, so Query() would return true.
1687 // Only if there is a database error will Query() come back as false
1688 if (!wxGetApp().Contact
->Query())
1691 tStr
= wxT("ODBC error during Query()\n\n");
1692 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
1693 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
1697 // Since Query succeeded, now get the row that was returned
1698 if (!wxGetApp().Contact
->GetNext())
1699 // If the GetNext() failed at this point, then there are no rows to retrieve,
1700 // so clear the values in the members of "Contact" so that PutData() blanks the
1701 // widgets on the dialog
1702 wxGetApp().Contact
->Initialize();
1704 wxGetApp().Contact->GetDb()->RollbackTrans();
1713 } // CeditorDlg::Initialize()
1715 #ifdef wxODBC_BLOB_SUPPORT
1717 void CeditorDlg::OnSelectPict()
1719 wxFileDialog
dlg(this, wxT("Choose an image file less than 60K"), wxEmptyString
, wxEmptyString
, wxT("JPEG files (*.jpg)|*.jpg|GIF files (*.gif)|*.gif|BMP files (*.bmp)|*.bmp|All Files (*.*)|*.*"), wxOPEN
);
1721 if (dlg
.ShowModal() == wxID_OK
)
1723 wxFile
file(dlg
.GetPath());
1725 if (file
.IsOpened())
1727 // assume not huge file in sample
1728 long iSize
= (long)file
.Length();
1730 if ((iSize
> 0) && (iSize
< MAX_PICTURE_SIZE
))
1732 wxGetApp().Contact
->BlobSize
= (size_t)iSize
;
1734 memset(wxGetApp().Contact
->Picture
, 0, MAX_PICTURE_SIZE
);
1736 wxFileOffset iReadSize
= file
.Read(wxGetApp().Contact
->Picture
, (size_t)iSize
);
1738 if (iReadSize
< iSize
)
1739 wxMessageBox(wxT("Something bad happened while reading..."), wxT("BLOB Loading Error"), wxOK
| wxICON_EXCLAMATION
);
1742 tStr
.Printf(wxT("%ld"),iSize
);
1743 pPictSizeTxt
->SetValue(tStr
);
1746 wxMessageBox(wxT("Selected File is TOO BIG. 60k is the max image size"), wxT("BLOB Loading Error"), wxOK
| wxICON_EXCLAMATION
);
1749 wxMessageBox(wxT("Unable to open the requested image file"), wxT("File Access Error"), wxOK
| wxICON_EXCLAMATION
);
1753 void CeditorDlg::OnShowImage()
1755 if (wxGetApp().Contact
->BlobSize
> 0)
1757 CimageDlg
dlg(this, wxGetApp().Contact
->Picture
, wxGetApp().Contact
->BlobSize
);
1765 void CeditorDlg::FieldsEditable()
1770 pNameTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1771 pAddress1Txt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1772 pAddress2Txt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1773 pCityTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1774 pStateTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1775 pPostalCodeTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1776 pCountryTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1778 pJoinDateTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1779 pContribTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1780 pLinesTxt
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1781 pNativeLangChoice
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1782 pDeveloperRadio
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1784 #ifdef wxODBC_BLOB_SUPPORT
1785 pPictSizeTxt
->Enable(false);
1786 pChooseImageBtn
->Enable((mode
== mCreate
) || (mode
== mEdit
));
1787 pShowImageBtn
->Enable(wxGetApp().Contact
&& wxGetApp().Contact
->BlobSize
> 0); //((mode == mCreate) || (mode == mEdit));
1790 } // CeditorDlg::FieldsEditable()
1793 void CeditorDlg::SetMode(enum DialogModes m
)
1814 pCreateBtn
->Enable( !edit
);
1815 pEditBtn
->Enable( !edit
&& (wxStrcmp(wxGetApp().Contact
->Name
, wxEmptyString
) != 0) );
1816 pDeleteBtn
->Enable( !edit
&& (wxStrcmp(wxGetApp().Contact
->Name
, wxEmptyString
)!=0) );
1817 pCopyBtn
->Enable( !edit
&& (wxStrcmp(wxGetApp().Contact
->Name
, wxEmptyString
)!=0) );
1818 pSaveBtn
->Enable( edit
);
1819 pCancelBtn
->Enable( edit
);
1820 pPrevBtn
->Enable( !edit
);
1821 pNextBtn
->Enable( !edit
);
1822 pQueryBtn
->Enable( !edit
);
1823 pResetBtn
->Enable( !edit
&& !wxGetApp().Contact
->qryWhereStr
.empty() );
1824 pNameListBtn
->Enable( !edit
);
1828 } // CeditorDlg::SetMode()
1831 bool CeditorDlg::PutData()
1835 pNameTxt
->SetValue(wxGetApp().Contact
->Name
);
1836 pAddress1Txt
->SetValue(wxGetApp().Contact
->Addr1
);
1837 pAddress2Txt
->SetValue(wxGetApp().Contact
->Addr2
);
1838 pCityTxt
->SetValue(wxGetApp().Contact
->City
);
1839 pStateTxt
->SetValue(wxGetApp().Contact
->State
);
1840 pCountryTxt
->SetValue(wxGetApp().Contact
->Country
);
1841 pPostalCodeTxt
->SetValue(wxGetApp().Contact
->PostalCode
);
1843 tStr
.Printf(wxT("%d/%d/%d"),wxGetApp().Contact
->JoinDate
.month
,wxGetApp().Contact
->JoinDate
.day
,wxGetApp().Contact
->JoinDate
.year
);
1844 pJoinDateTxt
->SetValue(tStr
);
1846 tStr
.Printf(wxT("%d"),wxGetApp().Contact
->Contributions
);
1847 pContribTxt
->SetValue(tStr
);
1849 tStr
.Printf(wxT("%lu"),wxGetApp().Contact
->LinesOfCode
);
1850 pLinesTxt
->SetValue(tStr
);
1852 pNativeLangChoice
->SetSelection(wxGetApp().Contact
->NativeLanguage
);
1854 pDeveloperRadio
->SetSelection(wxGetApp().Contact
->IsDeveloper
);
1856 #ifdef wxODBC_BLOB_SUPPORT
1857 tStr
.Printf(wxT("%lu"),wxGetApp().Contact
->BlobSize
);
1858 pPictSizeTxt
->SetValue(tStr
);
1859 pShowImageBtn
->Enable(wxGetApp().Contact
->BlobSize
> 0);
1863 } // Ceditor::PutData()
1867 * Reads the data out of all the widgets on the dialog. Some data evaluation is done
1868 * to ensure that there is a name entered and that the date field is valid.
1870 * A return value of true means that valid data was retrieved from the dialog, otherwise
1871 * invalid data was found (and a message was displayed telling the user what to fix), and
1872 * the data was not placed into the appropraite fields of Ccontact
1874 bool CeditorDlg::GetData()
1876 // Validate that the data currently entered into the widgets is valid data
1879 tStr
= pNameTxt
->GetValue();
1880 if (!wxStrcmp((const wxChar
*) tStr
, wxEmptyString
))
1882 wxMessageBox(wxT("A name is required for entry into the contact table"), wxT("Notice..."), wxOK
| wxICON_INFORMATION
);
1886 bool invalid
= false;
1887 int mm
= 1,dd
= 1,yyyy
= 2001;
1890 tStr
= pJoinDateTxt
->GetValue();
1891 if (tStr
.Freq(wxT('/')) != 2)
1894 // Find the month, day, and year tokens
1897 first
= tStr
.First(wxT('/'));
1898 second
= tStr
.Last(wxT('/'));
1900 mm
= wxAtoi(tStr
.SubString(0,first
));
1901 dd
= wxAtoi(tStr
.SubString(first
+1,second
));
1902 yyyy
= wxAtoi(tStr
.SubString(second
+1,tStr
.Length()-1));
1904 invalid
= !(mm
&& dd
&& yyyy
);
1907 // Force Year 2000 compliance
1908 if (!invalid
&& (yyyy
< 1000))
1911 // Check the token ranges for validity
1916 else if ((mm
< 1) || (mm
> 12))
1924 int days
[12] = {31,28,31,30,31,30,
1926 if (dd
> days
[mm
-1])
1929 if ((dd
== 29) && (mm
== 2))
1931 if (((yyyy
% 4) == 0) && (((yyyy
% 100) != 0) || ((yyyy
% 400) == 0)))
1941 wxGetApp().Contact
->JoinDate
.month
= (unsigned short) mm
;
1942 wxGetApp().Contact
->JoinDate
.day
= (unsigned short) dd
;
1943 wxGetApp().Contact
->JoinDate
.year
= (short) yyyy
;
1947 wxMessageBox(wxT("Improper date format. Please check the date\nspecified and try again.\n\nNOTE: Dates are in american format (MM/DD/YYYY)"),wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
1951 tStr
= pNameTxt
->GetValue();
1952 wxStrcpy(wxGetApp().Contact
->Name
,(const wxChar
*) tStr
);
1953 wxStrcpy(wxGetApp().Contact
->Addr1
,pAddress1Txt
->GetValue());
1954 wxStrcpy(wxGetApp().Contact
->Addr2
,pAddress2Txt
->GetValue());
1955 wxStrcpy(wxGetApp().Contact
->City
,pCityTxt
->GetValue());
1956 wxStrcpy(wxGetApp().Contact
->State
,pStateTxt
->GetValue());
1957 wxStrcpy(wxGetApp().Contact
->Country
,pCountryTxt
->GetValue());
1958 wxStrcpy(wxGetApp().Contact
->PostalCode
,pPostalCodeTxt
->GetValue());
1960 wxGetApp().Contact
->Contributions
= (UCHAR
)wxAtoi(pContribTxt
->GetValue());
1961 wxGetApp().Contact
->LinesOfCode
= wxAtol(pLinesTxt
->GetValue());
1963 wxGetApp().Contact
->NativeLanguage
= (enum Language
) pNativeLangChoice
->GetSelection();
1964 wxGetApp().Contact
->IsDeveloper
= pDeveloperRadio
->GetSelection() > 0;
1967 } // CeditorDlg::GetData()
1971 * Retrieve data from the dialog, verify the validity of the data, and if it is valid,
1972 * try to insert/update the data to the table based on the current 'mode' the dialog
1975 * A return value of true means the insert/update was completed successfully, a return
1976 * value of false means that Save() failed. If returning false, then this function
1977 * has displayed a detailed error message for the user.
1979 bool CeditorDlg::Save()
1981 bool failed
= false;
1983 // Read the data in the widgets of the dialog to get the user's data
1987 // Perform any other required validations necessary before saving
1990 wxBeginBusyCursor();
1992 if (mode
== mCreate
)
1994 RETCODE result
= (RETCODE
)wxGetApp().Contact
->Insert();
1996 failed
= (result
!= DB_SUCCESS
);
1999 // Some errors may be expected, like a duplicate key, so handle those instances with
2000 // specific error messages.
2001 if (result
== DB_ERR_INTEGRITY_CONSTRAINT_VIOL
)
2004 tStr
= wxT("A duplicate key value already exists in the table.\nUnable to save record\n\n");
2005 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
2006 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
2010 // Some other unexpected error occurred
2012 tStr
= wxT("Database insert failed\n\n");
2013 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
2014 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
2018 else // mode == mEdit
2020 wxGetApp().Contact
->GetDb()->RollbackTrans();
2021 wxGetApp().Contact
->whereStr
.Printf(wxT("NAME = '%s'"),saveName
.c_str());
2022 if (!wxGetApp().Contact
->UpdateWhere(wxGetApp().Contact
->whereStr
))
2025 tStr
= wxT("Database update failed\n\n");
2026 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
2027 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
2034 wxGetApp().Contact
->GetDb()->CommitTrans();
2035 SetMode(mView
); // Sets the dialog mode back to viewing after save is successful
2038 wxGetApp().Contact
->GetDb()->RollbackTrans();
2044 } // CeditorDlg::Save()
2048 * Where this program is only showing a single row at a time in the dialog,
2049 * a special where clause must be built to find just the single row which,
2050 * in sequence, would follow the currently displayed row.
2052 bool CeditorDlg::GetNextRec()
2056 if (wxGetApp().Contact
->GetDb()->Dbms() != dbmsPOSTGRES
&&
2057 wxGetApp().Contact
->GetDb()->Dbms() != dbmsMY_SQL
)
2059 w
= wxT("NAME = (SELECT MIN(NAME) FROM ");
2060 w
+= wxGetApp().Contact
->GetTableName();
2061 w
+= wxT(" WHERE NAME > '");
2064 w
= wxT("(NAME > '");
2066 w
+= wxGetApp().Contact
->Name
;
2069 // If a query where string is currently set, append that criteria
2070 if (!wxGetApp().Contact
->qryWhereStr
.empty())
2073 w
+= wxGetApp().Contact
->qryWhereStr
;
2080 } // CeditorDlg::GetNextRec()
2084 * Where this program is only showing a single row at a time in the dialog,
2085 * a special where clause must be built to find just the single row which,
2086 * in sequence, would precede the currently displayed row.
2088 bool CeditorDlg::GetPrevRec()
2092 if (wxGetApp().Contact
->GetDb()->Dbms() != dbmsPOSTGRES
&&
2093 wxGetApp().Contact
->GetDb()->Dbms() != dbmsMY_SQL
)
2095 w
= wxT("NAME = (SELECT MAX(NAME) FROM ");
2096 w
+= wxGetApp().Contact
->GetTableName();
2097 w
+= wxT(" WHERE NAME < '");
2100 w
= wxT("(NAME < '");
2102 w
+= wxGetApp().Contact
->Name
;
2105 // If a query where string is currently set, append that criteria
2106 if (!wxGetApp().Contact
->qryWhereStr
.empty())
2109 w
+= wxGetApp().Contact
->qryWhereStr
;
2117 } // CeditorDlg::GetPrevRec()
2121 * This function is here to avoid duplicating this same code in both the
2122 * GetPrevRec() and GetNextRec() functions
2124 bool CeditorDlg::GetRec(const wxString
&whereStr
)
2126 wxGetApp().Contact
->SetWhereClause(whereStr
);
2127 wxGetApp().Contact
->SetOrderByClause(wxT("NAME"));
2129 if (!wxGetApp().Contact
->Query())
2132 tStr
= wxT("ODBC error during Query()\n\n");
2133 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
2134 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
2139 if (wxGetApp().Contact
->GetNext())
2146 } // CeditorDlg::GetRec()
2151 * CparameterDlg constructor
2154 BEGIN_EVENT_TABLE(CparameterDlg
, wxDialog
)
2155 EVT_BUTTON(PARAMETER_DIALOG_SAVE
, CparameterDlg::OnButton
)
2156 EVT_BUTTON(PARAMETER_DIALOG_CANCEL
, CparameterDlg::OnButton
)
2157 EVT_CLOSE(CparameterDlg::OnCloseWindow
)
2160 CparameterDlg::CparameterDlg(wxWindow
*parent
) : wxDialog (parent
, PARAMETER_DIALOG
, wxT("ODBC parameter settings"), wxDefaultPosition
, wxSize(400, 325))
2162 // Since the ::OnCommand() function is overridden, this prevents the widget
2163 // detection in ::OnCommand() until all widgets have been initialized to prevent
2164 // uninitialized pointers from crashing the program
2165 widgetPtrsSet
= false;
2167 pParamODBCSourceMsg
= new wxStaticText(this, PARAMETER_DIALOG_SOURCE_MSG
, wxT("ODBC data sources:"), wxPoint( 10, 10), wxDefaultSize
, 0, wxT("ParamODBCSourceMsg"));
2168 pParamODBCSourceList
= new wxListBox(this, PARAMETER_DIALOG_SOURCE_LISTBOX
, wxPoint( 10, 29), wxSize(285, 150), 0, 0, wxLB_SINGLE
|wxLB_ALWAYS_SB
, wxDefaultValidator
, wxT("ParamODBCSourceList"));
2169 pParamUserNameMsg
= new wxStaticText(this, PARAMETER_DIALOG_NAME_MSG
, wxT("Database user name:"), wxPoint( 10, 193), wxDefaultSize
, 0, wxT("ParamUserNameMsg"));
2170 pParamUserNameTxt
= new wxTextCtrl(this, PARAMETER_DIALOG_NAME_TEXT
, wxEmptyString
, wxPoint(10, 209), wxSize( 140, 25), 0, wxDefaultValidator
, wxT("ParamUserNameTxt"));
2171 pParamPasswordMsg
= new wxStaticText(this, PARAMETER_DIALOG_PASSWORD_MSG
, wxT("Password:"), wxPoint(156, 193), wxDefaultSize
, 0, wxT("ParamPasswordMsg"));
2172 pParamPasswordTxt
= new wxTextCtrl(this, PARAMETER_DIALOG_PASSWORD_TEXT
, wxEmptyString
, wxPoint(156, 209), wxSize( 140, 25), 0, wxDefaultValidator
, wxT("ParamPasswordTxt"));
2173 pParamDirPathMsg
= new wxStaticText(this, PARAMETER_DIALOG_DIRPATH_MSG
, wxT("Directory:"), wxPoint( 10, 243), wxDefaultSize
, 0, wxT("ParamDirPathMsg"));
2174 pParamDirPathTxt
= new wxTextCtrl(this, PARAMETER_DIALOG_DIRPATH_TEXT
, wxEmptyString
, wxPoint( 10, 259), wxSize(140, 25), 0, wxDefaultValidator
, wxT("ParamDirPathTxt"));
2175 pParamSaveBtn
= new wxButton(this, PARAMETER_DIALOG_SAVE
, wxT("&Save"), wxPoint(310, 21), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("ParamSaveBtn"));
2176 pParamCancelBtn
= new wxButton(this, PARAMETER_DIALOG_CANCEL
, wxT("C&ancel"), wxPoint(310, 66), wxSize( 70, 35), 0, wxDefaultValidator
, wxT("ParamCancelBtn"));
2178 // Now that all the widgets on the panel are created, its safe to allow ::OnCommand() to
2179 // handle all widget processing
2180 widgetPtrsSet
= true;
2183 savedParamSettings
= wxGetApp().params
;
2188 } // CparameterDlg constructor
2191 void CparameterDlg::OnCloseWindow(wxCloseEvent
& event
)
2193 // Put any additional checking necessary to make certain it is alright
2194 // to close the program here that is not done elsewhere
2197 bool Ok
= (wxMessageBox(wxT("No changes have been saved.\n\nAre you sure you wish exit the parameter screen?"),wxT("Confirm"),wxYES_NO
|wxICON_QUESTION
) == wxYES
);
2205 wxGetApp().params
= savedParamSettings
;
2208 if (GetParent() != NULL
)
2209 GetParent()->SetFocus();
2215 SetReturnCode(0); // added so BoundsChecker would not report use of uninitialized variable
2218 } // CparameterDlg::OnCloseWindow()
2221 void CparameterDlg::OnButton( wxCommandEvent
&event
)
2223 wxWindow
*win
= (wxWindow
*) event
.GetEventObject();
2224 OnCommand( *win
, event
);
2228 void CparameterDlg::OnCommand(wxWindow
& win
, wxCommandEvent
& WXUNUSED(event
))
2230 wxString widgetName
;
2232 widgetName
= win
.GetName();
2237 if (widgetName
== pParamSaveBtn
->GetName())
2242 tStr
= wxT("Database parameters have been saved.");
2243 if (GetParent() != NULL
) // The parameter dialog was not called during startup due to a missing cfg file
2244 tStr
+= wxT("\nNew parameters will take effect the next time the program is started.");
2245 wxMessageBox(tStr
,wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
2252 if (widgetName
== pParamCancelBtn
->GetName())
2257 } // CparameterDlg::OnCommand()
2260 bool CparameterDlg::PutData()
2262 // Fill the data source list box
2263 FillDataSourceList();
2265 // Fill in the fields from the params object
2266 if (wxGetApp().params
.ODBCSource
&& wxStrlen(wxGetApp().params
.ODBCSource
))
2268 int index
= pParamODBCSourceList
->FindString(wxGetApp().params
.ODBCSource
);
2269 if (index
!= wxNOT_FOUND
)
2270 pParamODBCSourceList
->SetSelection(index
);
2272 pParamUserNameTxt
->SetValue(wxGetApp().params
.UserName
);
2273 pParamPasswordTxt
->SetValue(wxGetApp().params
.Password
);
2274 pParamDirPathTxt
->SetValue(wxGetApp().params
.DirPath
);
2276 } // CparameterDlg::PutData()
2279 bool CparameterDlg::GetData()
2282 if (pParamODBCSourceList
->GetStringSelection() != wxEmptyString
)
2284 tStr
= pParamODBCSourceList
->GetStringSelection();
2285 if (tStr
.Length() > ((int)(sizeof(wxGetApp().params
.ODBCSource
) / sizeof(wxChar
))-1))
2288 errmsg
.Printf(wxT("ODBC Data source name is longer than the data structure to hold it.\n'Cparameter.ODBCSource' must have a larger character array\nto handle a data source with this long of a name\n\nThe data source currently selected is %d characters long."), tStr
.Length());
2289 wxMessageBox(errmsg
, wxT("Internal program error..."), wxOK
| wxICON_EXCLAMATION
);
2292 wxStrcpy(wxGetApp().params
.ODBCSource
, tStr
);
2297 tStr
= pParamUserNameTxt
->GetValue();
2298 if (tStr
.Length() > ((int)(sizeof(wxGetApp().params
.UserName
) / sizeof(wxChar
))-1))
2301 errmsg
.Printf(wxT("User name is longer than the data structure to hold it.\n'Cparameter.UserName' must have a larger character array\nto handle a data source with this long of a name\n\nThe user name currently specified is %d characters long."), tStr
.Length());
2302 wxMessageBox(errmsg
, wxT("Internal program error..."), wxOK
| wxICON_EXCLAMATION
);
2305 wxStrcpy(wxGetApp().params
.UserName
, tStr
);
2307 tStr
= pParamPasswordTxt
->GetValue();
2308 if (tStr
.Length() > ((int)(sizeof(wxGetApp().params
.Password
) / sizeof(wxChar
))-1))
2311 errmsg
.Printf(wxT("Password is longer than the data structure to hold it.\n'Cparameter.Password' must have a larger character array\nto handle a data source with this long of a name\n\nThe password currently specified is %d characters long."), tStr
.Length());
2312 wxMessageBox(errmsg
, wxT("Internal program error..."), wxOK
| wxICON_EXCLAMATION
);
2315 wxStrcpy(wxGetApp().params
.Password
,tStr
);
2317 tStr
= pParamDirPathTxt
->GetValue();
2318 tStr
.Replace(wxT("\\"),wxT("/"));
2319 if (tStr
.Length() > ((int)(sizeof(wxGetApp().params
.DirPath
) / sizeof(wxChar
))-1))
2322 errmsg
.Printf(wxT("DirPath is longer than the data structure to hold it.\n'Cparameter.DirPath' must have a larger character array\nto handle a data source with this long of a name\n\nThe password currently specified is %d characters long."), tStr
.Length());
2323 wxMessageBox(errmsg
, wxT("Internal program error..."), wxOK
| wxICON_EXCLAMATION
);
2326 wxStrcpy(wxGetApp().params
.DirPath
,tStr
);
2328 } // CparameterDlg::GetData()
2331 bool CparameterDlg::Save()
2333 // Copy the current params in case user cancels changing
2334 // the params, so that we can reset them.
2337 wxGetApp().params
= savedParamSettings
;
2341 wxGetApp().WriteParamFile(wxGetApp().params
);
2344 } // CparameterDlg::Save()
2347 void CparameterDlg::FillDataSourceList()
2349 wxChar Dsn
[SQL_MAX_DSN_LENGTH
+1];
2350 wxChar DsDesc
[254+1];
2351 wxSortedArrayString strArr
;
2353 while (wxDbGetDataSource(wxGetApp().DbConnectInf
->GetHenv(), Dsn
,
2354 SQL_MAX_DSN_LENGTH
, DsDesc
, 254))
2359 for (size_t i
=0; i
< strArr
.GetCount(); i
++)
2361 pParamODBCSourceList
->Append(strArr
[i
].c_str());
2364 } // CparameterDlg::FillDataSourceList()
2367 BEGIN_EVENT_TABLE(CqueryDlg
, wxDialog
)
2368 EVT_BUTTON(wxID_ANY
, CqueryDlg::OnButton
)
2369 EVT_CLOSE(CqueryDlg::OnCloseWindow
)
2373 // CqueryDlg() constructor
2374 CqueryDlg::CqueryDlg(wxWindow
*parent
, wxDb
*pDb
, wxChar
*tblName
[],
2375 const wxString
&pWhereArg
) :
2376 wxDialog (parent
, QUERY_DIALOG
, wxT("Query"), wxDefaultPosition
, wxSize(480, 360))
2378 wxBeginBusyCursor();
2382 masterTableName
= tblName
[0];
2383 widgetPtrsSet
= false;
2386 // Initialize the WHERE clause from the string passed in
2387 pWhere
= pWhereArg
; // Save a pointer to the output buffer
2388 if (pWhere
.Length() > (unsigned int)DB_MAX_WHERE_CLAUSE_LEN
) // Check the length of the buffer passed in
2391 s
.Printf(wxT("Maximum where clause length exceeded.\nLength must be less than %d"), DB_MAX_WHERE_CLAUSE_LEN
+1);
2392 wxMessageBox(s
,wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
2397 pQueryCol1Msg
= new wxStaticText(this, QUERY_DIALOG_COL_MSG
, wxT("Column 1:"), wxPoint( 10, 10), wxSize( 69, 16), 0, wxT("QueryCol1Msg"));
2398 pQueryCol1Choice
= new wxChoice(this, QUERY_DIALOG_COL_CHOICE
, wxPoint( 10, 27), wxSize(250, 27), 0, 0, 0, wxDefaultValidator
, wxT("QueryCol1Choice"));
2399 pQueryNotMsg
= new wxStaticText(this, QUERY_DIALOG_NOT_MSG
, wxT("NOT"), wxPoint(268, 10), wxDefaultSize
, 0, wxT("QueryNotMsg"));
2400 pQueryNotCheck
= new wxCheckBox(this, QUERY_DIALOG_NOT_CHECKBOX
, wxEmptyString
, wxPoint(275, 37), wxSize( 20, 20), 0, wxDefaultValidator
, wxT("QueryNotCheck"));
2402 wxString choice_strings
[9];
2403 choice_strings
[0] = wxT("=");
2404 choice_strings
[1] = wxT("<");
2405 choice_strings
[2] = wxT(">");
2406 choice_strings
[3] = wxT("<=");
2407 choice_strings
[4] = wxT(">=");
2408 choice_strings
[5] = wxT("Begins");
2409 choice_strings
[6] = wxT("Contains");
2410 choice_strings
[7] = wxT("Like");
2411 choice_strings
[8] = wxT("Between");
2413 pQueryOperatorMsg
= new wxStaticText(this, QUERY_DIALOG_OP_MSG
, wxT("Operator:"), wxPoint(305, 10), wxDefaultSize
, 0, wxT("QueryOperatorMsg"));
2414 pQueryOperatorChoice
= new wxChoice(this, QUERY_DIALOG_OP_CHOICE
, wxPoint(305, 27), wxSize( 80, 27), 9, choice_strings
, 0, wxDefaultValidator
, wxT("QueryOperatorChoice"));
2415 pQueryCol2Msg
= new wxStaticText(this, QUERY_DIALOG_COL2_MSG
, wxT("Column 2:"), wxPoint( 10, 65), wxSize( 69, 16), 0, wxT("QueryCol2Msg"));
2416 pQueryCol2Choice
= new wxChoice(this, QUERY_DIALOG_COL2_CHOICE
, wxPoint( 10, 82), wxSize(250, 27), 0, 0, 0, wxDefaultValidator
, wxT("QueryCol2Choice"));
2417 pQuerySqlWhereMsg
= new wxStaticText(this, QUERY_DIALOG_WHERE_MSG
, wxT("SQL where clause:"), wxPoint( 10, 141), wxDefaultSize
, 0, wxT("QuerySqlWhereMsg"));
2418 pQuerySqlWhereMtxt
= new wxTextCtrl(this, QUERY_DIALOG_WHERE_TEXT
, wxEmptyString
, wxPoint( 10, 159), wxSize(377, 134), wxTE_MULTILINE
, wxDefaultValidator
, wxT("QuerySqlWhereMtxt"));
2419 pQueryAddBtn
= new wxButton(this, QUERY_DIALOG_ADD
, wxT("&Add"), wxPoint(406, 24), wxSize( 56, 26), 0, wxDefaultValidator
, wxT("QueryAddBtn"));
2420 pQueryAndBtn
= new wxButton(this, QUERY_DIALOG_AND
, wxT("A&nd"), wxPoint(406, 58), wxSize( 56, 26), 0, wxDefaultValidator
, wxT("QueryAndBtn"));
2421 pQueryOrBtn
= new wxButton(this, QUERY_DIALOG_OR
, wxT("&Or"), wxPoint(406, 92), wxSize( 56, 26), 0, wxDefaultValidator
, wxT("QueryOrBtn"));
2422 pQueryLParenBtn
= new wxButton(this, QUERY_DIALOG_LPAREN
, wxT("("), wxPoint(406, 126), wxSize( 26, 26), 0, wxDefaultValidator
, wxT("QueryLParenBtn"));
2423 pQueryRParenBtn
= new wxButton(this, QUERY_DIALOG_RPAREN
, wxT(")"), wxPoint(436, 126), wxSize( 26, 26), 0, wxDefaultValidator
, wxT("QueryRParenBtn"));
2424 pQueryDoneBtn
= new wxButton(this, QUERY_DIALOG_DONE
, wxT("&Done"), wxPoint(406, 185), wxSize( 56, 26), 0, wxDefaultValidator
, wxT("QueryDoneBtn"));
2425 pQueryClearBtn
= new wxButton(this, QUERY_DIALOG_CLEAR
, wxT("C&lear"), wxPoint(406, 218), wxSize( 56, 26), 0, wxDefaultValidator
, wxT("QueryClearBtn"));
2426 pQueryCountBtn
= new wxButton(this, QUERY_DIALOG_COUNT
, wxT("&Count"), wxPoint(406, 252), wxSize( 56, 26), 0, wxDefaultValidator
, wxT("QueryCountBtn"));
2427 pQueryValue1Msg
= new wxStaticText(this, QUERY_DIALOG_VALUE1_MSG
, wxT("Value:"), wxPoint(277, 66), wxDefaultSize
, 0, wxT("QueryValue1Msg"));
2428 pQueryValue1Txt
= new wxTextCtrl(this, QUERY_DIALOG_VALUE1_TEXT
, wxEmptyString
, wxPoint(277, 83), wxSize(108, 25), 0, wxDefaultValidator
, wxT("QueryValue1Txt"));
2429 pQueryValue2Msg
= new wxStaticText(this, QUERY_DIALOG_VALUE2_MSG
, wxT("AND"), wxPoint(238, 126), wxDefaultSize
, 0, wxT("QueryValue2Msg"));
2430 pQueryValue2Txt
= new wxTextCtrl(this, QUERY_DIALOG_VALUE2_TEXT
, wxEmptyString
, wxPoint(277, 120), wxSize(108, 25), 0, wxDefaultValidator
, wxT("QueryValue2Txt"));
2431 pQueryHintGrp
= new wxStaticBox(this, QUERY_DIALOG_HINT_GROUP
, wxEmptyString
, wxPoint( 10, 291), wxSize(377, 40), 0, wxT("QueryHintGrp"));
2432 pQueryHintMsg
= new wxStaticText(this, QUERY_DIALOG_HINT_MSG
, wxEmptyString
, wxPoint( 16, 306), wxDefaultSize
, 0, wxT("QueryHintMsg"));
2434 widgetPtrsSet
= true;
2435 // Initialize the dialog
2437 pQueryCol2Choice
->Append(wxT("VALUE -->"));
2438 colInf
= pDB
->GetColumns(tblName
);
2444 tStr
= wxT("ODBC error during GetColumns()\n\n");
2445 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
2446 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
2451 for (i
= 0; colInf
[i
].colName
&& wxStrlen(colInf
[i
].colName
); i
++)
2453 // If there is more than one table being queried, qualify
2454 // the column names with the table name prefix.
2455 if (tblName
[1] && wxStrlen(tblName
[1]))
2457 qualName
.Printf(wxT("%s.%s"), colInf
[i
].tableName
, colInf
[i
].colName
);
2458 pQueryCol1Choice
->Append(qualName
);
2459 pQueryCol2Choice
->Append(qualName
);
2461 else // Single table query, append just the column names
2463 pQueryCol1Choice
->Append(colInf
[i
].colName
);
2464 pQueryCol2Choice
->Append(colInf
[i
].colName
);
2468 pQueryCol1Choice
->SetSelection(0);
2469 pQueryCol2Choice
->SetSelection(0);
2470 pQueryOperatorChoice
->SetSelection(0);
2472 pQueryValue2Msg
->Show(false);
2473 pQueryValue2Txt
->Show(false);
2475 pQueryHintMsg
->SetLabel(langQRY_EQ
);
2477 pQuerySqlWhereMtxt
->SetValue(pWhere
.c_str());
2481 // Display the dialog window
2484 } // CqueryDlg() constructor
2487 CqueryDlg::~CqueryDlg()
2489 } // CqueryDlg::~CqueryDlg() destructor
2492 void CqueryDlg::OnButton(wxCommandEvent
&event
)
2494 wxWindow
*win
= (wxWindow
*) event
.GetEventObject();
2495 OnCommand( *win
, event
);
2496 } // CqueryDlg::OnButton()
2499 void CqueryDlg::OnCommand(wxWindow
& win
, wxCommandEvent
& WXUNUSED(event
))
2501 // Widget pointers won't be set when the dialog is constructed.
2502 // Control is passed through this function once for each widget on
2503 // a dialog as the dialog is constructed.
2507 wxString widgetName
= win
.GetName();
2509 // Operator choice box
2510 if (widgetName
== pQueryOperatorChoice
->GetName())
2512 // Set the help text
2513 switch((qryOp
) pQueryOperatorChoice
->GetSelection())
2516 pQueryHintMsg
->SetLabel(langQRY_EQ
);
2519 pQueryHintMsg
->SetLabel(langQRY_LT
);
2522 pQueryHintMsg
->SetLabel(langQRY_GT
);
2525 pQueryHintMsg
->SetLabel(langQRY_LE
);
2528 pQueryHintMsg
->SetLabel(langQRY_GE
);
2531 pQueryHintMsg
->SetLabel(langQRY_BEGINS
);
2534 pQueryHintMsg
->SetLabel(langQRY_CONTAINS
);
2537 pQueryHintMsg
->SetLabel(langQRY_LIKE
);
2540 pQueryHintMsg
->SetLabel(langQRY_BETWEEN
);
2544 // Hide the value2 widget
2545 pQueryValue2Msg
->Show(false); // BETWEEN will show this widget
2546 pQueryValue2Txt
->Show(false); // BETWEEN will show this widget
2548 // Disable the NOT operator for <, <=, >, >=
2549 switch((qryOp
) pQueryOperatorChoice
->GetSelection())
2555 pQueryNotCheck
->SetValue(0);
2556 pQueryNotCheck
->Enable(false);
2559 pQueryNotCheck
->Enable(true);
2563 // Manipulate the dialog to handle the selected operator
2564 switch((qryOp
) pQueryOperatorChoice
->GetSelection())
2571 pQueryCol2Choice
->Enable(true);
2572 if (pQueryCol2Choice
->GetSelection()) // Column name is highlighted
2574 pQueryValue1Msg
->Show(false);
2575 pQueryValue1Txt
->Show(false);
2577 else // "Value" is highlighted
2579 pQueryValue1Msg
->Show(true);
2580 pQueryValue1Txt
->Show(true);
2581 pQueryValue1Txt
->SetFocus();
2587 pQueryCol2Choice
->SetSelection(0);
2588 pQueryCol2Choice
->Enable(false);
2589 pQueryValue1Msg
->Show(true);
2590 pQueryValue1Txt
->Show(true);
2591 pQueryValue1Txt
->SetFocus();
2594 pQueryCol2Choice
->SetSelection(0);
2595 pQueryCol2Choice
->Enable(false);
2596 pQueryValue2Msg
->Show(true);
2597 pQueryValue2Txt
->Show(true);
2598 pQueryValue1Msg
->Show(true);
2599 pQueryValue1Txt
->Show(true);
2600 pQueryValue1Txt
->SetFocus();
2606 } // Operator choice box
2609 if (widgetName
== pQueryCol2Choice
->GetName())
2611 if (pQueryCol2Choice
->GetSelection()) // Column name is highlighted
2613 pQueryValue1Msg
->Show(false);
2614 pQueryValue1Txt
->Show(false);
2616 else // "Value" is highlighted
2618 pQueryValue1Msg
->Show(true);
2619 pQueryValue1Txt
->Show(true);
2620 pQueryValue1Txt
->SetFocus();
2623 } // Column 2 choice
2626 if (widgetName
== pQueryAddBtn
->GetName())
2633 if (widgetName
== pQueryAndBtn
->GetName())
2635 AppendToWhere(wxT(" AND\n"));
2640 if (widgetName
== pQueryOrBtn
->GetName())
2642 AppendToWhere(wxT(" OR\n"));
2646 // Left Paren button
2647 if (widgetName
== pQueryLParenBtn
->GetName())
2649 AppendToWhere(wxT("("));
2651 } // Left Paren button
2653 // Right paren button
2654 if (widgetName
== pQueryRParenBtn
->GetName())
2656 AppendToWhere(wxT(")"));
2658 } // Right Paren button
2661 if (widgetName
== pQueryDoneBtn
->GetName())
2663 // Be sure the where clause will not overflow the output buffer
2664 if (wxStrlen(pQuerySqlWhereMtxt
->GetValue()) > (unsigned int)DB_MAX_WHERE_CLAUSE_LEN
)
2667 s
.Printf(wxT("Maximum where clause length exceeded.\nLength must be less than %d"), DB_MAX_WHERE_CLAUSE_LEN
+1);
2668 wxMessageBox(s
,wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
2671 // Validate the where clause for things such as matching parens
2672 if (!ValidateWhereClause())
2674 // Copy the where clause to the output buffer and exit
2675 pWhere
= pQuerySqlWhereMtxt
->GetValue();
2681 if (widgetName
== pQueryClearBtn
->GetName())
2683 bool Ok
= (wxMessageBox(wxT("Are you sure you wish to clear the Query?"), wxT("Confirm"), wxYES_NO
|wxICON_QUESTION
) == wxYES
);
2686 pQuerySqlWhereMtxt
->SetValue(wxEmptyString
);
2692 if (widgetName
== pQueryCountBtn
->GetName())
2694 wxBeginBusyCursor();
2700 } // CqueryDlg::OnCommand
2703 void CqueryDlg::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
2710 GetParent()->SetFocus();
2715 SetReturnCode(1); // added so BoundsChecker would not report use of uninitialized variable
2718 } // CqueryDlg::OnCloseWindow()
2721 void CqueryDlg::AppendToWhere(wxChar
*s
)
2723 wxString whereStr
= pQuerySqlWhereMtxt
->GetValue();
2725 pQuerySqlWhereMtxt
->SetValue(whereStr
);
2726 } // CqueryDlg::AppendToWhere()
2729 void CqueryDlg::ProcessAddBtn()
2731 qryOp oper
= (qryOp
) pQueryOperatorChoice
->GetSelection();
2733 // Verify that eveything is filled in correctly
2734 if (pQueryCol2Choice
->GetSelection() == 0) // "Value" is selected
2736 // Verify that value 1 is filled in
2737 if (wxStrlen(pQueryValue1Txt
->GetValue()) == 0)
2740 pQueryValue1Txt
->SetFocus();
2743 // For the BETWEEN operator, value 2 must be filled in as well
2744 if (oper
== qryOpBETWEEN
&&
2745 wxStrlen(pQueryValue2Txt
->GetValue()) == 0)
2748 pQueryValue2Txt
->SetFocus();
2753 // Build the expression and append it to the where clause window
2754 wxString s
= pQueryCol1Choice
->GetStringSelection();
2756 if (pQueryNotCheck
->GetValue() && (oper
!= qryOpEQ
))
2762 if (pQueryNotCheck
->GetValue()) // NOT box is checked
2785 s
+= wxT(" BETWEEN");
2791 int col1Idx
= pQueryCol1Choice
->GetSelection();
2794 if (colInf
[col1Idx
].sqlDataType
== SQL_VARCHAR
||
2795 oper
== qryOpBEGINS
||
2796 oper
== qryOpCONTAINS
||
2800 if (pQueryCol2Choice
->GetSelection()) // Column name
2801 s
+= pQueryCol2Choice
->GetStringSelection();
2802 else // Column 2 is a "value"
2806 if (oper
== qryOpCONTAINS
)
2808 s
+= pQueryValue1Txt
->GetValue();
2809 if (oper
== qryOpCONTAINS
|| oper
== qryOpBEGINS
)
2815 if (oper
== qryOpBETWEEN
)
2820 s
+= pQueryValue2Txt
->GetValue();
2825 AppendToWhere((wxChar
*) (const wxChar
*) s
);
2827 } // CqueryDlg::ProcessAddBtn()
2830 void CqueryDlg::ProcessCountBtn()
2832 if (!ValidateWhereClause())
2835 if (!dbTable
) // wxDbTable object needs to be created and opened
2837 dbTable
= new wxDbTable(pDB
, masterTableName
, 0, (const wxString
&)wxEmptyString
,
2839 wxGetApp().DbConnectInf
->GetDefaultDir());
2842 wxMessageBox(wxT("Memory allocation failed creating a wxDbTable object."),wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
2845 if (!dbTable
->Open())
2848 tStr
= wxT("ODBC error during Open()\n\n");
2849 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
2850 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
2855 // Count() with WHERE clause
2858 whereStr
= pQuerySqlWhereMtxt
->GetValue();
2859 dbTable
->SetWhereClause(whereStr
.c_str());
2861 ULONG whereCnt
= dbTable
->Count();
2863 // Count() of all records in the table
2864 dbTable
->SetWhereClause(wxEmptyString
);
2865 ULONG totalCnt
= dbTable
->Count();
2867 if (whereCnt
> 0 || totalCnt
== 0)
2870 tStr
.Printf(wxT("%lu of %lu records match the query criteria."),whereCnt
,totalCnt
);
2871 wxMessageBox(tStr
,wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
2876 tStr
.Printf(wxT("%lu of %lu records match the query criteria.\n\nEither the criteria entered produced a result set\nwith no records, or there was a syntactical error\nin the clause you entered.\n\nPress the details button to see if any database errors were reported."),whereCnt
,totalCnt
);
2877 wxMessageBox(tStr
,wxT("Notice..."),wxOK
| wxICON_INFORMATION
);
2880 // After a wxMessageBox, the focus does not necessarily return to the
2881 // window which was the focus when the message box popped up, so return
2882 // focus to the Query dialog for certain
2885 } // CqueryDlg::ProcessCountBtn()
2888 bool CqueryDlg::ValidateWhereClause()
2890 wxString where
= pQuerySqlWhereMtxt
->GetValue();
2892 if (where
.Freq(wxT('(')) != where
.Freq(wxT(')')))
2894 wxMessageBox(wxT("There are mismatched parenthesis in the constructed where clause"),wxT("Error..."),wxOK
| wxICON_EXCLAMATION
);
2897 // After a wxMessageBox, the focus does not necessarily return to the
2898 // window which was the focus when the message box popped up, so return
2899 // focus to the Query dialog for certain
2904 } // CqueryDlg::ValidateWhereClause()
2906 #ifdef wxODBC_BLOB_SUPPORT
2908 BEGIN_EVENT_TABLE(CimageDlg
, wxDialog
)
2909 EVT_CLOSE(CimageDlg::OnCloseWindow
)
2912 CimageDlg::CimageDlg(wxWindow
*parent
, wxChar
*pImageData
, off_t iSize
)
2913 : wxDialog(parent
, IMAGE_DIALOG
, wxT("BLOB Image"), wxDefaultPosition
, wxDefaultSize
),
2914 m_pDisplayBmp(NULL
),
2918 wxMemoryInputStream
inStream(pImageData
, iSize
);
2922 m_pImage
= new wxImage(inStream
, wxBITMAP_TYPE_ANY
);
2926 m_pBmp
= new wxBitmap(m_pImage
);
2927 m_pDisplayBmp
= new wxStaticBitmap(this, IMAGE_DIALOG_STATIC_BMP
, *m_pBmp
, wxPoint(5,5), wxDefaultSize
);
2929 SetSize(m_pBmp
->GetWidth() + 10, m_pBmp
->GetHeight() + 30);
2934 CimageDlg::~CimageDlg()
2943 delete m_pDisplayBmp
;
2946 void CimageDlg::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
2948 GetParent()->SetFocus();
2957 void DisplayDbDiagnostics(wxDb
*pDb
)
2962 s
= wxT("Diagnostics Output\n");
2963 s
+= langDBINF_DB_NAME
;
2964 s
+= pDb
->dbInf
.dbmsName
;
2967 s
+= langDBINF_DB_VER
;
2968 s
+= pDb
->dbInf
.dbmsVer
;
2971 s
+= langDBINF_DRIVER_NAME
;
2972 s
+= pDb
->dbInf
.driverName
;
2975 s
+= langDBINF_DRIVER_ODBC_VER
;
2976 s
+= pDb
->dbInf
.odbcVer
;
2979 s
+= langDBINF_DRIVER_MGR_ODBC_VER
;
2980 s
+= pDb
->dbInf
.drvMgrOdbcVer
;
2983 s
+= langDBINF_DRIVER_VER
;
2984 s
+= pDb
->dbInf
.driverVer
;
2987 s
+= langDBINF_SERVER_NAME
;
2988 s
+= pDb
->dbInf
.serverName
;
2991 s
+= langDBINF_FILENAME
;
2992 s
+= pDb
->dbInf
.databaseName
;
2995 s
+= langDBINF_OUTER_JOINS
;
2996 s
+= pDb
->dbInf
.outerJoins
;
2999 s
+= langDBINF_STORED_PROC
;
3000 s
+= pDb
->dbInf
.procedureSupport
;
3003 if (pDb
->dbInf
.maxConnections
)
3004 t
.sprintf(wxT("%s%d\n"), langDBINF_MAX_HDBC
, pDb
->dbInf
.maxConnections
);
3006 t
.sprintf(wxT("%s%s\n"), langDBINF_MAX_HDBC
, langDBINF_UNLIMITED
);
3009 if (pDb
->dbInf
.maxStmts
)
3010 t
.sprintf(wxT("%s%d\n"), langDBINF_MAX_HSTMT
, pDb
->dbInf
.maxStmts
);
3012 t
.sprintf(wxT("%s%s\n"), langDBINF_MAX_HSTMT
, langDBINF_UNLIMITED
);
3015 s
+= langDBINF_API_LVL
;
3016 switch(pDb
->dbInf
.apiConfLvl
)
3018 case SQL_OAC_NONE
: s
+= langDBINF_NONE
; break;
3019 case SQL_OAC_LEVEL1
: s
+= langDBINF_LEVEL1
; break;
3020 case SQL_OAC_LEVEL2
: s
+= langDBINF_LEVEL2
; break;
3024 s
+= langDBINF_CLI_LVL
;
3025 switch(pDb
->dbInf
.cliConfLvl
)
3027 case SQL_OSCC_NOT_COMPLIANT
: s
+= langDBINF_NOT_COMPLIANT
; break;
3028 case SQL_OSCC_COMPLIANT
: s
+= langDBINF_COMPLIANT
; break;
3032 s
+= langDBINF_SQL_LVL
;
3033 switch(pDb
->dbInf
.sqlConfLvl
)
3035 case SQL_OSC_MINIMUM
: s
+= langDBINF_MIN_GRAMMAR
; break;
3036 case SQL_OSC_CORE
: s
+= langDBINF_CORE_GRAMMAR
; break;
3037 case SQL_OSC_EXTENDED
: s
+= langDBINF_EXT_GRAMMAR
; break;
3041 s
+= langDBINF_COMMIT_BEHAVIOR
;
3042 switch(pDb
->dbInf
.cursorCommitBehavior
)
3044 case SQL_CB_DELETE
: s
+= langDBINF_DELETE_CURSORS
; break;
3045 case SQL_CB_CLOSE
: s
+= langDBINF_CLOSE_CURSORS
; break;
3046 case SQL_CB_PRESERVE
: s
+= langDBINF_PRESERVE_CURSORS
; break;
3050 s
+= langDBINF_ROLLBACK_BEHAVIOR
;
3051 switch(pDb
->dbInf
.cursorRollbackBehavior
)
3053 case SQL_CB_DELETE
: s
+= langDBINF_DELETE_CURSORS
; break;
3054 case SQL_CB_CLOSE
: s
+= langDBINF_CLOSE_CURSORS
; break;
3055 case SQL_CB_PRESERVE
: s
+= langDBINF_PRESERVE_CURSORS
; break;
3059 s
+= langDBINF_SUPP_NOT_NULL
;
3060 switch(pDb
->dbInf
.supportNotNullClause
)
3062 case SQL_NNC_NULL
: s
+= langNO
; break;
3063 case SQL_NNC_NON_NULL
: s
+= langYES
; break;
3067 s
+= langDBINF_SUPP_IEF
;
3068 s
+= pDb
->dbInf
.supportIEF
;
3071 // DEFAULT setting for "Transaction Isolation Level"
3072 s
+= langDBINF_TXN_ISOLATION
;
3073 switch(pDb
->dbInf
.txnIsolation
)
3075 case SQL_TXN_READ_UNCOMMITTED
: s
+= langDBINF_READ_UNCOMMITTED
; break;
3076 case SQL_TXN_READ_COMMITTED
: s
+= langDBINF_READ_COMMITTED
; break;
3077 case SQL_TXN_REPEATABLE_READ
: s
+= langDBINF_REPEATABLE_READ
; break;
3078 case SQL_TXN_SERIALIZABLE
: s
+= langDBINF_SERIALIZABLE
; break;
3080 case SQL_TXN_VERSIONING
: s
+= langDBINF_VERSIONING
; break;
3085 // CURRENT setting for "Transaction Isolation Level"
3087 s
+= langDBINF_TXN_ISOLATION_CURR
;
3088 if (SQLGetConnectOption(pDb
->GetHDBC(),SQL_TXN_ISOLATION
,&txnIsoLvl
) == SQL_SUCCESS
)
3092 case SQL_TXN_READ_UNCOMMITTED
: s
+= langDBINF_READ_UNCOMMITTED
; break;
3093 case SQL_TXN_READ_COMMITTED
: s
+= langDBINF_READ_COMMITTED
; break;
3094 case SQL_TXN_REPEATABLE_READ
: s
+= langDBINF_REPEATABLE_READ
; break;
3095 case SQL_TXN_SERIALIZABLE
: s
+= langDBINF_SERIALIZABLE
; break;
3097 case SQL_TXN_VERSIONING
: s
+= langDBINF_VERSIONING
; break;
3104 #pragma message disable incboodep
3107 s
+= langDBINF_TXN_ISOLATION_OPTS
;
3108 if (pDb
->dbInf
.txnIsolationOptions
& SQL_TXN_READ_UNCOMMITTED
)
3109 {s
+= langDBINF_READ_UNCOMMITTED
; comma
++;}
3110 if (pDb
->dbInf
.txnIsolationOptions
& SQL_TXN_READ_COMMITTED
)
3111 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_READ_COMMITTED
;}
3112 if (pDb
->dbInf
.txnIsolationOptions
& SQL_TXN_REPEATABLE_READ
)
3113 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_REPEATABLE_READ
;}
3114 if (pDb
->dbInf
.txnIsolationOptions
& SQL_TXN_SERIALIZABLE
)
3115 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_SERIALIZABLE
;}
3117 if (pDb
->dbInf
.txnIsolationOptions
& SQL_TXN_VERSIONING
)
3118 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_VERSIONING
;}
3123 s
+= langDBINF_FETCH_DIRS
;
3124 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_NEXT
)
3125 {s
+= langDBINF_NEXT
; comma
++;}
3126 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_PRIOR
)
3127 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_PREV
;}
3128 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_FIRST
)
3129 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_FIRST
;}
3130 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_LAST
)
3131 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_LAST
;}
3132 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_ABSOLUTE
)
3133 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_ABSOLUTE
;}
3134 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_RELATIVE
)
3135 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_RELATIVE
;}
3137 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_RESUME
)
3138 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_RESUME
;}
3140 if (pDb
->dbInf
.fetchDirections
& SQL_FD_FETCH_BOOKMARK
)
3141 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_BOOKMARK
;}
3145 s
+= langDBINF_LOCK_TYPES
;
3146 if (pDb
->dbInf
.lockTypes
& SQL_LCK_NO_CHANGE
)
3147 {s
+= langDBINF_NO_CHANGE
; comma
++;}
3148 if (pDb
->dbInf
.lockTypes
& SQL_LCK_EXCLUSIVE
)
3149 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_EXCLUSIVE
;}
3150 if (pDb
->dbInf
.lockTypes
& SQL_LCK_UNLOCK
)
3151 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_UNLOCK
;}
3155 s
+= langDBINF_POS_OPERS
;
3156 if (pDb
->dbInf
.posOperations
& SQL_POS_POSITION
)
3157 {s
+= langDBINF_POSITION
; comma
++;}
3158 if (pDb
->dbInf
.posOperations
& SQL_POS_REFRESH
)
3159 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_REFRESH
;}
3160 if (pDb
->dbInf
.posOperations
& SQL_POS_UPDATE
)
3161 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_UPD
;}
3162 if (pDb
->dbInf
.posOperations
& SQL_POS_DELETE
)
3163 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_DEL
;}
3164 if (pDb
->dbInf
.posOperations
& SQL_POS_ADD
)
3165 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_ADD
;}
3169 s
+= langDBINF_POS_STMTS
;
3170 if (pDb
->dbInf
.posStmts
& SQL_PS_POSITIONED_DELETE
)
3171 {s
+= langDBINF_POS_DEL
; comma
++;}
3172 if (pDb
->dbInf
.posStmts
& SQL_PS_POSITIONED_UPDATE
)
3173 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_POS_UPD
;}
3174 if (pDb
->dbInf
.posStmts
& SQL_PS_SELECT_FOR_UPDATE
)
3175 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_SELECT_FOR_UPD
;}
3179 s
+= langDBINF_SCROLL_CONCURR
;
3180 if (pDb
->dbInf
.scrollConcurrency
& SQL_SCCO_READ_ONLY
)
3181 {s
+= langDBINF_READ_ONLY
; comma
++;}
3182 if (pDb
->dbInf
.scrollConcurrency
& SQL_SCCO_LOCK
)
3183 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_LOCK
;}
3184 if (pDb
->dbInf
.scrollConcurrency
& SQL_SCCO_OPT_ROWVER
)
3185 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_OPT_ROWVER
;}
3186 if (pDb
->dbInf
.scrollConcurrency
& SQL_SCCO_OPT_VALUES
)
3187 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_OPT_VALUES
;}
3191 s
+= langDBINF_SCROLL_OPTS
;
3192 if (pDb
->dbInf
.scrollOptions
& SQL_SO_FORWARD_ONLY
)
3193 {s
+= langDBINF_FWD_ONLY
; comma
++;}
3194 if (pDb
->dbInf
.scrollOptions
& SQL_SO_STATIC
)
3195 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_STATIC
;}
3196 if (pDb
->dbInf
.scrollOptions
& SQL_SO_KEYSET_DRIVEN
)
3197 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_KEYSET_DRIVEN
;}
3198 if (pDb
->dbInf
.scrollOptions
& SQL_SO_DYNAMIC
)
3199 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_DYNAMIC
;}
3200 if (pDb
->dbInf
.scrollOptions
& SQL_SO_MIXED
)
3201 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_MIXED
;}
3205 s
+= langDBINF_STATIC_SENS
;
3206 if (pDb
->dbInf
.staticSensitivity
& SQL_SS_ADDITIONS
)
3207 {s
+= langDBINF_ADDITIONS
; comma
++;}
3208 if (pDb
->dbInf
.staticSensitivity
& SQL_SS_DELETIONS
)
3209 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_DELETIONS
;}
3210 if (pDb
->dbInf
.staticSensitivity
& SQL_SS_UPDATES
)
3211 {if (comma
++) s
+= wxT(", "); s
+= langDBINF_UPDATES
;}
3214 #pragma message enable incboodep
3218 s
+= langDBINF_TXN_CAPABLE
;
3219 switch(pDb
->dbInf
.txnCapable
)
3221 case SQL_TC_NONE
: s
+= langNO
; break;
3222 case SQL_TC_DML
: s
+= langDBINF_DML_ONLY
; break;
3223 case SQL_TC_DDL_COMMIT
: s
+= langDBINF_DDL_COMMIT
; break;
3224 case SQL_TC_DDL_IGNORE
: s
+= langDBINF_DDL_IGNORE
; break;
3225 case SQL_TC_ALL
: s
+= langDBINF_DDL_AND_DML
; break;
3229 t
.sprintf(wxT("%s%lu\n"), langDBINF_LOGIN_TIMEOUT
, pDb
->dbInf
.loginTimeout
);
3232 // Oracle specific information
3233 if (pDb
->Dbms() == dbmsORACLE
)
3236 s
+= langDBINF_ORACLE_BANNER
;
3239 // Oracle cache hit ratio
3242 pDb
->ExecSql(wxT("SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'db block gets'"));
3244 if (pDb
->GetData(1, SQL_C_ULONG
, &dbBlockGets
, 0, &cb
))
3246 t
.sprintf(wxT("%s: %lu\n"), langDBINF_DB_BLOCK_GETS
, dbBlockGets
);
3250 ULONG consistentGets
;
3251 pDb
->ExecSql(wxT("SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'consistent gets'"));
3253 if (pDb
->GetData(1, SQL_C_ULONG
, &consistentGets
, 0, &cb
))
3255 t
.sprintf(wxT("%s: %lu\n"), langDBINF_CONSISTENT_GETS
, consistentGets
);
3260 pDb
->ExecSql(wxT("SELECT VALUE FROM V$SYSSTAT WHERE NAME = 'physical reads'"));
3262 if (pDb
->GetData(1, SQL_C_ULONG
, &physReads
, 0, &cb
))
3264 t
.sprintf(wxT("%s: %lu\n"), langDBINF_PHYSICAL_READS
, physReads
);
3268 ULONG hitRatio
= (ULONG
)((1.00 - ((float)physReads
/ (float)(dbBlockGets
+ consistentGets
))) * 100.00);
3269 t
.sprintf(wxT("*** %s: %lu%%\n"), langDBINF_CACHE_HIT_RATIO
, hitRatio
);
3272 // Tablespace information
3274 s
+= langDBINF_TABLESPACE_IO
;
3277 char tablespaceName
[256+1];
3278 pDb
->ExecSql(wxT("SELECT NAME,PHYRDS,PHYWRTS FROM V$DATAFILE, V$FILESTAT WHERE V$DATAFILE.FILE# = V$FILESTAT.FILE#"));
3279 while (pDb
->GetNext())
3281 pDb
->GetData(1, SQL_C_WXCHAR
, tablespaceName
, 256, &cb
);
3282 pDb
->GetData(2, SQL_C_ULONG
, &physReads
, 0, &cb
);
3283 pDb
->GetData(3, SQL_C_ULONG
, &physWrites
, 0, &cb
);
3284 t
.sprintf(wxT("%s\n\t%s: %lu\t%s: %lu\n"), tablespaceName
,
3285 langDBINF_PHYSICAL_READS
, physReads
, langDBINF_PHYSICAL_WRITES
, physWrites
);
3292 s
+= wxT("End of Diagnostics\n");
3295 } // DisplayDbDiagnostics()
3299 BEGIN_EVENT_TABLE(DbGridFrame
, wxFrame
)
3300 // EVT_CLOSE(DbGridFrame::OnCloseWindow)
3304 DbGridFrame::DbGridFrame(wxWindow
*parent
)
3305 : wxFrame (parent
, wxID_ANY
, wxT("Database Table"),
3306 wxDefaultPosition
, wxSize(400, 325))
3308 initialized
= false;
3312 void DbGridFrame::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
3318 bool DbGridFrame::Initialize()
3320 wxGrid
*grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
);
3322 grid
->RegisterDataType(wxGRID_VALUE_DATETIME
,
3323 new wxGridCellDateTimeRenderer(wxT("%d %b %Y")),
3324 new wxGridCellTextEditor
);
3326 grid
->RegisterDataType(wxGRID_VALUE_CHOICEINT
,
3327 new wxGridCellEnumRenderer
,
3328 new wxGridCellEnumEditor
);
3330 wxString
NativeLangChoice( wxString::Format(wxT("%s:%s,%s,%s,%s,%s"),wxGRID_VALUE_CHOICEINT
,
3338 // Columns must match the sequence specified in SetColDef() calls
3339 wxDbGridColInfo
* cols
=
3340 new wxDbGridColInfo( 0,wxGRID_VALUE_STRING
,wxT("Name"),
3341 new wxDbGridColInfo( 1,wxGRID_VALUE_STRING
,wxT("Address 1"),
3342 new wxDbGridColInfo( 2,wxGRID_VALUE_STRING
,wxT("Address 2"),
3343 new wxDbGridColInfo( 3,wxGRID_VALUE_STRING
,wxT("City"),
3344 new wxDbGridColInfo( 4,wxGRID_VALUE_STRING
,wxT("State"),
3345 new wxDbGridColInfo( 5,wxGRID_VALUE_STRING
,wxT("PostCode"),
3346 new wxDbGridColInfo( 6,wxGRID_VALUE_STRING
,wxT("Country"),
3347 new wxDbGridColInfo( 7,wxGRID_VALUE_DBAUTO
,wxT("Join Date"),
3348 new wxDbGridColInfo( 8,wxGRID_VALUE_BOOL
, wxT("Developer"),
3349 new wxDbGridColInfo( 9,wxGRID_VALUE_NUMBER
,wxT("Contributions"),
3350 new wxDbGridColInfo(10,wxGRID_VALUE_NUMBER
,wxT("Lines Of Code"),
3352 new wxDbGridColInfo(11,NativeLangChoice
, wxT("Native Language"),NULL
))))))))))));
3354 new wxDbGridColInfo(11,wxGRID_VALUE_NUMBER
,wxT("Native Language"),NULL
))))))))))));
3357 Ccontact
*Contact
= new Ccontact();
3358 //wxGetApp().Contact
3362 wxMessageBox(wxT("Unable to instantiate an instance of Ccontact"), wxT("Error..."), wxOK
| wxICON_EXCLAMATION
);
3366 if (!Contact
->Open())
3368 if (Contact
->GetDb()->TableExists(CONTACT_TABLE_NAME
, Contact
->GetDb()->GetUsername(),
3369 wxGetApp().DbConnectInf
->GetDefaultDir()))
3372 tStr
.Printf(wxT("Unable to open the table '%s'.\n\n"),CONTACT_TABLE_NAME
.c_str());
3373 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
3374 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
3380 // Execute the following query using the cursor designated
3381 // for full table query
3382 Contact
->SetRowMode(wxDbTable::WX_ROW_MODE_QUERY
);
3384 if (!Contact
->Query())
3387 tStr
= wxT("ODBC error during Query()\n\n");
3388 wxMessageBox(wxDbLogExtendedErrorMsg(tStr
.c_str(),wxGetApp().Contact
->GetDb(),__TFILE__
,__LINE__
),
3389 wxT("ODBC Error..."),wxOK
| wxICON_EXCLAMATION
);
3393 // No data has been read in from the database yet, so
3394 // we need to initialize the data members to valid values
3395 // so Fit() can correctly size the grid
3396 Contact
->Initialize();
3398 wxDbGridTableBase
* db
= new wxDbGridTableBase(Contact
, cols
, wxUSE_QUERY
, true);
3402 grid
->SetTable(db
,true);
3403 grid
->SetMargins(0, 0);
3406 wxSize size
= grid
->GetSize();
3409 SetClientSize(size
);
3412 } // DbGridFrame::Initialize()
3414 #endif // #if wxUSE_GRID
3417 TEST CODE FOR TESTING THE wxDbCreateDataSource() FUNCTION
3420 result = wxDbCreateDataSource(wxT("Microsoft Access Driver (*.mdb)"), wxT("GLT-TEST2"), wxT("GLT-Descrip"), false, wxEmptyString, this);
3423 // check for errors caused by ConfigDSN based functions
3426 wxChar errMsg[500+1];
3427 errMsg[0] = wxT('\0');
3429 SQLInstallerError(1, &retcode, errMsg, 500, &cb);
3431 wxMessageBox(wxT("FAILED creating data source"), wxT("FAILED"));
3434 wxMessageBox(wxT("SUCCEEDED creating data source"), wxT("SUCCESS"));