File: CDrivers.cpp

package info (click to toggle)
unixodbc 2.2.11-16
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 17,332 kB
  • ctags: 12,399
  • sloc: ansic: 116,624; cpp: 29,333; sh: 25,024; makefile: 3,002; lex: 241; yacc: 182; perl: 142; sed: 16; sql: 1
file content (717 lines) | stat: -rw-r--r-- 28,938 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/**************************************************
 * CDrivers
 *
 * see CDrivers.h for doco
 *
 **************************************************
 * This code was created by Peter Harvey @ CodeByDesign.
 * Released under GPL 31.JAN.99
 *
 * Contributions from...
 * -----------------------------------------------
 * Peter Harvey		- pharvey@codebydesign.com
 **************************************************/
#include "CDrivers.h"

#include "driver.xpm"

CDrivers::CDrivers( QWidget* parent, const char* name )
: QWidget( parent, name )
{
  QVBoxLayout *playoutTop   = new QVBoxLayout( this, 5 );

  QHBoxLayout *playoutMain  = new QHBoxLayout( playoutTop );

  lvwDrivers = new QListView( this, "lvwDrivers" );
  lvwDrivers->setGeometry( 10, 10, 270, 190 );
  lvwDrivers->setMinimumSize( 50, 50 );
  lvwDrivers->setMaximumSize( 32767, 32767 );
  lvwDrivers->setFocusPolicy( QWidget::TabFocus );
  lvwDrivers->setBackgroundMode( QWidget::PaletteBackground );
  lvwDrivers->setFrameStyle( QFrame::Box | QFrame::Raised );
  lvwDrivers->setResizePolicy( QScrollView::Manual );
  lvwDrivers->setVScrollBarMode( QScrollView::Auto );
  lvwDrivers->setHScrollBarMode( QScrollView::Auto );
  lvwDrivers->setTreeStepSize( 20 );
  lvwDrivers->setMultiSelection( FALSE );
  lvwDrivers->setAllColumnsShowFocus( FALSE );
  lvwDrivers->setItemMargin( 1 );
  lvwDrivers->setRootIsDecorated( FALSE );
  lvwDrivers->addColumn( "Name", -1 );
  lvwDrivers->setColumnWidthMode( 0, QListView::Maximum );
  lvwDrivers->setColumnAlignment( 0, 1 );
  lvwDrivers->addColumn( "Description", -1 );
  lvwDrivers->setColumnWidthMode( 1, QListView::Maximum );
  lvwDrivers->setColumnAlignment( 1, 1 );
  lvwDrivers->addColumn( "Driver Lib", -1 );
  lvwDrivers->setColumnWidthMode( 2, QListView::Maximum );
  lvwDrivers->setColumnAlignment( 2, 1 );
  lvwDrivers->addColumn( "Setup Lib", -1 );
  lvwDrivers->setColumnWidthMode( 3, QListView::Maximum );
  lvwDrivers->setColumnAlignment( 3, 1 );

  playoutMain->addWidget( lvwDrivers, 10 );

  QVBoxLayout *playoutButtons = new QVBoxLayout( playoutMain, 5 );

  pbAdd = new QPushButton( this, "pbAdd" );
  pbAdd->setGeometry( 290, 10, 100, 30 );
  pbAdd->setMinimumSize( 0, 0 );
  pbAdd->setMaximumSize( 32767, 32767 );
  pbAdd->setFocusPolicy( QWidget::TabFocus );
  pbAdd->setBackgroundMode( QWidget::PaletteBackground );
  pbAdd->setText( "A&dd..." );
  pbAdd->setAutoRepeat( FALSE );
  pbAdd->setAutoResize( FALSE );

  playoutButtons->addWidget( pbAdd );

  pbRemove = new QPushButton( this, "pbRemove" );
  pbRemove->setGeometry( 290, 50, 100, 30 );
  pbRemove->setMinimumSize( 0, 0 );
  pbRemove->setMaximumSize( 32767, 32767 );
  pbRemove->setFocusPolicy( QWidget::TabFocus );
  pbRemove->setBackgroundMode( QWidget::PaletteBackground );
  pbRemove->setText( "&Remove" );
  pbRemove->setAutoRepeat( FALSE );
  pbRemove->setAutoResize( FALSE );

  playoutButtons->addWidget( pbRemove );

  pbConfigure = new QPushButton( this, "pbConfigure" );
  pbConfigure->setGeometry( 290, 90, 100, 30 );
  pbConfigure->setMinimumSize( 0, 0 );
  pbConfigure->setMaximumSize( 32767, 32767 );
  pbConfigure->setFocusPolicy( QWidget::TabFocus );
  pbConfigure->setBackgroundMode( QWidget::PaletteBackground );
  pbConfigure->setText( "&Configure..." );
  pbConfigure->setAutoRepeat( FALSE );
  pbConfigure->setAutoResize( FALSE );

  playoutButtons->addWidget( pbConfigure );

  playoutButtons->addStretch( 10 );

  QFrame *pframe;
  pframe = new QFrame( this, "Frame_2" );
  pframe->setGeometry( 10, 204, 380, 90 );
  pframe->setMinimumSize( 0, 0 );
  pframe->setMaximumSize( 32767, 32767 );
  pframe->setFocusPolicy( QWidget::NoFocus );
  pframe->setBackgroundMode( QWidget::PaletteBackground );
  pframe->setFrameStyle( QFrame::Box | QFrame::Raised );

  playoutTop->addWidget( pframe );
  QGridLayout *playoutHelp = new QGridLayout( pframe, 1, 2, 5 );

  QLabel* plabel1;
  plabel1 = new QLabel( pframe, "Label_1" );
  plabel1->setMinimumSize( 32, 32 );
//	plabel1->setMaximumSize( 32, 32 );
  plabel1->setPixmap( xpmDriver );

  QLabel* plabel2;
  plabel2 = new QLabel( pframe, "Label_2" );
  plabel2->setMinimumSize( 0, 0 );
  plabel2->setMaximumSize( 32767, 32767 );
  plabel2->setText( "These drivers facilitate communication between the Driver Manager and the data server. Many ODBC drivers can be downloaded from the Internet while others are obtained from your database vendor. Typically; you must be a root/adminstrator user to add drivers." );
  plabel2->setAlignment( AlignLeft | WordBreak );

  playoutHelp->addWidget( plabel1, 0, 0 );
  playoutHelp->addWidget( plabel2, 0, 1 );
  playoutHelp->setColStretch( 1, 10 );

  lvwDrivers->setAllColumnsShowFocus( true );

  connect( pbAdd, SIGNAL(clicked()), this, SLOT(Add()) );
  connect( pbRemove, SIGNAL(clicked()), this, SLOT(Delete()) );
  connect( pbConfigure, SIGNAL(clicked()), this, SLOT(Edit()) );

  Load();
}


