summaryrefslogtreecommitdiff
path: root/VC++Files/mysqlmanager/TOOLSQL.CPP
blob: 1773a3a6dc78037eb3456a14d538eb1aef491794 (plain)
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
// ToolSql.cpp : implementation file
//

#include "stdafx.h"
#include "MySqlManager.h"
#include "ToolSql.h"

#define WINDOW_COORDS 0
#define CLIENT_COORDS 1

#define MY_TIMER_ID	0x1234

#ifdef _DEBUG
   #define new DEBUG_NEW
   #undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////

CToolSql::CToolSql(CWnd* pParent,CResource* pServer,CResource* pResource)
: CDialog(CToolSql::IDD, pParent)
, m_pQuery(0)
, m_pResults(0)
, m_pStatus(0)
, m_pServer(pServer)
, m_pResource(pResource)
, m_ui_timer(0)
{
   //{{AFX_DATA_INIT(CToolSql)
	m_nIntervalTimerSeconds = 10;
	m_bClear = FALSE;
	//}}AFX_DATA_INIT
   memset ( & m_lf, 0,sizeof(m_lf) );
}

/////////////////////////////////////////////////////////////////////////////

CToolSql::~CToolSql()
{

	if (m_ui_timer)
	{
		KillTimer(MY_TIMER_ID);
	}

	if (m_pdb)
   {
      mysql_close(m_pdb);
   }
   if (m_pQuery)
   {
      m_pQuery->DestroyWindow();
      delete m_pQuery;
   }
   if (m_pResults)
   {
      m_pResults->DestroyWindow();
      delete m_pResults;
   }
   if (m_pStatus)
   {
      m_pStatus->DestroyWindow();
      delete m_pStatus;
   }
}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::DoDataExchange(CDataExchange* pDX)
{
   CDialog::DoDataExchange(pDX);
   //{{AFX_DATA_MAP(CToolSql)
	DDX_Control(pDX, IDC_STOP_PB, m_ctl_Stop);
	DDX_Control(pDX, IDC_START_PB, m_ctl_Start);
	DDX_Control(pDX, IDC_SERVER_CB, m_ctl_Server);
   DDX_Control(pDX, IDC_TAB1, m_tabs);
	DDX_Text(pDX, IDC_TIMER_SECS, m_nIntervalTimerSeconds);
	DDV_MinMaxInt(pDX, m_nIntervalTimerSeconds, 1, 120);
	DDX_Check(pDX, IDC_CLEAR, m_bClear);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CToolSql, CDialog)
//{{AFX_MSG_MAP(CToolSql)
	ON_BN_CLICKED(IDC_QUERY_PB, OnQueryPb)
	ON_BN_CLICKED(IDC_DATABASES_PB, OnQueryDatabases)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
	ON_BN_CLICKED(IDC_FONT_PB, OnFontPb)
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_START_PB, OnStartPb)
	ON_BN_CLICKED(IDC_STOP_PB, OnStopPb)
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	ON_COMMAND(IDM_QUERY_EXEC, OnQueryPb)
	ON_COMMAND(IDM_QUERY_DATABASES, OnQueryDatabases)
	ON_EN_CHANGE(IDC_TIMER_SECS, OnChangeTimerSecs)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

