Was trying to upgrade my gateway from 8.1.17 to 8.1.26 but it caused many of my SELECT
Named Queries to break with the above error. Here's a singular example stack trace
WARN Vision.Binding.NamedQueryAdapter - Error running query:
com.inductiveautomation.factorypmi.application.gateway.NQuery@5be5d6e8@0ms
On: Invoices.Root Container.Table_Invoices.data
java.lang.Exception: Error running query:
com.inductiveautomation.factorypmi.application.gateway.NQuery@5be5d6e8@0ms
On: Invoices.Root Container.Table_Invoices.data
at com.inductiveautomation.factorypmi.application.gateway.QueryManager$QueryExecutor.run(QueryManager.java:311)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: java.sql.SQLException: Could not set parameter at position 1 (values was -1)
Query - conn:196(M) - "SELECT
0 as 'Check',
`view_listInvoices`.`idx`,
`view_listInvoices`.`dateEntered`,
`view_listInvoices`.`flag`,
`view_listInvoices`.`autoFlag`,
`listCustomers`.`name` as 'Customer',
`listLocations`.`name` as 'Location',
`listAreas`.`name` as 'Area',
`listAssets`.`name` as 'Asset',
`listsalesorders`.`number` as 'soNumber',
`listsalesorders`.`name` as 'soName',
`view_listInvoices`.`number` as 'invNumber',
`view_listInvoices`.`name`,
CONCAT(`listUsers`.`firstName`,' ', `listUsers`.`lastName`) as 'Cust Contact',
(SELECT `name` FROM `listposoinvstatus` WHERE `idx` = `view_listInvoices`.`status`) as 'status',
#`view_listInvoices`.`parentProjectID`,
`view_listInvoices`.`individualId`,
(SELECT
CASE
WHEN
`listsalesorders`.`state` IS NULL
THEN
"
ELSE
(SELECT description FROM descsostate WHERE descsostate.idx=listsalesorders.state)
END) as 'SO State',
(SELECT
CASE
WHEN
(`view_listInvoices`.`state` IS NULL OR `view_listInvoices`.`state` IN (4, 5, 6, 7))
THEN
"
ELSE
(SELECT descriptio..."
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:351)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:325)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:278)
at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.invoke(GatewayInterface.java:954)
at com.inductiveautomation.factorypmi.application.db.namedqueries.ClientNamedQueryManager.execute(ClientNamedQueryManager.java:32)
at com.inductiveautomation.factorypmi.application.gateway.NQuery.execute(NQuery.java:70)
at com.inductiveautomation.factorypmi.application.gateway.QueryManager$Query.execute(QueryManager.java:668)
at com.inductiveautomation.factorypmi.application.gateway.QueryManager$QueryExecutor.run(QueryManager.java:308)
... 1 common frames omitted
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayResponse$GatewayThrowable: java.sql.SQLException: Could not set parameter at position 1 (values was -1)
Query - conn:196(M) - "SELECT
0 as 'Check',
`view_listInvoices`.`idx`,
`view_listInvoices`.`dateEntered`,
`view_listInvoices`.`flag`,
`view_listInvoices`.`autoFlag`,
`listCustomers`.`name` as 'Customer',
`listLocations`.`name` as 'Location',
`listAreas`.`name` as 'Area',
`listAssets`.`name` as 'Asset',
`listsalesorders`.`number` as 'soNumber',
`listsalesorders`.`name` as 'soName',
`view_listInvoices`.`number` as 'invNumber',
`view_listInvoices`.`name`,
CONCAT(`listUsers`.`firstName`,' ', `listUsers`.`lastName`) as 'Cust Contact',
(SELECT `name` FROM `listposoinvstatus` WHERE `idx` = `view_listInvoices`.`status`) as 'status',
#`view_listInvoices`.`parentProjectID`,
`view_listInvoices`.`individualId`,
(SELECT
CASE
WHEN
`listsalesorders`.`state` IS NULL
THEN
"
ELSE
(SELECT description FROM descsostate WHERE descsostate.idx=listsalesorders.state)
END) as 'SO State',
(SELECT
CASE
WHEN
(`view_listInvoices`.`state` IS NULL OR `view_listInvoices`.`state` IN (4, 5, 6, 7))
THEN
"
ELSE
(SELECT descriptio..."
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor$NamedQueryInstance.execute(NamedQueryExecutor.java:407)
at com.inductiveautomation.ignition.gateway.db.namedquery.NamedQueryExecutor.execute(NamedQueryExecutor.java:173)
at com.inductiveautomation.ignition.gateway.db.namedquery.GatewayNamedQueryManager.execute(GatewayNamedQueryManager.java:92)
at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.NamedQueryFunctions.execute(NamedQueryFunctions.java:49)
at jdk.internal.reflect.GeneratedMethodAccessor71.invoke(null)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(null)
at java.lang.reflect.Method.invoke(null)
at com.inductiveautomation.ignition.gateway.servlets.gateway.AbstractGatewayFunction.invoke(AbstractGatewayFunction.java:228)
at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:434)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:523)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
at com.inductiveautomation.ignition.gateway.bootstrap.MapServlet.service(MapServlet.java:86)
at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1410)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1665)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:527)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:131)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:223)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1570)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1383)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1543)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1305)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
at com.inductiveautomation.catapult.handlers.RemoteHostNameLookupHandler.handle(RemoteHostNameLookupHandler.java:121)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:301)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:51)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
at org.eclipse.jetty.server.Server.handle(Server.java:563)
at org.eclipse.jetty.server.HttpChannel.lambda$handle$0(HttpChannel.java:505)
at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:762)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:497)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:282)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.runTask(AdaptiveExecutionStrategy.java:416)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:385)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:272)
at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.lambda$new$0(AdaptiveExecutionStrategy.java:140)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:934)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1078)
at java.lang.Thread.run(null)
And the named query definition - all parameters are used in the WHERE
clause for filtering -
SELECT
0 as 'Check',
`listSalesOrders`.`idx`,
`listSalesOrders`.`dateEntered`,
`listCustomers`.`name` as 'Customer',
`listLocations`.`name` as 'Location',
`listAreas`.`name` as 'Area',
`listAssets`.`name` as 'Asset',
`listSalesOrders`.`number` as 'soNumber',
`listSalesOrders`.`name` as 'soName',
IFNULL(`view_listinvoices`.`number`,'') as 'invNumber',
IFNULL(`view_listinvoices`.`name`,'') as 'invName',
CONCAT(`cu`.`firstName`,' ', `cu`.`lastName`) as 'Cust Contact',
(SELECT `name` FROM `listposoinvstatus` WHERE `idx` = `listSalesOrders`.`status`) as 'status',
(SELECT label FROM descsotype WHERE value = `listSalesOrders`.`type`) as 'type',
`listSalesOrders`.`billThisMonth` as 'billThisMonth',
`listSalesOrders`.`parentProjectID`,
`listSalesOrders`.`individualId`,
`listSalesOrders`.`taxable`,
`listSalesOrders`.`totalPreTaxAmt`,
`listSalesOrders`.`totalTax`,
`view_salesordersalreadybilled`.`totalamountleft` as 'Amount Left',
`listSalesOrders`.`totalMargin`,
`listSalesOrders`.`totalWeeks`,
`listSalesOrders`.`leftMargin`,
`listSalesOrders`.`leftWeeks`,
(Case (`listSalesOrders`.`leftWeeks`) WHEN 0 THEN 0 ELSE (`listSalesOrders`.`leftMargin`)/(`listSalesOrders`.`leftWeeks`) END ) as 'Margin per Week',
`listProjects`.`idx` as 'parentProjectId',
`listProjects`.`number` as 'ProjectNumber',
`listAssets`.`idx` as 'parentAssetId',
`listAreas`.`idx` as 'parentAreaId',
`listLocations`.`idx` as 'parentLocationId',
`listCustomers`.`idx` as 'parentCustomerId',
`view_salesorderscostallocated`.`costAllocatedTotal`,
`view_salesordersalreadybilled`.`alreadyBilledTotal`,
`listSalesOrders`.`totalSOAmount` as 'Total',
`listSalesOrders`.`comment` as 'comment',
(SELECT
CASE
WHEN
`listsalesorders`.`state` IS NULL
THEN
"---"
ELSE
(SELECT description FROM descsostate WHERE descsostate.idx=listsalesorders.state)
END) as 'SO State',
(SELECT
CASE
WHEN
(`view_listInvoices`.`state` IS NULL OR `view_listInvoices`.`state` IN (0, 4, 5, 6, 7))
THEN
"---"
ELSE
(SELECT description FROM descinvoicestate WHERE descinvoicestate.idx=view_listInvoices.state)
END) as 'Invoice State',
(SELECT CASE
WHEN
`view_listInvoices`.`contNN` = 1
THEN
"Not Needed"
WHEN
`view_listInvoices`.`sentToContact` = 1
THEN
"Sent"
WHEN
`view_listInvoices`.`state` IS NULL AND `view_listInvoices`.`status` = 7
THEN
"---"
ELSE
"No"
END) as 'Contact',
(SELECT CASE
WHEN
`view_listInvoices`.`acctNN` = 1
THEN
"Not Needed"
WHEN
`view_listInvoices`.`receivedConfirmation`=1
THEN
"Confirmed"
WHEN
`view_listInvoices`.`sentToAccounting` = 1
THEN
"Sent"
WHEN
`view_listInvoices`.`state` IS NULL AND `view_listInvoices`.`status` = 7
THEN
"---"
ELSE
"No"
END) as 'Acct',
(SELECT CASE
WHEN
`listsalesorders`.`quoteSent`=1
THEN
"Sent"
WHEN
`listsalesorders`.`quoteNeeded`=1
THEN
"Needed"
ELSE
"---"
END) as 'Quote',
(SELECT CASE
WHEN
`listsalesorders`.`poSent`=1
THEN
"Received"
WHEN
`listsalesorders`.`poRequested`
THEN
"Requested"
WHEN
`listsalesorders`.`poNeeded`=1
THEN
"Needed"
ELSE
"---"
END) as 'PO',
(SELECT CASE
WHEN
datediff(now(), view_listInvoices.dateDue) <= 30 AND `view_listInvoices`.`status`!=7
THEN
"Out for Payment"
WHEN
datediff(now(), view_listInvoices.dateDue) > 30 AND datediff(now(), view_listInvoices.dateDue)<=60 AND `view_listInvoices`.`status`!=7
THEN
"Past Due"
WHEN
(datediff(now(), `view_listInvoices`.`dateDue`) > 60 AND `view_listInvoices`.`status`!=7)
THEN
"Way Past Due"
WHEN
(`view_listInvoices`.`status`=7)
THEN
"Paid"
ELSE
"---"
END) as 'Payment'
FROM `listSalesOrders`
LEFT JOIN `view_listinvoices` ON `listsalesorders`.`idx` = `view_listinvoices`.`parentSOId`
LEFT JOIN `listUsers` as `soprep` ON `soprep`.`idx` = `listsalesorders`.`individualId`
LEFT JOIN `listUsers` as `ilu` ON `ilu`.`idx` = `view_listinvoices`.`individualId`
LEFT JOIN `listProjects` ON `listProjects`.`idx` = `listSalesOrders`.`parentProjectId`
LEFT JOIN `listAssets` ON `listAssets`.`idx` = `listProjects`.`parentAssetId`
LEFT JOIN `listAreas` ON `listAreas`.`idx` = `listAssets`.`parentAreaId`
LEFT JOIN `listLocations` ON `listLocations`.`idx` = `listAreas`.`parentLocationId`
LEFT JOIN `listCustomers` ON `listCustomers`.`idx` = `listLocations`.`parentCustomerId`
LEFT JOIN `listUsers` as `cu` ON `cu`.`idx` = `listSalesOrders`.`custContactId`
LEFT JOIN `view_salesordersalreadybilled` ON `view_salesordersalreadybilled`.`idx` = `listSalesOrders`.`idx`
LEFT JOIN `view_salesorderscostallocated` ON `view_salesorderscostallocated`.`idx` = `listSalesOrders`.`idx`
WHERE
(:salesOrderId=-1 OR `listSalesOrders`.`idx`= :salesOrderId) AND
(:customerId=-1 OR `listCustomers`.`idx`=:customerId) AND
(:locationId=-1 OR `listLocations`.`idx`=:locationId) AND
(:areaId=-1 OR `listAreas`.`idx`=:areaId) AND
(:assetId=-1 OR `listAssets`.`idx`=:assetId) AND
(:projectId=-1 OR `listProjects`.`idx`=:projectId)
AND
CASE
WHEN (DATE_FORMAT(:startDate, '%Y-%m-%d')='1985-08-09' AND DATE_FORMAT(:endDate, '%Y-%m-%d')='1985-08-09') OR (:startDate IS NULL AND :endDate IS NULL)
THEN 1=1
ELSE
`listsalesorders`.`dateEntered` >= :startDate AND `listsalesorders`.`dateEntered` <= :endDate
END
AND
(:ItemStatus = -1 OR `listsalesorders`.`status`= :ItemStatus)
AND
(:ShippingStatus =-1 OR `listsalesorders`.`shippingstatus`= :ShippingStatus)
ORDER BY `listCustomers`.`name`, `listLocations`.`name`, `listSalesOrders`.`number`
with the parameters -
Is it really just a singular parameter that is causing the issue (the one at position 1 - ItemStatus or ShippingStatus?) or is there something with the structure of my NQ that is no longer acceptable in 8.1.26?