views:

13

answers:

1

I am using sqliteodbc and for some reason it won't get the hours, minutes, and seconds. I bind the column using this:

SQLBindCol(hTimeStampNotes, 5, SQL_C_TIMESTAMP, &(noteTimeStamp.submitTime), 16, &junkLong);

noteTimeStamp.submitTime is a time stamp data type:

typedef struct tagTimeStampType {//TIMESTAMP_STRUCT 
    short year;
    short month;
    short day;
    short hour;
    short minute;
    short second;
    unsigned int fraction; 
} TimeStampType;//TIMESTAMP_STRUCT;

My hour, minute, second, and fraction always come out as 0. This works for me using an access database. Has anybody else had this problem? I could have sworn that this was working for me a week ago.

A: 

Ok I couldn't figure out why this was happening here is how I got around it:

first I added an array to the end of the type

typedef struct tagTimeStampType//TIMESTAMP_STRUCT 
   {
   short year;
   short month;
   short day;
   short hour;
   short minute;
   short second;
   unsigned int fraction; 
   char  timeStampStr[20];
   } TimeStampType;//TIMESTAMP_STRUCT;

then added #ifdef

#ifdef SQLITE
   SQLBindCol(hTimeStampNotes, 5, SQL_C_CHAR, noteTimeStamp.submitTime.timeStampStr, 20, &junkLong);
#else
   SQLBindCol(hTimeStampNotes, 5, SQL_C_TIMESTAMP, &(noteTimeStamp.submitTime), 16, &junkLong);

and just paced the string myself with a little function

void TimeStampPrep(TimeStampType *timeStamp)
{
#ifdef SQLITE
   timeStamp->year = atoi(timeStamp->timeStampStr);
   timeStamp->month = atoi(&(timeStamp->timeStampStr[5]));
   timeStamp->day = atoi(&(timeStamp->timeStampStr[8]));
   timeStamp->hour = atoi(&(timeStamp->timeStampStr[11]));
   timeStamp->minute = atoi(&(timeStamp->timeStampStr[14]));
   timeStamp->second = atoi(&(timeStamp->timeStampStr[17]));
   return;
#else
   return;
#endif
}

I am still trying to figure out why this my original code wouldn't work with sqlite.

Tbone