File: sqlite3table.cpp

package info (click to toggle)
wxsqlite3 3.0.0.1~dfsg0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,740 kB
  • sloc: cpp: 20,130; sh: 2,837; makefile: 302; ansic: 197; php: 9
file content (768 lines) | stat: -rwxr-xr-x 24,998 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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
/*---------------------------------------------------------------------------*/
/* Logiciel de gestion de fichier de bases de données SQLite                 */
/*---------------------------------------------------------------------------*/
/* Projet  : wxSQLitePlus                              Version  : 0.3.0.0    */
/* Fichier : sqlite3table.cpp                                                */
/* Auteur  : Fred Cailleau-Lepetit                     Date     : 29/06/2007 */
/* email   : softinthebox@free.fr                      Révision : 07/03/2009 */
/*---------------------------------------------------------------------------*/
/* Copyright (C) Fred Cailleau-Lepetit 2007-2008                             */
/* Licence GNU General Public License  http://www.fsf.org/copyleft/gpl.html  */
/*---------------------------------------------------------------------------*/
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation (version 3);

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Ce programme est libre, vous pouvez le redistribuer et/ou le modifier
selon les termes de la Licence Publique Générale GNU publiée par la
Free Software Foundation (version 3).

Ce programme est distribué car potentiellement utile, mais
SANS AUCUNE GARANTIE, ni explicite ni implicite, y compris
les garanties de commercialisation ou d'adaptation dans un but
spécifique. Reportez-vous à la Licence Publique Générale GNU
pour plus de détails.
*/
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "sqlite3table.h"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/arrimpl.cpp>
/*---------------------------------------------------------------------------*/
#include "sqlite3table.h"
#include "triggerparser.h"
#include "wxsqliteplusapp.h"
#include "specgrid.h"
/*---------------------------------------------------------------------------*/
#define wxGRID_VALUE_BLOB     _T("blob")
/*---------------------------------------------------------------------------*/
wxGridEmptyTable g_EmptyTable;
wxString g_NullValString(_T("(null)"));
/*---------------------------------------------------------------------------*/
// wxSQLite3TableColumn
/*---------------------------------------------------------------------------*/
class wxSQLite3TableColumn
{
   public:

      wxSQLite3TableColumn(){m_ShowNull = true;}
      virtual ~wxSQLite3TableColumn(){}

      virtual void AddValue(wxSQLite3ResultSet& WXUNUSED(resultSet), int WXUNUSED(columnIndex)){}
      virtual void AddValue(const wxString& WXUNUSED(value)){}
      virtual void AddValue(long WXUNUSED(value)){}
      virtual void AddValue(double WXUNUSED(value)){}

      wxString GetLabelValue(){return m_Label;}
      void SetLabelValue(const wxString& value){m_Label = value;}
      int GetSize();

      virtual wxString GetType() const {return wxEmptyString;}

      virtual wxString GetString(int WXUNUSED(row))
      {
         return wxEmptyString;
      }

      virtual bool GetBool(int WXUNUSED(row))
      {
         return false;
      }

      bool IsNull(int row)
      {
         return (m_nullValues.Item(row) == 0);
      }

      bool GetShowNull(){return m_ShowNull;}
      void SetShowNull(bool value){m_ShowNull = value;}

      wxString GetNullString()
      {
         if (m_ShowNull)
            return g_NullValString;
         else
            return wxEmptyString;
      }

   protected:

      wxArrayInt m_nullValues;

   private:

      bool m_ShowNull;
      wxString m_Label;
};
/*---------------------------------------------------------------------------*/
int wxSQLite3TableColumn::GetSize()
{
   int m_Size;

   if (GetType() == wxGRID_VALUE_STRING)
      m_Size = 24;
   else if (GetType() == wxGRID_VALUE_BOOL)
      m_Size = 5;
   else if (GetType() == wxGRID_VALUE_NUMBER)   // 4 000 000 000
      m_Size = 10;
   else if (GetType() == wxGRID_VALUE_FLOAT)
      m_Size = 12;
   else if (GetType() == wxGRID_VALUE_CHOICE)
      m_Size = 28;
   else if (GetType() == wxGRID_VALUE_BLOB)
      m_Size = 8;
   else
      m_Size = 0;
   return m_Size;
}
/*---------------------------------------------------------------------------*/
// wxSQLite3TableStringColumn
/*---------------------------------------------------------------------------*/
class wxSQLite3TableStringColumn : public wxSQLite3TableColumn
{
   public:

      virtual void AddValue(wxSQLite3ResultSet& resultSet, int columnIndex)
      {
         if (resultSet.IsNull(columnIndex))
            m_nullValues.Add(0);
         else
            m_nullValues.Add(1);

         m_Array.Add(resultSet.GetString(columnIndex));
      }
      virtual void AddValue(const wxString& value)
      {
         m_nullValues.Add(1);
         m_Array.Add(value);
      }

      virtual wxString GetType() const {return wxGRID_VALUE_STRING;}

      virtual wxString GetString(int row)
      {
         if (row >= 0)
         {
            if (m_nullValues.Item(row) == 0)
               return GetNullString();
            return m_Array.Item(row);
         }
         return wxEmptyString;
      }

   private:

      wxArrayString m_Array;
};
/*---------------------------------------------------------------------------*/
// wxSQLite3TableLongColumn
/*---------------------------------------------------------------------------*/
class wxSQLite3TableLongColumn : public wxSQLite3TableColumn
{
   public:

      virtual void AddValue(wxSQLite3ResultSet& resultSet, int columnIndex)
      {
         if (resultSet.IsNull(columnIndex))
            m_nullValues.Add(0);
         else
            m_nullValues.Add(1);

         m_Array.Add(resultSet.GetInt(columnIndex));
      }
      virtual void AddValue(long value)
      {
         m_nullValues.Add(1);
         m_Array.Add(value);
      }

      virtual wxString GetType(){return wxGRID_VALUE_NUMBER;}

      virtual wxString GetString(int row)
      {
         if (row >= 0)
         {
            if (m_nullValues.Item(row) == 0)
               return GetNullString();
            return wxString::Format(_("%li"), m_Array.Item(row));
         }
         return wxEmptyString;
      }

      virtual bool GetBool(int row)
      {
         if (row >= 0)
            return m_Array.Item(row) != 0;
         return false;
      }

   private:

      wxArrayLong m_Array;
};
/*---------------------------------------------------------------------------*/
// wxSQLite3TableDoubleColumn
/*---------------------------------------------------------------------------*/
class wxSQLite3TableDoubleColumn : public wxSQLite3TableColumn
{
   public:

      virtual void AddValue(wxSQLite3ResultSet& resultSet, int columnIndex)
      {
         if (resultSet.IsNull(columnIndex))
            m_nullValues.Add(0);
         else
            m_nullValues.Add(1);

         m_Array.Add(resultSet.GetDouble(columnIndex));
      }
      virtual void AddValue(double value)
      {
         m_nullValues.Add(1);
         m_Array.Add(value);
      }

      virtual wxString GetString(int row)
      {
         if (row >= 0)
         {
            if (m_nullValues.Item(row) == 0)
               return GetNullString();
            return wxString::Format(_("%g"), m_Array.Item(row));
         }
         return wxEmptyString;
      }
      virtual wxString GetType()const {return wxGRID_VALUE_FLOAT;}

      virtual bool GetBool(int row)
      {
         if (row >= 0)
            return m_Array.Item(row) != 0;
         return false;
      }

   private:

      wxArrayDouble m_Array;
};
/*---------------------------------------------------------------------------*/
// wxSQLite3TableBlobColumn
/*---------------------------------------------------------------------------*/
WX_DECLARE_OBJARRAY(wxMemoryBuffer, wxArrayOfBlob);
WX_DEFINE_OBJARRAY(wxArrayOfBlob);
/*---------------------------------------------------------------------------*/
class wxSQLite3TableBlobColumn : public wxSQLite3TableColumn
{
   public:

      ~wxSQLite3TableBlobColumn()
      {
         m_BlobArray.Clear();
      }

      virtual void AddValue(wxSQLite3ResultSet& resultSet, int columnIndex)
      {
         if (resultSet.IsNull(columnIndex))
         {
            m_nullValues.Add(0);
            m_BlobArray.Add(NULL);
         }
         else
         {
            wxMemoryBuffer* memBuf = new  wxMemoryBuffer;
            m_nullValues.Add(1);
            resultSet.GetBlob(columnIndex, *memBuf);
            m_BlobArray.Add(memBuf);
         }
     }
      virtual void AddValue(const wxString& value)
      {
         size_t sizeUsed;
         wxMemoryBuffer* memBuf = new wxMemoryBuffer;

#if wxCHECK_VERSION(2,9,0)
         const wxScopedCharBuffer utf8value = value.utf8_str();
         sizeUsed = value.Len() * utf8value.length();
         memBuf->SetBufSize(sizeUsed + 1);
         memBuf->AppendData((const char*)utf8value, sizeUsed);
#else
         sizeUsed = value.Len() * sizeof(wxChar);
         memBuf->SetBufSize(sizeUsed + 1);
         memBuf->AppendData((void*)value.GetData(), sizeUsed);
#endif
         memBuf->AppendByte(0);

         m_nullValues.Add(1);
         m_BlobArray.Add(memBuf);
      }

      virtual wxString GetType() const {return wxGRID_VALUE_BLOB;}

      virtual wxString GetString(int row)
      {
         if (row >= 0)
         {
            if (m_nullValues.Item(row) == 0)
               return GetNullString();
            return _T("(blob)");
         }
         return wxEmptyString;
      }

      wxMemoryBuffer* GetBuffer(size_t index)
      {
         if (index < m_BlobArray.Count())
            return &m_BlobArray[index];
         return NULL;
      }

   private:

