{"id":3094,"date":"2026-11-16T23:44:34","date_gmt":"2026-11-16T14:44:34","guid":{"rendered":"https:\/\/danlabs.kr\/?p=3094"},"modified":"2026-11-16T23:44:34","modified_gmt":"2026-11-16T14:44:34","slug":"python-sqlite3-%ec%9e%90%eb%a6%ac%ed%91%9c%ec%8b%9c%ec%9e%90-%eb%ac%bc%ec%9d%8c%ed%91%9c%ec%99%80-%ec%9d%b4%eb%a6%84-%eb%b0%94%ec%9d%b8%eb%94%a9","status":"publish","type":"post","link":"https:\/\/danlabs.kr\/?p=3094","title":{"rendered":"Python sqlite3 \uc790\ub9ac\ud45c\uc2dc\uc790, \ubb3c\uc74c\ud45c\uc640 \uc774\ub984 \ubc14\uc778\ub529"},"content":{"rendered":"<p>SQL \ubb38\uc790\uc5f4\uc744 \ud30c\uc774\uc36c\uc5d0\uc11c \uc774\uc5b4 \ubd99\uc774\uba74, \uc790\ub9ac\ud45c\uc2dc\uc790\uac00 \ub9c9\uc744 \uad6c\uba4d\uc774 \uc5f4\ub824\uc694. \uacf5\uc2dd \ubb38\uc11c\ub294 \uadf8 \uae38\uc744 \uc4f0\uc9c0 \ub9d0\ub77c\uace0 \ud558\uace0, \uc608\uc2dc\uc5d0 Never do this\ub77c\uace0 \uc801\uc5b4 \ub461\ub2c8\ub2e4.[1]<\/p>\n<p><code>sqlite3<\/code> \uc790\ub9ac\ud45c\uc2dc\uc790 \uc548\ub0b4\uc758 \uc608\ub294 \uc774\ub807\uc2b5\ub2c8\ub2e4. \uc785\ub825\uac12\uc774 <code>' OR TRUE; --<\/code>\ucc98\ub7fc \ub530\uc634\ud45c\ub97c \ub2eb\uc73c\uba74, <code>\"SELECT * FROM stocks WHERE symbol = '%s'\" % symbol<\/code>\ub85c \ub9cc\ub4e0 \ubb38\uc790\uc5f4\uc774 <code>SELECT * FROM stocks WHERE symbol = '' OR TRUE; --'<\/code>\uac00 \ub3fc\uc694. \ubb38\uc11c\ub294 \uc774 \uc870\ub9bd\uc774 SQL \uc778\uc81d\uc158\uc5d0 \ub178\ucd9c\ub41c\ub2e4\uace0 \ud574\uc694. \ub300\uc2e0 DB-API \ub9e4\uac1c\ubcc0\uc218 \uce58\ud658\uc744 \uc4f0\uace0, \uc790\ub9ac\ud45c\uc2dc\uc790\ub97c \ubb38\uc790\uc5f4\uc5d0 \ub454 \ub4a4 \uc2e4\uc81c \uac12\uc740 <code>execute()<\/code>\uc758 \ub450 \ubc88\uc9f8 \uc778\uc790\ub85c \ub118\uae30\ub77c\uace0 \ud569\ub2c8\ub2e4.[1]<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-inline1.jpg\" alt=\"\ubcf8\ubb38 \uadf8\ub9bc 1\" \/><\/figure>\n<h2>\ubb3c\uc74c\ud45c\uc640 \uc774\ub984, \uae38\uc774\uac00 \ub2e4\ub974\uba74 \uc624\ub958\ub2e4<\/h2>\n<p>\ubb38\uc11c\ub294 \uc790\ub9ac\ud45c\uc2dc\uc790\ub97c \ub450 \uc885\ub958\ub85c \ub098\ub220\uc694. \ubb3c\uc74c\ud45c(qmark)\ub294 \uc2dc\ud000\uc2a4\uc5ec\uc57c \ud558\uace0, \uae38\uc774\uac00 \uc790\ub9ac \uc218\uc640 \ub2e4\ub974\uba74 <code>ProgrammingError<\/code>\uac00 \ub0a9\ub2c8\ub2e4. \uc774\ub984 \uc2a4\ud0c0\uc77c\uc740 dict \ub610\ub294 \uadf8 \ud558\uc704 \ud074\ub798\uc2a4\uc5ec\uc57c \ud558\uace0, \uc774\ub984 \uc788\ub294 \ub9e4\uac1c\ubcc0\uc218 \ud0a4\ub97c \ubaa8\ub450 \ub2f4\uc544\uc57c \ud574\uc694. \ub0a8\ub294 \ud0a4\ub294 \ubb34\uc2dc\ub429\ub2c8\ub2e4. PEP 249\uc758 \uc22b\uc790 \uc790\ub9ac\ud45c\uc2dc\uc790\ub294 \uc9c0\uc6d0\ub418\uc9c0 \uc54a\uace0, \uc4f0\uba74 \uc774\ub984 \uc790\ub9ac\ud45c\uc2dc\uc790\ub85c \ud574\uc11d\ub41c\ub2e4\uace0 \uc801\ud600 \uc788\uc5b4\uc694. <code>paramstyle<\/code>\uc740 DB-API \uc694\uad6c\ub85c \ubaa8\ub4c8\uc5d0 <code>\"qmark\"<\/code>\ub85c \uace0\uc815\ub3fc \uc788\uc2b5\ub2c8\ub2e4.[1]<\/p>\n<p>\ubb38\uc11c\uc758 \uc774\ub984 \uc2a4\ud0c0\uc77c \uc608\ub294 <code>executemany(\"INSERT INTO lang VALUES(:name, :year)\", data)<\/code>\uc774\uace0, \ubb3c\uc74c\ud45c \uc608\ub294 <code>execute(\"SELECT * FROM lang WHERE first_appeared = ?\", params)<\/code>\uc608\uc694. <code>executemany<\/code>\ub3c4 \uac19\uc740 \uc790\ub9ac\ud45c\uc2dc\uc790 \uaddc\uce59\uc744 \ub530\ub985\ub2c8\ub2e4.[1]<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-inline2.jpg\" alt=\"\ubcf8\ubb38 \uadf8\ub9bc 2\" \/><\/figure>\n<h2>\uc774 \ud658\uacbd\uc5d0\uc11c \ub3cc\ub824 \ubcf8 \ubc14\uc778\ub529<\/h2>\n<p>\uc774 \uae00\uc758 \uc2e4\ud589\uc740 2026\ub144 11\uc6d4 16\uc77c, Python 3.14.7\uc758 \uba54\ubaa8\ub9ac \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc5d0\uc11c \ud588\uc5b4\uc694. \ud30c\uc77c\ub85c \ub0a8\uae34 \uc5c5\ubb34 \ub370\uc774\ud130\ubca0\uc774\uc2a4\ub294 \uc544\ub2d9\ub2c8\ub2e4.<\/p>\n<pre><code>import sqlite3\ncon = sqlite3.connect(&quot;:memory:&quot;)\ncur = con.cursor()\ncur.execute(&quot;CREATE TABLE lang(name, first_appeared)&quot;)\ncur.executemany(&quot;INSERT INTO lang VALUES(?, ?)&quot;, [(&quot;C&quot;, 1972), (&quot;Python&quot;, 1991)])\nprint(cur.execute(&quot;SELECT name FROM lang WHERE first_appeared=?&quot;, (1991,)).fetchone())\ncur.executemany(&quot;INSERT INTO lang VALUES(:name, :year)&quot;, [{&quot;name&quot;: &quot;Go&quot;, &quot;year&quot;: 2009}])\nprint(cur.execute(&quot;SELECT name, first_appeared FROM lang WHERE name=:name&quot;, {&quot;name&quot;: &quot;Go&quot;}).fetchone())\nprint(sqlite3.paramstyle)\ntry:\n    cur.execute(&quot;SELECT * FROM lang WHERE first_appeared=?&quot;, ())\nexcept sqlite3.ProgrammingError as e:\n    print(type(e).__name__, e)\nsymbol = &quot;&#x27; OR TRUE; --&quot;\nsql = &quot;SELECT * FROM stocks WHERE symbol = &#x27;%s&#x27;&quot; % symbol\nprint(sql)<\/code><\/pre>\n<p>\ucd9c\ub825\uc740 \uc774\ub807\uac8c \ub098\uc654\uc5b4\uc694.<\/p>\n<pre><code>(&#x27;Python&#x27;,)\n(&#x27;Go&#x27;, 2009)\nqmark\nProgrammingError Incorrect number of bindings supplied. The current statement uses 1, and there are 0 supplied.\nSELECT * FROM stocks WHERE symbol = &#x27;&#x27; OR TRUE; --&#x27;<\/code><\/pre>\n<p>\ubb3c\uc74c\ud45c \uc870\ud68c\ub294 <code>('Python',)<\/code>, \uc774\ub984 \uc870\ud68c\ub294 <code>('Go', 2009)<\/code>\uc600\uc5b4\uc694. \ube48 \ud29c\ud50c\uc740 \ubb38\uc11c\uac00 \ub9d0\ud55c <code>ProgrammingError<\/code>\ub85c \uba48\ucdc4\uace0, \uba54\uc2dc\uc9c0\uc5d0 \ubb38\uc7a5\uc774 1\uac1c\ub97c \uc4f0\ub294\ub370 0\uac1c\uac00 \ub4e4\uc5b4\uc654\ub2e4\uace0 \ub098\uc635\ub2c8\ub2e4. \ub9c8\uc9c0\ub9c9 \uc904\uc740 \uc8fc\uc785 \ucffc\ub9ac\ub97c \uc2e4\ud589\ud55c \uacb0\uacfc\uac00 \uc544\ub2c8\ub77c, \ubb38\uc11c\uac00 \uc704\ud5d8\ud558\ub2e4\uace0 \ud55c \ubb38\uc790\uc5f4 \uc870\ub9bd\uc744 \uadf8\ub300\ub85c \uc778\uc1c4\ud55c \uac70\uc608\uc694.[1]<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-inline3.jpg\" alt=\"\ubcf8\ubb38 \uadf8\ub9bc 3\" \/><\/figure>\n<h2>\ud2b8\ub79c\uc7ad\uc158 \uae30\ubcf8\uac12\uc740 \uc544\uc9c1 \ub808\uac70\uc2dc\ub2e4<\/h2>\n<p>\uc790\ub9ac\ub294 \ub9de\uc558\ub294\ub370 <code>commit()<\/code>\uc744 \ube7c\uba74 \ud30c\uc77c \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc5d0\uc11c\ub294 \ub2e4\ub978 \ubb38\uc81c\uac00 \uc0dd\uaca8\uc694. \ubb38\uc11c\uc758 \ud29c\ud1a0\ub9ac\uc5bc\uc740 INSERT \ub4a4\uc5d0 \ud2b8\ub79c\uc7ad\uc158\uc744 \ucee4\ubc0b\ud558\ub77c\uace0 \uc801\uc2b5\ub2c8\ub2e4. <code>autocommit<\/code>\uc758 \ud604\uc7ac \uae30\ubcf8\uac12\uc740 <code>LEGACY_TRANSACTION_CONTROL<\/code>\uc774\uace0, 3.12\uc5d0\uc11c \uc774 \ub9e4\uac1c\ubcc0\uc218\uac00 \ucd94\uac00\ub410\uc5b4\uc694. \ubb38\uc11c\ub294 \ud2b8\ub79c\uc7ad\uc158 \uc81c\uc5b4\uc5d0 <code>autocommit<\/code>\uc744 \uc4f0\ub294 \ucabd\uc744 \uad8c\ud558\uace0, <code>False<\/code>\ub85c \ub450\ub294 \uc81c\uc548\uc744 \ud574\uc694. <code>True<\/code>\ub294 SQLite \uc790\uccb4\uc758 autocommit \ubaa8\ub4dc\ub77c <code>commit()<\/code>\uacfc <code>rollback()<\/code>\uc774 \ud6a8\uacfc\uac00 \uc5c6\ub2e4\uace0 \uc801\ud600 \uc788\uc2b5\ub2c8\ub2e4. \uc774\ubc88 \uc2e4\ud589\uc740 <code>:memory:<\/code>\ub77c \ud504\ub85c\uc138\uc2a4 \uc885\ub8cc\uc640 \ud568\uaed8 \uc0ac\ub77c\uc84c\uace0, \ud30c\uc77c\uc5d0 <code>commit()<\/code>\uc744 \ube80 \uacbd\uc6b0\ub97c \ub2e4\uc2dc \uc5f4\uc5b4\uc11c \ud655\uc778\ud558\uc9c0\ub294 \uc54a\uc558\uc5b4\uc694.[1]<\/p>\n<p>\ud55c \uc904\uc529 \uae68\uc9c4 \ub85c\uadf8\ub97c \ub2e4\ub8e8\ub294 \uae00\uc740 <a href=\"https:\/\/danlabs.kr\/?p=3073\" target=\"_blank\" rel=\"noopener noreferrer\">Python JSONL \uc77d\uace0 \uc4f0\uae30<\/a>\uc5d0 \uc788\uc5b4\uc694. SQL\uc744 \ubd99\uc774\ub294 \ubb38\uc81c\uc640, \uc904 \ub2e8\uc704\ub85c \uc2e4\ud328\ub97c \ub118\uae30\ub294 \ubb38\uc81c\ub294 \ub2e4\ub978 \uce35\uc785\ub2c8\ub2e4.<\/p>\n<p>Sources<\/p>\n<p>[1] <a href=\"https:\/\/docs.python.org\/3\/library\/sqlite3.html\" target=\"_blank\" rel=\"noopener noreferrer\">Python sqlite3 docs<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud30c\uc774\uc36c \uacf5\uc2dd \ubb38\uc11c\ub294 SQL \ubb38\uc790\uc5f4 \uc870\ub9bd \ub300\uc2e0 \uc790\ub9ac\ud45c\uc2dc\uc790\ub97c \uc4f0\ub77c\uace0 \ud569\ub2c8\ub2e4. Python 3.14.7\uc5d0\uc11c \ubb3c\uc74c\ud45c\uc640 \uc774\ub984 \ubc14\uc778\ub529\uc744 \uc2e4\ud589\ud574 \uc624\ub958 \uba54\uc2dc\uc9c0\ub97c \ud655\uc778\ud588\uc2b5\ub2c8\ub2e4.<\/p>\n","protected":false},"author":1,"featured_media":3090,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-3094","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"featured_image_urls":{"full":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat.jpg",1280,720,false],"thumbnail":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat-150x150.jpg",150,150,true],"medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat-300x169.jpg",300,169,true],"medium_large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat-768x432.jpg",640,360,true],"large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat-1024x576.jpg",640,360,true],"1536x1536":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat.jpg",1280,720,false],"2048x2048":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat.jpg",1280,720,false],"morenews-large":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat.jpg",825,464,false],"morenews-medium":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat.jpg",590,332,false],"danlabs-list-small":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat-366x190.jpg",366,190,true],"danlabs-list-retina":["https:\/\/danlabs.kr\/wp-content\/uploads\/2026\/11\/dev-2026-11-16-feat.jpg",1280,720,false]},"author_info":{"display_name":"DanLABs","author_link":"https:\/\/danlabs.kr\/author\/hello-danlabs-kr"},"category_info":"<a href=\"https:\/\/danlabs.kr\/?cat=19\" rel=\"category\">\uac1c\ubc1c<\/a>","tag_info":"\uac1c\ubc1c","comment_count":"0","_links":{"self":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3094"}],"version-history":[{"count":1,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3094\/revisions"}],"predecessor-version":[{"id":3114,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/posts\/3094\/revisions\/3114"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=\/wp\/v2\/media\/3090"}],"wp:attachment":[{"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danlabs.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}