DropdownBox , memory tags to handle Mysql database

Hi all, I want to take data from mysql database , for example the Cumulative Energy produced by the plants each month. I Created this for the User so he can select which month , year , Plant he wants to view and at the result to the right side the energy must appear

I have also Created these tags below in order to be able to call them through a query call and the result to be stored at the result tag. I have been testing some scripting but i have a big list of errors
image

I have been testing some scripting but i have a big list of errors

have you had any similar issues?

This feels very un-perspective.

I am not sure I understand the flow. What are the tags being used for exactly? are you just using them as value place holders?

Where is the query actually being ran?

Based on what I am seeing you should be using custom properties and named queries to retrieve data from your specific database.

1 Like

You cut off any part of the error message that would indicate what actually went wrong. Post the full stacktrace here, as preformatted text (using the </> icon above each post) if you can't figure out what it means.

1 Like

Using tags as you have in your post will cause all clients to interfere with each other.
Instead,

  • create custom properties on the view (if they're only used within the view) or on the Project Browser | Perspective and then in Properties Browser | CUSTOM. Create one for each dropdown.
  • Use these to store the dropdown selection by creating a bidirectional binding on each dropdown's value to the appropriate custom property.
  • In your Named Query or scripted query use the custom properties in the WHERE clause.
1 Like

Hi Griffith sorry for the poor details i gave you , below is my code
try:

month = system.tag.read("[Default]HistoricalData/Month").value  
year = system.tag.read("[Default]HistoricalData/Year").value    
plant_name = system.tag.read("[Default]HistoricalData/Plant").value  


print("Month: {}, Year: {}, Plant Name: {}".format(month, year, plant_name))


if month is None or year is None or plant_name is None:
    raise ValueError("One or more tag values are missing or invalid.")

query_first_day = """
    SELECT cumulative_energy 
    FROM IgnitionDB.Plants_Cumulative_Energy
    WHERE plant_name = ? 
    AND MONTH(production_date) = ? 
    AND YEAR(production_date) = ? 
    ORDER BY production_date ASC 
    LIMIT 1
"""
print("Executing first query with parameters: Plant Name: {}, Month: {}, Year: {}".format(plant_name, month, year))

result_first_day = system.db.runPrepQuery(query_first_day, [plant_name, month, year])


if result_first_day:
    first_day_energy = result_first_day[0]["cumulative_energy"]
    print("First Day Energy: {}".format(first_day_energy))
else:
    first_day_energy = None
    print("No first day energy data found.")

query_last_day = """
    SELECT cumulative_energy 
    FROM IgnitionDB.Plants_Cumulative_Energy
    WHERE plant_name = ? 
    AND MONTH(production_date) = ? 
    AND YEAR(production_date) = ? 
    ORDER BY production_date DESC 
    LIMIT 1
"""
print("Executing second query with parameters: Plant Name: {}, Month: {}, Year: {}".format(plant_name, month, year))

result_last_day = system.db.runPrepQuery(query_last_day, [plant_name, month, year])


if result_last_day:
    last_day_energy = result_last_day[0]["cumulative_energy"]
    print("Last Day Energy: {}".format(last_day_energy))
else:
    last_day_energy = None
    print("No last day energy data found.")


if first_day_energy is not None and last_day_energy is not None:
    monthly_energy_production = last_day_energy - first_day_energy
    print("Monthly energy production for {} in {}/{}: {}".format(plant_name, month, year, monthly_energy_production))
else:
    print("Energy data for the specified period is incomplete.")

except Exception as e:
print("An error occurred: {}".format(e))

  • And The Error is here below

try:

month = system.tag.read("[Default]HistoricalData/Month").value  
year = system.tag.read("[Default]HistoricalData/Year").value    
plant_name = system.tag.read("[Default]HistoricalData/Plant").value  


print("Month: {}, Year: {}, Plant Name: {}".format(month, year, plant_name))


if month is None or year is None or plant_name is None:
    raise ValueError("One or more tag values are missing or invalid.")

query_first_day = """
    SELECT cumulative_energy 
    FROM IgnitionDB.Plants_Cumulative_Energy
    WHERE plant_name = ? 
    AND MONTH(production_date) = ? 
    AND YEAR(production_date) = ? 
    ORDER BY production_date ASC 
    LIMIT 1
"""
print("Executing first query with parameters: Plant Name: {}, Month: {}, Year: {}".format(plant_name, month, year))

result_first_day = system.db.runPrepQuery(query_first_day, [plant_name, month, year])


if result_first_day:
    first_day_energy = result_first_day[0]["cumulative_energy"]
    print("First Day Energy: {}".format(first_day_energy))
else:
    first_day_energy = None
    print("No first day energy data found.")

query_last_day = """
    SELECT cumulative_energy 
    FROM IgnitionDB.Plants_Cumulative_Energy
    WHERE plant_name = ? 
    AND MONTH(production_date) = ? 
    AND YEAR(production_date) = ? 
    ORDER BY production_date DESC 
    LIMIT 1
"""
print("Executing second query with parameters: Plant Name: {}, Month: {}, Year: {}".format(plant_name, month, year))

result_last_day = system.db.runPrepQuery(query_last_day, [plant_name, month, year])


if result_last_day:
    last_day_energy = result_last_day[0]["cumulative_energy"]
    print("Last Day Energy: {}".format(last_day_energy))
else:
    last_day_energy = None
    print("No last day energy data found.")


if first_day_energy is not None and last_day_energy is not None:
    monthly_energy_production = last_day_energy - first_day_energy
    print("Monthly energy production for {} in {}/{}: {}".format(plant_name, month, year, monthly_energy_production))
else:
    print("Energy data for the specified period is incomplete.")

except Exception as e:
print("An error occurred: {}".format(e))

  • List item

I think the error i get is in this block im not sure if the syntax here is correct

/query_last_day = """
SELECT cumulative_energy
FROM IgnitionDB.Plants_Cumulative_Energy
WHERE plant_name = ?
AND MONTH(production_date) = ?
AND YEAR(production_date) = ?
ORDER BY production_date DESC
LIMIT 1
/ """

Hi Transistor , i have the dropdown set to bidirectional for all 3 dropdown boxes

have made a named query with this code below

if result_first_day:
first_day_energy = result_first_day[0]["cumulative_energy"]
print("First Day Energy: {}".format(first_day_energy))
else:
first_day_energy = None
print("No first day energy data found.")

query_last_day = """
    SELECT cumulative_energy 
    FROM IgnitionDB.Plants_Cumulative_Energy
    WHERE plant_name = ? 
    AND MONTH(production_date) = ? 
    AND YEAR(production_date) = ? 
    ORDER BY production_date DESC 
    LIMIT 1
"""
print("Executing second query with parameters: Plant Name: {}, Month: {}, Year: {}".format(plant_name, month, year))

result_last_day = system.db.runPrepQuery(query_last_day, [plant_name, month, year])


if result_last_day:
    last_day_energy = result_last_day[0]["cumulative_energy"]
    print("Last Day Energy: {}".format(last_day_energy))
else:
    last_day_energy = None
    print("No last day energy data found.")


if first_day_energy is not None and last_day_energy is not None:
    monthly_energy_production = last_day_energy - first_day_energy
    print("Monthly energy production for {} in {}/{}: {}".format(plant_name, month, year, monthly_energy_production))
else:
    print("Energy data for the specified period is incomplete.")

except Exception as e:
print("An error occurred: {}".format(e))

when i try to execute it i recieve this error message


.

I just need to know if this part has the correct syntax, and how to use the SQL query code in the Script enviroment.

Btw this code works just fine

query = "SELECT * FROM Plants_Cumulative_Energy LIMIT 5"
try:
results = system.db.runQuery(query, "IgnitionDB")
for row in results:
print(row) # Prints each row
except Exception as e:
print("Error fetching data:", str(e))

Filippos, can you go back through your previous few posts and fix the formatting as shown in Wiki - how to post code on this forum. It will help us to see what's code and what's not and to check for indentation errors. Thanks.

2 Likes

You posted your code twice, but not the error.

3 Likes

A few things:

  1. You should not read tags in one at a time. Definitely not causing your issue but better to get in the habit. Instead you should use system.tag.readBlocking() with a list of tag paths to read all of the tags in a single call.

  2. It is best practice to only wrap the things which might result in an error in the the Try...Except block. Since you're not doing anything to specifically react to the error (just printing out some information) then IMHO, a there is no need for try...except in this example.

  3. There is no need to create two variables to hold the exact same query string. Just reuse the same variable and send a different parameter value.

  4. Since you are only returning a single column and row, you should use system.db.runScalarPrepQuery() to just return the single value.

  5. You have not actually posted the error, so we can not see what the true cause of the error is.

paths = ['[Default]HistoricalData/{}' for path in ('Month','Year','Plant')]
month, year, plant_name = [qv.value for qv in system.tag.readBlocking(paths)]

print("Month: {}, Year: {}, Plant Name: {}".format(month, year, plant_name))

if not all(month,year,plant_name):
    raise ValueError("One or more tag values are missing or invalid.")

query= """
    SELECT cumulative_energy 
    FROM IgnitionDB.Plants_Cumulative_Energy
    WHERE plant_name = ? 
    AND MONTH(production_date) = ? 
    AND YEAR(production_date) = ? 
    ORDER BY production_date {}
    LIMIT 1
"""

first_day_energy = system.db.runScalarPrepQuery(query.format('ASC'), [plant_name, month, year])
result_last_day = system.db.runScalarPrepQuery(query.format('DESC'), [plant_name, month, year])

if all(first_day_energy, last_day_energy):
    monthly_energy_production = last_day_energy - first_day_energy
    print("Monthly energy production for {} in {}/{}: {}".format(plant_name, month, year, monthly_energy_production))
else:
    print("Energy data for the specified period is incomplete.")

A named query will only have SQL in it so there should be no scripting at all. You haven't shown what you actually input in to the Named Query authoring tab, and so there is no way for us to know why that SQL didn't produce a result set.

3 Likes

@Transistor provided instructions in comment #7 on how to post code on this forum. Please edit your comment and apply the "Preformatted Text" styling to that traceback.

1 Like
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 25, in <module>
  File "<input>", line 25, in <module>
        SELECT `CKGSunenergy_1MW_CE` 
        FROM Plants_Cumulative_Energy 
        WHERE MONTH(production_date) = ? 
        AND YEAR(production_date) = ? 
        ORDER BY production_date ASC 
        LIMIT 1
    , IgnitionDB, [12, 2025], )
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:302)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(
        SELECT `CKGSunenergy_1MW_CE` 
        FROM Plants_Cumulative_Energy 
        WHERE MONTH(production_date) = ? 
        AND YEAR(production_date) = ? 
        ORDER BY production_date ASC 
        LIMIT 1
    , IgnitionDB, [12, 2025], )

	at org.python.core.Py.JavaError(Py.java:545)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:302)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:553)
	at org.python.core.PyObject.__call__(PyObject.java:494)
	at org.python.core.PyObject.__call__(PyObject.java:498)
	at org.python.pycode._pyx63.f$0(<input>:35)
	at org.python.pycode._pyx63.call_function(<input>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1703)
	at org.python.core.Py.exec(Py.java:1747)
	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)
	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:628)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:616)
	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Exception: Error executing system.db.runPrepQuery(
        SELECT `CKGSunenergy_1MW_CE` 
        FROM Plants_Cumulative_Energy 
        WHERE MONTH(production_date) = ? 
        AND YEAR(production_date) = ? 
        ORDER BY production_date ASC 
        LIMIT 1
    , IgnitionDB, [12, 2025], )
	... 26 more
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Unknown column 'production_date' in 'where clause'
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:360)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:334)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:287)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.runLimitQuery(GatewayInterface.java:893)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.runQuery(GatewayInterface.java:864)
	at com.inductiveautomation.ignition.client.script.ClientDBUtilities._runPrepQuery(ClientDBUtilities.java:328)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:294)
	... 24 more
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'production_date' in 'where clause'
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:112)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:114)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:987)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1055)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
	at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper$SRPreparedStatement.executeQuery(SRConnectionWrapper.java:973)
	at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.RunQuery.run(RunQuery.java:101)
	at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.AbstractDBAction.invoke(AbstractDBAction.java:66)
	at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:435)
	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:598)
	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:1580)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1384)
	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:1553)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1306)
	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$RequestDispatchable.dispatch(HttpChannel.java:1598)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:287)
	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:421)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:199)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
	at java.lang.Thread.run(null)
