sqlite odbc 获取小时分钟。秒

发布于 2024-09-28 18:34:07 字数 614 浏览 0 评论 0原文

我正在使用 sqliteodbc ,由于某种原因,它无法获取小时、分钟和秒。我使用以下方式绑定列:

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

noteTimeStamp.submitTime 是一种时间戳数据类型:

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

我的小时、分钟、秒和分数始终显示为 0。这对我使用 access 数据库有效。还有其他人遇到过这个问题吗?一周前我就可以发誓这对我有用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

左秋 2024-10-05 18:34:07

好吧,我不明白为什么会发生这种情况,我是这样解决的:

首先我在类型的末尾添加了一个数组

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;

,然后添加了#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);

,然后自己用一个小函数调整了字符串的速度,

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
}

我仍在尝试弄清楚弄清楚为什么我的原始代码不能与 sqlite 一起使用。

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.

忆梦 2024-10-05 18:34:07

几年过去了,但什么都没有改变:)

对于那些想知道实际原因的人:

...来自 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);
     }

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);
     }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文