{"id":190268,"date":"2024-11-12T11:10:21","date_gmt":"2024-11-12T03:10:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/190268\/"},"modified":"2024-11-12T11:10:22","modified_gmt":"2024-11-12T03:10:22","slug":"%e5%be%ae%e8%bb%9fwp7%e6%9c%ac%e5%9c%b0%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b9%8bsqlite%e7%b7%a8%e7%a8%8b%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/190268\/","title":{"rendered":"\u5fae\u8edfWP7\u672c\u5730\u6578\u64da\u5eab\u4e4bSQLite\u7de8\u7a0b\u6280\u5de7"},"content":{"rendered":"<h1 id=\"%e5%be%ae%e8%bb%9fwp7%e6%9c%ac%e5%9c%b0%e6%95%b8%e6%93%9a%e5%ba%ab%e4%b9%8bsqlite%e7%b7%a8%e7%a8%8b%e6%8a%80%e5%b7%a7-nRWKoAacbq\">\u5fae\u8edfWP7\u672c\u5730\u6578\u64da\u5eab\u4e4bSQLite\u7de8\u7a0b\u6280\u5de7<\/h1>\n<p>\u5728\u79fb\u52d5\u61c9\u7528\u958b\u767c\u4e2d\uff0c\u6578\u64da\u7684\u5b58\u5132\u548c\u7ba1\u7406\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u5c0d\u65bc\u4f7f\u7528\u5fae\u8edfWindows Phone 7\uff08WP7\uff09\u5e73\u53f0\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0cSQLite\u662f\u4e00\u500b\u975e\u5e38\u6d41\u884c\u7684\u9078\u64c7\u3002SQLite\u662f\u4e00\u500b\u8f15\u91cf\u7d1a\u7684\u95dc\u806f\u6578\u64da\u5eab\uff0c\u9069\u5408\u7528\u65bc\u79fb\u52d5\u8a2d\u5099\uff0c\u56e0\u70ba\u5b83\u4e0d\u9700\u8981\u4e00\u500b\u7368\u7acb\u7684\u4f3a\u670d\u5668\u4f86\u904b\u884c\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5728WP7\u4e2d\u4f7f\u7528SQLite\u7684\u7de8\u7a0b\u6280\u5de7\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u6709\u6548\u5730\u7ba1\u7406\u672c\u5730\u6578\u64da\u3002<\/p>\n<h2 id=\"sqlite%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-nRWKoAacbq\">SQLite\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>SQLite\u662f\u4e00\u500b\u81ea\u7d66\u81ea\u8db3\u7684\u3001\u7121\u4f3a\u670d\u5668\u7684\u3001\u96f6\u914d\u7f6e\u7684SQL\u6578\u64da\u5eab\u5f15\u64ce\u3002\u5b83\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u8f15\u91cf\u7d1a\uff1aSQLite\u7684\u5eab\u6587\u4ef6\u975e\u5e38\u5c0f\uff0c\u9069\u5408\u79fb\u52d5\u8a2d\u5099\u4f7f\u7528\u3002<\/li>\n<li>\u7121\u9700\u5b89\u88dd\uff1aSQLite\u4e0d\u9700\u8981\u5b89\u88dd\u904e\u7a0b\uff0c\u958b\u767c\u8005\u53ea\u9700\u5c07\u5176\u5eab\u6587\u4ef6\u5305\u542b\u5728\u61c9\u7528\u4e2d\u5373\u53ef\u3002<\/li>\n<li>\u8de8\u5e73\u53f0\uff1aSQLite\u53ef\u4ee5\u5728\u591a\u7a2e\u64cd\u4f5c\u7cfb\u7d71\u4e0a\u904b\u884c\uff0c\u5305\u62ecWindows\u3001Linux\u548ciOS\u7b49\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%9c%a8wp7%e4%b8%ad%e4%bd%bf%e7%94%a8sqlite-nRWKoAacbq\">\u5728WP7\u4e2d\u4f7f\u7528SQLite<\/h2>\n<p>\u5728WP7\u4e2d\u4f7f\u7528SQLite\uff0c\u958b\u767c\u8005\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e5%bc%95%e5%85%a5sqlite%e5%ba%ab-nRWKoAacbq\">1. \u5f15\u5165SQLite\u5eab<\/h3>\n<p>\u9996\u5148\uff0c\u958b\u767c\u8005\u9700\u8981\u5c07SQLite\u7684DLL\u6587\u4ef6\u6dfb\u52a0\u5230WP7\u9805\u76ee\u4e2d\u3002\u53ef\u4ee5\u5f9eSQLite\u7684\u5b98\u65b9\u7db2\u7ad9\u4e0b\u8f09\u76f8\u61c9\u7684\u7248\u672c\uff0c\u7136\u5f8c\u5c07\u5176\u6dfb\u52a0\u5230\u9805\u76ee\u5f15\u7528\u4e2d\u3002<\/p>\n<h3 id=\"2-%e5%89%b5%e5%bb%ba%e6%95%b8%e6%93%9a%e5%ba%ab-nRWKoAacbq\">2. \u5275\u5efa\u6578\u64da\u5eab<\/h3>\n<p>\u5728\u61c9\u7528\u555f\u52d5\u6642\uff0c\u958b\u767c\u8005\u9700\u8981\u5275\u5efa\u4e00\u500bSQLite\u6578\u64da\u5eab\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u6578\u64da\u5eab\u7684\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>using (var connection = new SQLiteConnection(\"Data Source=mydatabase.db\"))\n{\n    connection.Open();\n    var command = connection.CreateCommand();\n    command.CommandText = \"CREATE TABLE IF NOT EXISTS Users (Id INTEGER PRIMARY KEY, Name TEXT, Age INTEGER)\";\n    command.ExecuteNonQuery();\n}<\/code><\/pre>\n<h3 id=\"3-%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-nRWKoAacbq\">3. \u63d2\u5165\u6578\u64da<\/h3>\n<p>\u63d2\u5165\u6578\u64da\u7684\u904e\u7a0b\u4e5f\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u63d2\u5165\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>using (var connection = new SQLiteConnection(\"Data Source=mydatabase.db\"))\n{\n    connection.Open();\n    var command = connection.CreateCommand();\n    command.CommandText = \"INSERT INTO Users (Name, Age) VALUES ('John Doe', 30)\";\n    command.ExecuteNonQuery();\n}<\/code><\/pre>\n<h3 id=\"4-%e6%9f%a5%e8%a9%a2%e6%95%b8%e6%93%9a-nRWKoAacbq\">4. \u67e5\u8a62\u6578\u64da<\/h3>\n<p>\u67e5\u8a62\u6578\u64da\u662f\u4f7f\u7528SQLite\u7684\u53e6\u4e00\u500b\u91cd\u8981\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u67e5\u8a62\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>using (var connection = new SQLiteConnection(\"Data Source=mydatabase.db\"))\n{\n    connection.Open();\n    var command = connection.CreateCommand();\n    command.CommandText = \"SELECT * FROM Users\";\n    using (var reader = command.ExecuteReader())\n    {\n        while (reader.Read())\n        {\n            Console.WriteLine($\"Id: {reader[\"Id\"]}, Name: {reader[\"Name\"]}, Age: {reader[\"Age\"]}\");\n        }\n    }\n}<\/code><\/pre>\n<h3 id=\"5-%e6%9b%b4%e6%96%b0%e5%92%8c%e5%88%aa%e9%99%a4%e6%95%b8%e6%93%9a-nRWKoAacbq\">5. \u66f4\u65b0\u548c\u522a\u9664\u6578\u64da<\/h3>\n<p>\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u7684\u64cd\u4f5c\u4e5f\u975e\u5e38\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\/\/ \u66f4\u65b0\u6578\u64da\nusing (var connection = new SQLiteConnection(\"Data Source=mydatabase.db\"))\n{\n    connection.Open();\n    var command = connection.CreateCommand();\n    command.CommandText = \"UPDATE Users SET Age = 31 WHERE Name = 'John Doe'\";\n    command.ExecuteNonQuery();\n}\n\n\/\/ \u522a\u9664\u6578\u64da\nusing (var connection = new SQLiteConnection(\"Data Source=mydatabase.db\"))\n{\n    connection.Open();\n    var command = connection.CreateCommand();\n    command.CommandText = \"DELETE FROM Users WHERE Name = 'John Doe'\";\n    command.ExecuteNonQuery();\n}<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-nRWKoAacbq\">\u7e3d\u7d50<\/h2>\n<p>\u5728WP7\u958b\u767c\u4e2d\uff0cSQLite\u63d0\u4f9b\u4e86\u4e00\u500b\u7c21\u55ae\u800c\u5f37\u5927\u7684\u672c\u5730\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u3002\u901a\u904e\u4e0a\u8ff0\u7684\u7de8\u7a0b\u6280\u5de7\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5275\u5efa\u3001\u8b80\u53d6\u3001\u66f4\u65b0\u548c\u522a\u9664\u6578\u64da\u3002\u9019\u4e9b\u57fa\u672c\u64cd\u4f5c\u662f\u69cb\u5efa\u4efb\u4f55\u79fb\u52d5\u61c9\u7528\u7684\u57fa\u790e\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7ba1\u7406\u61c9\u7528\u4e2d\u7684\u6578\u64da\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u61c9\u7528\u958b\u767c\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u96f2\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5fae\u8edfWP7\u4e2d\u4f7f\u7528SQLite\u7684\u672c\u5730\u6578\u64da\u5eab\u7de8\u7a0b\u6280\u5de7\uff0c\u63d0\u5347\u61c9\u7528\u6027\u80fd\u8207\u6578\u64da\u7ba1\u7406\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-190268","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=190268"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190268\/revisions"}],"predecessor-version":[{"id":190269,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/190268\/revisions\/190269"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=190268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=190268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=190268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}