Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Created September 19, 2012 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/3751114 to your computer and use it in GitHub Desktop.
Save adamcameron/3751114 to your computer and use it in GitHub Desktop.
An Application.cfc to test what happens when this.datasource is set by a conditional using a CGI variable
component {
this.name = "testPseudoConstructor";
this.applicationTimeout = createTimeSpan(0,0,1,0);
this.sessionManagement = true;
this.sessionTimeout = createTimeSpan(0,0,0,30);
if (CGI.server_name == "localhost"){
this.datasource = "dsn1";
}else if (CGI.server_name == "testing.local"){
this.datasource = "dsn2";
}else{
// yer out of luck, mate
}
function onApplicationStart(){
logIt("onApplicationStart [#CGI.server_name#]");
}
function onSessionStart(){
logIt("onSessionStart [#CGI.server_name#]");
}
function onRequestStart(){
logIt("onRequestStart [#CGI.server_name#]");
}
function onRequest(){
include arguments[1];
}
function onSessionEnd(){
logIt("onSessionEnd [#CGI.server_name#]");
}
function onApplicationEnd(){
logIt("onApplicationEnd [#CGI.server_name#]");
}
function logIt(required string message){
param name="this.dataSource" default="NOT_SET";
writeLog(file=this.name, text="Start of logIt(). #message# [#this.dataSource#]");
try {
new Query(
sql = "
INSERT INTO t_test (
tst_data
) VALUES (
'#message#'
)
"
).execute();
}
catch (any e){
writeLog(file=this.name, text="CATCH in logIt(). #message# [#this.dataSource#] [#e.message#] [#e.detail#]");
rethrow;
}
writeLog(file=this.name, text="End of logIt(). #message# [#this.dataSource#]");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment