Skip to content

Instantly share code, notes, and snippets.

@gokaybiz
Last active Dec 26, 2020
Embed
What would you like to do?
insert query builder
def sql_insert(cursor, table, dictionary):
columns = ','.join(dictionary.keys())
placeholders = ', '.join('?' * len(dictionary))
sql_cmd = "INSERT INTO {0} ({1}) VALUES ({2})".format(table, columns, placeholders)
return cursor.execute(sql_cmd, list(dictionary.values()))
#example usage
#gene_rows = {}
#gene_rows['gene_name'] = parsedCSVColumns['GeneSymbol']
#...
#sql_insert(cursor, 'ACC', gene_rows)
#conn.commit()
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment