+ if (!val.IsNull())
+ {
+ if ((colDefs[colNumber].SqlCtype == SQL_C_DATE)
+ || (colDefs[colNumber].SqlCtype == SQL_C_TIME)
+ || (colDefs[colNumber].SqlCtype == SQL_C_TIMESTAMP))
+ {
+ //Returns null if invalid!
+ if (!dateval.ParseDate(val.GetString()))
+ SetColNull((UWORD)colNumber, true);
+ }
+
+ switch (colDefs[colNumber].SqlCtype)
+ {
+#if wxUSE_UNICODE
+ #if defined(SQL_WCHAR)
+ case SQL_WCHAR:
+ #endif
+ #if defined(SQL_WVARCHAR)
+ case SQL_WVARCHAR:
+ #endif
+#endif
+ case SQL_CHAR:
+ case SQL_VARCHAR:
+ csstrncpyt((wxChar *)(colDefs[colNumber].PtrDataObj),
+ val.GetString().c_str(),
+ colDefs[colNumber].SzDataObj-1); //TODO: glt ??? * sizeof(wxChar) ???
+ break;
+ case SQL_C_LONG:
+ case SQL_C_SLONG:
+ *(long *)(colDefs[colNumber].PtrDataObj) = val;
+ break;
+ case SQL_C_SHORT:
+ case SQL_C_SSHORT:
+ *(short *)(colDefs[colNumber].PtrDataObj) = (short)val.GetLong();
+ break;
+ case SQL_C_ULONG:
+ *(unsigned long *)(colDefs[colNumber].PtrDataObj) = val.GetLong();
+ break;
+ case SQL_C_TINYINT:
+ *(wxChar *)(colDefs[colNumber].PtrDataObj) = val.GetChar();
+ break;
+ case SQL_C_UTINYINT:
+ *(wxChar *)(colDefs[colNumber].PtrDataObj) = val.GetChar();
+ break;
+ case SQL_C_USHORT:
+ *(unsigned short *)(colDefs[colNumber].PtrDataObj) = (unsigned short)val.GetLong();
+ break;
+ //FIXME: Add proper wxDateTime support to wxVariant..
+ case SQL_C_DATE:
+ {
+ DATE_STRUCT *dataptr =
+ (DATE_STRUCT *)colDefs[colNumber].PtrDataObj;
+
+ dataptr->year = (SWORD)dateval.GetYear();
+ dataptr->month = (UWORD)(dateval.GetMonth()+1);
+ dataptr->day = (UWORD)dateval.GetDay();
+ }
+ break;
+ case SQL_C_TIME:
+ {
+ TIME_STRUCT *dataptr =
+ (TIME_STRUCT *)colDefs[colNumber].PtrDataObj;
+
+ dataptr->hour = dateval.GetHour();
+ dataptr->minute = dateval.GetMinute();
+ dataptr->second = dateval.GetSecond();
+ }
+ break;
+ case SQL_C_TIMESTAMP:
+ {
+ TIMESTAMP_STRUCT *dataptr =
+ (TIMESTAMP_STRUCT *)colDefs[colNumber].PtrDataObj;
+ dataptr->year = (SWORD)dateval.GetYear();
+ dataptr->month = (UWORD)(dateval.GetMonth()+1);
+ dataptr->day = (UWORD)dateval.GetDay();
+
+ dataptr->hour = dateval.GetHour();
+ dataptr->minute = dateval.GetMinute();
+ dataptr->second = dateval.GetSecond();
+ }
+ break;
+ case SQL_C_DOUBLE:
+ *(double *)(colDefs[colNumber].PtrDataObj) = val;
+ break;
+ default:
+ assert(0);
+ } // switch
+ } // if (!val.IsNull())
+} // wxDbTable::SetCol()
+
+
+GenericKey wxDbTable::GetKey()
+{
+ void *blk;
+ wxChar *blkptr;
+
+ blk = malloc(m_keysize);
+ blkptr = (wxChar *) blk;
+
+ int i;
+ for (i=0; i < m_numCols; 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;
+ wxChar *blkptr;
+
+ blk = k.GetBlk();
+ blkptr = (wxChar *)blk;
+
+ int i;
+ for (i=0; i < m_numCols; i++)
+ {
+ if (colDefs[i].KeyField)
+ {
+ SetColNull((UWORD)i, false);
+ memcpy(colDefs[i].PtrDataObj, blkptr, colDefs[i].SzDataObj);
+ blkptr += colDefs[i].SzDataObj;
+ }
+ }
+} // wxDbTable::SetKey()
+
+
+#endif // wxUSE_ODBC