开发者

sqlite odbc getting hour min. sec

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 t开发者_运维技巧ype:

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.


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.


Years passed but nothing changed :)

For those who would like to know the actual reason:

...from sqlite3odbc.c

     if (p->coldef && p->coldef <= 16) {
         sprintf(p->strbuf, "%04d-%02d-%02d %02d:%02d:00.000",
                 ((TIMESTAMP_STRUCT *) p->param)->year,
                 ((TIMESTAMP_STRUCT *) p->param)->month,
                 ((TIMESTAMP_STRUCT *) p->param)->day,
                 ((TIMESTAMP_STRUCT *) p->param)->hour,
                 ((TIMESTAMP_STRUCT *) p->param)->minute);
     } else if (p->coldef && p->coldef <= 19) {
         sprintf(p->strbuf, "%04d-%02d-%02d %02d:%02d:%02d.000",
                 ((TIMESTAMP_STRUCT *) p->param)->year,
                 ((TIMESTAMP_STRUCT *) p->param)->month,
                 ((TIMESTAMP_STRUCT *) p->param)->day,
                 ((TIMESTAMP_STRUCT *) p->param)->hour,
                 ((TIMESTAMP_STRUCT *) p->param)->minute,
                 ((TIMESTAMP_STRUCT *) p->param)->second);
     } else {
         sprintf(p->strbuf, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
                 ((TIMESTAMP_STRUCT *) p->param)->year,
                 ((TIMESTAMP_STRUCT *) p->param)->month,
                 ((TIMESTAMP_STRUCT *) p->param)->day,
                 ((TIMESTAMP_STRUCT *) p->param)->hour,
                 ((TIMESTAMP_STRUCT *) p->param)->minute,
                 ((TIMESTAMP_STRUCT *) p->param)->second,
                 len);
     }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