如何使用 Delphi 2007 从 firebird 中的时间戳字段获取毫秒值
我有一个 Firebird 数据库(在服务器版本 2.1.3 上运行),并使用 DBExpress 对象(使用 Interbase 驱动程序)通过 Delphi 2007 连接到它。
我在数据库中的一个表看起来像这样,
CREATE TABLE MYTABLE
(
MYDATE Timestamp NOT NULL,
MYINDEX Integer NOT NULL,
...
Snip
...
PRIMARY KEY (MYDATE ,MYINDEX)
);
我可以添加到表中,确定,并且在 Flame Robin 中,它将时间戳字段显示为具有毫秒值。
但是,当我在表上执行全选(select * from MYTABLE
)时,我无法获取毫秒值,因为它始终返回为 000。
这会导致重大问题,因为它是主表的一部分key(不幸的是我没有设计该表并且无权更改它)。
我已尝试以下方法来获取毫秒值:
sql1.fieldbyname('MYDATE').AsDateTime;
sql1.fieldbyname('MYDATE').AsSQLTimeStamp;
sql1.fieldbyname('MYDATE').AsStirng;
sql1.fieldbyname('MYDATE').AsFloat;
但格式化时它们都返回 14/09/2009 14:25:06.000 。
如何从时间戳中检索毫秒?
更新: 如果这对将来的任何人有帮助,这里是我尝试过的 DBExpress 驱动程序和结果。
- Embarcadero - dbExpress 驱动程序 火鸟(德尔福2010 试用版)- 时间戳中不支持毫秒。
- Chau Chee Yang 的 - dbExpress Firebird 驱动程序 (Delphi 2007) - 时间戳中不支持毫秒。
- UpScene - InterXpress 对于火鸟(德尔福 2007) - 时间戳支持毫秒。
- DevArt - 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)
);
I can add to the table OK, and in Flame Robin it shows the timestamp field as having a millisecond value.
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;
But they all return 14/09/2009 14:25:06.000 when formatted.
How do I retrieve the millisecond from a timestamp?
UPDATE:
In case this helps anyone in the future, here are the drivers I tried for DBExpress and the results.
- Embarcadero - dbExpress Driver for
Firebird (Delphi 2010
Trial Version) - Milliseconds not supported in timestamps. - Chau Chee Yang's - dbExpress
Driver for Firebird (Delphi 2007) - Milliseconds not supported in timestamps. - UpScene - InterXpress
for Firebird (Delphi
2007) - Milliseconds are supported in timestamps. - DevArt - dbExpress Driver for
InterBase (Delphi 2007) - Milliseconds are supported in timestamps.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的一位同事 (Edwin van der Kraan) 刚刚检查过:它适用于 FIBplus!
他检查了 FIBPlus 版本 6.9.6 和 Firebird 2.1.1。
他插入了一个 current_timestamp 插入,并使用 FormatDateTime('dd-mm-yyyy hh:nn:ss:zzz', TestpFIBDataSetMYDATE.Value) 提取它
然后他取回日期和时间,包括毫秒。
——杰罗恩
A colleague of mine (Edwin van der Kraan) just checked: it works with FIBplus!
He checked with FIBPlus version 6.9.6 and Firebird 2.1.1.
He inserte a current_timestamp insert, and extracted it with
FormatDateTime('dd-mm-yyyy hh:nn:ss:zzz', TestpFIBDataSetMYDATE.Value)
Then he got back the date and time including milliseconds.
--jeroen
我不知道 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.
Firebird FAQ #305 解释了如何通过简单的 varchar CAST 轻松解决此问题。
Firebird FAQ #305 explains how to easily work around this via simple varchar CAST.
Firebird dbx 驱动程序存在(您可以尝试一下):
http://sites.google.com/site/ dbxfirebird/(免费)
http://www.upscene.com/products .dbx.dbx_fb.php
Firebird dbx drivers exist (you can try them):
http://sites.google.com/site/dbxfirebird/ (free)
http://www.upscene.com/products.dbx.dbx_fb.php