Skip to content

Instantly share code, notes, and snippets.

@gokaybiz
Last active December 26, 2020 04:54
Show Gist options
  • Save gokaybiz/327b97720a814b5eb52f8b2e6a211798 to your computer and use it in GitHub Desktop.
Save gokaybiz/327b97720a814b5eb52f8b2e6a211798 to your computer and use it in GitHub Desktop.
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