Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.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
Delphi 德尔福7&x2B;Zeos:如何防止sqlite 3将日期和整数/浮点转换为字符串?_Delphi_Sqlite_Delphi 7_Zeos - Fatal编程技术网

Delphi 德尔福7&x2B;Zeos:如何防止sqlite 3将日期和整数/浮点转换为字符串?

Delphi 德尔福7&x2B;Zeos:如何防止sqlite 3将日期和整数/浮点转换为字符串?,delphi,sqlite,delphi-7,zeos,Delphi,Sqlite,Delphi 7,Zeos,测试数据库: create table a ( d date not null primary key); create table b ( d date not null primary key); insert into a values ('2013-01-01'); insert into b values ('2014-01-01'); 在Delphi 7中使用Zeos lib时,这些查询都返回TDateTimeField: select d from a order by 1;

测试数据库:

create table a ( d date not null primary key);
create table b ( d date not null primary key);
insert into a values ('2013-01-01');
insert into b values ('2014-01-01');
在Delphi 7中使用Zeos lib时,这些查询都返回TDateTimeField:

select d from a order by 1;

select d from b order by 1;

select d from a union all select d from b;

select * from (select d from a union all select d from b) s;
但是,此查询返回一个TStringField:

select * from (select d from a union all select d from b) s order by 1;
select * from ( select * from c union all select * from d) s order by 1
问题:

  • 为什么呢
  • 如何防止这种情况发生
  • 这是虫子吗?对结果集进行排序究竟是如何改变列的类型的
  • 这是一个严重的问题,因为我无法从程序生成SQL查询并在设计时创建的TZReadOnlyQuery中打开它们
更新:它也不适用于整数

create table c ( id integer not null primary key);
create table d ( id integer not null primary key);
insert into c values(1);
insert into d values(2);
这些将导致TLargeIntField:

select * from c order by 1

select * from d order by 1

select * from ( select * from c union all select * from d) s
但是,这会导致TStringField:

select * from (select d from a union all select d from b) s order by 1;
select * from ( select * from c union all select * from d) s order by 1
如本文所述:

SQLite没有为存储日期预留存储类 和/或时间。相反,SQLite的内置日期和时间函数 能够将日期和时间存储为文本、实数或整数 价值观:

文本为ISO8601字符串(“YYYY-MM-DD HH:MM:SS.SSS”)<像朱利安一样真实 day number,自11月12日格林威治中午以来的天数 公元前244714年,根据公历公历
整数 作为Unix时间,自UTC 1970-01-01 00:00:00以来的秒数。 应用程序可以选择将日期和时间存储在其中任何一个中 格式,并使用内置的日期和 时间函数

那么,你能试试下面的陈述并公布结果吗

select date(*) as test from (select date(d) from a union all select date(d) from b) s order by 1;

问题显然在于“全民联合”。通过一个简单的“联合”,它确实可以正常工作!实数域也是如此。我刚查过。如果在此之前添加订单,则订单将从TFloatField更改为TStringField。太糟糕了。我刚刚用Zeos7.1.3-stable测试了这个,它按照预期创建了一个TDateField和一个TLargeintField(尽管在Delphi XE中),我知道SQLite在内部只存储这三种类型。但是,此类型由底层zeos库自动转换!我的问题是关于Delphi7+ZeosLib+SQLite的。因此,如果ZeosLib可以将union select的日期字符串转换为TDateField字段,那么为什么不能对union all select执行相同的操作呢?有没有一种方法可以编写符合我要求的查询?当然我不想重写zeoslib。你用的是哪个版本的Zeos?我不知道。这个项目是几年前用Delphi7创建的。大约在2004年。我很乐意升级到一个新版本,但我担心它会破坏所有其他代码。这一定是关于工会和秩序的基本问题。我刚刚发现这个问题也适用于实数!除非我将union与order by组合,否则将转换为TFloatField。然后它们变成了弦-(好的,请进行上面的测试并告诉我结果。我正在安装Zeos以进行试用。我刚刚在Delphi 7上安装了最新的ZeosLib,它没有破坏我的代码。幸运的是,您的查询将作为日期字段打开。但下一个问题是:它仍然不能处理整数。(将编辑问题)