CDrivers::~CDrivers()
{
  if ( hIni != NULL )
    iniClose( hIni );

}


void CDrivers::Add()
{
  QString       qsError         = "";

  CPropertiesFrame    *pProperties;
  HODBCINSTPROPERTY hFirstProperty  = NULL;
  HODBCINSTPROPERTY hCurProperty  = NULL;
  HODBCINSTPROPERTY hLastProperty;
  char        szINI[FILENAME_MAX+1];

  sprintf( szINI, "%s/odbcinst.ini", odbcinst_system_file_path() );

  // SET UP PROPERTIES LIST
  hFirstProperty            = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  memset( hFirstProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hFirstProperty->nPromptType     = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hFirstProperty->pNext       = NULL;
  hFirstProperty->bRefresh      = 0;
  hFirstProperty->hDLL        = NULL;
  hFirstProperty->pWidget       = NULL;
  hFirstProperty->pszHelp       = strdup( ODBC_HELP_DRIVER_NAME );
  hFirstProperty->aPromptData     = NULL;
  strncpy( hFirstProperty->szName, "Name", INI_MAX_PROPERTY_NAME );
  strcpy( hFirstProperty->szValue, "" );
  hLastProperty = hFirstProperty;

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_DESC );
  hLastProperty->aPromptData        = NULL;
  strncpy( hLastProperty->szName, "Description", INI_MAX_PROPERTY_NAME );
  strcpy( hLastProperty->szValue, "" );

  /*
   * Don't have a deflib for 64 bit, the user may not want a driver entry, just a driver64
   */

#ifdef PLATFORM64
#undef DEFLIB_PATH
#endif

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_DRIVER );
  strncpy( hLastProperty->szName, "Driver", INI_MAX_PROPERTY_NAME );
#ifdef DEFLIB_PATH
  strncpy( hLastProperty->szValue, DEFLIB_PATH, INI_MAX_PROPERTY_VALUE );
#else
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
#endif

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_DRIVER64 );
  strncpy( hLastProperty->szName, "Driver64", INI_MAX_PROPERTY_NAME );
#ifdef DEFLIB_PATH
  strncpy( hLastProperty->szValue, DEFLIB_PATH, INI_MAX_PROPERTY_VALUE );
#else
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
#endif

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_SETUP );
  strncpy( hLastProperty->szName, "Setup", INI_MAX_PROPERTY_NAME );
#ifdef DEFLIB_PATH
  strncpy( hLastProperty->szValue, DEFLIB_PATH, INI_MAX_PROPERTY_VALUE );
#else
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
#endif

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_SETUP64 );
  strncpy( hLastProperty->szName, "Setup64", INI_MAX_PROPERTY_NAME );
#ifdef DEFLIB_PATH
  strncpy( hLastProperty->szValue, DEFLIB_PATH, INI_MAX_PROPERTY_VALUE );
#else
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
#endif

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_USAGECOUNT );
  hLastProperty->aPromptData        = NULL;
  strncpy( hLastProperty->szName, "UsageCount", INI_MAX_PROPERTY_NAME );
  strcpy( hLastProperty->szValue, "1" );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_CPTIMEOUT );
  hLastProperty->aPromptData        = NULL;
  strncpy( hLastProperty->szName, "CPTimeout", INI_MAX_PROPERTY_NAME );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_CPREUSE );
  hLastProperty->aPromptData        = NULL;
  strncpy( hLastProperty->szName, "CPReuse", INI_MAX_PROPERTY_NAME );


  // ALLOW USER TO EDIT
  pProperties = new CPropertiesFrame( this, "Properties", hFirstProperty );
  pProperties->setCaption( "Driver Properties (new)" );
  if ( pProperties->exec() )
  {
    /* DELETE ENTIRE SECTION IF IT EXISTS (no entry given) */
    if ( SQLWritePrivateProfileString( hFirstProperty->szValue, NULL, NULL, szINI ) == FALSE )
    {
      delete pProperties;
      FreeProperties( &hFirstProperty );
      qsError.sprintf( "Could not write to (%s)", szINI );
      QMessageBox::information( this, "ODBC Config",  qsError );
      return;
    }

    /* ADD ENTRIES; SECTION CREATED ON FIRST CALL */
    for ( hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext )
    {
      SQLWritePrivateProfileString( hFirstProperty->szValue, hCurProperty->szName, hCurProperty->szValue, szINI );
    }
  }
  delete pProperties;
  FreeProperties( &hFirstProperty );

  // RELOAD (slow but safe)
  Load();
}

