{"id":50099,"date":"2024-12-03T15:51:22","date_gmt":"2024-12-03T07:51:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/50099\/"},"modified":"2024-12-03T15:51:22","modified_gmt":"2024-12-03T07:51:22","slug":"%e4%bd%bf%e7%94%a8pymysql%e6%97%b6%e5%a6%82%e4%bd%95%e5%ae%89%e5%85%a8%e5%9c%b0%e6%a0%bc%e5%bc%8f%e5%8c%96sql%e8%af%ad%e5%8f%a5%ef%bc%8c%e9%81%bf%e5%85%8d%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/50099\/","title":{"rendered":"\u4f7f\u7528PyMySQL\u65f6\u5982\u4f55\u5b89\u5168\u5730\u683c\u5f0f\u5316SQL\u8bed\u53e5\uff0c\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u4f7f\u7528PyMySQL\u65f6\u5982\u4f55\u5b89\u5168\u5730\u683c\u5f0f\u5316SQL\u8bed\u53e5\uff0c\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff1f<\/h1>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241111\/17313172616731ce0d1ac64.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528PyMySQL\u65f6\u5982\u4f55\u5b89\u5168\u5730\u683c\u5f0f\u5316SQL\u8bed\u53e5\uff0c\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff1f\u63d2\u56fe\" alt=\"\u4f7f\u7528PyMySQL\u65f6\u5982\u4f55\u5b89\u5168\u5730\u683c\u5f0f\u5316SQL\u8bed\u53e5\uff0c\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u95ee\u9898\u7684\u6839\u6e90\uff1a<\/strong><br \/>pymysql\u6ca1\u6709\u6b63\u786e\u8f6c\u4e49%()s\uff0c\u5bfc\u81f4sql\u8bed\u53e5\u4e2d\u51fa\u73b0\u4e86\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528pymysql\u63d0\u4f9b\u7684format()\u65b9\u6cd5\u8fdb\u884csql\u8bed\u53e5\u7684\u683c\u5f0f\u5316\uff0c\u8fd9\u6837\u53ef\u4ee5\u81ea\u52a8\u8f6c\u4e49\u53d8\u91cf\u503c\uff1a<\/p>\n<pre># \u4f7f\u7528format\u65b9\u6cd5\u8fdb\u884cSQL\u8bed\u53e5\u683c\u5f0f\u5316\ncursor.executemany('''insert into myfund(fcode,fname,NAV,ACCNAV,updatetime)\nvalues(%(fcode)s,%(fname)s,%(NAV)s,%(ACCNAV)s,%(updatetime)s) \non duplicate key update `updatetime`= %(updatetime)s,NAV= %(NAV)s,ACCNAV= %(ACCNAV)s ''',\nresult)<\/pre>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u4f7f\u7528PyMySQL\u65f6\u5982\u4f55\u5b89\u5168\u5730\u683c\u5f0f\u5316SQL\u8bed\u53e5\uff0c\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528PyMySQL\u65f6\u5982\u4f55\u5b89\u5168\u5730\u683c\u5f0f\u5316SQL\u8bed\u53e5\uff0c\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff1f \u95ee\u9898\u7684\u6839\u6e90\uff1apymysql\u6ca1\u6709\u6b63\u786e\u8f6c\u4e49%()s\uff0c\u5bfc\u81f4sql\u8bed\u53e5\u4e2d\u51fa\u73b0\u4e86\u8bed\u6cd5\u9519\u8bef\u3002 \u89e3\u51b3\u65b9\u6848\uff1a\u53ef\u4ee5\u4f7f\u7528pymysql\u63d0\u4f9b\u7684format()\u65b9\u6cd5\u8fdb\u884csql\u8bed\u53e5\u7684\u683c\u5f0f\u5316\uff0c\u8fd9\u6837\u53ef\u4ee5\u81ea\u52a8\u8f6c\u4e49\u53d8\u91cf\u503c\uff1a # \u4f7f\u7528format\u65b9\u6cd5\u8fdb\u884cSQL\u8bed\u53e5\u683c\u5f0f\u5316 cursor.executemany(&#8221;&#8217;insert into myfund(fcode,fname,NAV,ACCNAV,updatetime) values(%(fcode)s,%(fname)s,%(NAV)s,%(ACCNAV)s,%(updatetime)s) on duplicate key update `updatetime`= %(updatetime)s,NAV= %(NAV)s,ACCNAV= %(ACCNAV)s &#8221;&#8217;, result) \u4ee5\u4e0a\u5c31\u662f\u300a\u4f7f\u7528PyMySQL\u65f6\u5982\u4f55\u5b89\u5168\u5730\u683c\u5f0f\u5316SQL\u8bed\u53e5\uff0c\u907f\u514d\u8bed\u6cd5\u9519\u8bef\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-50099","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=50099"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/50099\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=50099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=50099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=50099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}