BOOL CToolSql::OnInitDialog()
{

   CDialog::OnInitDialog();

	m_ctl_Start . EnableWindow(TRUE);
	m_ctl_Stop  . EnableWindow(FALSE);

   CString strTitle;

   strTitle.Format ("mySql Query to %s on %s",m_pServer->GetDisplayName(),m_pServer->GetHostName());

	m_ctl_Server.AddString ( m_pServer->GetDisplayName() );
	m_ctl_Server.SetCurSel (0);

   SetWindowText(strTitle);

   CWaitCursor x;

   m_btn_QueryExec.AutoLoad ( IDC_QUERY_PB, this );
   m_btn_QueryDatabases.AutoLoad ( IDC_DATABASES_PB, this );
   m_btn_Font.AutoLoad ( IDC_FONT_PB, this );

   m_tabs.GetWindowRect ( m_rectTab[WINDOW_COORDS] );
   GetWindowRect        ( m_rectDlg[WINDOW_COORDS] );

   m_tabs.GetClientRect ( m_rectTab[CLIENT_COORDS] );
   GetClientRect        ( m_rectDlg[CLIENT_COORDS] );

   CMenu* pSysMenu = GetSystemMenu(FALSE);
   if (pSysMenu != NULL)
   {
      CString strText;
      strText.LoadString(IDS_QUERY_EXEC);
      if (!strText.IsEmpty())
      {
         pSysMenu->AppendMenu(MF_SEPARATOR);
         pSysMenu->AppendMenu(MF_STRING, IDM_QUERY_EXEC, strText);
      }
      strText.LoadString(IDS_QUERY_DATABASES);
      if (!strText.IsEmpty())
      {
         pSysMenu->AppendMenu(MF_STRING, IDM_QUERY_DATABASES, strText);
      }
   }


   m_pdb = new MYSQL;

   CString strQuery   ( "Query" );
   CString strResults ( "Results" );
   CString strStatus  ( "Status" );

   TC_ITEM tc1 = { TCIF_TEXT, 0,0, (LPSTR)(LPCTSTR)strQuery,   strQuery.GetLength(), 0,0};
   TC_ITEM tc2 = { TCIF_TEXT, 0,0, (LPSTR)(LPCTSTR)strResults, strResults.GetLength(), 0,0};
   TC_ITEM tc3 = { TCIF_TEXT, 0,0, (LPSTR)(LPCTSTR)strStatus,  strStatus.GetLength(), 0,0};

   m_tabs.InsertItem ( 0,&tc1 );
   m_tabs.InsertItem ( 1,&tc2 );
   m_tabs.InsertItem ( 2,&tc3 );

   m_pQuery   = new CToolSqlQuery ( NULL );
   m_pResults = new CToolSqlResults ( NULL );
   m_pStatus  = new CToolSqlStatus ( NULL );

   try
   {

//   OpenDatabase();
//
//   m_pSelection->SetDatabase ( & m_db );
//   m_pScript->SetDatabase ( & m_db );
//   m_pLog->SetDatabase ( & m_db );

      m_pQuery   -> Create ( (LPCTSTR)IDD_TOOL_SQL_QUERY,   &m_tabs );
      m_pResults -> Create ( (LPCTSTR)IDD_TOOL_SQL_RESULTS, &m_tabs );
      m_pStatus  -> Create ( (LPCTSTR)IDD_TOOL_SQL_STATUS,  &m_tabs );

      ActivateTab ( 0 );

      m_pQuery   -> SetWindowPos(NULL,20,24,0,0,SWP_NOZORDER|SWP_NOSIZE);
      m_pResults -> SetWindowPos(NULL,20,24,0,0,SWP_NOZORDER|SWP_NOSIZE);
      m_pStatus  -> SetWindowPos(NULL,20,24,0,0,SWP_NOZORDER|SWP_NOSIZE);

      DoOnSize( SIZE_RESTORED, m_rectDlg[CLIENT_COORDS].Width(), m_rectDlg[CLIENT_COORDS].Height() );

   }
   catch (...)
   {
   }

   mysql_init(m_pdb);
   if (!mysql_real_connect(m_pdb,m_pServer->GetHostName(), m_pServer->GetUserName(),m_pServer->GetPassword(),0,m_pServer->GetPortNumber(), NullS,0))
   {
//     my_printf_error(0,"connect to server at '%s' failed; error: '%s'",
//     MYF(ME_BELL), pResource->GetHostName(), mysql_error(&mysql));
      CString strText;
      strText.Format ( "connect to server at '%s' failed; error: '%s'", m_pServer->GetHostName(), mysql_error(m_pdb));
      AfxMessageBox(strText);
      EndDialog(IDCANCEL);
      return FALSE;
   }

   if ( m_pResource && m_pResource->GetType() == CResource::eDatabase )
   {
      CString strDB = m_pResource->GetDisplayName();
      strDB.TrimRight();
      if (mysql_select_db(m_pdb,strDB))
      {
      }
   }

   return FALSE;  // return TRUE unless you set the focus to a control
   // EXCEPTION: OCX Property Pages should return FALSE
}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::ActivateTab ( int tab )

