{"id":148,"date":"2025-10-09T09:03:11","date_gmt":"2025-10-09T00:03:11","guid":{"rendered":"https:\/\/devserver.kr\/blog\/?p=148"},"modified":"2025-10-09T09:03:11","modified_gmt":"2025-10-09T00:03:11","slug":"ios-sqlite","status":"publish","type":"post","link":"https:\/\/devserver.kr\/blog\/ios\/ios-sqlite\/","title":{"rendered":"iOS Sqlite"},"content":{"rendered":"\n<div class=\"wp-block-jetpack-markdown\"><h3>\uc790\ub8cc\ud615<\/h3>\n<p>\uc0ac\uc6a9\ud560 \uc218 \uc788\ub294 \uc790\ub8cc\ud615\uc740 5\uac00\uc9c0\nNULL: \ub110\uac12<\/p>\n<p>INTEGER: 1,2,3,4,6,8bytes\uc758 \uc815\uc218\uac12\n(\uc790\ub3d9\uc99d\uac00 \uc2dc\ud0ac \uacbd\uc6b0 INTEGER PRIMARY KEY AUTOINCREMENT \ub85c \ud45c\uae30)<\/p>\n<p>REAL: 8bytes\uc758 \ubd80\ub3d9\uc18c\uc218\uc810\uac12<\/p>\n<p>TEXT: UTF-8, UTF-16BE, UTF-16LE\uc778\ucf54\ub529\uc758 \ubb38\uc790\uc5f4<\/p>\n<p>BLOB: \uc785\ub825\ub41c \uadf8\ub300\ub85c \uc800\uc7a5, \ubc14\uc774\ub108\ub9ac \ud30c\uc77c \ub4f1<\/p>\n<p>\ub2e4\ub978 \ud615\ud0dc\ub294 \uc5b4\ub5bb\uac8c \ub9cc\ub4e4\uba74 \ub420\uae4c?\nBoolean\ud0c0\uc785: INTEGER\ub85c \ub9cc\ub4e4\uc5b4\uc11c 0\uacfc 1\ub85c \uad6c\ubcc4.<\/p>\n<p>Date, Time\ud0c0\uc785\nTEXT: YYYY-MM-DD HH:MM:SS.SSS \ud615\ud0dc\ub85c \uc800\uc7a5\nREAL: \uc728\ub9ac\uc6b0\uc2a4\ub825\uc744 \uae30\uc900\uc73c\ub85c \ud558\ub294 \uc815\ubcf4\ub97c \uc800\uc7a5\nINTEGER: UTC\ud0c0\uc785\uc73c\ub85c \uc800\uc7a5<\/p>\n<p>SQLite\uc5d0 \uc22b\uc790, \ubb38\uc790, \ubc14\uc774\ub108\ub9ac\ub97c \ub123\uc744 \uc218 \uc788\uc73c\ub2c8 \uc790\uc720\ub86d\uac8c \ub123\uace0 \uac1c\ubc1c\uc790\uac00 \uc54c\uc544\uc11c \uc815\ud574\uc11c \uc0ac\uc6a9\ud558\uba74 \ub41c\ub2e4.<\/p>\n<h3>SQLite in iOS<\/h3>\n<pre><code class=\"language-swift\">import SQLite3\n<\/code><\/pre>\n<p>\uc800\uc7a5 \uc7a5\uc18c \uc124\uc815<\/p>\n<pre><code class=\"language-swift\">let path: String = {\n      let fm = FileManager.default\n      return fm.urls(for:.libraryDirectory, in:.userDomainMask).last!\n               .appendingPathComponent(&quot;ToDo.db&quot;).path\n    }()\n<\/code><\/pre>\n<p>DB \uc0dd\uc131<\/p>\n<pre><code class=\"language-swift\">let createTableString = &quot;&quot;&quot;\n    CREATE TABLE IF NOT EXISTS ToDo(\n    Id INTEGER PRIMARY KEY AUTOINCREMENT,\n    Work CHAR(255),\n    Done INT);\n    &quot;&quot;&quot;\n<\/code><\/pre>\n<pre><code class=\"language-swift\">var db:OpaquePointer?\n<\/code><\/pre>\n<h3>INSERT<\/h3>\n<p>sqlite3_bind_text() \ud560 \ub54c, String\uc744 NSString\uc73c\ub85c \ubcc0\ud658\ud55c \ud6c4, utf8string \uc73c\ub85c \ub118\uaca8\uc918\uc57c \uc815\uc0c1\uc801\uc73c\ub85c insert\uac00 \ub41c\ub2e4.<\/p>\n<pre><code class=\"language-swift\">func insert() {\n  var insertStatement: OpaquePointer?\n  \/\/ 1\n  if sqlite3_prepare_v2(db, insertStatementString, -1, &amp;insertStatement, nil) == \n      SQLITE_OK {\n    let id: Int32 = 1\n    let name: NSString = &quot;Ray&quot;\n    \/\/ 2\n    sqlite3_bind_int(insertStatement, 1, id)\n    \/\/ 3\n    sqlite3_bind_text(insertStatement, 2, name.utf8String, -1, nil)\n    \/\/ 4\n    if sqlite3_step(insertStatement) == SQLITE_DONE {\n      print(&quot;\\nSuccessfully inserted row.&quot;)\n    } else {\n      print(&quot;\\nCould not insert row.&quot;)\n    }\n  } else {\n    print(&quot;\\nINSERT statement is not prepared.&quot;)\n  }\n  \/\/ 5\n  sqlite3_finalize(insertStatement)\n}\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-ios"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":1,"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":149,"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/posts\/148\/revisions\/149"}],"wp:attachment":[{"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devserver.kr\/blog\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}