Last active
December 26, 2020 04:54
-
-
Save gokaybiz/327b97720a814b5eb52f8b2e6a211798 to your computer and use it in GitHub Desktop.
insert query builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EXEC sp_MSForEachTable 'TRUNCATE TABLE ?' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment