Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFLDAP with hypen in attribute name

New Here ,
Feb 22, 2010 Feb 22, 2010

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!

TOPICS
Advanced techniques
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 22, 2010 Feb 22, 2010

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 irr

...
Translate
LEGEND ,
Feb 22, 2010 Feb 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2010 Feb 22, 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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2010 Feb 22, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2010 Feb 22, 2010

Thanks very much for keeping up with me Adam. Much appreciated.

I just did the dump to find that the "this-hyphen" attribute had renamed to "this_hyphen"

CFLDAP is accepting the hyphen in attribute name fine, but when the query is returned, it is somehow renaming the attribute name - to _.

I'm not too sure what the reason is for that but at least we have found out what the cause for the non-recognisable attribute name.

Do you know why it is renaming the hyphen?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 22, 2010 Feb 22, 2010

Aha!  Weird.

No, I don't know why that has happened.  I'm "certain" it never used to do that.  I can only assume it's to facilitate code using non-scoped column names in a <cfloop type="query">, which will baulk at the hyphen.

I do not have access to an LDAP dir, otherwise I'd look into this further.

Still: at least you're moving fwd again.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 23, 2010 Feb 23, 2010
LATEST

I just installed Apache Directory Services locally and had a wee test.  When I do a <cfldap> call that returns attributes with hyphens in their names, they come through having hyphens in their names.

However just because Apache does it that way doesn't mean ADS does (although I thought it did...).

It's not a problem with <cfldap>, anyhow.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources