gratzc
04/08/2022, 1:01 PMgratzc
04/08/2022, 1:01 PM<cfscript>
q = QueryNew("num");
numbers = [1,2,3,4,5,6,7,8,9,10]
for (num in numbers) {
r = QueryAddRow(q);
QuerySetCell(q,"num", num, r);
}
</cfscript>
<cfset list = [] >
<cfdump var="#q#">
<cfquery name="q2" dbtype="query">
select * from q
where
num IN (<cfqueryparam cfsqltype="cf_sql_integer" value="#arrayToList(list)#" list="true" />)
</cfquery>
<cfdump var="#q2#">gratzc
04/08/2022, 1:03 PMUnexpected token: [ in statement [select * from q
where
num IN (]gratzc
04/08/2022, 1:03 PMgratzc
04/08/2022, 1:03 PMbdw429s
04/08/2022, 1:04 PMbdw429s
04/08/2022, 1:05 PMbdw429s
04/08/2022, 1:06 PMgratzc
04/08/2022, 2:29 PMgratzc
04/08/2022, 2:29 PMgratzc
04/08/2022, 2:30 PMbdw429s
04/08/2022, 2:31 PMSELECT *
FROM table
WHERE col in ()
which wouldn't even be valid SQLbdw429s
04/08/2022, 2:32 PMgratzc
04/08/2022, 2:37 PMgratzc
04/08/2022, 2:37 PMgratzc
04/08/2022, 2:37 PMbdw429s
04/08/2022, 2:40 PMUnexpected token: [ in statement [select * from q
where
num IN (]gratzc
04/08/2022, 2:40 PMbdw429s
04/08/2022, 2:40 PMin from your example entirelybdw429s
04/08/2022, 2:41 PMgratzc
04/08/2022, 2:41 PMbdw429s
04/08/2022, 2:41 PMgratzc
04/08/2022, 2:41 PMUnexpected token: [ in statement [select * from q
where
num = ]gratzc
04/08/2022, 2:41 PMlucee.runtime.exp.DatabaseException: Unexpected token: [ in statement [select * from q
where
num = ]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at lucee.runtime.type.util.QueryUtil.execute(QueryUtil.java:320)
at lucee.runtime.type.QueryImpl.execute(QueryImpl.java:287)
at lucee.runtime.type.QueryImpl.<init>(QueryImpl.java:235)
at lucee.runtime.db.HSQLDBHandler.__execute(HSQLDBHandler.java:358)
at lucee.runtime.db.HSQLDBHandler._execute(HSQLDBHandler.java:319)
at lucee.runtime.db.HSQLDBHandler.execute(HSQLDBHandler.java:307)
at lucee.runtime.tag.Query.executeQoQ(Query.java:1110)
at lucee.runtime.tag.Query._doEndTag(Query.java:680)
at lucee.runtime.tag.Query.doEndTag(Query.java:565)
at qoqintest_cfm$cf$9.call(/qoqInTest.cfm:16)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:1034)
at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:926)
at lucee.runtime.listener.ClassicAppListener._onRequest(ClassicAppListener.java:65)
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:45)
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2460)
at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2450)
at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2421)
at lucee.runtime.engine.Request.exe(Request.java:45)
at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1179)
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1125)
at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.cfmlprojects.regexpathinfofilter.RegexPathInfoFilter.doFilter(RegexPathInfoFilter.java:47)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:64)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:336)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)bdw429s
04/08/2022, 2:42 PMbdw429s
04/08/2022, 2:43 PMDECLARE @val as INT
select *
from table
where col = @valbdw429s
04/08/2022, 2:43 PMgratzc
04/08/2022, 2:44 PMbdw429s
04/08/2022, 2:44 PM<cfqueryparam cfsqltype="cf_sql_integer" value="#val#"/>
didn't throw a type validation error if val was an empty string since you specified cf_sql_integerbdw429s
04/08/2022, 2:44 PMbdw429s
04/08/2022, 2:45 PMgratzc
04/08/2022, 2:45 PMgratzc
04/08/2022, 2:45 PMgratzc
04/08/2022, 2:45 PMgratzc
04/08/2022, 2:47 PMgratzc
04/08/2022, 2:47 PMbdw429s
04/08/2022, 3:10 PMbdw429s
04/08/2022, 3:10 PMbdw429s
04/08/2022, 3:11 PMbdw429s
04/08/2022, 3:13 PMgratzc
04/08/2022, 3:16 PMgratzc
04/08/2022, 3:16 PMbdw429s
04/08/2022, 3:17 PMbdw429s
04/08/2022, 3:17 PMgratzc
04/08/2022, 3:17 PMbdw429s
04/08/2022, 3:17 PMbdw429s
04/08/2022, 3:17 PMgratzc
04/08/2022, 3:18 PMbdw429s
04/08/2022, 3:18 PMselect *
from foo
where col in ( select col from bar where 1 = 0 )
that for example, wouldn't error, it just wouldn't return anythingbdw429s
04/08/2022, 3:18 PMgratzc
04/08/2022, 3:20 PMbdw429s
04/08/2022, 3:21 PMbdw429s
04/08/2022, 3:21 PMbdw429s
04/08/2022, 3:21 PMbdw429s
04/08/2022, 3:22 PMgratzc
04/08/2022, 3:22 PMgratzc
04/08/2022, 3:23 PMbdw429s
04/08/2022, 3:24 PMbdw429s
04/08/2022, 3:25 PMbdw429s
04/08/2022, 3:25 PMbdw429s
04/08/2022, 3:28 PM<cfquery name="q2" dbtype="query">
select num, <cfqueryparam cfsqltype="cf_sql_integer" value="test" > as foo
from q
</cfquery>
where passing a string to a cfqueryparam with a type of integer throws an odd error.bdw429s
04/08/2022, 3:29 PM42 instead of test does work thereMichael Schmidt
04/08/2022, 3:29 PMbdw429s
04/08/2022, 3:29 PMgratzc
04/08/2022, 3:29 PMzackster
04/08/2022, 3:29 PMbdw429s
04/08/2022, 3:29 PMgratzc
04/08/2022, 3:30 PMbdw429s
04/08/2022, 3:30 PMselect *
from table
where col in (null)
which I suppose would workzackster
04/08/2022, 3:31 PMzackster
04/08/2022, 3:31 PMbdw429s
04/08/2022, 3:31 PMgratzc
04/08/2022, 3:31 PMbdw429s
04/08/2022, 3:31 PMMichael Schmidt
04/08/2022, 3:32 PMselect num from table where col in ()
would failbdw429s
04/08/2022, 3:32 PMzackster
04/08/2022, 3:32 PMbdw429s
04/08/2022, 3:32 PMselect num, [CF_SQL_INTEGER] as foo from q
which is why it's talking about a [ chargratzc
04/08/2022, 3:33 PMbdw429s
04/08/2022, 3:33 PMhow would you exepct it to react in non Query of Query but as a database i would expect@Michael Schmidt I answered that above. https://cfml.slack.com/archives/C06TA0A9W/p1649431127487969?thread_ts=1649422898.443549&cid=C06TA0A9W
bdw429s
04/08/2022, 3:34 PM(). But in this case, the developer is saying, all the values in this data struture, which if empty, the engine should be able to deal with properly just like a sub select would.bdw429s
04/08/2022, 3:34 PMbdw429s
04/08/2022, 3:43 PMbdw429s
04/08/2022, 3:46 PMbdw429s
04/08/2022, 3:46 PMselect *
from table
where column in ('')Michael Schmidt
04/08/2022, 3:46 PMgratzc
04/08/2022, 3:46 PMbdw429s
04/08/2022, 3:47 PMbdw429s
04/08/2022, 3:47 PMCommandBox> #listlen ""
will give you zerogratzc
04/08/2022, 3:48 PMbdw429s
04/08/2022, 3:48 PMbdw429s
04/08/2022, 3:49 PMbdw429s
04/08/2022, 3:50 PMzackster
04/08/2022, 3:50 PMbdw429s
04/08/2022, 3:50 PMMichael Schmidt
04/08/2022, 3:51 PMselect *, '1' as t, <cfqueryparam cfsqltype="cf_sql_integer" value="1"> as q from q
where
num IN (<cfqueryparam cfsqltype="cf_sql_integer" value="#list#" />)
And it does work lolbdw429s
04/08/2022, 3:52 PMlist variable in that case? Also, you didn't specify list=trueMichael Schmidt
04/08/2022, 3:52 PMMichael Schmidt
04/08/2022, 3:52 PM<cfset list = [] >bdw429s
04/08/2022, 3:52 PMgratzc
04/08/2022, 3:56 PM<cfset list = [] >
<cfquery name="q2">
select * from users
where
userID IN (<cfqueryparam cfsqltype="cf_sql_integer" value="#arrayToList(list)#" list="true" />)
</cfquery>
<cfdump var="#q2#">
for a regular query, it doesn’t throw and returns an empty result set, the complied SQL for ^^ is
select * from users
where
userID IN ([CF_SQL_INTEGER])gratzc
04/08/2022, 3:56 PMbdw429s
04/08/2022, 4:06 PMbdw429s
04/08/2022, 4:07 PMbdw429s
04/08/2022, 4:07 PMbdw429s
04/08/2022, 4:08 PMgratzc
04/08/2022, 4:08 PMbdw429s
04/08/2022, 4:09 PMbdw429s
04/08/2022, 4:10 PMbdw429s
04/08/2022, 4:11 PMbdw429s
04/08/2022, 4:12 PMbdw429s
04/08/2022, 4:22 PMbdw429s
04/08/2022, 4:22 PMNOT IN scenario, in which passing an empty set as null no longer works since null is never equal or unequal to anything!bdw429s
04/08/2022, 4:23 PMnot in ( null ) gives the opposite behavior desired.bdw429s
04/08/2022, 5:04 PMbdw429s
04/08/2022, 5:13 PMIN and NOT IN but only when an empty array is used to denote an empty set, and with some DB-specific SQL hackery.Adam Cameron
IN (value,...).
An empty string is a zero-length list (as Brad observed), which should not be valid.
IN(subquery) is a different function, so a zero-row subquery is not analogous to a zero-lenth list-of-values.
Think of the two like f(String s) and f(Integer i) in Java: different implementations, and the sense of what constitutes "empty" or "valid" differs from the two. Using that metaphor, IN () is not the same "method signature" as IN (value,...), and the no-param version does not exist. Therefore: error. This is legit.
Trying to find if ANSI SQL has anything specific to say.bdw429s
04/08/2022, 5:25 PM