--
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+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/ca74a061-1ed5-4430-9575-96dcbfd3c49f%40googlegroups.com.
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();
--
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+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/d8c82fb4-6626-4cd1-b87d-9c68f696dd5f%40googlegroups.com.
<cfquery name="getUsers" datasource="main">select userId, userName, userEmailfrom userswhere userStatus = "active"<cfif len(arguments.userName)>and userName = <cfqueryparam value="#arguments.userName#" cfsqltype="string"></cfif><cfif len(arguments.userEmail)>and userEmail = <cfqueryparam value="#arguments.userEmail#" cfsqltype="string"></cfif></cfquery>How would you write a similar query in cfscript?
sql = '
select userId, userName, userEmail
from users
where userStatus = "active"
';
params = {}
if (arguments.userName.len()){
sql &= ' and userName = :userName'
params.userName = {value=arguments.userName, cfsqltype="string"};
}
if (arguments.userEmail.len()){
sql &= ' and userEmail = :userEmail'
params.userEmail = {value=arguments.userEmail, cfsqltype="string"};
}
getUsers = queryExecute(sql, params, {datasource="main"});
--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+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/8c580a12-8fce-42c8-8861-7ac9da91f887%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAG-7QUtt87azrfaWZ0O%2BzZYrvdGa%2BDROcsg5LcK%3D_yi37CRqJg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAGHrs%3D8h906N-0qqm%2B%2BVAsG-EH9m7c_tVhshw%3DTY_HDxKqcK_A%40mail.gmail.com.
the script version is too much of a hack
the script version is too much of a hack for no true benefit in my opinion.
--
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+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAOPrabWGQ56uMK7bvz8fCjn5XW8B9fCHfg%2BgunvHu%3DAjn0m-tw%40mail.gmail.com.
"Lectures" by Adam the Great. Soon on Amazon.
I like tags for queries. That's it, it is my opinion.
--
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+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAOPrabXdPR8y%3D4BE0Yx%2Byo8HMAq0r_91nMXciifr84wubr5dJA%40mail.gmail.com.
Igal Sapir
Lucee Core Developer
Lucee.org
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAG-7QUua9tw_UOLv3TtM_LamAhkOitC0SXd6cbjvssNRZbw_Xw%40mail.gmail.com.
For me this is the best approach:
getUsers = queryExecute(sql:
"SELECT userId, userName, userEmail
FROM users
WHERE userStatus = "active"
#len(arguments.userName) ? 'AND userName = :name' : ''#
#len(arguments.userEmail) ? 'AND userMail = :mail' : ''#
", options: {
datasource: 'main'
}, params: {
name: {sqltype:'string', value:arguments.userName},
email: {sqltype:'string', value:arguments.userEmail}
});
I actually don’t know whether the not needed params are ignored, I didn’t test it. But if they don’t then there’s a little more coding necessary. But I like this a lot!
Sincerely
Gert Franz
RASIA GmbH
Spittelgasse 7
5103 Moeriken-Wildegg
Email: ge...@rasia.ch
Skype: gert.franz
Phone Switzerland: +41 76 5680 231
--
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+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/15ff5236-1346-4329-a014-97ef34c611bb%40googlegroups.com.
For me this is the best approach:
getUsers = queryExecute(sql:
"SELECT userId, userName, userEmail
FROM users
WHERE userStatus = "active"
#len(arguments.userName) ? 'AND userName = :name' : ''#
#len(arguments.userEmail) ? 'AND userMail = :mail' : ''#
", options: {
datasource: 'main'
}, params: {
name: {sqltype:'string', value:arguments.userName},
email: {sqltype:'string', value:arguments.userEmail}
});
I actually don’t know whether the not needed params are ignored,
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/00b201d0be2e%24443cc230%24ccb64690%24%40rasia.ch.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/00b201d0be2e%24443cc230%24ccb64690%24%40rasia.ch.
Lucee 4.5.1.022 Error (expression) | |
Message | Element at position [1] doesn't exist in array |
Stacktrace | The Error Occurred in /var/www/vmhost/apps/MuraCMS/WEB-INF/lucee/components/org/lucee/cfml/Query.cfc: line 126 124: elseif (NextChar EQ '?')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 Stacktrace | Element 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 |
Timestamp | 7/23/15 12:00:17 PM CDT |
--
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+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/d8c82fb4-6626-4cd1-b87d-9c68f696dd5f%40googlegroups.com.