void CDrivers::Edit()
{
  QString       qsName          = "";
  QString       qsError         = "";

  CPropertiesFrame    *pProperties;
  HODBCINSTPROPERTY hFirstProperty  = NULL;
  HODBCINSTPROPERTY hCurProperty  = NULL;
  HODBCINSTPROPERTY hLastProperty;
  char        szINI[FILENAME_MAX+1];
  QListViewItem   *pListViewItem;

  sprintf( szINI, "%s/odbcinst.ini", odbcinst_system_file_path() );

  // HAS THE USER SELECTED SOMETHING
  pListViewItem = lvwDrivers->currentItem();
  if ( pListViewItem )
    qsName    = pListViewItem->text( 0 );
  else
  {
    QMessageBox::information( this, "ODBC Config",  "Please select a Driver from the list first." );
    return;
  }


  // SET UP PROPERTIES LIST STARTING WITH MANDATORY PROPERTIES
  hFirstProperty            = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  memset( hFirstProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hFirstProperty->nPromptType     = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hFirstProperty->pNext       = NULL;
  hFirstProperty->bRefresh      = 0;
  hFirstProperty->hDLL        = NULL;
  hFirstProperty->pWidget       = NULL;
  hFirstProperty->pszHelp       = strdup( ODBC_HELP_DRIVER_NAME );
  hFirstProperty->aPromptData     = NULL;
  strncpy( hFirstProperty->szName, "Name", INI_MAX_PROPERTY_NAME );
  strcpy( hFirstProperty->szValue, qsName.data() );
  hLastProperty = hFirstProperty;

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_DESC );
  hLastProperty->aPromptData        = NULL;
  strncpy( hLastProperty->szName, "Description", INI_MAX_PROPERTY_NAME );
  strcpy( hLastProperty->szValue, "" );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_DRIVER );
  strncpy( hLastProperty->szName, "Driver", INI_MAX_PROPERTY_NAME );
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_DRIVER64 );
  strncpy( hLastProperty->szName, "Driver64", INI_MAX_PROPERTY_NAME );
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_SETUP );
  strncpy( hLastProperty->szName, "Setup", INI_MAX_PROPERTY_NAME );
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_FILENAME;
  hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_SETUP64 );
  strncpy( hLastProperty->szName, "Setup64", INI_MAX_PROPERTY_NAME );
  strncpy( hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->aPromptData        = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_USAGECOUNT );
  strncpy( hLastProperty->szName, "UsageCount", INI_MAX_PROPERTY_NAME );
  strcpy( hLastProperty->szValue, "1" );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_CPTIMEOUT );
  hLastProperty->aPromptData        = NULL;
  strncpy( hLastProperty->szName, "CPTimeout", INI_MAX_PROPERTY_NAME );
  strcpy( hLastProperty->szValue, "0" );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
  hLastProperty             = hLastProperty->pNext;
  memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
  hLastProperty->nPromptType        = ODBCINST_PROMPTTYPE_TEXTEDIT;
  hLastProperty->pNext          = NULL;
  hLastProperty->bRefresh         = 0;
  hLastProperty->hDLL           = NULL;
  hLastProperty->pWidget          = NULL;
  hLastProperty->pszHelp          = strdup( ODBC_HELP_DRIVER_CPREUSE );
  hLastProperty->aPromptData        = NULL;
  strncpy( hLastProperty->szName, "CPReuse", INI_MAX_PROPERTY_NAME );
  strcpy( hLastProperty->szValue, "0" );
  SQLGetPrivateProfileString((char*) qsName.data(), hLastProperty->szName, "", hLastProperty->szValue, sizeof(hLastProperty->szValue)-1, szINI );

  // ACCEPT ANY DRIVER SPECIFIC PROPERTIES THAT HAVE BEEN TYPED IN MANUALLY OR INSTALLED 
  // NOTE: This is a quick enhancement. Much room to optimize this func.
  {
    char  szDriverName[INI_MAX_OBJECT_NAME+1];
    char  szPropertyName[INI_MAX_PROPERTY_NAME+1];
    char  szPropertyNameUpper[INI_MAX_PROPERTY_NAME+1];
    char  szPropertyValue[INI_MAX_PROPERTY_VALUE+1];

    strcpy( szDriverName, qsName.data() );
    if ( iniOpen( &hIni, szINI, "#;", '[', ']', '=', TRUE ) != INI_ERROR )
    {
      if ( iniObjectSeek( hIni, szDriverName ) == INI_SUCCESS )
      {
        while ( iniPropertyEOL( hIni ) == FALSE )
        {
          iniProperty( hIni, szPropertyName );
          iniProperty( hIni, szPropertyNameUpper );
          iniToUpper( szPropertyNameUpper );

          if ( strncmp( szPropertyNameUpper, "NAME", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "DESCRIPTION", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "DRIVER", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "DRIVER64", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "SETUP", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "SETUP64", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "CPTIMEOUT", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "CPREUSE", INI_MAX_PROPERTY_NAME ) != 0 &&
//                         strncmp( szPropertyNameUpper, "DONTDLCLOSE", INI_MAX_PROPERTY_NAME ) != 0 &&
               strncmp( szPropertyNameUpper, "USAGECOUNT", INI_MAX_PROPERTY_NAME ) != 0  )
          {
            iniValue( hIni, szPropertyValue );

            hLastProperty->pNext        = (HODBCINSTPROPERTY)malloc( sizeof(ODBCINSTPROPERTY) );
            hLastProperty             = hLastProperty->pNext;
            memset( hLastProperty, 0, sizeof(ODBCINSTPROPERTY) );
            hLastProperty->nPromptType      = ODBCINST_PROMPTTYPE_TEXTEDIT;
            hLastProperty->pNext        = NULL;
            hLastProperty->bRefresh       = 0;
            hLastProperty->hDLL         = NULL;
            hLastProperty->pWidget        = NULL;
            hLastProperty->pszHelp        = strdup( ODBC_HELP_DRIVER_UNKNOWN );
            hLastProperty->aPromptData      = NULL;
            strncpy( hLastProperty->szName, szPropertyName, INI_MAX_PROPERTY_NAME );
            strncpy( hLastProperty->szValue, szPropertyValue, sizeof(hLastProperty->szValue)-1 );
          }
          iniPropertyNext( hIni );
        }
      }
    }
  }

  // ALLOW USER TO EDIT
  pProperties = new CPropertiesFrame( this, "Properties", hFirstProperty );
  pProperties->setCaption( "Driver Properties (edit)" );
  if ( pProperties->exec() )
  {
    /* DELETE ENTIRE SECTION IF IT EXISTS (no entry given) */
    if ( SQLWritePrivateProfileString((char*) qsName.ascii(), NULL, NULL, szINI ) == FALSE )
    {
      delete pProperties;
      FreeProperties( &hFirstProperty );
      qsError.sprintf( "Could not write to (%s)", szINI );
      QMessageBox::information( this, "ODBC Config",  qsError );
      return;
    }

    /* ADD ENTRIES; SECTION CREATED ON FIRST CALL */
    for ( hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext )
    {
      SQLWritePrivateProfileString( hFirstProperty->szValue, hCurProperty->szName, hCurProperty->szValue, szINI );
    }
  }
  delete pProperties;
  FreeProperties( &hFirstProperty );

  // RELOAD (slow but safe)
  Load();
}

void CDrivers::Delete()
{
  QListViewItem   *pListViewItem;
  char        szINI[FILENAME_MAX+1];
  char        *pszName;
  QString       qsError;
  DWORD       nErrorCode;
  char        szErrorMsg[FILENAME_MAX+1];

  sprintf( szINI, "%s/odbcinst.ini", odbcinst_system_file_path() );

  // GET SELECT DATA SOURCE NAME
  pListViewItem = lvwDrivers->currentItem();
  if ( pListViewItem )
  {
    pszName = (char *)pListViewItem->text( 0 ).ascii();
  }
  else
  {
    QMessageBox::information( this, "ODBC Config",  "Please select a Driver from the list first" );
    return;
  }

  // DELETE ENTIRE SECTION IF IT EXISTS (given NULL entry)
  if ( SQLWritePrivateProfileString( pszName, NULL, NULL, szINI ) == FALSE )
  {
    qsError.sprintf( "Could not write property list for (%s)", pszName );
    QMessageBox::information( this, "ODBC Config",  qsError );
    while ( SQLInstallerError( 1, &nErrorCode, szErrorMsg, FILENAME_MAX, NULL ) == SQL_SUCCESS )
      QMessageBox::information( this, "ODBC Config",  szErrorMsg );
  }

  // RELOAD (slow but safe)
  Load();
}



