views:

531

answers:

6

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 :)

+1  A: 

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.

Adam Tuttle
+1  A: 

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

Ben Doom
+1  A: 

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

Patrick McElhaney
A: 

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)

Mike Oliver
A: 

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.

Henry
A: 

Hello,

This is more of a question since I am facing the same problem. What if you are not using a page to create the query content will work in a CFC?

Thanks,

kamo