{"id":102807,"date":"2025-03-23T14:19:41","date_gmt":"2025-03-23T09:49:41","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/ru-he-zai-hong-meng-nextkai-fa-zhong-shi-yong-shu-ju-ku-5773\/"},"modified":"2025-03-23T14:19:41","modified_gmt":"2025-03-23T09:49:41","slug":"ru-he-zai-hong-meng-nextkai-fa-zhong-shi-yong-shu-ju-ku-5773","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/ru-he-zai-hong-meng-nextkai-fa-zhong-shi-yong-shu-ju-ku-5773\/","title":{"rendered":"\u0646\u062d\u0648\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0627\u0632 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u062f\u0631 Hongmeng Development"},"content":{"rendered":"<p>\u0627\u06cc\u0646 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u062f\u0631 Hongmeng \u0628\u0631 \u0627\u0633\u0627\u0633 \u0627\u062c\u0632\u0627\u06cc SQLite \u0627\u0633\u062a \u0648 \u0628\u0631\u0627\u06cc \u067e\u0631\u062f\u0627\u0632\u0634 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0628\u0627 \u0631\u0648\u0627\u0628\u0637 \u0646\u0633\u0628\u062a\u0627\u064b \u067e\u06cc\u0686\u06cc\u062f\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f.<\/p>\n<p>1. \u0627\u0628\u062a\u062f\u0627 \u0645\u0627\u0698\u0648\u0644 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import relationalStore from '@ohos.data.relationalStore';\n\n<\/code><\/pre>\n<\/div>\n<p>2. \u0627\u0637\u0644\u0627\u0639\u0627\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0631\u0627 \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>const STORE_CONFIG :relationalStore.StoreConfig= {\n\n      name: 'RdbTest.db', \/\/ \u6570\u636e\u5e93\u6587\u4ef6\u540d\n\n      securityLevel: relationalStore.SecurityLevel.S1, \/\/ \u6570\u636e\u5e93\u5b89\u5168\u7ea7\u522b\n\n      encrypt: false, \/\/ \u53ef\u9009\u53c2\u6570\uff0c\u6307\u5b9a\u6570\u636e\u5e93\u662f\u5426\u52a0\u5bc6\uff0c\u9ed8\u8ba4\u4e0d\u52a0\u5bc6\n\n      dataGroupId: 'dataGroupID' \/\/ \u53ef\u9009\u53c2\u6570\uff0c\u4ec5\u53ef\u5728Stage\u6a21\u578b\u4e0b\u4f7f\u7528\uff0c\u8868\u793a\u4e3a\u5e94\u7528\u7ec4ID\uff0c\u9700\u8981\u5411\u5e94\u7528\u5e02\u573a\u83b7\u53d6\u3002\u6307\u5b9a\u5728\u6b64Id\u5bf9\u5e94\u7684\u6c99\u7bb1\u8def\u5f84\u4e0b\u521b\u5efa\u5b9e\u4f8b\uff0c\u5f53\u6b64\u53c2\u6570\u4e0d\u586b\u65f6\uff0c\u9ed8\u8ba4\u5728\u672c\u5e94\u7528\u6c99\u7bb1\u76ee\u5f55\u4e0b\u521b\u5efa\u3002\n\n    };\n<\/code><\/pre>\n<\/div>\n<p>3. \u0628\u0631\u0627\u06cc \u0628\u0647 \u062f\u0633\u062a \u0622\u0648\u0631\u062f\u0646 \u0646\u0645\u0648\u0646\u0647 RDBStore \u060c \u0644\u0627\u0632\u0645 \u0628\u0647 \u0630\u06a9\u0631 \u0627\u0633\u062a \u06a9\u0647 GetContext (\u0627\u06cc\u0646) \u062f\u0631 \u0627\u06cc\u0646\u062c\u0627 \u0628\u0631\u0627\u06cc \u0628\u0647 \u062f\u0633\u062a \u0622\u0648\u0631\u062f\u0646 \u0632\u0645\u06cc\u0646\u0647 \u0628\u0631\u0646\u0627\u0645\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>const STORE_CONFIG :relationalStore.StoreConfig= {\n\n      name: 'RdbTest.db', \/\/ \u6570\u636e\u5e93\u6587\u4ef6\u540d\n\n      securityLevel: relationalStore.SecurityLevel.S1, \/\/ \u6570\u636e\u5e93\u5b89\u5168\u7ea7\u522b\n\n      encrypt: false, \/\/ \u53ef\u9009\u53c2\u6570\uff0c\u6307\u5b9a\u6570\u636e\u5e93\u662f\u5426\u52a0\u5bc6\uff0c\u9ed8\u8ba4\u4e0d\u52a0\u5bc6\n\n      \/\/ dataGroupId: 'dataGroupID' \/\/ \u53ef\u9009\u53c2\u6570\uff0c\u4ec5\u53ef\u5728Stage\u6a21\u578b\u4e0b\u4f7f\u7528\uff0c\u8868\u793a\u4e3a\u5e94\u7528\u7ec4ID\uff0c\u9700\u8981\u5411\u5e94\u7528\u5e02\u573a\u83b7\u53d6\u3002\u6307\u5b9a\u5728\u6b64Id\u5bf9\u5e94\u7684\u6c99\u7bb1\u8def\u5f84\u4e0b\u521b\u5efa\u5b9e\u4f8b\uff0c\u5f53\u6b64\u53c2\u6570\u4e0d\u586b\u65f6\uff0c\u9ed8\u8ba4\u5728\u672c\u5e94\u7528\u6c99\u7bb1\u76ee\u5f55\u4e0b\u521b\u5efa\u3002\n\n    };\n\n\n\n    const SQL_CREATE_TABLE = 'CREATE TABLE IF NOT EXISTS WORKER (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, GENDER TEXT NOT NULL)'; \n\n\n\n    relationalStore.getRdbStore(getContext(this),STORE_CONFIG,(err,store)=&gt;{\n\n      if (err) {\n\n        console.error(`Failed to get RdbStore. Code:${err.code}, message:${err.message}`);\n\n        return;\n\n      }\n\n      console.info('Succeeded in getting RdbStore.');\n\n\n\n      \/\/ \u5f53\u6570\u636e\u5e93\u521b\u5efa\u65f6\uff0c\u6570\u636e\u5e93\u9ed8\u8ba4\u7248\u672c\u4e3a0\n\n      if (store.version === 0) {\n\n        store.executeSql(SQL_CREATE_TABLE); \/\/ \u521b\u5efa\u6570\u636e\u8868\n\n        \/\/ \u8bbe\u7f6e\u6570\u636e\u5e93\u7684\u7248\u672c\uff0c\u5165\u53c2\u4e3a\u5927\u4e8e0\u7684\u6574\u6570\n\n        store.version = 3;\n\n      }\n\n\n\n\n\n\n\n    })\n<\/code><\/pre>\n<\/div>\n<p>\u062f\u0631\u062c \u062f\u0627\u062f\u0647 \u0647\u0627<\/p>\n<p>\u0646\u0648\u0639 \u062f\u0627\u062f\u0647 \u062f\u0631\u062c \u0634\u062f\u0647 \u0645\u0642\u0627\u062f\u06cc\u0631 bucket \u0627\u0633\u062a \u060c \u0648 \u0645\u0627\u0698\u0648\u0644 \u0645\u0642\u0627\u062f\u06cc\u0631 bucket \u0627\u0628\u062a\u062f\u0627 \u0628\u0627\u06cc\u062f \u0645\u0639\u0631\u0641\u06cc \u0634\u0648\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import { ValuesBucket } from '@ohos.data.ValuesBucket';\n\n\n\nconst valueBucket1: ValuesBucket = {\n\n        'NAME': 'Bob',\n\n        'AGE': '18',\n\n        'GENDER': '\u7537',\n\n      };\n\nif (store !== undefined) {\n\n   (store as relationalStore.RdbStore).insert('WORKER', valueBucket1, (err: BusinessError, rowId: number) =&gt; {\n\n       if (err) {\n\n            console.error(`Failed to insert data. Code:${err.code}, message:${err.message}`);\n\n            return;\n\n          }\n\n          console.info(`Succeeded in inserting data. rowId:${rowId}`);\n\n     })\n\n}\n<\/code><\/pre>\n<\/div>\n<p>\u062a\u063a\u06cc\u06cc\u0631 \u062f\u0627\u062f\u0647 \u0647\u0627<\/p>\n<p>\u0628\u0647 \u0639\u0646\u0648\u0627\u0646 \u0646\u0645\u0648\u0646\u0647 \u060c \u0633\u0646 \u0628\u0627\u0628 \u0631\u0627 \u0627\u0635\u0644\u0627\u062d \u06a9\u0646\u06cc\u062f:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>const valueBucket2: ValuesBucket = {\n\n        'NAME': 'Bob',\n\n        'AGE': '24',\n\n        'GENDER': '\u7537',\n\n};\n\/\/ \u4fee\u6539\u6570\u636e\n\nlet predicates = new relationalStore.RdbPredicates('WORKER');\n\npredicates.equalTo('NAME', 'Bob'); \n\nif (store !== undefined) {\n\n   (store as relationalStore.RdbStore).update(valueBucket2, predicates, (err: BusinessError, rows: number) =&gt; {\n\n       if (err) {\n\n          console.error(`Failed to update data. Code:${err.code}, message:${err.message}`);\n\n          return;\n\n        }\n\n          console.info(`Succeeded in updating data. row count: ${rows}`);\n\n     }\n\n}\n<\/code><\/pre>\n<\/div>\n<p>\u062d\u0630\u0641 \u062f\u0627\u062f\u0647 \u0647\u0627:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>\/\/ \u5220\u9664\u6570\u636e\npredicates.equalTo('NAME', 'Bob');\n\n  if (store !== undefined) {\n\n     (store as relationalStore.RdbStore).delete(predicates, (err: BusinessError, rows: number) =&gt; {\n\n        if (err) {\n\n          console.error(`Failed to delete data. Code:${err.code}, message:${err.message}`);\n\n          return;\n\n        }\n\n        console.info(`Delete rows: ${rows}`);\n\n   }\n\n}\n<\/code><\/pre>\n<\/div>\n<p>\u062f\u0627\u062f\u0647 \u0647\u0627\u06cc \u067e\u0631\u0633 \u0648 \u062c\u0648:\n<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>if (store !== undefined) {\n\n        (store as relationalStore.RdbStore).query(predicates, ['ID', 'NAME', 'AGE', 'GENDER'], (err: BusinessError, resultSet) =&gt; {\n\n          if (err) {\n\n            console.error(`Failed to query data. Code:${err.code}, message:${err.message}`);\n\n            return;\n\n          }\n\n          console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`);\n\n          \/\/ resultSet\u662f\u4e00\u4e2a\u6570\u636e\u96c6\u5408\u7684\u6e38\u6807\uff0c\u9ed8\u8ba4\u6307\u5411\u7b2c-1\u4e2a\u8bb0\u5f55\uff0c\u6709\u6548\u7684\u6570\u636e\u4ece0\u5f00\u59cb\u3002\n\n          while (resultSet.goToNextRow()) {\n\n            const id = resultSet.getLong(resultSet.getColumnIndex('ID'));\n\n            const name = resultSet.getString(resultSet.getColumnIndex('NAME'));\n\n            const age = resultSet.getLong(resultSet.getColumnIndex('AGE'));\n\n            const gender = resultSet.getDouble(resultSet.getColumnIndex('GENDER'));\n\n            console.info(`id=${id}, name=${name}, age=${age}, gender=${gender}`);\n\n          }\n\n          \/\/ \u91ca\u653e\u6570\u636e\u96c6\u7684\u5185\u5b58\n\n          resultSet.close();\n\n        })\n\n      }\n<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0627\u06cc\u0646 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u062f\u0631 Hongmeng \u0628\u0631 \u0627\u0633\u0627\u0633 \u0627\u062c\u0632\u0627\u06cc SQLite \u0627\u0633\u062a \u0648 \u0628\u0631\u0627\u06cc \u067e\u0631\u062f\u0627\u0632\u0634 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0628\u0627 \u0631\u0648\u0627\u0628\u0637 \u0646\u0633\u0628\u062a\u0627\u064b \u067e\u06cc\u0686\u06cc\u062f\u0647 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0645\u06cc \u0634\u0648\u062f. 1. \u0627\u0628\u062a\u062f\u0627 \u0645\u0627\u0698\u0648\u0644 \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f: import relationalStore from &#8216;@ohos.data.relationalStore&#8217;; 2. \u0627\u0637\u0644\u0627\u0639\u0627\u062a \u067e\u0627\u06cc\u06af\u0627\u0647 \u062f\u0627\u062f\u0647 \u0631\u0627 \u067e\u06cc\u06a9\u0631\u0628\u0646\u062f\u06cc \u06a9\u0646\u06cc\u062f: const STORE_CONFIG :relationalStore.StoreConfig= { name: &#8216;RdbTest.db&#8217;, \/\/ \u6570\u636e\u5e93\u6587\u4ef6\u540d securityLevel: relationalStore.SecurityLevel.S1, \/\/ \u6570\u636e\u5e93\u5b89\u5168\u7ea7\u522b encrypt: false, &hellip;<\/p>\n","protected":false},"author":2,"featured_media":102808,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-102807","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/102807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=102807"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/102807\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/102808"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=102807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=102807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=102807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}