I have a query l.q. l is var scoped:
var l = {};
If I dump l:
writeDump(var:l, abort:true);
I get
You can see that q (l.q) shows [undefined struct element]. However if I do:
writeDump(var:isQuery(l.q), abort:true);
I get yes as the output? Dumping l.q.recordCount returns 1.
If I dump l.q I get an error: Error Type java.lang.ArrayIndexOutOfBoundsException : [N/A].
This is causing me quite a headache as on my website I get variables randomly disappearing like this all the time.
Any ideas of what could be going on here? CF9.0.1 Ent running on Windows Server 2005.
It looks like whatever is populating your l.q variable is not working correctly. How is l.q being populated?
If you're using l = {} as a "local" scope replacement - don't ColdFusion 9 already has a local scope inside of functions and you can dump it.
Are these dumps in the same place? Remember that if you execute a query that does not return anything (such as an update or delete) but use the name parameter, that variable will be set to undefined. It sounds like this could be happening here.
Related
The following code works:
<cfoutput>#$.currentURL()#</cfoutput>
However, within a function, "$" is not available.
<cfscript>
function myTest() {
return $.currentURL();
}
</cfscript>
Does anyone know what actually is the equivalent of $ within a function?
Likewise, #pluginConfig.getDirectory()# works when used directly in cfoutput. However, within a cfscript function, it reports "unknown variable pluginConfig."
Thank you for advance for guiding me in the right direction.
When writing code outside the Mura Event Scope (like you do with that function), you have to obtain an instance of the Mura Scope ($) yourself. This can be done using the following code:
$ = application.serviceFactory.getBean('$');
Next you'll have to initialise the instance using an event object, a struct with value pairs or a 'siteID':
$.init(event);
$.init(myStruct);
$.init(siteID);
The same counts for the pluginConfig, this you can abtain via the Mura Scope. You'll have to pass the pluginID, moduleID, name or package of the plugin:
$.getPlugin(pluginID);
$.getPlugin(moduleID);
$.getPlugin(name);
$.getPlugin(package);
An other option you have is to pass the Mura Scope and the pluginConfig as arguments to the function. When writing a small plugin, this might be the easier way. But when writting medium or large plugins, it will get a bit messy when you're passing along these objects all the time.
The $ is used as a special framework variable in some CF frameworks (like Mura). You will need to figure out the framework context (if any) your code is executing in
I have an error that seems to be associated with <cfscript> db operation
// traffic tracking
myQry = new Query();
myQry.setSQL("INSERT INTO dbo.Traffic (Circuit, Fuseaction, IP_hash) VALUES (:circuit, :fuseaction, :ip_hash)");
myQry.addParam(name="circuit", value="#listfirst(rc.fuseaction, '.')#", cfsqltype="CF_SQL_VARCHAR");
myQry.addParam(name="fuseaction", value="#listlast(rc.fuseaction, '.')#", cfsqltype="CF_SQL_VARCHAR");
myQry.addParam(name="ip_hash", value="#cgi.remote_addr#", cfsqltype="CF_SQL_VARCHAR");
myQry.execute();
The really strange thing is, it looks like the operation completed. What kind of a error is this?
Short answer: It's probably a scoping issue. Try:
var myQry = new Query();
Long-winded waffley answer:
I'd call it an Adobe-developers-being-useless kind of error.
If you look at line 460 of that file, you'll see the error is due to a failure of StructFind to find the query name in the variables scope, and the reason it's appearing in debug input is because there's a try/catch with type any surrounding it. The same functionality could be achieved without causing/catching an error by replacing the try/catch with <cfif StructKeyExists(variables,tagAttributes['name']) > which is basic CFML knowledge, and certainly something a developer of the CF product should know!
The same code still exists in the CF10 version of base.cfc, so you may or not feel like submitting it as a bug in Adobe's CF bugbase - though it's unlikely they'll fix it for CF9 (and uncertain whether they'll feel CF10 is worth the effort either).
However, that would only be side-stepping the issue of the variable not existing, not addressing the real issue of why it doesn't actually exist. Given that the debug info shows the query is successfully executing, and the query code is basically right above that line (starts at line 442), it shouldn't be a repeated/common error, but it may be due to your myQry variable not being scoped, and thus it could be colliding with another variable also called myQry (or even the same var from a separate call to the function) which is happening between the execution of the new Query() and .execute() lines, and thus causing the original query to not be there when the StructFind looks for it.
The solution is to put the keyword var before the first use of myQry which will place it in the local scope for that function - something that should be done for all variables that are only for use within an instance of a function, (otherwise they are placed in the variables scope of the component/request that the function exists within).
I need to call a function of an object and pass it a variable. Because I need to make multiple call to function of this object I've tried to make one only handler that invoke the specific function by the form value I pass it. The code works, but CFBuilder show me that there is an error (missing semicolon on the last row). I'm on Railo.
local.myReport = seoUtility.init();
local.func = form.action;
local.report = local.myReport[local.func](form.user);
So the question is: this code is correct? I could simply ignore the cfbuilder error icon?
If you don't want CFBuilder to nag you about the syntax, you can change to this:
local.myReport = seoUtility.init();
local.func = local.myReport[form.action];
local.myReport.func = local.func;
local.report = local.myReport.func(form.user);
This sets local.func to the instance of seoUtility as a reference to the actual function you want to call, preserving its relationship to the parent object. This way the offending []() syntax isn't needed.
However, this only works if seoUtility.init() is returning a fresh instance every time, as opposed to a singleton shared by the application, in which case there would be a race condition on all calls to local.myReport.func().
I am trying to use the Google geocoder to do a reverse-geocoder lookup. I am running the exact same command on 8 values, and I am only having an error on two of them, which has me confused as one of the failing values is identical to one of the working values. (The 'working' values aren't really working- they still return a value of undefined from the 'formatted_address' field, but they aren't throwing errors). The command that I am running is as follows:
geocoder.geocode({latLng: new google.maps.LatLng(machineList[i].y, machineList[i].x)}, function(results, status) { address = results[0]; });
I am receiving a type error from Javascript, claiming that results is null. I'm not sure why this is happening. Any ideas?
Well, it turns out this was a timing issue. The geocode() command was taking longer to complete for certain locations than for others, which caused the value to show up as null. I ended up eliminating the problem by moving all the subsequent code into the callback function (I hadn't done this earlier because the whole thing is running inside of a loop, and I was having some difficulty getting it to pass in the iterator as a parameter). Now everything seems to be working well and the locations are showing up as they should.
I am calling a stored procedure with cfscript, but when I add the addProcResult method to the call, ColdFusion returns the error The specified key, result, does not exist in the structure. Removing the method fixes the error and doesn't effect the results, but I still would like to know why the error appeared. Using <cfstoredproc> and <cfprocparam> doesn't generate the error. I am running CF9. My code is below.
spService = new storedProc();
spService.setDatasource("mydb");
spService.setProcedure("someSP");
spService.setUsername("TaskRunner");
spService.setPassword("password");
spService.addProcResult(name="result",resultset=1);
spService.execute();
You'll get this error if your stored procedure actually doesn't return a resultset (perhaps it returns an output parameter--or nothing at all).
Simply remove the call to .addProcResult(), and you'll be fine.