+} // wxDbTable::DeleteCursor()
+
+//////////////////////////////////////////////////////////////
+// wxDbGrid support functions
+//////////////////////////////////////////////////////////////
+
+void wxDbTable::SetRowMode(const rowmode_t rowmode)
+{
+ if (!m_hstmtGridQuery)
+ {
+ m_hstmtGridQuery = GetNewCursor(false,false);
+ if (!bindCols(*m_hstmtGridQuery))
+ return;
+ }
+
+ m_rowmode = rowmode;
+ switch (m_rowmode)
+ {
+ case WX_ROW_MODE_QUERY:
+ SetCursor(m_hstmtGridQuery);
+ break;
+ case WX_ROW_MODE_INDIVIDUAL:
+ SetCursor(hstmtDefault);
+ break;
+ default:
+ assert(0);
+ }
+} // wxDbTable::SetRowMode()
+
+
+wxVariant wxDbTable::GetCol(const int col) const
+{
+ wxVariant val;
+ if ((col < noCols) && (!IsColNull(col)))
+ {
+ switch (colDefs[col].SqlCtype)
+ {
+ case SQL_CHAR:
+ case SQL_VARCHAR:
+ val = (char *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_LONG:
+ case SQL_C_SLONG:
+ val = *(long *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_SHORT:
+ case SQL_C_SSHORT:
+ val = (long int )(*(short *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_ULONG:
+ val = (long)(*(unsigned long *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_TINYINT:
+ val = (long)(*(char *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_UTINYINT:
+ val = (long)(*(unsigned char *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_USHORT:
+ val = (long)(*(UWORD *)(colDefs[col].PtrDataObj));
+ break;
+ case SQL_C_DATE:
+ val = (DATE_STRUCT *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_TIME:
+ val = (TIME_STRUCT *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_TIMESTAMP:
+ val = (TIMESTAMP_STRUCT *)(colDefs[col].PtrDataObj);
+ break;
+ case SQL_C_DOUBLE:
+ val = *(double *)(colDefs[col].PtrDataObj);
+ break;
+ default:
+ assert(0);
+ }
+ }
+ return val;
+} // wxDbTable::GetCol()
+
+
+void csstrncpyt(char *s, const char *t, int n)
+{
+ while ((*s++ = *t++) && --n)
+ {};
+
+ *s = '\0';
+}
+
+void wxDbTable::SetCol(const int col, const wxVariant val)
+{
+ //FIXME: Add proper wxDateTime support to wxVariant..
+ wxDateTime dateval;
+
+ SetColNull(col, val.IsNull());
+
+ if (!val.IsNull())
+ {
+ if ((colDefs[col].SqlCtype == SQL_C_DATE)
+ || (colDefs[col].SqlCtype == SQL_C_TIME)
+ || (colDefs[col].SqlCtype == SQL_C_TIMESTAMP))
+ {
+ //Returns null if invalid!
+ if (!dateval.ParseDate(val.GetString()))
+ SetColNull(col,true);
+ }
+
+ switch (colDefs[col].SqlCtype)
+ {
+ case SQL_CHAR:
+ case SQL_VARCHAR:
+ csstrncpyt((char *)(colDefs[col].PtrDataObj),
+ val.GetString().c_str(),
+ colDefs[col].SzDataObj-1);
+ break;
+ case SQL_C_LONG:
+ case SQL_C_SLONG:
+ *(long *)(colDefs[col].PtrDataObj) = val;
+ break;
+ case SQL_C_SHORT:
+ case SQL_C_SSHORT:
+ *(short *)(colDefs[col].PtrDataObj) = val.GetLong();
+ break;
+ case SQL_C_ULONG:
+ *(unsigned long *)(colDefs[col].PtrDataObj) = val.GetLong();
+ break;
+ case SQL_C_TINYINT:
+ *(char *)(colDefs[col].PtrDataObj) = val.GetChar();
+ break;
+ case SQL_C_UTINYINT:
+ *(unsigned char *)(colDefs[col].PtrDataObj) = val.GetChar();
+ break;
+ case SQL_C_USHORT:
+ *(unsigned short *)(colDefs[col].PtrDataObj) = val.GetLong();
+ break;
+ //FIXME: Add proper wxDateTime support to wxVariant..
+ case SQL_C_DATE:
+ {
+ DATE_STRUCT *dataptr =
+ (DATE_STRUCT *)colDefs[col].PtrDataObj;
+
+ dataptr->year = dateval.GetYear();
+ dataptr->month = dateval.GetMonth()+1;
+ dataptr->day = dateval.GetDay();
+ }
+ break;
+ case SQL_C_TIME:
+ {
+ TIME_STRUCT *dataptr =
+ (TIME_STRUCT *)colDefs[col].PtrDataObj;
+
+ dataptr->hour = dateval.GetHour();
+ dataptr->minute = dateval.GetMinute();
+ dataptr->second = dateval.GetSecond();
+ }
+ break;
+ case SQL_C_TIMESTAMP:
+ {
+ TIMESTAMP_STRUCT *dataptr =
+ (TIMESTAMP_STRUCT *)colDefs[col].PtrDataObj;
+ dataptr->year = dateval.GetYear();
+ dataptr->month = dateval.GetMonth()+1;
+ dataptr->day = dateval.GetDay();
+
+ dataptr->hour = dateval.GetHour();
+ dataptr->minute = dateval.GetMinute();
+ dataptr->second = dateval.GetSecond();
+ }
+ break;
+ case SQL_C_DOUBLE:
+ *(double *)(colDefs[col].PtrDataObj) = val;
+ break;
+ default:
+ assert(0);
+ } // switch
+ } // if (!val.IsNull())
+} // wxDbTable::SetCol()
+
+
+GenericKey wxDbTable::GetKey()
+{
+ void *blk;
+ char *blkptr;
+
+ blk = malloc(m_keysize);
+ blkptr = (char *) blk;
+
+ int i;
+ for (i=0; i < noCols; i++)
+ {
+ if (colDefs[i].KeyField)
+ {
+ memcpy(blkptr,colDefs[i].PtrDataObj, colDefs[i].SzDataObj);
+ blkptr += colDefs[i].SzDataObj;
+ }
+ }
+
+ GenericKey k = GenericKey(blk, m_keysize);
+ free(blk);
+
+ return k;
+} // wxDbTable::GetKey()
+
+
+void wxDbTable::SetKey(const GenericKey& k)
+{
+ void *blk;
+ char *blkptr;
+
+ blk = k.GetBlk();
+ blkptr = (char *)blk;
+
+ int i;
+ for (i=0; i < noCols; i++)
+ {
+ if (colDefs[i].KeyField)
+ {
+ SetColNull(i, false);
+ memcpy(colDefs[i].PtrDataObj, blkptr, colDefs[i].SzDataObj);
+ blkptr += colDefs[i].SzDataObj;
+ }
+ }
+} // wxDbTable::SetKey()
+