{
   switch (tab)
   {
      case 0:   ;
         m_pResults-> ShowWindow(SW_HIDE);
         m_pStatus-> ShowWindow(SW_HIDE);
         m_pQuery-> ShowWindow(SW_SHOW);
         m_pQuery->m_ctl_edit.SetFocus();
         break;
      case 1:   ;
         m_pQuery-> ShowWindow(SW_HIDE);
         m_pStatus-> ShowWindow(SW_HIDE);
         m_pResults-> ShowWindow(SW_SHOW);
         m_pResults->m_ctl_edit.SetFocus();
         break;
      case 2:   ;
         m_pResults-> ShowWindow(SW_HIDE);
         m_pQuery-> ShowWindow(SW_HIDE);
         m_pStatus-> ShowWindow(SW_SHOW);
         m_pStatus->m_ctl_edit.SetFocus();
         break;
      default:
         break;
   }

}

/////////////////////////////////////////////////////////////////////////////

void CalculateFontSize ( CEdit& ed, CSize& sizeRet )

{

   CDC* pdc = ed.GetDC();

   int nAveWidth , nAveHeight;
   int i ;

   CSize size ;

   static BOOL bFirstTime = TRUE;
   static char rgchAlphabet [54] ;

   if ( bFirstTime )
   {
      bFirstTime = false;
      for ( i = 0 ; i <= 25 ; i++)
      {
         rgchAlphabet[i]    = (char)(i+(int)'a') ;
         rgchAlphabet[i+26] = (char)(i+(int)'A') ;
      }
      rgchAlphabet[52] = 0x20;
      rgchAlphabet[53] = 0x20;
   }

   CFont* pf = ed.GetFont();
   LOGFONT lf;
   pf->GetLogFont(&lf);
   pdc->SelectObject (pf);
   GetTextExtentPoint32 ( pdc->m_hDC, (LPSTR) rgchAlphabet, 54, & size ) ;

   nAveWidth = size.cx / 54 ;

   if ( size.cx % 54 )
   {
      nAveWidth++;
   }

   nAveHeight = size.cy; //6 * size.cy / 4;

   sizeRet.cx = nAveWidth;
   sizeRet.cy = nAveHeight; // tm.tmHeight;

   ed.ReleaseDC(pdc);

}

///////////////////////////////////////////////////////////////////////////////
int ProcessYieldMessage ()
{

   CWinApp* pApp = AfxGetApp();

   if ( pApp )
   {
      MSG msgx;
      while (::PeekMessage(&msgx, NULL, NULL, NULL, PM_NOREMOVE))
         try
         {
            if (!pApp->PumpMessage())
            {
//       ExitProcess(1);
            }
         }
         catch (...)
         {
         }
   }

   return 0;

}


/////////////////////////////////////////////////////////////////////////////

void print_table_data(MYSQL_RES *result,CString& str,CEdit& ed,LOGFONT& lf)
{
   MYSQL_ROW    cur;
   uint         length;
   MYSQL_FIELD* field;
   bool*        num_flag;
   my_ulonglong nRows  =  mysql_num_rows(result);
   uint         nFields = mysql_num_fields(result);
   int*         rgi = new int [nFields];
   memset ( rgi, 0,   nFields*sizeof(int) );
   num_flag=(bool*) my_alloca(sizeof(bool)*nFields);

   ed.SetLimitText(65535*16);

   CSize sizeFont;
   CalculateFontSize ( ed, sizeFont );
   uint index = 0;
   rgi[index++]=0;
   CString separator("");

   mysql_field_seek(result,0);

   for (uint off=0; (field = mysql_fetch_field(result)) ; off++)
   {
      uint length= (uint) strlen(field->name);
      length=max(length,field->max_length);
      if (length < 4 && !IS_NOT_NULL(field->flags))
         length=4;               // Room for "NULL"
      field->max_length=length+1;
      int n=length+2;
      for (uint i=lstrlen(field->name); i-- > 0 ; ) separator+="-";
      if ( index!= nFields )
      {
         int o = rgi[index-1];
         rgi[index++]=o+((n+1)*sizeFont.cx)/2;
      }
      separator+='\t';
      str += field->name;
      str += "\t";
      num_flag[off]= IS_NUM(field->type);
   }
   separator += "\r\n";
   str += "\r\n";
   str += separator;
   ed.SetSel(-1,-1);
   ed.ReplaceSel(str);

   if ( 1 || nRows > 100 )
   {
      while ((cur = mysql_fetch_row(result)))
      {
         ProcessYieldMessage ();
         mysql_field_seek(result,0);
         str.Empty();
         ed.SetSel(-1,-1);
         for (uint off=0 ; off < mysql_num_fields(result); off++)
         {
            field = mysql_fetch_field(result);
            length=field->max_length;
            CString strText;
            strText.Format ("%s", cur[off] ? (char*) cur[off] : "NULL");
            str += strText;
            str += "\t";
         }
         str += "\r\n";
         ed.SetSel(-1,-1);
         ed.ReplaceSel(str);
      }
   }
   else
   {
      while ((cur = mysql_fetch_row(result)))
      {
         mysql_field_seek(result,0);
         for (uint off=0 ; off < mysql_num_fields(result); off++)
         {
            field = mysql_fetch_field(result);
            length=field->max_length;
            CString strText;
            strText.Format ("%s", cur[off] ? (char*) cur[off] : "NULL");
            str += strText;
            str += "\t";
         }
         str += "\r\n";
      }
   }
   my_afree((gptr) num_flag);
   str += "\r\n";
   ed.SetTabStops(nFields,rgi);
   delete [] rgi;
}



/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnQueryPb()
{

   CWaitCursor x;
//   mysql_select_db(m_pdb,"mysql");

   if ( m_pResource && m_pResource->GetType() == CResource::eDatabase )
   {
      CString strDB = m_pResource->GetDisplayName();
      strDB.TrimRight();
      if (mysql_select_db(m_pdb,strDB))
      {
      }
   }

   m_pQuery->UpdateData();
   m_pResults->m_edit.Empty();
   CString str = m_pQuery->m_edit;
   if ( mysql_real_query(m_pdb,str,str.GetLength())==0 )
   {
      MYSQL_RES *result;
      if ((result=mysql_store_result(m_pdb)))
      {
         my_ulonglong nRows = mysql_num_rows(result);
         m_pResults->UpdateData(FALSE);
         m_tabs.SetCurSel(1);
         ActivateTab ( 1 );
         print_table_data(result,m_pResults->m_edit,m_pResults->m_ctl_edit,m_lf);
//       m_pResults->UpdateData(FALSE);
         m_pResults->m_ctl_edit.SetSel(-1,-1);
         CString strText;
         strText.Format ( "\r\n(%d row(s) affected)\r\n", nRows );
         m_pResults->m_ctl_edit.ReplaceSel(strText);
			mysql_free_result(result);
      }
      else
      {
         m_pResults->m_edit = mysql_error(m_pdb);
         m_pResults->UpdateData(FALSE);
      }
   }
   else
   {
      m_pResults->m_edit = mysql_error(m_pdb);
      m_pResults->UpdateData(FALSE);
   }

   m_tabs.SetCurSel(1);
   ActivateTab ( 1 );

}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnQueryDatabases()
{
   CWaitCursor x;
   MYSQL_RES *result;
   m_pResults->m_edit.Empty();
   if ((result=mysql_list_dbs(m_pdb,0)))
   {
      my_ulonglong nRows = mysql_num_rows(result);
      print_table_data(result,m_pResults->m_edit,m_pResults->m_ctl_edit,m_lf);
      //m_pResults->UpdateData(FALSE);
      mysql_free_result(result);
   }
   else
   {
      m_pResults->m_edit = mysql_error(m_pdb);
      m_pResults->UpdateData(FALSE);
   }

   m_tabs.SetCurSel(1);
   ActivateTab ( 1 );

}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
   ActivateTab ( m_tabs.GetCurSel() );
   *pResult = 0;
}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnFontPb()
{

   CFontDialog FontDlg ( & m_lf );

   if ( FontDlg.DoModal ( ) == IDOK )
   {
      if (m_font.GetSafeHandle())
         m_font.DeleteObject();
      m_lf = *FontDlg.m_cf.lpLogFont;
      m_font.CreateFontIndirect(FontDlg.m_cf.lpLogFont);
      m_pQuery->SetFont(&m_font);
      m_pResults->SetFont(&m_font);
      m_pStatus->SetFont(&m_font);
   }

}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::DoOnSize(UINT nType, int cx, int cy)
{

   int nx = cx - ( m_rectDlg[CLIENT_COORDS].Width  ( ) - m_rectTab[CLIENT_COORDS].Width  ( ) );
   int ny = cy - ( m_rectDlg[CLIENT_COORDS].Height ( ) - m_rectTab[CLIENT_COORDS].Height ( ) );

   if (IsWindow(m_tabs.GetSafeHwnd()))
   {
      m_tabs.SetWindowPos ( NULL
                            , 0
                            , 0
                            , nx
                            , ny
                            , SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW );

      if (m_pResults&&IsWindow(m_pResults->GetSafeHwnd()))
         m_pResults -> SetWindowPos(NULL,20,24,nx-40,ny-48,SWP_NOZORDER | SWP_NOMOVE );
      if (m_pQuery&&IsWindow(m_pQuery->GetSafeHwnd()))
         m_pQuery -> SetWindowPos(NULL,20,24,nx-40,ny-48,SWP_NOZORDER | SWP_NOMOVE );
      if (m_pStatus&&IsWindow(m_pStatus->GetSafeHwnd()))
         m_pStatus -> SetWindowPos(NULL,20,24,nx-40,ny-48,SWP_NOZORDER | SWP_NOMOVE );
//     switch ( m_tabs.GetCurSel() )
//     {
//        case 0:
//        {
//          if (m_pResults&&IsWindow(m_pResults->GetSafeHwnd()))
//             m_pResults -> SetWindowPos(NULL,20,24,nx-40,ny-48,SWP_NOZORDER | SWP_NOMOVE | SWP_HIDEWINDOW );
//          if (m_pQuery&&IsWindow(m_pQuery->GetSafeHwnd()))
//             m_pQuery -> SetWindowPos(NULL,20,24,nx-40,ny-48,SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW );
//          break;
//        }
//        case 1:
//        {
//          if (m_pQuery&&IsWindow(m_pQuery->GetSafeHwnd()))
//             m_pQuery -> SetWindowPos(NULL,20,24,nx-40,ny-48,SWP_NOZORDER | SWP_NOMOVE | SWP_HIDEWINDOW );
//          if (m_pResults&&IsWindow(m_pResults->GetSafeHwnd()))
//             m_pResults -> SetWindowPos(NULL,20,24,nx-40,ny-48,SWP_NOZORDER | SWP_NOMOVE | SWP_SHOWWINDOW );
//          break;
//        }
//     }
   }

}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnSize(UINT nType, int cx, int cy)
{

   CDialog::OnSize(nType, cx, cy);

   DoOnSize ( nType, cx, cy );

}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnOK()
{
   CDialog::OnOK();
}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnCancel()
{
   CDialog::OnCancel();
}

/////////////////////////////////////////////////////////////////////////////

BOOL CToolSql::PreTranslateMessage(MSG* pMsg)
{
   return CDialog::PreTranslateMessage(pMsg);
}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::DoProcessListQuery()
{

	MYSQL_RES *result;
	if (result=mysql_list_processes(m_pdb))
	{
		if (m_bClear)
		{
			m_pStatus->m_edit.Empty();
			m_pStatus->UpdateData(FALSE);
		}
		print_table_data(result,m_pStatus->m_edit,m_pStatus->m_ctl_edit,m_lf);
		mysql_free_result(result);
	}
	else
	{
//		my_printf_error(0,"process list failed; error: '%s'",MYF(ME_BELL),mysql_error(mysql));
	}

}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnStartPb()
{
	UpdateData();
	if (m_ui_timer) return;
	if (m_nIntervalTimerSeconds<1) return;
	ActivateTab ( 2 );
	m_ui_timer = SetTimer( MY_TIMER_ID, m_nIntervalTimerSeconds*1000, NULL );
	m_ctl_Start . EnableWindow(FALSE);
	m_ctl_Stop  . EnableWindow(TRUE);
	DoProcessListQuery();
}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnStopPb()
{
	UpdateData();
	if (m_ui_timer)
	{
		KillTimer(MY_TIMER_ID);
		m_ui_timer = 0;
	}
	m_ctl_Start . EnableWindow(TRUE);
	m_ctl_Stop  . EnableWindow(FALSE);
}

/////////////////////////////////////////////////////////////////////////////

void CToolSql::OnTimer(UINT nIDEvent)
{
	DoProcessListQuery();
	CDialog::OnTimer(nIDEvent);
}

void CToolSql::OnDestroy()
{
	if (m_ui_timer)
	{
		KillTimer(MY_TIMER_ID);
		m_ui_timer = 0;
	}
	CDialog::OnDestroy();
}

void CToolSql::OnClear()
{
	UpdateData();
}

void CToolSql::OnChangeTimerSecs()
{
	UpdateData();
}