runPrepUpdate not updating?

I have this query that works:

UPDATE DTIM_TIME_TABLE
SET LEVEL6ID = 'TEST'
WHERE LEVEL5ID IN ('TEST', 'TEST1')

but this doesn't:

list2 = [
	"TEST",
	"TEST1"
]

r = '(' + ', '.join(["'%s'" % (l) for l in list2]) + ')'
# r = ('TEST', 'TEST1')

system.db.runPrepUpdate(
	"UPDATE DTIM_TIME_TABLE SET LEVEL6ID = 'TEST' WHERE LEVEL5ID IN ?",
	[r]
)

I'm dumb? Any idea?
Thanks in advance

You're not dumb. It was discussed a few times on the forum. Here's one from eight years ago.

1 Like

Just as documentation. I ended using system.db.runQuery() and I simply build the string.

statement = 'UPDATE DTIM_TIME_TABLE SET LEVEL6ID = 'TEST' WHERE LEVEL5ID IN "
r = '(' + ', '.join(["'%s'" % (l) for l in list2]) + ')'

query = statement + r
# \_> UPDATE DTIM_TIME_TABLE SET LEVEL6ID = 'TEST' WHERE LEVEL5ID IN ('TEST', 'TEST1')

system.db.runQuery(query)
1 Like

That is extremely unsafe for quoted strings as you show. Don't do that. Anyone encountering this topic in the future is highly encouraged to not follow Daniel's example.

1 Like