如何使用Delphi 2007从Firebird中的Timestamp字段获取毫秒值 [英] How to get the millisecond value from a Timestamp field in firebird with Delphi 2007

查看:127
本文介绍了如何使用Delphi 2007从Firebird中的Timestamp字段获取毫秒值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Firebird数据库(在服务器版本2.1.3上运行),并且正在使用DBExpress对象(使用Interbase驱动程序)与Delphi 2007进行连接

I have a Firebird database (running on server version 2.1.3) and am connecting to it with Delphi 2007 using the DBExpress objects (using the Interbase driver)

我在数据库中的一个表看起来像这样

One of my tables in the database looks something like this

CREATE TABLE MYTABLE
(
  MYDATE Timestamp NOT NULL,
  MYINDEX Integer NOT NULL,
  ...
  Snip
  ...
  PRIMARY KEY (MYDATE ,MYINDEX)
);

我可以添加到表OK中,并且在Flame Robin中将timestamp字段显示为毫秒值。

I can add to the table OK, and in Flame Robin it shows the timestamp field as having a millisecond value.

但是当我在表上执行全选( select * from MYTABLE )时,我无法获得毫秒值,因为它始终返回为000。

But when I do a select all (select * from MYTABLE) on the table I can not get the millisecond value, as it is always returned as 000.

由于它是主键的一部分,因此,这会引起严重的问题(不幸的是,我没有设计表并且没有

This causes major problems as it is part of the primary key (unfortunately I didn't design the table and don't have authority to change it).

我尝试了以下方法来获取毫秒值:

I have tried the following to get the millisecond value:

sql1.fieldbyname('MYDATE').AsDateTime;
sql1.fieldbyname('MYDATE').AsSQLTimeStamp;
sql1.fieldbyname('MYDATE').AsStirng;
sql1.fieldbyname('MYDATE').AsFloat;

但是它们在格式化时都返回14/09/2009 14:25:06.000。

But they all return 14/09/2009 14:25:06.000 when formatted.

如何从时间戳中检索毫秒?

How do I retrieve the millisecond from a timestamp?

更新:
在这种情况以后对任何人都有帮助,这是我为DBExpress尝试的驱动程序和结果。

UPDATE: In case this helps anyone in the future, here are the drivers I tried for DBExpress and the results.

推荐答案

我不知道Firebird是否真正支持毫秒,但我知道Delphi 2007的InterBase驱动程序不支持毫秒。这是因为InterBase在其C API中不返回毫秒;尽管InterBase将DateTimes存储为毫秒级精度,但是InterBase API在不包含毫秒字段的C TM结构中返回时间。因此,为InterBase设计的dbExpress驱动程序将不支持该功能。因此,您需要至少更改驱动程序,前提是Firebird实际上完全支持此驱动程序。

I don't know if Firebird actually supports milliseconds, but I know for a fact that the InterBase driver for Delphi 2007 does not. This is because InterBase does not return milliseconds in its C API; although InterBase stores DateTimes to sub-milliseconds precision, the InterBase API returns times in a C TM struct which does not contain a millisecond field. Therefore, the dbExpress driver designed for InterBase is not going to support that. So, you will need to change drivers at a minimum, presuming that Firebird actually supports this at all.

这篇关于如何使用Delphi 2007从Firebird中的Timestamp字段获取毫秒值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