Skip to main content
Inspiring
July 29, 2008
Question

cfqueryparam and mssql

  • July 29, 2008
  • 2 replies
  • 950 views
I'm a little confused about using cfqueryparam:

I know the defualt CFSQLTYPE is CF_SQL_CHAR. Most of my fields are nvarchar, so would I HAVE to use CF_SQL_VARCHAR? Or would CF_SQL_CHAR work as well?
This topic has been closed for replies.

2 replies

Inspiring
July 30, 2008
> I know the defualt CFSQLTYPE is CF_SQL_CHAR. Most of my fields are nvarchar,
> so would I HAVE to use CF_SQL_VARCHAR? Or would CF_SQL_CHAR work as well?

You should use VARCHAR. The CHAR / VARCHAR thing is to do with the size of
the storage, not what's being stored. A CHAR field occupies the size
specified, irrespective of what you put in it. If you ahve a CHAR(10) and
put 'A' in it: it still uses 10 bytes. In a VARCHAR(10) it would only take
one byte.

That said, from a JDBC perspective, I'm pretty sure it wouldn't matter,
because I think the validation done is just for type of data (and both are
character data) and size (and as long as it's within the max you specify:
fine). And the unicode-ness of the data doesn't seem to come into it
either. Someone might correct me on that.

But even if either would work, I think VARCHAR is more sensible because
it's the closest to the real situation.

--
Adam
jeremy1Author
Inspiring
July 30, 2008
Thanks for the help guys.

I tried both and they both seem to work the same as far as I can tell. If the field is set to nvarchar they both input the same data. Entering one letter in a 255 length field still only stores as one letter.

The only real value for me to use CF_SQL_CHAR is that it is just that much less typing! I have to update an old site with 450+ queries to use CFQUERYPARAM. Of course, most of them are nvarchar fields. I found a free script that updates your pages but uses the default CF_SQL_CHAR. It would be great to just use that and same me all the hassle.
Inspiring
July 30, 2008
jeremy@noble wrote:
> I'm a little confused about using cfqueryparam:
>
> I know the defualt CFSQLTYPE is CF_SQL_CHAR. Most of my fields are nvarchar,
> so would I HAVE to use CF_SQL_VARCHAR? Or would CF_SQL_CHAR work as well?

use varchar & make sure you set the "Enable High ASCII characters and Unicode
for data sources configured for non-Latin characters" under advanced settings
for that dsn.