Created
April 4, 2012 09:41
-
-
Save mryoshio/2300017 to your computer and use it in GitHub Desktop.
Update many records all at once using pymysql module.
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 main(): | |
""" | |
Execute three actions. | |
1. get id, new title from a file. e.g. [(title, id),(title, id)] | |
2. update DB | |
""" | |
id_titles = get_id_titles(EXPECTED_LIST) | |
conn = pymysql.Connect(host=DB_HOST, db=DB, user=DB_USER, passwd=DB_PSWD, charset=CHARSET) | |
cursor = conn.cursor() | |
query = "UPDATE aegifpage SET page_title = %s where page_id = %s" | |
cursor.executemany(query, id_titles) | |
cursor.close() | |
conn.commit() | |
conn.close() | |
print "updated successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment