Error When Using system.db.runPrepQuery

I'm trying to execute a basic SQL query.
This is the code I'm using:

mq="SELECT MeltCount FROM M7Pour WHERE MeltCount>?"
data=system.db.runPrepQuery(mq,4)

This generates the error:

java.lang.Exception: java.lang.Exception: Error executing system.db.runPrepQuery(SELECT MeltCount FROM M7Pour WHERE MeltCount>?, , [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], )

I've tried converting my search (the 4 in the above code) to float, int, and string, but still get errors.

When I change my code to this:

mq="SELECT MeltCount FROM M7Pour WHERE MeltCount>4"
data=system.db.runPrepQuery(mq)

I don't get any errors and it returns the data I want. Is there some casting I need to do in my query or conversion I need to do for the value I'm searching? In the meantime I can add my search to the string being queried, but this seems like an unfortunate workaround.

It would be easier to confirm if you shared the full depth of the error stacktrace, but...
You probably need to wrap your parameter list in square brackets, to make a list.
As in:
data = system.db.runPrepQuery(mq, [4]).
Because the function expects some kind of multi-valued collection as a first step, before it starts checking input types.

2 Likes

Thanks, this fixed it