Skip to main content
Participant
February 22, 2010
Answered

CFLDAP with hypen in attribute name

  • February 22, 2010
  • 1 reply
  • 1190 views

Hello folks,

I have come across a problem where an AD attribute has hyphen in its name.

so the code would be something like:

<cfldap name="MyQuery" action="query" .... attributes="one,two,this-hyphen">

how would I be able to retrieve the attributes value for the "this-hyphen" in the code?

I have tried:

<cfset MyVar = MyQuery.this-hyphen>

<cfset MyVar = Variable['MyQuery.this-hyphen']>

<cfset MyVar = MyQuery['this-hyphen']>

None of them works!

This topic has been closed for replies.
Correct answer Adam Cameron.

Oh yeah, that seems to be working.. sort of!

I have tried MyQuery['one'][1] and it seems to retrieve the correct data but when I try to access MyQuery['this-hyphen'][1], I get the following error message:

The member "THIS-HYPHEN" in dimension 1 of object "MyQuery" cannot be found. Please, modify the member name.

This comes to following conclusions:

1. CFLDAP is not retrieving "this-hyphen" attribute properly due to hyphen in its name

2. "this-hyphen" does not exist in AD.

For point 1, I would of thought that it is OK to put hyphen in attribute list because it is passing the string.

For point 2, I just tried to bring in RANDOM attribute that does not exist in AD (eg ASWEQ), and it doesn't seem to throw any error when I try to access that attribute in CFSET.

So what exactly is going on here?


This comes to following conclusions:

1. CFLDAP is not retrieving "this-hyphen" attribute properly due to hyphen in its name

2. "this-hyphen" does not exist in AD.

For point 1, I would of thought that it is OK to put hyphen in attribute list because it is passing the string.


I can't vouch for how the remote directory will react to being asked for an attribute that doesn't exist... one would need to read the LDAP spec for that I guess.  I'm not gonna ;-)

However how the diectory system handles it is irrelevant, to a point.  You're code should busy itself with what gets delivered back to you.  So you don't even know if your returned query even has this column in it?  Wouldn't that be a good place to start?  Have you dumped the query out and checked?

I do know that <cfldap> itself has no problems with attributes with hyphenated names.  Well when I went through all this a few years ago (following similar steps to what we're doing here ;-) the data came back fine.

For point 2, I just tried to bring in RANDOM attribute that does not exist in AD (eg ASWEQ), and it doesn't seem to throw any error when I try to access that attribute in CFSET.

So what exactly is going on here?

OK, well I suppose that answers my question above.  ADS will echo back any (?) attribute you ask for, with just a blank value if it doesn't exist.  I doubt it would act any differently for hyphenated names, but this is easily answered by dumping out your query and seeing what you've got.  Is it there?

What happens if you query for a valid attribute with a hyphen in the name?  I'm not sure there's much merit querying for stuff that doesn't exist...

--

Adam

1 reply

Inspiring
February 22, 2010

The first two of those never would have worked, but the third one is on the right track.   Or should be.  Remember that<cfldap> returns a query, and bracket-notation like that references a column, not an individual cell of the query.  So unless you want the whole column, you're gonna need to give it a row number too.

--

Adam

Mooo0Author
Participant
February 23, 2010

I tried that but it is giving me some error!

The query should return one row so I tried accessing the variable like this

<cfset MyVar = MyQuery[1]['the-hyphen']>

but that gives me error :

The member "1" in dimension 1 of object "MyQuery" cannot be found. Please, modify the member name.

I tried with:

<cfset MyVar = MyQuery[1][1]>

and that gives me the same error!

Is there some other way of accessing this variable?

There has to be!

Inspiring
February 23, 2010

As per the docs - http://livedocs.adobe.com/coldfusion/8/htmldocs/Variables_18.html - the syntax is:

queryName["column name"][row number]

Does that work?

It was the one option you didn't seem to have tried ;-)

--

Adam