Use system.db.runUpdateQuery with variable value counts

Instead of inserting a ‘%s’ for each value that you want, build a single string representing the value list that you need. Similar to how you converted the Tuple to a string.

def transactionInsert(Labels, Values):
    system.db.runUpdateQuery('INSERT INTO DataTable (%s) VALUES (%s) ' % (','.join(Labels),','.join(Values))

There is no need to import system, that is done automatically for you.

Be careful here, as this approach can be open to SQL Injection.

2 Likes