Traceback (most recent call last):
  File "<input>", line 25, in <module>
  File "<input>", line 25, in <module>
        SELECT `CKGSunenergy_1MW_CE` 
        FROM Plants_Cumulative_Energy 
        WHERE MONTH(production_date) = ? 
        AND YEAR(production_date) = ? 
        ORDER BY production_date ASC 
        LIMIT 1
    , IgnitionDB, [12, 2025], )
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:302)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(
        SELECT `CKGSunenergy_1MW_CE` 
        FROM Plants_Cumulative_Energy 
        WHERE MONTH(production_date) = ? 
        AND YEAR(production_date) = ? 
        ORDER BY production_date ASC 
        LIMIT 1
    , IgnitionDB, [12, 2025], )
>>> Keyboard Interrupt
>>> Keyboard Interrupt
>>> 

SyntaxError: no viable alternative at input 'COLUMNS' (<input>, line 1)
>>> 
Java Traceback:
Traceback (most recent call last):
  File "<input>", line 25, in <module>
  File "<input>", line 25, in <module>
    SELECT `CKGSunenergy_1MW_CE` 
    FROM Plants_Cumulative_Energy 
    WHERE MONTH(timestamp) = ? 
    AND YEAR(timestamp) = ? 
    ORDER BY timestamp ASC 
    LIMIT 1
, IgnitionDB, [12, 2025], )
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:302)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(
    SELECT `CKGSunenergy_1MW_CE` 
    FROM Plants_Cumulative_Energy 
    WHERE MONTH(timestamp) = ? 
    AND YEAR(timestamp) = ? 
    ORDER BY timestamp ASC 
    LIMIT 1
, IgnitionDB, [12, 2025], )

	at org.python.core.Py.JavaError(Py.java:545)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:302)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
	at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:553)
	at org.python.core.PyObject.__call__(PyObject.java:494)
	at org.python.core.PyObject.__call__(PyObject.java:498)
	at org.python.pycode._pyx67.f$0(<input>:35)
	at org.python.pycode._pyx67.call_function(<input>)
	at org.python.core.PyTableCode.call(PyTableCode.java:173)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1703)
	at org.python.core.Py.exec(Py.java:1747)
	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)
	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:628)
	at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:616)
	at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)
	at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
	at java.desktop/javax.swing.SwingWorker.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Exception: Error executing system.db.runPrepQuery(
    SELECT `CKGSunenergy_1MW_CE` 
    FROM Plants_Cumulative_Energy 
    WHERE MONTH(timestamp) = ? 
    AND YEAR(timestamp) = ? 
    ORDER BY timestamp ASC 
    LIMIT 1
, IgnitionDB, [12, 2025], )
	... 26 more
Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Unknown column 'timestamp' in 'where clause'
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.newGatewayException(GatewayInterface.java:360)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:334)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.sendMessage(GatewayInterface.java:287)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.runLimitQuery(GatewayInterface.java:893)
	at com.inductiveautomation.ignition.client.gateway_interface.GatewayInterface.runQuery(GatewayInterface.java:864)
	at com.inductiveautomation.ignition.client.script.ClientDBUtilities._runPrepQuery(ClientDBUtilities.java:328)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:294)
	... 24 more
Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'timestamp' in 'where clause'
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:112)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:114)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:987)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1055)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
	at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:122)
	at com.inductiveautomation.ignition.gateway.datasource.SRConnectionWrapper$SRPreparedStatement.executeQuery(SRConnectionWrapper.java:973)
	at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.RunQuery.run(RunQuery.java:101)
	at com.inductiveautomation.ignition.gateway.servlets.gateway.functions.AbstractDBAction.invoke(AbstractDBAction.java:66)
	at com.inductiveautomation.ignition.gateway.servlets.Gateway.doPost(Gateway.java:435)
	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:598)
	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:1580)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1384)
	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:1553)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1306)
	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$RequestDispatchable.dispatch(HttpChannel.java:1598)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:287)
	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:421)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.consumeTask(AdaptiveExecutionStrategy.java:390)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.tryProduce(AdaptiveExecutionStrategy.java:277)
	at org.eclipse.jetty.util.thread.strategy.AdaptiveExecutionStrategy.run(AdaptiveExecutionStrategy.java:199)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:411)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:969)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1194)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1149)
	at java.lang.Thread.run(null)
