Question

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.

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

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

Was it helpful?

Solution

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

<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.

QueryParam livedoc (referenced for nvarchar data type)

QueryNew livedoc (referenced for data type definition)

Managing Data Types livedoc (referenced for using cf_sql_datatype)

OTHER TIPS

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.

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

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top