Use an always false statement
Before creating the SQL, check for the array size.
If the size is 0, generate the where statement as 1 = 2
, as in:
SELECT * FROM USERS WHERE name in ()
becomes
SELECT * FROM USERS WHERE 1 = 2
For "not in" on an empty array, generate an always true statement as in:
SELECT * FROM USERS WHERE name not in ()
becomes
SELECT * FROM USERS WHERE 1 = 1
This should work for more complex queries as:
SELECT * FROM USERS WHERE (name in () OR name = 'Alice')
becomes
SELECT * FROM USERS WHERE (1 = 2 OR name = 'Alice')