{"id":43023,"date":"2024-12-01T10:42:48","date_gmt":"2024-12-01T02:42:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/43023\/"},"modified":"2024-12-01T10:42:48","modified_gmt":"2024-12-01T02:42:48","slug":"%e5%b0%86%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a1%8c%e8%af%bb%e5%85%a5%e6%98%a0%e5%b0%84%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/43023\/","title":{"rendered":"\u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span>  <span>&gt;<\/span> <span>\u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32<\/span><\/p>\n<h1>\u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32<\/h1>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-28 15:45:32<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u60f3\u4ece\u4e00\u4e2a\u7b80\u5355\u7684 sql \u8868\u4e2d\u8bfb\u53d6\u7ed3\u679c\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<table>\n<thead>\n<tr>\n<th>customer<\/th>\n<th>key<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>A<\/td>\n<td>12345<\/td>\n<\/tr>\n<tr>\n<td>B<\/td>\n<td>6789<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u73b0\u5728\uff0c\u6211\u60f3\u6784\u9020\u4e00\u4e2a <code>map[string]string<\/code> \uff0c\u5b83\u7684\u952e\u503c\u5bf9\u7b49\u4e8e\u884c\u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>map[a:12345, b:6789]<\/pre>\n<p>\u4f46\u662f\uff0c\u6211\u5728\u4ece\u67e5\u8be2\u7ed3\u679c\u4e2d\u53d6\u51fa\u503c\u5e76\u52a8\u6001\u521b\u5efa\u952e\u503c\u5bf9\u65f6\u9047\u5230\u4e86\u9ebb\u70e6\u3002\u6211\u5c06\u63d0\u4f9b\u4ee3\u7801\u7684\u7c97\u7565\u8f6e\u5ed3\uff08sql \u8fde\u63a5\u4e0d\u662f\u95ee\u9898\uff0c\u6211\u5df2\u7ecf\u5f04\u6e05\u695a\u4e86\uff09<\/p>\n<pre>import \"database\/sql\"\n\nfunc main() {\n\n    \/\/ some code to connect to mssql...\n\n    db, _ := sql.open(\"mssql\", connstring)\n\n    stmt := \"select customer, key from tbl\"\n    rows, _ := db.query(stmt)\n    defer rows.close()\n\n    data := make(map[string]string)\n    for rows.next() {\n        \/\/ need help here grabbing each row pair and adding them to my map...\n    }\n}<\/pre>\n<p>\u6211\u4e5f\u613f\u610f\u5c1d\u8bd5\u4f7f\u7528\u7a7a\u7ed3\u6784\u6765\u6267\u884c\u6b64\u64cd\u4f5c\uff0c\u5176\u4e2d\u5b57\u6bb5\u6210\u4e3a\u7ed3\u679c\u96c6\u7684\u7b2c\u4e00\u5217\uff08\u52a8\u6001\uff09\uff0c\u503c\u6210\u4e3a\u7ed3\u679c\u96c6\u7684\u7b2c\u4e8c\u5217\u3002<\/p>\n<p> <\/p>\n<h2>\u6b63\u786e\u7b54\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u53ef\u4ee5\u5c06\u503c\u4e34\u65f6\u5b58\u50a8\u5728\u4e24\u4e2a\u53d8\u91cf\u4e2d\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u5b58\u50a8\u5728\u5730\u56fe\u4e2d\uff1a<\/p>\n<pre>func main() {\n    stmt := \"SELECT customer, key from tbl\"\n    rows, _ := db.Query(stmt)\n    defer rows.Close()\n\n    data := make(map[string]string)\n    var (\n        consumer string\n        key string\n    )\n    for rows.Next() {\n        if err := rows.Scan(&amp;consumer, &amp;key); err != nil {\n            \/\/ Handle err\n        }\n\n        data[consumer] = key \n    }\n\n    for k, v := range data {\n        fmt.Println(k, v)\n    }\n    \/\/ \"A\" \"12345\"\n    \/\/ \"B\" \"6789\"\n\n}\n<\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c<code>consumer<\/code> \u548c <code>key<\/code> \u53d8\u91cf\u662f\u5728\u5faa\u73af\u5916\u90e8\u5206\u914d\u7684\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b83\u4eec\u3002\u5373\u4f7f\u503c\u662f\u7a7a\u5b57\u7b26\u4e32\uff0c\u53d8\u91cf\u4e5f\u4f1a\u5728\u6bcf\u6b21\u8fed\u4ee3\u65f6\u88ab\u8986\u76d6\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &gt; &gt; \u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32 \u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32 \u6765\u6e90\uff1astackoverflow 2024-04-28 15:45:32 0\u6d4f\u89c8 \u6536\u85cf \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300a\u5c06\u6570\u636e\u5e93\u884c\u8bfb\u5165\u6620\u5c04\u5b57\u7b26\u4e32\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 \u95ee\u9898\u5185\u5bb9 \u6211\u60f3\u4ece\u4e00\u4e2a\u7b80\u5355\u7684 sql \u8868\u4e2d\u8bfb\u53d6\u7ed3\u679c\uff0c\u5982\u4e0b\u6240\u793a customer key A 12345 B 6789 \u73b0\u5728\uff0c\u6211\u60f3\u6784\u9020\u4e00\u4e2a map[string]string \uff0c\u5b83\u7684\u952e\u503c\u5bf9\u7b49\u4e8e\u884c\u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a map[a:12345, b:6789] \u4f46\u662f\uff0c\u6211\u5728\u4ece\u67e5\u8be2\u7ed3\u679c\u4e2d\u53d6\u51fa\u503c\u5e76\u52a8\u6001\u521b\u5efa\u952e\u503c\u5bf9\u65f6\u9047\u5230\u4e86\u9ebb\u70e6\u3002\u6211\u5c06\u63d0\u4f9b\u4ee3\u7801\u7684\u7c97\u7565\u8f6e\u5ed3\uff08sql \u8fde\u63a5\u4e0d\u662f\u95ee\u9898\uff0c\u6211\u5df2\u7ecf\u5f04\u6e05\u695a\u4e86\uff09 import &#8220;database\/sql&#8221; func main() { \/\/ some code to connect to mssql&#8230; db, _ := sql.open(&#8220;mssql&#8221;, connstring) stmt := &#8220;select customer, key from tbl&#8221; rows, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-43023","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=43023"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/43023\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=43023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=43023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=43023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}