void CDrivers::Load()
{
  lvwDrivers->clear();

  /***************************************
   * METHOD 1 - Using Driver Manager
   ***************************************/


  /***************************************
   * METHOD 2 - Using ODBCINST lib (also see SQLGetInstalledDrivers)
   ***************************************/
  /*
  QListViewItem	*pListViewItem;
  QString			qsError;
  DWORD			nErrorCode;
  char   			szErrorMsg[101];

  char			szINI[FILENAME_MAX+1];
  char			szSectionNames[4096];
  char			szSectionName[INI_MAX_OBJECT_NAME+1];
  int				nElement;
  
  char 			szDriverName[INI_MAX_OBJECT_NAME+1];
  char 			szDescription[INI_MAX_PROPERTY_VALUE+1];
  char 			szDriver[INI_MAX_PROPERTY_VALUE+1];
  char 			szSetup[INI_MAX_PROPERTY_VALUE+1];

    sprintf( szINI, "%s/odbcinst.ini", odbcinst_system_file_path() );

  memset( szSectionNames, 0, sizeof(szSectionNames) );
  if ( SQLGetPrivateProfileString( NULL, NULL, NULL, szSectionNames, 4090, szINI ) >= 0 )
  {
    for ( nElement = 0; iniElement( szSectionNames, '\0', '\0', nElement, szSectionName, INI_MAX_OBJECT_NAME ) == INI_SUCCESS ; nElement++ )
    {
      szDriverName[0]		= '\0';
      szDescription[0]	= '\0';
      szDriver[0]			= '\0';
      szSetup[0]			= '\0';
      SQLGetPrivateProfileString( szSectionName, "Driver", "", szDriverName, INI_MAX_PROPERTY_VALUE, szINI );
      SQLGetPrivateProfileString( szSectionName, "Description", "", szDescription, INI_MAX_PROPERTY_VALUE, szINI );
      SQLGetPrivateProfileString( szSectionName, "Driver", "", szDriver, INI_MAX_PROPERTY_VALUE, szINI );
      SQLGetPrivateProfileString( szSectionName, "Setup", "", szSetup, INI_MAX_PROPERTY_VALUE, szINI );
      pListViewItem = new QListViewItem( lvwDrivers, szDriverName, szDescription, szDriver, szSetup );
    }
  }
  else
  {
    qsError.sprintf( "Could not load %s", szINI );
    QMessageBox::information(	this, "ODBC Config",  qsError );
    while ( SQLInstallerError( 1, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS )
      QMessageBox::information( this, "ODBC Config",  szErrorMsg );
  }
  */

  /***************************************
   * METHOD 3 - Using INI lib
   ***************************************/
  char      szDriverName[INI_MAX_OBJECT_NAME+1];
  char      szPropertyName[INI_MAX_PROPERTY_NAME+1];
  char      szDescription[INI_MAX_PROPERTY_VALUE+1];
  char      szDriver[INI_MAX_PROPERTY_VALUE+1];
  char      szDriver64[INI_MAX_PROPERTY_VALUE+1];
  char      szSetup[INI_MAX_PROPERTY_VALUE+1];
  char      szSetup64[INI_MAX_PROPERTY_VALUE+1];
  QListViewItem *pListViewItem;
  QString     qsError;

  sprintf( szINI, "%s/odbcinst.ini", odbcinst_system_file_path());

  if ( iniOpen( &hIni, szINI, "#;", '[', ']', '=', TRUE ) != INI_ERROR )
  {
    iniObjectFirst( hIni );
    while ( iniObjectEOL( hIni ) == FALSE )
    {
      szDriverName[0] = '\0';
      szDescription[0]  = '\0';
      szDriver[0]   = '\0';
      szDriver64[0]   = '\0';
      szSetup64[0]   = '\0';
      szSetup[0]    = '\0';
      iniObject( hIni, szDriverName );
      iniPropertyFirst( hIni );
      if ( strcmp( szDriverName, "ODBC" ) == 0 )
      {
        iniObjectNext( hIni );
        continue;
      }

      while ( iniPropertyEOL( hIni ) == FALSE )
      {
        iniProperty( hIni, szPropertyName );
        iniToUpper( szPropertyName );

        if ( strncmp( szPropertyName, "DESCRIPTION", INI_MAX_PROPERTY_NAME ) == 0 )
          iniValue( hIni, szDescription );
#ifdef PLATFORM64
	if ( strncmp( szPropertyName, "DRIVER64", INI_MAX_PROPERTY_NAME ) == 0 )
          		iniValue( hIni, szDriver64 );
	if ( strncmp( szPropertyName, "DRIVER", INI_MAX_PROPERTY_NAME ) == 0 )
          		iniValue( hIni, szDriver );

        if ( strncmp( szPropertyName, "SETUP64", INI_MAX_PROPERTY_NAME ) == 0 )
          iniValue( hIni, szSetup64 );
        if ( strncmp( szPropertyName, "SETUP", INI_MAX_PROPERTY_NAME ) == 0 )
          iniValue( hIni, szSetup );
#else
        if ( strncmp( szPropertyName, "DRIVER", INI_MAX_PROPERTY_NAME ) == 0 )
          iniValue( hIni, szDriver );

        if ( strncmp( szPropertyName, "SETUP", INI_MAX_PROPERTY_NAME ) == 0 )
          iniValue( hIni, szSetup );
#endif

        iniPropertyNext( hIni );
      }

#ifdef PLATFORM64
      if ( szDriver64[ 0 ] != '\0' )
      {
	      strcpy( szDriver, szDriver64 );
      }
      if ( szSetup64[ 0 ] != '\0' )
      {
	      strcpy( szSetup, szSetup64 );
      }
#endif

      pListViewItem = new QListViewItem( lvwDrivers, szDriverName, szDescription, szDriver, szSetup );
      iniObjectNext( hIni );
    }
  }
  else
  {
    qsError.sprintf( "Could not open system file at %s", szINI );
    QMessageBox::information( this, "ODBC Config",  qsError );
  }

}

void CDrivers::FreeProperties( HODBCINSTPROPERTY *hFirstProperty )
{
  HODBCINSTPROPERTY hNextProperty;
  HODBCINSTPROPERTY hCurProperty;

  /* SANITY CHECKS */
  if ( (*hFirstProperty) == NULL )
    return;

  /* FREE MEMORY */
  for ( hCurProperty = (*hFirstProperty); hCurProperty != NULL; hCurProperty = hNextProperty )
  {
    hNextProperty = hCurProperty->pNext;

    /* FREE ANY PROMPT DATA (ie pick list options and such) */
    if ( hCurProperty->aPromptData != NULL )
      free( hCurProperty->aPromptData );

    /* FREE OTHER STUFF */
    if ( hCurProperty->pszHelp != NULL )
      free( hCurProperty->pszHelp );

    free( hCurProperty );
  }
  (*hFirstProperty) = NULL;
}