{"id":137427,"date":"2020-07-20T20:07:39","date_gmt":"2020-07-20T12:07:39","guid":{"rendered":"http:\/\/4563.org\/?p=137427"},"modified":"2020-07-20T20:07:39","modified_gmt":"2020-07-20T12:07:39","slug":"python-%e4%b8%ad%e4%bd%bf%e7%94%a8-sqlite3-%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e5%8c%85%e5%90%ab%e5%8f%98%e9%87%8f%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=137427","title":{"rendered":"Python \u4e2d\u4f7f\u7528 sqlite3, \u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u53d8\u91cf\u600e\u4e48\u5199"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u4e2d\u4f7f\u7528 sqlite3, \u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u53d8\u91cf\u600e\u4e48\u5199               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : youthfire <\/span>  <span><i><\/i> 6<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>df = pd.DataFrame(pd.read_sql(&#8216;select * from f65 where offer &#8216; &#8216;+&#8217; in offervalue, conn))<\/p>\n<p>\u5176\u4e2d offervalue \u662f\u4e00\u4e2a\u53d8\u91cf,\u5177\u4f53\u5c31\u662f\u4e00\u4e2a\u5217\u8868.\u6211\u60f3\u7ed9\u4e88\u7684\u6761\u4ef6\u662f offer \u53f7\u5fc5\u987b\u5728 offervalue \u8fd9\u4e2a\u5217\u8868\u91cc<\/p>\n<p>\u8fd0\u884c\u63d0\u793a\u9519\u8bef:pandas.io.sql.DatabaseError: Execution failed on sql &#8216;False&#8217;: operation parameter must be str<\/p>\n<p>\u5982\u679c\u6211\u5728&#8217;select * from f65 where offer &#8216; &#8216;+&#8217; in offervalue \u5916\u9762\u52a0\u53cc\u5f15\u53f7,\u53d8\u91cf\u5c31\u53d8\u6210\u5b57\u7b26\u4e32\u4e86.<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>12<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2559815\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : linuxkj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5f15\u7528\u53d8\u91cf\uff1f\u5982\u679c\u8fd8\u662f python \u7684\u8bed\u6cd5\uff0c\u683c\u5f0f\u5316\u4e0d\u5c31\u884c\u4e86\u5417\uff0c%s \u6216\u7740 format \u65b9\u6cd5<br \/>&#8216;select * from f65 where offer in %s&#8217; %(offervalue)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559816\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : InkStone <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u5148\u522b\u8003\u8651 pd \u554a sqlite3 \u554a\u4ec0\u4e48\u7684\u4e1c\u897f\u2026\u2026\u5148\u5b66\u4e60\u4e00\u4e0b Python \u7684\u57fa\u672c\u8bed\u6cd5\u3002<\/p>\n<p>\u7b2c\u4e00\u4e2a\u8bed\u53e5\u4f20\u5165\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f False\uff0c\u6839\u672c\u4e0d\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u2026\u2026                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559817\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nightv2 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u6570\u4e86\u4e00\u4e0b\u5355\u5f15\u53f7\uff0c\u597d\u50cf\u62ec\u53f7\u91cc\u9762\u4e0d\u80fd\u7ec4\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u5427\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559818\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : crella <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5173\u952e\u8bcd sql \u8f6c\u4e49                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559819\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ruanimal <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &#8220;`<br \/>sql = &#8216;&#8230;WHERE name=? and id=?&#8217;<br \/>curs.execute(cmd, (name, id))<br \/>&#8220;`<\/p>\n<p>https:\/\/bobby-tables.com\/python.html                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559820\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fucker <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             sql = f&#8221;select * from f65 where offer in ({&#8216;,&#8217;.join(list(map(str, offervalue)))})&#8221;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559821\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : l4ever <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u516d\u6b63\u89e3, sql \u8bed\u53e5\u5148\u6574\u7406\u597d, \u518d\u7528 python \u53bb\u62fc\u51d1.\u8fd9\u662f\u4e24\u7801\u4e8b.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559822\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dingwen07 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             cursor.execute(&#8221;&#8217;SELECT * FROM &#8220;table&#8221; where _rowid_=?&#8221;&#8217;, (rowid,))                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559823\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6bcf\u4e2a\u503c\u662f\u5b57\u4e32\u7684\u8bdd\uff0c\u6700\u597d\u4e0a\u5f15\u53f7<br \/>val = &#8216;,&#8217;.join([f'&#8221;{v}&#8221;&#8216; for v in offervalue])<br \/>sql = f&#8217;select * from f65 where offer in ({val})&#8217;<br \/>\u53cd\u6b63\u5c31\u662f\u62fc\u63a5\u5b57\u7b26\u4e32\uff0c\u4f60\u8be5\u53bb\u5b66\u5b66 string format \u8bed\u6cd5\u4e86\uff0c\u524d\u7f6e f \u5c31\u662f format \u7684\u7f29\u7565\u5199\u6cd5<br \/>\u5982\u679c\u641e\u4e0d\u6e05\u5f15\u53f7\uff0c\u6700\u5916\u9762\u5957\u4e09\u5f15\u53f7\u5c31\u597d\u4e86\uff0cf&#8221;&#8217;\u5b57\u4e32&#8221;&#8217;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559824\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : youthfire <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @imn1 \u975e\u5e38\u611f\u8c22,\u4ee3\u7801\u5b8c\u5168\u7b26\u5408\u9700\u6c42,\u8fd0\u884c\u6b63\u5e38.\u6211\u7279\u610f\u53bb\u770b\u4e86\u4e0b f \u7684\u4fe1\u606f,\u80fd\u591f\u60f3\u5230\u7684\u662f<br \/>df = pd.DataFrame(pd.read_sql(f&#8217;select * from f65 where offer in {offervalue}&#8217;, conn))<\/p>\n<p>\u5982\u679c\u53ef\u80fd\u7684\u8bdd,\u6c42\u6559\u4e00\u4e0b,\u4e3a\u4ec0\u4e48\u9700\u8981\u904d\u5386 offervalue \u91cc\u6bcf\u4e2a\u5143\u7d20\u91cd\u65b0\u8fde\u63a5,\u4e0d\u80fd\u7528\u73b0\u6709\u7684 list \u5417? ({val})\u662f\u8f6c\u5236\u4e3a turple \u7684\u610f\u601d\u4e48? \u7528\u6211\u7684\u5199\u6cd5\u8dd1\u7684\u65f6\u5019,pycharm \u603b\u662f\u63d0\u793a\u4e0d\u5b58\u5728 offervalue \u8fd9\u4e2a table.\u800c\u6211\u7684\u610f\u601d\u53ea\u662f\u60f3\u67e5\u8fd9\u4e2a list,\u800c\u4e0d\u662f table<\/p>\n<p>\u8bf4\u7684\u6709\u70b9\u4e71,\u5f53\u7136,\u60a8\u7684\u4ee3\u7801\u7ed3\u679c\u662f\u5b8c\u5168\u6b63\u786e\u7684,\u6211\u53ea\u662f\u6709\u70b9\u4e0d\u77e5\u6240\u4ee5\u7136.<\/p>\n<p>\u540c\u65f6\u611f\u8c22\u4e0a\u6240\u6709\u5173\u6ce8\u7684\u670b\u53cb,\u867d\u7136\u4ee3\u7801\u6211\u9650\u4e8e\u80fd\u529b\u6ca1\u6709\u4e00\u4e00\u5c1d\u8bd5.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559825\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : imn1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @youthfire #10<br \/>{offervalue} \u8fd9\u6837\u5199\u662f\u4e0d\u5bf9\u7684\uff0c\u4f60\u80fd\u6b63\u5e38\u4f30\u8ba1\u662f tuple\uff0ctuple \u5de6\u53f3\u662f\u5706\u62ec\u53f7\uff0crepr \u521a\u597d\u7b26\u5408 sql \u8bed\u6cd5<br \/>\u5982\u679c\u662f list \u5de6\u53f3\u65b9\u62ec\u53f7\uff0crepr \u51fa\u6765\u5c31\u662f[val1, val2&#8230;]\uff0c\u8fd9\u4e2a\u5728 sql \u5c31\u8981\u62a5\u9519\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2559826\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : levelworm <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             fstring \u5c31\u53ef\u4ee5\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d\u4f7f\u7528 sqlite&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/137427"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=137427"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/137427\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=137427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=137427"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=137427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}