Traceback (most recent call last):
  File "<input>", line 25, in <module>
  File "<input>", line 25, in <module>
    SELECT `CKGSunenergy_1MW_CE` 
    FROM Plants_Cumulative_Energy 
    WHERE MONTH(timestamp) = ? 
    AND YEAR(timestamp) = ? 
    ORDER BY timestamp ASC 
    LIMIT 1
, IgnitionDB, [12, 2025], )
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.error(AbstractDBUtilities.java:392)
	at com.inductiveautomation.ignition.common.script.builtin.AbstractDBUtilities.runPrepQuery(AbstractDBUtilities.java:302)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(
    SELECT `CKGSunenergy_1MW_CE` 
    FROM Plants_Cumulative_Energy 
    WHERE MONTH(timestamp) = ? 
    AND YEAR(timestamp) = ? 
    ORDER BY timestamp ASC 
    LIMIT 1
, IgnitionDB, [12, 2025], )

1 Like

Thank you Phil

Phil asked you to follow my instructions to go and edit all your previous posts to fix the formatting so they are readable by anyone with a similar problem or anyone trying to help you. Instead you have left a big mess in post #10 and posted the whole thing again but as one continuous code block in post #12. Please follow the instructions, keep the forum tidy and make it easy for us to help you.

Can you go back and tidy up all your posts?

1 Like

Caused by: com.inductiveautomation.ignition.client.gateway_interface.GatewayException: Unknown column 'production_date' in 'where clause'

Well... You're trying to get data from a column that doesn't exist in that table.

3 Likes

And also 'timestamp'

1 Like

Hi Transistor i have solved it diferently i have added a table and connected it to a name query which will do the job for our needs at the moment. Since this might needed more coding and scripting which make it more complicated. About tiding up my post will try to do that , you are correct and thank you for your advices, i will try to tide them up.