Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux下如何从C编写的udf返回firebird时间戳_C_Linux_Firebird_Udf - Fatal编程技术网

Linux下如何从C编写的udf返回firebird时间戳

Linux下如何从C编写的udf返回firebird时间戳,c,linux,firebird,udf,C,Linux,Firebird,Udf,有人能告诉我如何从用C编写的udf返回firebird时间戳类型吗 更具体地说,Firebird中是否有对应于时间戳类型的C类型?如果是,哪个标题包含其定义?谢谢 您需要使用在ibase.h中定义的ISC\u时间戳。你应该能够使用 iCyCon代码的时间戳转换为 TM >代码> 时间> h >代码>,但是由于我没有在C或C++中编程,我没有更详细的信息或一个示例准备好。 < P>使用马克的建议,这里有一个实现: #include <time.h> #include <ibase

有人能告诉我如何从用C编写的udf返回firebird时间戳类型吗


更具体地说,Firebird中是否有对应于时间戳类型的C类型?如果是,哪个标题包含其定义?谢谢

您需要使用在
ibase.h
中定义的
ISC\u时间戳。你应该能够使用<代码> iCyCon代码的时间戳<代码>转换为<代码> TM >代码> <代码>时间> h >代码>,但是由于我没有在C或C++中编程,我没有更详细的信息或一个示例准备好。

< P>使用马克的建议,这里有一个实现:

#include <time.h>
#include <ibase.h>
#include <ib_util.h>


typedef long long int SINT64;


ISC_TIME encode_time(int hours, int minutes, int seconds, int fractions)
{

    return ((hours * 60 + minutes) * 60 + seconds) * ISC_TIME_SECONDS_PRECISION + fractions;
}

ISC_DATE encodeDate(const struct tm* t){
    // Convert a calendar date to a numeric day
    // (the number of days since the base date)

    const int day = t->tm_mday;
    int month = t->tm_mon + 1;
    int year = t->tm_year + 1900;

    if (month > 2)
        month -= 3;
    else
    {
        month += 9;
        year -= 1;
    }

    const int c = year / 100;
    const int ya = year - 100 * c;


    return (ISC_DATE) (((SINT64) 146097 * c) / 4 +
                   (1461 * ya) / 4 +
                   (153 * month + 2) / 5 + day + 1721119 - 2400001);
}



ISC_TIMESTAMP* UTCServerTime(){
    time_t t = time(NULL);

    struct tm utc;
    gmtime_r(&t, &utc);

    ISC_TIMESTAMP* ib_utc = (ISC_TIMESTAMP*)
        ib_util_malloc(sizeof(ISC_TIMESTAMP));

    ib_utc->timestamp_date = encodeDate(&utc);
    ib_utc->timestamp_time = encode_time(utc.tm_hour,utc.tm_min,utc.tm_sec, 0);

    return ib_utc;
}
#包括
#包括
#包括
typedef long long int SINT64;
ISC_时间编码_时间(整数小时、整数分钟、整数秒、整数分数)
{
返回((小时*60+分钟)*60+秒)*ISC\u时间\u秒\u精度+分数;
}
ISC_日期编码日期(const struct tm*t){
//将日历日期转换为数字日期
//(自基准日期起的天数)
const int day=t->tm\u mday;
整月=t->tm\u mon+1;
int year=t->tm\U year+1900;
如果(月份>2)
月份-=3;
其他的
{
月份+=9;
年份-=1;
}
const int c=年份/100;
const int ya=年份-100*c;
申报表(ISC_日期)(SINT64)146097*c)/4+
(1461*ya)/4+
(153*月+2)/5+日+1721119-2400001);
}
ISC_时间戳*UTCServerTime(){
时间t=时间(空);
结构tm utc;
gmtime\U r&t和utc);
ISC_时间戳*ib_utc=(ISC_时间戳*)
ib_util_malloc(sizeof(ISC_时间戳));
ib_utc->timestamp_date=encodeDate(&utc);
ib_utc->timestamp_time=编码_时间(utc.tm_小时,utc.tm_分钟,utc.tm_秒,0);
返回ib_utc;
}