What's the cleanest way to set queryOptions in a cfscript query in lucee?

I’m looking for a concise, CF 9/Lucee 4.5-compatible cfscript syntax. I
don’t have CF9 handy, but I tried Adam’s syntax in Lucee.

I got:

Lucee 4.5.1.022 Error (expression)MessageElement at position [1] doesn’t
exist in arrayStacktraceThe Error Occurred in
/var/www/vmhost/apps/MuraCMS/WEB-INF/lucee/components/org/lucee/cfml/Query.cfc:
line 126

124: elseif (NextChar EQ ‘?’)
125: {
126: result.add( positionalParams[positionalCursor] );
127: positionalCursor++ ;
128: Pos++ ;

called from /var/www/vmhost/apps/MuraCMS/WEB-INF/lucee/components/org/lucee/cfml/Query.cfc:
line 50
called from /var/www/vmhost/apps/MuraCMS/test/foo.cfm: line 32
Java StacktraceElement at position [1] doesn’t exist in array
at lucee.runtime.type.ArrayImpl.invalidPosition(ArrayImpl.java:194):194
at lucee.runtime.type.ArrayImpl.getE(ArrayImpl.java:171):171
at lucee.runtime.type.ArrayImpl.get(ArrayImpl.java:124):124
at lucee.runtime.type.util.ArraySupport.get(ArraySupport.java:314):314
at lucee.runtime.util.VariableUtilImpl.get(VariableUtilImpl.java:255):255
at lucee.runtime.PageContextImpl.get(PageContextImpl.java:1435):1435
at
org.lucee.cfml.query_cfc$cf.udfCall(/var/www/vmhost/apps/MuraCMS/WEB-INF/lucee/components/org/lucee/cfml/Query.cfc:126):126
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229
at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:766):766
at
lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742
at
lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1589):1589
at
org.lucee.cfml.query_cfc$cf.udfCall(/var/www/vmhost/apps/MuraCMS/WEB-INF/lucee/components/org/lucee/cfml/Query.cfc:50):50
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:641):641
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524
at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1760):1760
at
lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742
at
lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1589):1589
at test.foo_cfm$cf.call(/var/www/vmhost/apps/MuraCMS/test/foo.cfm:32):32
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:950):950
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:902):902
at
lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:223):223
at
lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:35):35
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2257):2257
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2224):2224
at
lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:456):456
at lucee.loader.servlet.CFMLServlet.service(Unknown Source):-1
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727):727
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303):303
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208):208
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52):52
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241):241
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208):208
at
org.apache.catalina.filters.RemoteIpFilter.doFilter(RemoteIpFilter.java:834):834
at
org.apache.catalina.filters.RemoteIpFilter.doFilter(RemoteIpFilter.java:870):870
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241):241
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208):208
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220):220
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122):122
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504):504
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170):170
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103):103
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116):116
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421):421
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074):1074
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611):611
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314):314
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145):1145
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615):615
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61):61
at java.lang.Thread.run(Thread.java:745):745
Timestamp7/23/15 12:00:17 PM CDT

Line 32 is: ).execute().getResult();

Recommendations?

Thanks,
JamieOn Wed, Jul 8, 2015 at 6:04 PM, Adam Cameron <@Adam_Cameron> wrote:

On Wednesday, 8 July 2015 20:20:29 UTC+1, thorste...@googlemail.com wrote:

What’s the cleanest way to add queryOptions like cachedWithin to
queryService in lucee?

This works, but I guess there is a nicer way.

    var queryService = new query(cachedWithin=createTimespan(0, 0,

10, 0));
queryService.setName(“qryItems”);

queryService.setDatasource(“#application.wheels.dataSourceName#”);

queryService.addParam(name=“IsTestData”,value=“True”,cfsqltype=“CF_SQL_BIT”);
queryService.setSQL("
SELECT bla bla
");

I can’t vouch for Lucee, but I guess their Query.cfc works the same as
ColdFusion’s one. That being the case, one doesn’t need to call all the
individual setter methods to set properties, one can just pass them all
into the constructor call.

Details here:
Adam Cameron's Dev Blog: CFML: Using Query.cfc doesn't have to be the drama Adobe wants it to be,
but the sample code is thus:

GetParks = new Query(
datasource=“cfdocexamples”,
cachedwithin=createTimeSpan(0, 6, 0, 0),
sql = "
SELECT PARKNAME, REGION, STATE
FROM Parks
WHERE STATE = ?
and REGION = ?
ORDER BY ParkName
",
parameters = [
{value=“MD”, cfsqltype=“cf_sql_varchar”},
{value=“National Capital Region”, cfsqltype=“cf_sql_varchar”}
]
).execute().getResult();


Adam


You received this message because you are subscribed to the Google Groups
“Lucee” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/d8c82fb4-6626-4cd1-b87d-9c68f696dd5f%40googlegroups.com
https://groups.google.com/d/msgid/lucee/d8c82fb4-6626-4cd1-b87d-9c68f696dd5f%40googlegroups.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.