]> git.saurik.com Git - wxWidgets.git/blame - src/common/dbgrid.cpp
Cleaned up some and started using path joins and normalization instead
[wxWidgets.git] / src / common / dbgrid.cpp
CommitLineData
32a2907b
GT
1///////////////////////////////////////////////////////////////////////////////
2// Name: dbgrid.cpp
3// Purpose: Displays a wxDbTable in a wxGrid.
4// Author: Roger Gammans, Paul Gammans
eae630f1
DW
5// Modified by:
6// Created:
32a2907b
GT
7// RCS-ID: $Id$
8// Copyright: (c) 1999 The Computer Surgery (roger@computer-surgery.co.uk)
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11// Branched From : dbgrid.cpp,v 1.18 2000/12/19 13:00:58
12///////////////////////////////////////////////////////////////////////////////
13
14#ifdef __GNUG__
15 #pragma implementation "dbgrid.h"
16#endif
17
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21 #pragma hdrstop
22#endif
23
24
25#if wxUSE_ODBC
26#if wxUSE_NEW_GRID
27
28#ifndef WX_PRECOMP
29 #include "wx/textctrl.h"
30 #include "wx/dc.h"
31#endif // WX_PRECOMP
32
33#include "wx/generic/gridctrl.h"
34#include "wx/dbgrid.h"
35
36
37wxDbGridCellAttrProvider::wxDbGridCellAttrProvider()
38{
39 m_data=NULL;
40 m_ColInfo=NULL;
41}
42
43wxDbGridCellAttrProvider::wxDbGridCellAttrProvider(wxDbTable *tab, wxDbGridColInfoBase* ColInfo)
44{
45 m_data=tab;
46 m_ColInfo=ColInfo;
47}
48
49wxDbGridCellAttrProvider::~wxDbGridCellAttrProvider()
50{
51}
52
53wxGridCellAttr *wxDbGridCellAttrProvider::GetAttr(int row, int col,
54 wxGridCellAttr::wxAttrKind kind) const
55{
56 wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row,col,kind);
57
58 if (m_data && m_ColInfo && (m_data->GetNumberOfColumns() > m_ColInfo[col].DbCol))
59 {
60 //FIXME: this test could.
61 // ??::InsertPending == m_data->get_ModifiedStatus()
62 // and if InsertPending use colDef[].InsertAllowed
63 if (!(m_data->GetColDefs()[(m_ColInfo[col].DbCol)].Updateable))
64 {
65 switch(kind)
66 {
67 case (wxGridCellAttr::Any):
68 if (!attr)
69 {
70 attr = new wxGridCellAttr;
71 // Store so we don't keep creating / deleting this...
72 wxDbGridCellAttrProvider * self = wxConstCast(this, wxDbGridCellAttrProvider) ;
73 attr->IncRef();
74 self->SetColAttr(attr, col);
75 attr->SetReadOnly();
76 }
77 else
78 {
79 //We now must check what we were returned. and do the right thing (tm)
80 wxGridCellAttr::wxAttrKind attrkind = attr->GetKind();
81 if ((attrkind == (wxGridCellAttr::Default)) || (attrkind == (wxGridCellAttr::Cell)) ||
82 (attrkind == (wxGridCellAttr::Col)))
83 {
84 wxGridCellAttr *attrtomerge = attr;
85 attr = new wxGridCellAttr;
86 attr->SetKind(wxGridCellAttr::Merged);
87 attr->MergeWith(attrtomerge);
88 attr->SetReadOnly();
89 attrtomerge->DecRef();
90 }
91 attr->SetReadOnly();
92 }
93 break;
94 case (wxGridCellAttr::Col):
95 //As we must have a Coll, and were setting Coll attributes
96 // we can based on wxdbTable's so just set RO if attr valid
97 if (!attr)
98 {
99 attr = new wxGridCellAttr;
100 wxDbGridCellAttrProvider * self = wxConstCast(this, wxDbGridCellAttrProvider) ;
101 attr->IncRef();
102 self->SetColAttr(attr, col);
103 }
104 attr->SetReadOnly();
105 break;
106 default:
107 //Dont add RO for...
108 // wxGridCellAttr::Cell - Not required, will inherit on merge from row.
109 // wxGridCellAttr::Row - If wxDbtable ever supports row locking could add
110 // support to make RO on a row basis also.
111 // wxGridCellAttr::Default - Don't edit this ! or all cell with a attr will become readonly
112 // wxGridCellAttr::Merged - This should never be asked for.
113 break;
114 }
115 }
eae630f1 116
32a2907b
GT
117 }
118 return attr;
119}
120
121void wxDbGridCellAttrProvider::AssignDbTable(wxDbTable *tab)
122{
123 m_data = tab;
124}
125
126wxDbGridTableBase::wxDbGridTableBase(wxDbTable *tab, wxDbGridColInfo* ColInfo,
127 int count, bool takeOwnership) :
eae630f1 128 m_keys(),
32a2907b
GT
129 m_data(tab),
130 m_dbowner(takeOwnership),
a144affe 131 m_rowmodified(FALSE)
32a2907b
GT
132{
133
134 if (count == wxUSE_QUERY)
135 {
136 m_rowtotal = m_data ? m_data->Count() : 0;
137 }
138 else
139 {
140 m_rowtotal = count;
141 }
142// m_keys.Size(m_rowtotal);
143 m_row = -1;
144 if (ColInfo)
145 {
146 m_nocols = ColInfo->Length();
147 m_ColInfo = new wxDbGridColInfoBase[m_nocols];
148 //Do Copy.
149 wxDbGridColInfo *ptr = ColInfo;
150 int i =0;
151 while (ptr && i < m_nocols)
152 {
153 m_ColInfo[i] = ptr->m_data;
154 ptr = ptr->m_next;
155 i++;
156 }
157#ifdef __WXDEBUG__
158 if (ptr)
159 {
160 wxLogDebug(wxT("NoCols over length after traversing %i items"),i);
161 }
162 if (i < m_nocols)
163 {
164 wxLogDebug(wxT("NoCols under length after traversing %i items"),i);
eae630f1 165 }
32a2907b
GT
166#endif
167 }
168}
169
170wxDbGridTableBase::~wxDbGridTableBase()
171{
172 wxDbGridCellAttrProvider *provider;
173
eae630f1 174 //Can't check for update here as
32a2907b
GT
175
176 //FIXME: should i remove m_ColInfo and m_data from m_attrProvider if a wxDbGridAttrProvider
177// if ((provider = dynamic_cast<wxDbGridCellAttrProvider *>(GetAttrProvider())))
178 // Using C casting for now until we can support dynamic_cast with wxWindows
eae630f1
DW
179 provider = (wxDbGridCellAttrProvider *)(GetAttrProvider());
180 if (provider)
32a2907b
GT
181 {
182 provider->AssignDbTable(NULL);
183 }
184 delete [] m_ColInfo;
eae630f1 185
32a2907b
GT
186 Writeback();
187 if (m_dbowner)
188 {
189 delete m_data;
190 }
191}
192
193bool wxDbGridTableBase::CanHaveAttributes()
194{
195 if (!GetAttrProvider())
196 {
197 // use the default attr provider by default
198 SetAttrProvider(new wxDbGridCellAttrProvider(m_data, m_ColInfo));
199 }
a144affe 200 return TRUE;
32a2907b
GT
201}
202
203
204bool wxDbGridTableBase::AssignDbTable(wxDbTable *tab, int count, bool takeOwnership)
205{
206 wxDbGridCellAttrProvider *provider;
207
208 //Remove Information from grid about old data
209 if (GetView())
210 {
211 wxGrid *grid = GetView();
212 grid->BeginBatch();
213 grid->ClearSelection();
214 if (grid->IsCellEditControlEnabled())
215 {
216 grid->DisableCellEditControl();
217 }
218 wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_DELETED,0,m_rowtotal);
219 grid->ProcessTableMessage(msg);
220 }
221
222 //reset our internals...
223 Writeback();
224 if (m_dbowner)
225 {
226 delete m_data;
227 }
228 m_keys.Empty();
229 m_data = tab;
eae630f1 230 //FIXME: Remove dynamic_cast before sumision to wxwin
32a2907b
GT
231// if ((provider = dynamic_cast<wxDbGridCellAttrProvider *> (GetAttrProvider())))
232 // Using C casting for now until we can support dynamic_cast with wxWindows
eae630f1
DW
233 provider = (wxDbGridCellAttrProvider *)(GetAttrProvider());
234 if (provider)
32a2907b
GT
235 {
236 provider->AssignDbTable(m_data);
237 }
eae630f1 238
32a2907b
GT
239 if (count == wxUSE_QUERY)
240 {
241 m_rowtotal = m_data ? m_data->Count() : 0;
242 }
243 else
244 {
245 m_rowtotal = count;
246 }
247 m_row = -1;
248
249 //Add Information to grid about new data
250 if (GetView())
251 {
252 wxGrid * grid = GetView();
253 wxGridTableMessage msg(this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, m_rowtotal);
254 grid->ProcessTableMessage(msg);
255 grid->EndBatch();
256 }
257 m_dbowner = takeOwnership;
a144affe
GT
258 m_rowmodified = FALSE;
259 return TRUE;
32a2907b
GT
260}
261
262wxString wxDbGridTableBase::GetTypeName(int row, int col)
263{
264 if (col == 8)
265 int breakpoint = 1;
266
267 if (GetNumberCols() > col)
268 {
269 if (m_ColInfo[col].wxtypename == wxGRID_VALUE_DBAUTO)
270 {
271 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
272 {
273 wxFAIL_MSG (_T("You can not use wxGRID_VALUE_DBAUTO for virtual columns"));
274 }
275 switch(m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype)
276 {
277 case SQL_C_CHAR:
278 return wxGRID_VALUE_STRING;
279 break;
280 case SQL_C_SSHORT:
281 return wxGRID_VALUE_NUMBER;
282 break;
283 case SQL_C_USHORT:
284 return wxGRID_VALUE_NUMBER;
285 break;
286 case SQL_C_SLONG:
287 return wxGRID_VALUE_NUMBER;
288 break;
289 case SQL_C_ULONG:
290 return wxGRID_VALUE_NUMBER;
291 break;
292 case SQL_C_FLOAT:
293 return wxGRID_VALUE_FLOAT;
294 break;
295 case SQL_C_DOUBLE:
296 return wxGRID_VALUE_FLOAT;
297 break;
298 case SQL_C_DATE:
299 return wxGRID_VALUE_DATETIME;
300 break;
301 case SQL_C_TIME:
302 return wxGRID_VALUE_DATETIME;
303 break;
304 case SQL_C_TIMESTAMP:
305 return wxGRID_VALUE_DATETIME;
306 break;
307 default:
308 return wxGRID_VALUE_STRING;
309 break;
310 }
311 }
312 else
313 {
314 return m_ColInfo[col].wxtypename;
315 }
316 }
317 wxFAIL_MSG (_T("unknown column"));
318 return wxString();
319}
320
321bool wxDbGridTableBase::CanGetValueAs(int row, int col, const wxString& typeName)
322{
323 wxLogDebug(wxT("CanGetValueAs() on %i,%i"),row,col);
324 //Is this needed? As it will be validated on GetValueAsXXXX
325 ValidateRow(row);
326
327 if (typeName == wxGRID_VALUE_STRING)
328 {
329 //FIXME ummm What about blob field etc.
a144affe 330 return TRUE;
32a2907b
GT
331 }
332
333 if (m_data->IsColNull(m_ColInfo[col].DbCol))
334 {
a144affe 335 return FALSE;
32a2907b
GT
336 }
337
338 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
339 {
eae630f1 340 //If a virtual column then we can't find it's type. we have to
a144affe
GT
341 // return FALSE to get using wxVariant.
342 return FALSE;
32a2907b
GT
343 }
344 int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype;
eae630f1 345
32a2907b
GT
346 if (typeName == wxGRID_VALUE_DATETIME)
347 {
348 if ((sqltype == SQL_C_DATE) ||
eae630f1 349 (sqltype == SQL_C_TIME) ||
32a2907b
GT
350 (sqltype == SQL_C_TIMESTAMP))
351 {
a144affe 352 return TRUE;
32a2907b 353 }
a144affe 354 return FALSE;
32a2907b
GT
355 }
356 if (typeName == wxGRID_VALUE_NUMBER)
357 {
358 if ((sqltype == SQL_C_SSHORT) ||
eae630f1 359 (sqltype == SQL_C_USHORT) ||
32a2907b
GT
360 (sqltype == SQL_C_SLONG) ||
361 (sqltype == SQL_C_ULONG))
362 {
a144affe 363 return TRUE;
32a2907b 364 }
a144affe 365 return FALSE;
32a2907b
GT
366 }
367 if (typeName == wxGRID_VALUE_FLOAT)
368 {
369 if ((sqltype == SQL_C_SSHORT) ||
eae630f1 370 (sqltype == SQL_C_USHORT) ||
32a2907b
GT
371 (sqltype == SQL_C_SLONG) ||
372 (sqltype == SQL_C_ULONG) ||
373 (sqltype == SQL_C_FLOAT) ||
374 (sqltype == SQL_C_DOUBLE))
375 {
a144affe 376 return TRUE;
32a2907b 377 }
a144affe 378 return FALSE;
32a2907b 379 }
a144affe 380 return FALSE;
32a2907b
GT
381}
382
383bool wxDbGridTableBase::CanSetValueAs(int row, int col, const wxString& typeName)
384{
385 //Is this needed? As will be validated on SetValueAsXXXX
386 ValidateRow(row);
387
388 if (m_data->IsColNull(m_ColInfo[col].DbCol))
389 {
a144affe 390 return FALSE;
32a2907b
GT
391 }
392
393 if (typeName == wxGRID_VALUE_STRING)
394 {
395 //FIXME ummm What about blob field etc.
a144affe 396 return TRUE;
32a2907b
GT
397 }
398
399 if (!(m_data->GetColDefs()[(m_ColInfo[col].DbCol)].Updateable))
400 {
a144affe 401 return FALSE;
32a2907b
GT
402 }
403
404 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
405 {
eae630f1 406 //If a virtual column then we can't find it's type. we have to faulse to
32a2907b 407 //get using wxVairent.
a144affe 408 return FALSE;
32a2907b
GT
409 }
410
411 int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype;
412 if (typeName == wxGRID_VALUE_DATETIME)
413 {
414 if ((sqltype == SQL_C_DATE) ||
eae630f1 415 (sqltype == SQL_C_TIME) ||
32a2907b
GT
416 (sqltype == SQL_C_TIMESTAMP))
417 {
a144affe 418 return TRUE;
32a2907b 419 }
a144affe 420 return FALSE;
32a2907b
GT
421 }
422 if (typeName == wxGRID_VALUE_NUMBER)
423 {
424 if ((sqltype == SQL_C_SSHORT) ||
eae630f1 425 (sqltype == SQL_C_USHORT) ||
32a2907b
GT
426 (sqltype == SQL_C_SLONG) ||
427 (sqltype == SQL_C_ULONG))
428 {
a144affe 429 return TRUE;
32a2907b 430 }
a144affe 431 return FALSE;
32a2907b
GT
432 }
433 if (typeName == wxGRID_VALUE_FLOAT)
434 {
435 if ((sqltype == SQL_C_SSHORT) ||
eae630f1 436 (sqltype == SQL_C_USHORT) ||
32a2907b
GT
437 (sqltype == SQL_C_SLONG) ||
438 (sqltype == SQL_C_ULONG) ||
439 (sqltype == SQL_C_FLOAT) ||
440 (sqltype == SQL_C_DOUBLE))
441 {
a144affe 442 return TRUE;
32a2907b 443 }
a144affe 444 return FALSE;
32a2907b 445 }
a144affe 446 return FALSE;
32a2907b
GT
447}
448
449long wxDbGridTableBase::GetValueAsLong(int row, int col)
450{
451 ValidateRow(row);
452
453 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
454 {
455 wxFAIL_MSG (_T("You can not use GetValueAsLong for virtual columns"));
456 return 0;
457 }
458 int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype;
459 if ((sqltype == SQL_C_SSHORT) ||
eae630f1 460 (sqltype == SQL_C_USHORT) ||
32a2907b
GT
461 (sqltype == SQL_C_SLONG) ||
462 (sqltype == SQL_C_ULONG))
463 {
464 wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol);
465 return val.GetLong();
466 }
467 wxFAIL_MSG (_T("unknown column, "));
468 return 0;
469}
470
471double wxDbGridTableBase::GetValueAsDouble(int row, int col)
472{
473 wxLogDebug(wxT("GetValueAsDouble() on %i,%i"),row,col);
474 ValidateRow(row);
475
476 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
477 {
478 wxFAIL_MSG (_T("You can not use GetValueAsDouble for virtual columns"));
479 return 0.0;
480 }
481 int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype;
482 if ((sqltype == SQL_C_SSHORT) ||
eae630f1 483 (sqltype == SQL_C_USHORT) ||
32a2907b
GT
484 (sqltype == SQL_C_SLONG) ||
485 (sqltype == SQL_C_ULONG) ||
486 (sqltype == SQL_C_FLOAT) ||
487 (sqltype == SQL_C_DOUBLE))
488 {
489 wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol);
490 return val.GetDouble();
491 }
492 wxFAIL_MSG (_T("unknown column"));
493 return 0.0;
494}
495
496bool wxDbGridTableBase::GetValueAsBool(int row, int col)
497{
498 wxLogDebug(wxT("GetValueAsBool() on %i,%i"),row,col);
499 ValidateRow(row);
500
501 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
502 {
503 wxFAIL_MSG (_T("You can not use GetValueAsBool for virtual columns"));
504 return 0;
505 }
506 int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype;
507 if ((sqltype == SQL_C_SSHORT) ||
eae630f1 508 (sqltype == SQL_C_USHORT) ||
32a2907b
GT
509 (sqltype == SQL_C_SLONG) ||
510 (sqltype == SQL_C_ULONG))
511 {
512 wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol);
513 return val.GetBool();
514 }
515 wxFAIL_MSG (_T("unknown column, "));
516 return 0;
517}
518
519void* wxDbGridTableBase::GetValueAsCustom(int row, int col, const wxString& typeName)
520{
521 wxLogDebug(wxT("GetValueAsCustom() on %i,%i"),row,col);
522 ValidateRow(row);
eae630f1 523
32a2907b
GT
524 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
525 {
526 wxFAIL_MSG (_T("You can not use GetValueAsCustom for virtual columns"));
527 return NULL;
528 }
529 if (m_data->IsColNull(m_ColInfo[col].DbCol))
530 return NULL;
531
532 if (typeName == wxGRID_VALUE_DATETIME)
533 {
534 wxDbColDef *pColDefs = m_data->GetColDefs();
535 int sqltype = pColDefs[(m_ColInfo[col].DbCol)].SqlCtype;
536
537 if ((sqltype == SQL_C_DATE) ||
538 (sqltype == SQL_C_TIME) ||
539 (sqltype == SQL_C_TIMESTAMP))
540 {
541 wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol);
542 return new wxDateTime(val.GetDateTime());
543 }
544 }
545 wxFAIL_MSG (_T("unknown column data type "));
546 return NULL;
547}
548
549
550void wxDbGridTableBase::SetValueAsCustom(int row, int col, const wxString& typeName, void* value)
551{
552 wxLogDebug(wxT("SetValueAsCustom() on %i,%i"),row,col);
553 ValidateRow(row);
554
555 if (m_data->GetNumberOfColumns() <= m_ColInfo[col].DbCol)
556 {
557 wxFAIL_MSG (_T("You can not use SetValueAsCustom for virtual columns"));
558 return;
559 }
560
561 if (typeName == wxGRID_VALUE_DATETIME)
562 {
563 int sqltype = m_data->GetColDefs()[(m_ColInfo[col].DbCol)].SqlCtype;
564 if ((sqltype == SQL_C_DATE) ||
565 (sqltype == SQL_C_TIME) ||
566 (sqltype == SQL_C_TIMESTAMP))
567 {
568 //FIXME: you can't dynamic_cast from (void *)
569 //wxDateTime *date = wxDynamicCast(value, wxDateTime);
570 wxDateTime *date = (wxDateTime *)value;
571 if (!date)
572 {
573 wxFAIL_MSG (_T("Failed to convert data"));
574 return;
575 }
576 wxVariant val(date);
a144affe 577 m_rowmodified = TRUE;
32a2907b
GT
578 m_data->SetCol(m_ColInfo[col].DbCol,val);
579 }
580 }
581 wxFAIL_MSG (_T("unknown column data type"));
582 return ;
583}
584
585
586wxString wxDbGridTableBase::GetColLabelValue(int col)
587{
588 if (GetNumberCols() > col)
589 {
590 return m_ColInfo[col].Title;
591 }
592 wxFAIL_MSG (_T("unknown column"));
593 return wxString();
594}
595
596bool wxDbGridTableBase::IsEmptyCell(int row, int col)
597{
598 wxLogDebug(wxT("IsEmtpyCell on %i,%i"),row,col);
599
600 ValidateRow(row);
601 return m_data->IsColNull(m_ColInfo[col].DbCol);
602}
603
604
605wxString wxDbGridTableBase::GetValue(int row, int col)
606{
607 wxLogDebug(wxT("GetValue() on %i,%i"),row,col);
eae630f1 608
32a2907b
GT
609 ValidateRow(row);
610 wxVariant val = m_data->GetCol(m_ColInfo[col].DbCol);
611 wxLogDebug(wxT("\tReturning \"%s\"\n"),val.GetString().c_str());
eae630f1
DW
612
613 return val.GetString();
32a2907b
GT
614}
615
616
617void wxDbGridTableBase::SetValue(int row, int col,const wxString& value)
618{
619 wxLogDebug(wxT("SetValue() on %i,%i"),row,col);
620
621 ValidateRow(row);
622 wxVariant val(value);
623
a144affe 624 m_rowmodified = TRUE;
32a2907b
GT
625 m_data->SetCol(m_ColInfo[col].DbCol,val);
626}
627
628
629void wxDbGridTableBase::SetValueAsLong(int row, int col, long value)
630{
631 wxLogDebug(wxT("SetValueAsLong() on %i,%i"),row,col);
632
633 ValidateRow(row);
634 wxVariant val(value);
635
a144affe 636 m_rowmodified = TRUE;
32a2907b
GT
637 m_data->SetCol(m_ColInfo[col].DbCol,val);
638}
639
640
641void wxDbGridTableBase::SetValueAsDouble(int row, int col, double value)
642{
643 wxLogDebug(wxT("SetValueAsDouble() on %i,%i"),row,col);
644
645 ValidateRow(row);
646 wxVariant val(value);
647
a144affe 648 m_rowmodified = TRUE;
32a2907b
GT
649 m_data->SetCol(m_ColInfo[col].DbCol,val);
650
651}
652
653
654void wxDbGridTableBase::SetValueAsBool(int row, int col, bool value)
655{
656 wxLogDebug(wxT("SetValueAsBool() on %i,%i"),row,col);
657
658 ValidateRow(row);
659 wxVariant val(value);
660
a144affe 661 m_rowmodified = TRUE;
32a2907b
GT
662 m_data->SetCol(m_ColInfo[col].DbCol,val);
663}
664
665
666void wxDbGridTableBase::ValidateRow(int row)
667{
668 wxLogDebug(wxT("ValidateRow(%i) currently on row (%i). Array count = %i"),row,m_row,m_keys.GetCount());
669
670 if (row == m_row)
671 return;
672 Writeback();
673
674 //We add to row as Count is unsigned!
675 if ((unsigned)(row+1) > m_keys.GetCount())
676 {
677 wxLogDebug(wxT("\trow key unknown"));
678 // Extend Array, iterate through data filling with keys
679 m_data->SetRowMode(wxDbTable::WX_ROW_MODE_QUERY);
680 int trow;
681 for (trow = m_keys.GetCount(); trow <= row; trow++)
682 {
683 wxLogDebug(wxT("Fetching row %i.."), trow);
684 bool ret = m_data->GetNext();
685
686 wxLogDebug(wxT(" ...success=(%i)"),ret);
687 GenericKey k = m_data->GetKey();
688 m_keys.Add(k);
689 }
690 m_row = row;
691 }
692 else
693 {
694 wxLogDebug(wxT("\trow key known centering data"));
695 GenericKey k = m_keys.Item(row);
696 m_data->SetRowMode(wxDbTable::WX_ROW_MODE_INDIVIDUAL);
697 m_data->ClearMemberVars();
698 m_data->SetKey(k);
699 if (!m_data->QueryOnKeyFields())
700 {
701 wxDbLogExtendedErrorMsg("ODBC error during Query()\n\n", m_data->GetDb(),__FILE__,__LINE__);
702 }
703
704 m_data->GetNext();
705
706 m_row = row;
707 }
a144affe 708 m_rowmodified = FALSE;
32a2907b
GT
709}
710
711bool wxDbGridTableBase::Writeback() const
712{
713 if (!m_rowmodified)
714 {
a144affe 715 return TRUE;
32a2907b
GT
716 }
717
a144affe 718 bool result=TRUE;
32a2907b
GT
719 wxLogDebug(wxT("\trow key unknown"));
720
eae630f1 721// FIXME: this code requires dbtable support for record status
32a2907b
GT
722#if 0
723 switch (m_data->get_ModifiedStatus())
724 {
725 case wxDbTable::UpdatePending:
726 result = m_data->Update();
727 break;
728 case wxDbTable::InsertPending:
729 result = (m_data->Insert() == SQL_SUCCESS);
730 break;
731 default:
732 //Nothing
733 break;
734 }
735#else
736 wxLogDebug(wxT("WARNING : Row writeback not implemented "));
737#endif
738 return result;
739}
740
741#include <wx/arrimpl.cpp>
742
743WX_DEFINE_OBJARRAY(keyarray);
744
745#endif // #if wxUSE_NEW_GRID
746#endif // #if wxUSE_ODBC
747