I tried that, and it did not work unfortunately. The datasource did test ok after adding the sql string in the validation query box, but when I ran a query, it gave me an owner name not specified error. I also tried the specifying username and password in the cfquery tag. That didnt work either. I can do the following:
<cfquery name="tripList" DATASOURCE="myDatasource">
<cfinclude template="shared/setOwner.cfm">
SELECT * from "TRIPS"
</cfquery>
The above works fine. The contents of setOwner.cfm is: "SET OWNER='myOwner';"
That way, I only have one file with the ownername. Is this an acceptable workaround?
|
wannab0133 wrote:
<cfquery name="tripList" DATASOURCE="myDatasource">
<cfinclude template="shared/setOwner.cfm">
SELECT * from "TRIPS"
</cfquery>
|
That is, naturally, a correct and good example of reuse. However, my preferred solution would be to treat the query string as an application constant. That is, I would place the following in the onApplicationStart method in Application.cfc:
<cfset application.setOwnerQuery = "SET OWNER='myOwner';">
(If the variable depends on the current user, then store it in the session scope instead, in the method onSessionStart.)
Later on,
<cfquery name="tripList" DATASOURCE="myDatasource">
#application.setOwnerQuery#
SELECT * from "TRIPS"
</cfquery>
I consider this simpler in concept.