{"id":2047,"date":"2021-12-06T17:06:46","date_gmt":"2021-12-06T09:06:46","guid":{"rendered":"http:\/\/cnliutz.uicp.io\/?p=2047"},"modified":"2021-12-06T17:06:46","modified_gmt":"2021-12-06T09:06:46","slug":"python%e8%af%bb%e5%86%99sqlite-3-%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"http:\/\/i10bu9ku.ipyingshe.net:5347\/?p=2047","title":{"rendered":"python\u8bfb\u5199sqlite 3 \u6570\u636e\u5e93"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\n#encoding:utf-8\nimport sqlite3\n#\u6253\u5f00\u6570\u636e\u5e93\u8fde\u63a5\nconn = sqlite3.connect('test.db')\nprint(\"Opend database successfully\")\n\n##\u6e05\u9664\u5df2\u5b58\u5728\u7684\u8868 -students\n##conn.execute('''DROP TABLE students''');\n##conn.commit()\n\n##\u521b\u5efa\u4e00\u4e2a\u8868students\nconn.execute('''CREATE TABLE IF NOT EXISTS students\n\t\t(ID INT PRIMARY KEY NOT NULL,\n\t\tNAME         TEXT  NOT NULL,\n\t\tAGE          INT   NOT NULL);''')\nprint(\"Table created successfully\");\n\nconn.commit()\n\n##\u63d2\u5165\u6570\u636e\nconn.execute(\"INSERT INTO sTudents(ID,NAME,AGE)\\\n\t\tVALUES(1,'Allen',25)\");\nconn.execute(\"INSERT INTO sTudents(ID,NAME,AGE)\\\n\t\tVALUES(2,'Maxsu',20)\");\nconn.execute(\"INSERT INTO sTudents(ID,NAME,AGE)\\\n\t\tVALUES(3,'Teddy',24)\");\n\nconn.commit()\nprint(\"Records Insert successfully\");\nprint(\"--\"*30);\n\n##\u8bfb\u53d6\u8868students\ncursor =conn.execute(\"SELECT * from students\")\nprint (\"ID NAME AGE\")\nfor it in cursor:\n\tfor i in range(len(it)):\n\t\tprint(it&#91;i],end=\" \")\n\tprint ('\\n')\nconn.close()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-2047","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2047"}],"version-history":[{"count":0,"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2047\/revisions"}],"wp:attachment":[{"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2047"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/i10bu9ku.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}