Default Application Datasources
It would be handy if you could specify a default datasource name in the cfapplication tag, or Application.cfc, and then omit the datasource attribute in the cfquery tag.
I don't know about you but most apps I've built only have one datasource, and I typically set the datasource name with a variable in the Application.cfm file. Being able to omit the datasource attribute would save a bunch of typing.
I just suggested this feature on the Macromedia wish form.
Update - this feature has been added to ColdFusion 9!
Tweet
Trackbacks
Comments
In the meantime, just set up a snippet in CFE or DW that does the typing for you. Same for CFQUERYPARAM.
If you only ever use one DSN, just write one method that queries a DSN and pass SQL (and any other params you want to set) to it? Seems like a problem which could be solved by trying something different with the design of said app?
Context gives your application Persist Scope, meaning your Application can one day use XML as its storage, then the next it could use SQL.
What happens if you store information within Multiple DSN's? Audit Information goes in DSNA, while mainstream Data goes into DSNB (why? seperation of security for one).
I've built / used a config business object, and I pass that into all of my "Services/Managers/Herders/Builder" classes. This configuration object initializes itself based on an XML packet that I "couple" with the application. Now, at this point i don't simply have routines "getDSN()" for example.
I class my overall DSN information based on the persist service they provide, meaning i have a method within my config which is like: "getPersistService('security')" which depending on the DB Server type, returns appropriate DSN information.
Another classic mistake is folks sometimes use username + password, while other times they don't (ie shared hosting, its a must. Dedicated hosting, not so much).
Point is this, the only points of customization within my cf applications are:
- config.xml - DAO_SQL, DAO_Oracle, DG_SQL, DG_Oracle etc..
The rest of the business logic doesn't give two hoots. The main reason for this is simply that while Application.cfc is great, its easily abused and in a nutshell Application.cfm is probably the best suited aspect of a coldfusion application which provides appropriate context to its intended use, resulting in promoting a better "re-use" capability within your code.
If i had to pick this setting, i'd much prefer Barneys approach whereby we leveridge some kind of Mapping/Alias to suite our CFQUERY code. To me thats a much easier and more elegant approach.
<cfquery datasource="request.db">
<cf_myquery>
</cf_myquery>
The way we currently do things here is to set Request.Datasource in the Application file (depending on live/test/dev mode) and use <cfquery name="something" datasource="#Request.Datasource#">..</cfquery> - but it would be very nice to cut out those thirty five characters.
I do think it would be nice if you could specify a default in the <cfapplication> tag. Better would be being able to specify a list of datasources to which coldfusion would choose the first available one and perform load balancing.
We've been looking for potential database load balancing software as well, and came across this: http://c-jdbc.objectweb.org/
Nice thing about CJDBC is that it's a multiplexing datasource, so in theory, you get load balancing without modifying your application code.
Note that I've not been able to look at this yet, but this is one of the ideas that's on the cards to investigate as a matter of performance improvements.
However, this tag is broken, and won't never work, because of the way ColdFusion handles quotes inside CFQUERY's: for security concerns, all expressions dumped using the ## notation, inside the body of any CFQUERY, is first processed in order to replace all ' by \'. This way, SQL injection is avoided. For further information, see the comments below the CFMX8 documentation page for CFQUERY. These comments include also a way to make this custom tag work.
Suppose now you have such a tag. I personnally use a similar thing in my developments, and consider the drawbacks it brings along: - error reporting. The SQL error is not reported to have happened in the location the custom tag is called at, but in the custom tag itself. Ok, you can trace back where the error is by looking at the stack and, why not, to create your own error handler to beautify all this mess. - more annoying, the nice feature of automatic quote escaping goes away...
I'll be glad if anyone here knows how to turn on this escaping thing again.
Post a Comment
Recent Entries
- Nginx redirect www to non www domain
- HashDOS and ColdFusion
- HackMyCF Updated for APSB11-29 Security Hotfix
- Adobe eSeminar on FuseGuard
- Determining Which Cumulative Hotfixes are Installed on ColdFusion
- Adding Two Factor Authentication to ColdFusion Administrator
- ColdFusion Developer Week at Adobe.com
- Bug Loading Scripts for CFFileUpload and CFMediaPlayer


add to del.icio.us