      wxArrayOfBlob m_BlobArray;

};
/*---------------------------------------------------------------------------*/
// OddRowsGridCellAttrProvider
/*---------------------------------------------------------------------------*/
OddRowsGridCellAttrProvider::OddRowsGridCellAttrProvider(wxColour colour)
{
   m_attrForOddRows = new wxGridCellAttr;
   m_OddColour = colour;
   m_attrForOddRows->SetBackgroundColour(m_OddColour);
}
/*---------------------------------------------------------------------------*/
OddRowsGridCellAttrProvider::~OddRowsGridCellAttrProvider()
{
   m_attrForOddRows->DecRef();
}
/*---------------------------------------------------------------------------*/
wxGridCellAttr* OddRowsGridCellAttrProvider::GetAttr(int row, int col,
                                                     wxGridCellAttr::wxAttrKind  kind) const
{
   wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);

   if (row % 2)
   {
      if ( !attr )
      {
         attr = m_attrForOddRows;
         attr->IncRef();
      }
      else
      {
         if (!attr->HasBackgroundColour())
         {
            wxGridCellAttr *attrNew = attr->Clone();
            attr->DecRef();
            attr = attrNew;
            attr->SetBackgroundColour(m_OddColour);
         }
      }
   }

   return attr;
}
/*---------------------------------------------------------------------------*/
// wxGridSQLite3TableBase
/*---------------------------------------------------------------------------*/
wxGridSQLite3TableBase::wxGridSQLite3TableBase()
{
   Init();
}
/*---------------------------------------------------------------------------*/
wxGridSQLite3TableBase::~wxGridSQLite3TableBase()
{
   WX_CLEAR_ARRAY(m_ArrayColumn)
}
/*---------------------------------------------------------------------------*/
bool wxGridSQLite3TableBase::IsEmptyCell(int row, int col)
{
   if (m_ArrayColumn[col]->IsNull(row))
      return true;
   return false;
}
/*---------------------------------------------------------------------------*/
wxString wxGridSQLite3TableBase::GetValue(int row, int col)
{
   return m_ArrayColumn[col]->GetString(row);
}
/*---------------------------------------------------------------------------*/
void wxGridSQLite3TableBase::SetValue(int row, int col, const wxString& value)
{
  wxUnusedVar(row);
  wxUnusedVar(col);
  wxUnusedVar(value);
   // rien pour l'instant
}
/*---------------------------------------------------------------------------*/
wxString wxGridSQLite3TableBase::GetColLabelValue(int col)
{
   return m_ArrayColumn[col]->GetLabelValue();
}
/*---------------------------------------------------------------------------*/
wxString wxGridSQLite3TableBase::GetTypeName(int row, int col)
{
  wxUnusedVar(row);
  wxUnusedVar(col);
   return m_ArrayColumn[col]->GetType();
}
/*---------------------------------------------------------------------------*/
void wxGridSQLite3TableBase::SetView(wxGrid* grid)
{
   if (grid)
   {
      m_CharWidth = grid->GetCharWidth();

      wxString tmp = wxString::Format(_(" %i "), GetNumberRows());

      grid->SetRowLabelSize(tmp.Length() * m_CharWidth);
   }

   wxGridTableBase::SetView(grid);
}
/*---------------------------------------------------------------------------*/
void wxGridSQLite3TableBase::AdaptColumnsSize()
{
   if (GetView())
   {
      for (int i = 0; i < m_NumberCols; i++)
      {
         GetView()->SetColSize(i, m_ArrayColumn[i]->GetSize() * m_CharWidth);
         if (m_ArrayColumn[i]->GetType() == wxGRID_VALUE_FLOAT)
            GetView()->SetColFormatFloat(i, m_FloatWidth, m_FloatPrecision);
         else if (m_ArrayColumn[i]->GetType() == wxGRID_VALUE_STRING)
         {
            wxGridCellAttr* textAttr = new wxGridCellAttr;

            textAttr->SetEditor(new wxGridCellAutoWrapStringEditor);
            textAttr->SetRenderer(new wxGridCellAutoWrapStringRenderer);
            GetView()->SetColAttr(i, textAttr);
         }
         else if (m_ArrayColumn[i]->GetType() == wxGRID_VALUE_BLOB)
         {
            wxGridCellAttr* textAttr = new wxGridCellAttr;

            textAttr->SetRenderer(new wxGridCellBlobRenderer);
            textAttr->SetEditor(new wxGridCellBlobEditor);
            GetView()->SetColAttr(i, textAttr);
         }
      }
   }
}
/*---------------------------------------------------------------------------*/
void wxGridSQLite3TableBase::Init()
{
   m_CharWidth = 10; // par défaut
   m_NumberRows = m_NumberCols = 0;
   m_FloatWidth = -1;
   m_FloatPrecision = 2;
}
/*---------------------------------------------------------------------------*/
void wxGridSQLite3TableBase::PopulateArray(wxSQLite3ResultSet* resultSet)
{
   wxSQLite3TableColumn* p_Column;
   wxString colType;

   if (resultSet == NULL)
      return;
   m_NumberCols = resultSet->GetColumnCount();
   // Création des colonnes
   for (int i = 0; i < m_NumberCols; i++)
   {
      colType = resultSet->GetDeclaredColumnType(i).Upper();
      switch (resultSet->GetColumnType(i))
      {
         case WXSQLITE_INTEGER :
            p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableLongColumn;
            break;
         case WXSQLITE_FLOAT   :
            p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableDoubleColumn;
            break;
         case WXSQLITE_BLOB    :
            p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableBlobColumn;
            break;
         default : // WXSQLITE_TEXT WXSQLITE_NULL
            if (colType == _T("BLOB") || colType == _T("CLOB") ||
                colType == _T("GLOB"))
               p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableBlobColumn;
            else
               p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableStringColumn;
      }
      // Nommer les colonnes
      p_Column->SetLabelValue(resultSet->GetColumnName(i));
      // Ajouter la colonne
      m_ArrayColumn.Add(p_Column);
   }
   // boucler et incrémenter
   while (resultSet->NextRow())
   {
      m_NumberRows++;
      for (int i = 0; i < m_NumberCols; i++)
         m_ArrayColumn[i]->AddValue(*resultSet, i);
   }
}
/*---------------------------------------------------------------------------*/
// wxGridSQLite3Table
/*---------------------------------------------------------------------------*/
wxGridSQLite3Table::wxGridSQLite3Table(wxSQLite3ResultSet* resultSet) :
                    wxGridSQLite3TableBase()
{
   PopulateArray(resultSet);
}
/*---------------------------------------------------------------------------*/
wxGridSQLite3Table::wxGridSQLite3Table(wxSQLite3Database* db,
                                       const wxString& tablename,
                                       const wxString& base) :
                    wxGridSQLite3TableBase()
{
   if (db == NULL)
      return;
   if (db->TableExists(tablename))
   {
      m_TableName = tablename;
      wxSQLite3ResultSet resultSet = GetResultSet(db, base);
      PopulateArray(&resultSet);
      resultSet.Finalize();
   }
}
/*---------------------------------------------------------------------------*/
bool wxGridSQLite3Table::GetBlob(size_t row, size_t col, wxMemoryBuffer*& buffer)
{
   if (row < (size_t)GetNumberRows() && col < (size_t)GetNumberCols())
      if (m_ArrayColumn[col]->GetType() == wxGRID_VALUE_BLOB)
      {
         buffer =  ((wxSQLite3TableBlobColumn*)m_ArrayColumn[col])->GetBuffer(row);
         return true;
      }
   return false;
}
/*---------------------------------------------------------------------------*/
wxSQLite3ResultSet wxGridSQLite3Table::GetResultSet(wxSQLite3Database* db,
                                                    const wxString& base)
{
   wxSQLite3ResultSet resultSet;
   wxString sql;
   sql = _("SELECT * FROM ");
   if (base != wxEmptyString)
      sql += base + _T(".");
   sql += m_TableName + _(";");
   try
   {
      resultSet = db->ExecuteQuery(ToUTF8(sql));
   }
   catch(wxSQLite3Exception& ex)
   {
      wxGetApp().ShowError(_T("GetResultSet"), ex);
   }
   return resultSet;
}
/*---------------------------------------------------------------------------*/
wxGridTblIndexesTable::wxGridTblIndexesTable(wxSQLite3Database* db,
                                             const wxString& tablename,
                                             const wxString& base) :
                    wxGridSQLite3TableBase()
{
   if (db == NULL)
      return;
   if (db->TableExists(tablename))
   {
      wxSQLite3ResultSet resultSet = GetResultSet(db, tablename, base);
      PopulateArray(&resultSet);
      resultSet.Finalize();
      for (int i = 0; i < m_NumberCols; i++)
         m_ArrayColumn[i]->SetShowNull(false);
   }
}
/*---------------------------------------------------------------------------*/
wxString wxGridTblIndexesTable::GetTypeName(int row, int col)
{
   if (col == 2)
         return wxGRID_VALUE_BOOL;
   else
      return wxGridSQLite3TableBase::GetTypeName(row, col);
}
/*---------------------------------------------------------------------------*/
wxString wxGridTblIndexesTable::GetValue(int row, int col)
{
   // dans certain cas au lieu de 1 la colonne est égale à 99
   // les coches sont alors mal gérées
   if (col == 2)
      return m_ArrayColumn[col]->GetBool(row) ? _T("1") : _T("0");
   else
      return m_ArrayColumn[col]->GetString(row);
}
/*---------------------------------------------------------------------------*/
wxSQLite3ResultSet wxGridTblIndexesTable::GetResultSet(wxSQLite3Database* db,
                                                       const wxString& tablename,
                                                       const wxString& base)
{
   wxSQLite3ResultSet resultSet;
   wxString sql, basename;

   if (base != wxEmptyString)
      basename = base;
   else
      basename = _T("main");
   sql = wxString::Format(_T("PRAGMA %s.index_list(\"%s\");"), basename.c_str(),
                          tablename.c_str());
   try
   {
      resultSet = db->ExecuteQuery(ToUTF8(sql));
   }
   catch(wxSQLite3Exception& ex)
   {
      wxGetApp().ShowError(_T("GetResultSet"), ex);
   }
   return resultSet;
}
/*---------------------------------------------------------------------------*/
wxGridTblColumnsTable::wxGridTblColumnsTable(wxSQLite3Database* db,
                                             const wxString& tablename,
                                             const wxString& base) :
                    wxGridSQLite3TableBase()
{
   if (db == NULL)
      return;
   wxSQLite3ResultSet resultSet = GetResultSet(db, tablename, base);
   PopulateArray(&resultSet);
   resultSet.Finalize();
   for (int i = 0; i < m_NumberCols; i++)
      m_ArrayColumn[i]->SetShowNull(false);
}
/*---------------------------------------------------------------------------*/
wxString wxGridTblColumnsTable::GetTypeName(int row, int col)
{
   if ((col == 3)||(col == 5))
         return wxGRID_VALUE_BOOL;
   else
      return wxGridSQLite3TableBase::GetTypeName(row, col);
}
/*---------------------------------------------------------------------------*/
wxString wxGridTblColumnsTable::GetValue(int row, int col)
{
   // dans certain cas au lieu de 1 la colonne est égale à 99
   // les coches sont alors mal gérées
   if ((col == 3)||(col == 5))
      return m_ArrayColumn[col]->GetBool(row) ? _T("1") : _T("0");
   else
      return m_ArrayColumn[col]->GetString(row);
}
/*---------------------------------------------------------------------------*/
wxSQLite3ResultSet wxGridTblColumnsTable::GetResultSet(wxSQLite3Database* db,
                                                       const wxString& tablename,
                                                       const wxString& base)
{
   wxSQLite3ResultSet resultSet;
   wxString sql, basename;

   if (base != wxEmptyString)
      basename = base;
   else
      basename = _T("main");
   sql = wxString::Format(_T("PRAGMA %s.table_info(\"%s\");"), basename.c_str(),
                          tablename.c_str());
   try
   {
      resultSet = db->ExecuteQuery(ToUTF8(sql));
   }
   catch(wxSQLite3Exception& ex)
   {
      wxGetApp().ShowError(_T("GetResultSet"), ex);
   }
   return resultSet;
}
/*---------------------------------------------------------------------------*/
wxGridTriggerTable::wxGridTriggerTable(wxSQLite3Database* db,
                                       const wxString& tablename,
                                       const wxString& base) :
                    wxGridSQLite3TableBase()
{
   if (db == NULL)
      return;
   if (db->TableExists(tablename))
   {
      wxSQLite3ResultSet resultSet = GetResultSet(db, tablename, base);
      PopulateArray(&resultSet);
      resultSet.Finalize();
   }
}
/*---------------------------------------------------------------------------*/
void wxGridTriggerTable::PopulateArray(wxSQLite3ResultSet* resultSet)
{
   wxSQLite3TableColumn* p_Column;
   wxString sql;

   if (resultSet == NULL||resultSet->GetColumnCount() == 0)
      return;
   m_NumberCols = 3;
   p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableStringColumn;
   p_Column->SetLabelValue(_T("name"));
   p_Column->SetShowNull(false);
   m_ArrayColumn.Add(p_Column);
   p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableStringColumn;
   p_Column->SetLabelValue(_T("type"));
   p_Column->SetShowNull(false);
   m_ArrayColumn.Add(p_Column);
   p_Column = (wxSQLite3TableColumn*)new wxSQLite3TableStringColumn;
   p_Column->SetLabelValue(_T("column/Event"));
   p_Column->SetShowNull(false);
   m_ArrayColumn.Add(p_Column);
   // boucler et incrémenter
   while (resultSet->NextRow())
   {
      m_NumberRows++;
      m_ArrayColumn[0]->AddValue(*resultSet, 0);
      sql = resultSet->GetString(1);
      wxCreateTrigerParserMinimal parser(sql);
      m_ArrayColumn[1]->AddValue(parser.GetEvent());
      m_ArrayColumn[2]->AddValue(parser.GetColumn());
   }
}
/*---------------------------------------------------------------------------*/
wxSQLite3ResultSet wxGridTriggerTable::GetResultSet(wxSQLite3Database* db,
                                                    const wxString& tablename,
                                                    const wxString& base)
{
   wxSQLite3ResultSet resultSet;
   wxString sql;

   if ((base == wxEmptyString)||(base == _T("main")))
   {
      sql = _T("SELECT name, sql FROM  sqlite_master WHERE type = 'trigger' AND tbl_name = '");
      sql += tablename + _T("' UNION SELECT name, sql FROM sqlite_temp_master WHERE type = 'trigger' AND tbl_name = '");
      sql += tablename + _T("';");
   }
   else
   {
      sql = _T("SELECT name, sql FROM ");
      sql += base + _T(".");
      sql += _T("sqlite_master WHERE type = 'trigger' AND tbl_name = '");
      sql += tablename + _T("';");
   }
   try
   {
      resultSet = db->ExecuteQuery(ToUTF8(sql));
   }
   catch(wxSQLite3Exception& ex)
   {
      wxGetApp().ShowError(_T("GetResultSet"), ex);
   }
   return resultSet;
}
/*---------------------------------------------------------------------------*/