数据对于变量而言太大

数据对于变量而言太大

本文介绍了在获取“数据对于变量而言太大”时,如何正确访问FireDAC数据集的VARCHAR(MAX)参数值。错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序使用SQL Server 2014更新和访问数据。

Our application updates and accesses data using SQL Server 2014.

我有一个表,其中最后一列(内容)创建为 VARCHAR(MAX)

I have a table of which the last column ('Contents') is created as VARCHAR(MAX).

我们正在使用Delphi XE8,并且正在使用FireDAC TFDQuery 组件以更新此列。

We are using Delphi XE8, and are using a FireDAC TFDQuery component to update this column.

.....
FDquery.ParamByName('Contents').AsString:=Contents;
FDquery.ExecSQL;

运行此更新时,出现以下错误:

When running this update, I get the following error:

'Contents '可以是长度可变的字符串。

'Contents' can be string of varying length.

浏览网络时,我发现的唯一合理的简单解决方案是按如下方式更改查询:

Browsing the web, the only reasonably simple solution that I found is changing the query as follows:

 FDquery.ParamByName('Contents').AsWideMemo:=Contents;
 FDquery.ExecSQL;

这是可以接受的,还是应该以不同的方式处理?

Is this acceptable, or should I be handling this differently?

内容没有什么特别的,正如我提到的那样,它只是一个长字符串。

There is nothing fancy with 'Contents', as I mentioned, it is simply a long string.

推荐答案

是否可以通过AsWideMemo属性访问VARCHAR(MAX)类型的字段参数值?



不是特别如此。对于字段参数使用访问权限。这是因为您可能会将非Unicode字段的Unicode值发送到DBMS。来自:

Is it acceptable to access a VARCHAR(MAX) type field parameter value by the AsWideMemo property?

Not especially. For VARCHAR(MAX) field parameter use AsMemo access. It is because you could be sending to your DBMS Unicode values to a non Unicode field. From the reference:

如果您的字段为,使用访问参数值将是正确的选择。

If your field would be NVARCHAR(MAX), using AsWideMemo access to the parameter value would be the right choice.

为什么会发生这种情况?通过属性,引擎还会设置参数(如果您之前未明确进行过此操作)。在这种特殊情况下,您暗示引擎如果将参数数据类型设置为或,只需通过属性。

Some background to why this happens. By accessing a certain parameter value by As<T> property, the engine also sets the parameter DataType, if you don't explicitly do that before. In this particular case you hinted the engine that it's fine for you if it sets the parameter data type to ftWideString or ftString just by accessing parameter value by the AsString property.

由于数据类型映射,该参数被视为或数据类型,包括其限制(因此

And thanks to data type mapping such parameter is treated as the VARCHAR[n] or NVARCHAR[n] data type including its limits (hence you got a string length limit error here).

类似,当您通过属性,默认为数据类型,它映射到。如您所料,
访问权限默认为映射到数据类型。如果您不想显式设置参数数据类型,而是使用此提示,请查阅手册,以了解每个使用的访问属性如何设置默认参数数据类型。

Similar, just more specific data type hint is used when you access the parameter value by AsMemo property, it defaults to ftMemo data type which maps to VARCHAR(MAX). And as you may predict, AsWideMemo access defaults to ftWideMemo which maps to NVARCHAR(MAX) data type. If you don't want to explicitly set the parameter data types but use this hinting, consult the manual to see how each used access property sets the default parameter data type.

这篇关于在获取“数据对于变量而言太大”时,如何正确访问FireDAC数据集的VARCHAR(MAX)参数值。错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 12:33