ColdFusion中的数据类型支持querynew()

时间:2022-01-12 20:23:56

Does anyone know of a way to store values as NVARCHAR in a manually created query in ColdFusion using the querynew() function? I have multiple parts of a largish program relying on using a query as an input point to construct an excel worksheet (using Ben's POI) so it's somewhat important I can continue to use it as a query to avoid a relatively large rewrite.

有没有人知道使用querynew()函数在ColdFusion中手动创建的查询中将值存储为NVARCHAR的方法?我有一个较大的程序的多个部分依赖于使用查询作为输入点来构建一个excel工作表(使用Ben的POI),所以有点重要我可以继续使用它作为查询来避免相对大的重写。

The problem came up when a user tried storing something that is outside of the VARCHAR range, some Japanese characters and such.

当用户尝试存储VARCHAR范围之外的东西,一些日文字符等时,问题出现了。

Edit: If this is not possible, and you are 100% sure, I'd like to know that too :)

编辑:如果这是不可能的,你100%肯定,我也想知道:)

5 个解决方案

#1


1  

When creating a ColdFusion query with queryNew(), you can pass a list of datatypes as a second argument. For example:

使用queryNew()创建ColdFusion查询时,可以将数据类型列表作为第二个参数传递。例如:

<cfset x = queryNew("foo,bar","integer,varchar") />

Alternatively, you can use cf_sql_varchar (which you would use in queryparam tags). According to the livedocs, nvarchar is accepted for the CF varchar data type.

或者,您可以使用cf_sql_varchar(您将在queryparam标记中使用)。根据livesocs,CF varchar数据类型接受nvarchar。

QueryParam livedoc (referenced for nvarchar data type)

QueryParam livedoc(引用nvarchar数据类型)

QueryNew livedoc (referenced for data type definition)

QueryNew livedoc(引用数据类型定义)

Managing Data Types livedoc (referenced for using cf_sql_datatype)

管理数据类型livedoc(使用cf_sql_datatype引用)

#2


1  

The only thing I've been able to come up with so far is this:

到目前为止,我唯一能想出的就是:

<cfset x = QueryNew("foobar")/>
<cfset queryAddRow(x) />
<cfset querySetCell(x, "foobar", chr(163)) />
<cfdump var="#x#">

When dumped, this query does contain the British Pound symbol.

转储时,此查询确实包含英镑符号。

I haven't tried this with Ben's POI utility, but hopefully it helps you some.

我没有尝试使用Ben的POI实用程序,但希望它能帮到你一些。

#3


1  

You might try using JavaCast() to set the values, as shown here: Kinky Solutions (Ben Nadel) on JavaCast()

您可以尝试使用JavaCast()来设置值,如下所示:JavaCast上的Kinky Solutions(Ben Nadel)()

#4


1  

Make sure you're using Unicode end-to-end.

确保您使用的是端到端的Unicode。

#5


0  

This is pretty much all you need:

这几乎是你所需要的:

<cfprocessingdirective pageEncoding="utf-8"> 

ColdFusion (& java) stores string in UTF-8 by default. All you need is to tell CF that the encoding of the page is UTF8. The alternative way is to save the Byte-order mark (BOM), but Eclipse/CFEclipse doesn't do it.

ColdFusion(&java)默认以UTF-8存储字符串。您所需要的只是告诉CF页面的编码是UTF8。另一种方法是保存字节顺序标记(BOM),但Eclipse / CFEclipse不会这样做。

#1


1  

When creating a ColdFusion query with queryNew(), you can pass a list of datatypes as a second argument. For example:

使用queryNew()创建ColdFusion查询时,可以将数据类型列表作为第二个参数传递。例如:

<cfset x = queryNew("foo,bar","integer,varchar") />

Alternatively, you can use cf_sql_varchar (which you would use in queryparam tags). According to the livedocs, nvarchar is accepted for the CF varchar data type.

或者,您可以使用cf_sql_varchar(您将在queryparam标记中使用)。根据livesocs,CF varchar数据类型接受nvarchar。

QueryParam livedoc (referenced for nvarchar data type)

QueryParam livedoc(引用nvarchar数据类型)

QueryNew livedoc (referenced for data type definition)

QueryNew livedoc(引用数据类型定义)

Managing Data Types livedoc (referenced for using cf_sql_datatype)

管理数据类型livedoc(使用cf_sql_datatype引用)

#2


1  

The only thing I've been able to come up with so far is this:

到目前为止,我唯一能想出的就是:

<cfset x = QueryNew("foobar")/>
<cfset queryAddRow(x) />
<cfset querySetCell(x, "foobar", chr(163)) />
<cfdump var="#x#">

When dumped, this query does contain the British Pound symbol.

转储时,此查询确实包含英镑符号。

I haven't tried this with Ben's POI utility, but hopefully it helps you some.

我没有尝试使用Ben的POI实用程序,但希望它能帮到你一些。

#3


1  

You might try using JavaCast() to set the values, as shown here: Kinky Solutions (Ben Nadel) on JavaCast()

您可以尝试使用JavaCast()来设置值,如下所示:JavaCast上的Kinky Solutions(Ben Nadel)()

#4


1  

Make sure you're using Unicode end-to-end.

确保您使用的是端到端的Unicode。

#5


0  

This is pretty much all you need:

这几乎是你所需要的:

<cfprocessingdirective pageEncoding="utf-8"> 

ColdFusion (& java) stores string in UTF-8 by default. All you need is to tell CF that the encoding of the page is UTF8. The alternative way is to save the Byte-order mark (BOM), but Eclipse/CFEclipse doesn't do it.

ColdFusion(&java)默认以UTF-8存储字符串。您所需要的只是告诉CF页面的编码是UTF8。另一种方法是保存字节顺序标记(BOM),但Eclipse / CFEclipse不会这样做。