0

I am getting a coldfusion error on referencing query from application variable.

Application.Shops is an application variable and is a query referenced in another file.

<cfquery name="qFilterLocations" dbtype="query">
    SELECT * FROM Application.Shops
</cfquery>

However, I do get 'Error Executing Database Query. Query Of Queries runtime error.Table named Application.Shops was not found in memory. The name is misspelled or the table is not defined.

I don't understand what is wrong here.

user2675939
  • 361
  • 2
  • 6
  • 22
  • Try using associative array notation - `Application['Shops']` – Dan Bracuk Aug 18 '21 at 20:07
  • I have used this in so many files before, but it never threw an error, however they have been referenced as – user2675939 Aug 18 '21 at 20:10
  • Can you dump it? – Dan Bracuk Aug 18 '21 at 20:14
  • yes, its being referenced at so many places so am not sure why this wouldn't work, except this is a query of a query – user2675939 Aug 18 '21 at 20:15
  • Have you tried `[Application].Shops` as table name? – rrk Aug 18 '21 at 20:20
  • My guess is that CF is applying the dot notation in a different way. The dots in a table name mean something else and therefore Application.Shops is not getting parsed as expected. And that's why `` works. See https://helpx.adobe.com/coldfusion/developing-applications/accessing-and-using-data/using-query-of-queries/query-of-queries-user-guide.html – snackboy Aug 18 '21 at 21:02
  • oh ok, so what do you suggest instead of dot notation? – user2675939 Aug 18 '21 at 21:03
  • The query works without issue in 2016,0,17,325979 . – SOS Aug 18 '21 at 22:23
  • It works fine with 2016,0,01,298513 too. Sounds like the issue is something else ... Could you verify your CF version? `#server.coldFusion#` – SOS Aug 19 '21 at 18:00
  • we are using CF 2018 – user2675939 Aug 19 '21 at 18:29
  • The question tags say CF2016, but it works with CF 2018 too, as long as the query actually exists in the app scope. Dump the app scope. Is the query there? – SOS Aug 19 '21 at 20:08
  • It does, I think this one is just bit odd, am going to use what snackboy has below and just go with it for now, thanks all for the help! – user2675939 Aug 19 '21 at 20:13
  • Yeah, I think it's something specific to your app setup, as QoQ's have no problem with that syntax otherwise. Anyway, glad you found a workaround for the issue. – SOS Aug 19 '21 at 20:27

1 Answers1

0

It appears that CF is interpreting the dot notation in a specific way (see https://helpx.adobe.com/coldfusion/developing-applications/accessing-and-using-data/using-query-of-queries/query-of-queries-user-guide.html). I would restructure the code in the following way:

<cfset qShops = Application.Shops>
<cfquery name="qFilterLocations" dbtype="query">
    SELECT * FROM qShops
</cfquery>

Follow Up: I was able to run the following in CF2018 with no issue. As @SOS suggested, this is likely a specific environment issue.

<cfquery datasource="myDS" name="application.shops">
    select 1 from dual
</cfquery>

<cfdump var="#application.shops#">

<cfquery dbtype="query" name="qResult">
    select * from application.shops
</cfquery>

<cfdump var="#qResult#">

Both query results are dumped without error.

snackboy
  • 624
  • 3
  • 12
  • 1
    FWIW, this is probably a special environment specific case, as CF2016 and CF2018 have no problem referencing Application.Shops in a QoQ :) – SOS Aug 19 '21 at 20:28
  • @SOS, I think you are right. I updated my answer with test code validating that the dot notation works in at least CF18 without error. – snackboy Aug 20 '21 at 05:20