如何从MySQL行类型生成数组?

如何从MySQL行类型生成数组?,mysql,d,variant,Mysql,D,Variant,我正在使用。我的代码: ResultRange MySQLTablesRange = mysqlconnection.query(`SELECT historysensor FROM TableName`); auto historysensor = MySQLTablesRange.array.filter!(a=>a[0].coerce!string.canFind("historysensor")); 但在发送字符串时,我得到的是historysensor不是一个数组,而是类似于:

我正在使用。我的代码:

ResultRange MySQLTablesRange = mysqlconnection.query(`SELECT historysensor FROM TableName`);
auto historysensor = MySQLTablesRange.array.filter!(a=>a[0].coerce!string.canFind("historysensor"));
但在发送字符串时,我得到的是
historysensor
不是一个数组,而是类似于:
行([historysensor_10774],[false])
的结构。 因此,每次为了获得价值,我都需要做大量的铸造工作,比如:

foreach(sensor;historysensor)
{
    writeln(sensor[0].coerce!string.split("_")[1]);
}

我如何将
历史传感器
制作成简单的数组,以便在没有
[0]的情况下工作。强制!字符串

您可以在执行其他操作之前映射它

auto historysensor = MySQLTablesRange.array.
   map!(a => a[0].coerce!string). // this is new
   filter!(a.canFind("historysensor"). // no need for coerce here now
   array; // convert to plain array of strings

顺便说一句,使用
filter
这里可能也是一个错误,将查询的这一部分设置为数据库执行,这样可能会更高效、更容易阅读。

您的
.array
没有用。如果你想要的话,就把它放在最后。亚当,为我没有
.array
而感到遗憾,我没有得到任何结果:(我不知道为什么:(我也尝试了
auto-historysensor=MySQLTablesRange.array.filter!(a=>a[0]。强制!string.canFind(“historysensor”))数组,但仍然得到<代码>行< /代码>数据类型。在调用之后,你是否正确地循环了它,或者在中间有其他查询或一些东西吗?我讨厌编辑。但是,当然,你会得到结果,这就是范围的返回,你必须“代码> map < /CODE >或者一些东西来拉一个单独的行。非常感谢艾达。m!你总是有完美的解决方案!